summaryrefslogtreecommitdiff
path: root/thirdparty
diff options
context:
space:
mode:
Diffstat (limited to 'thirdparty')
-rw-r--r--thirdparty/README.md50
-rw-r--r--thirdparty/assimp/assimp/config.h16
-rw-r--r--thirdparty/assimp/code/CApi/AssimpCExport.cpp156
-rw-r--r--thirdparty/assimp/code/CApi/CInterfaceIOWrapper.cpp (renamed from thirdparty/assimp/code/CInterfaceIOWrapper.cpp)0
-rw-r--r--thirdparty/assimp/code/CApi/CInterfaceIOWrapper.h (renamed from thirdparty/assimp/code/CInterfaceIOWrapper.h)0
-rw-r--r--thirdparty/assimp/code/Common/Assimp.cpp695
-rw-r--r--thirdparty/assimp/code/Common/BaseImporter.cpp (renamed from thirdparty/assimp/code/BaseImporter.cpp)6
-rw-r--r--thirdparty/assimp/code/Common/BaseProcess.cpp (renamed from thirdparty/assimp/code/BaseProcess.cpp)2
-rw-r--r--thirdparty/assimp/code/Common/BaseProcess.h (renamed from thirdparty/assimp/code/BaseProcess.h)0
-rw-r--r--thirdparty/assimp/code/Common/Bitmap.cpp (renamed from thirdparty/assimp/code/Bitmap.cpp)0
-rw-r--r--thirdparty/assimp/code/Common/CreateAnimMesh.cpp (renamed from thirdparty/assimp/code/CreateAnimMesh.cpp)4
-rw-r--r--thirdparty/assimp/code/Common/DefaultIOStream.cpp (renamed from thirdparty/assimp/code/DefaultIOStream.cpp)0
-rw-r--r--thirdparty/assimp/code/Common/DefaultIOSystem.cpp (renamed from thirdparty/assimp/code/DefaultIOSystem.cpp)0
-rw-r--r--thirdparty/assimp/code/Common/DefaultLogger.cpp (renamed from thirdparty/assimp/code/DefaultLogger.cpp)0
-rw-r--r--thirdparty/assimp/code/Common/DefaultProgressHandler.h (renamed from thirdparty/assimp/code/DefaultProgressHandler.h)0
-rw-r--r--thirdparty/assimp/code/Common/Exporter.cpp (renamed from thirdparty/assimp/code/Exporter.cpp)32
-rw-r--r--thirdparty/assimp/code/Common/FileLogStream.h (renamed from thirdparty/assimp/code/FileLogStream.h)0
-rw-r--r--thirdparty/assimp/code/Common/FileSystemFilter.h (renamed from thirdparty/assimp/code/FileSystemFilter.h)0
-rw-r--r--thirdparty/assimp/code/Common/IFF.h102
-rw-r--r--thirdparty/assimp/code/Common/Importer.cpp (renamed from thirdparty/assimp/code/Importer.cpp)19
-rw-r--r--thirdparty/assimp/code/Common/Importer.h (renamed from thirdparty/assimp/code/Importer.h)0
-rw-r--r--thirdparty/assimp/code/Common/ImporterRegistry.cpp (renamed from thirdparty/assimp/code/ImporterRegistry.cpp)96
-rw-r--r--thirdparty/assimp/code/Common/PolyTools.h (renamed from thirdparty/assimp/code/PolyTools.h)0
-rw-r--r--thirdparty/assimp/code/Common/PostStepRegistry.cpp (renamed from thirdparty/assimp/code/PostStepRegistry.cpp)63
-rw-r--r--thirdparty/assimp/code/Common/RemoveComments.cpp (renamed from thirdparty/assimp/code/RemoveComments.cpp)0
-rw-r--r--thirdparty/assimp/code/Common/SGSpatialSort.cpp (renamed from thirdparty/assimp/code/SGSpatialSort.cpp)0
-rw-r--r--thirdparty/assimp/code/Common/SceneCombiner.cpp (renamed from thirdparty/assimp/code/SceneCombiner.cpp)0
-rw-r--r--thirdparty/assimp/code/Common/ScenePreprocessor.cpp (renamed from thirdparty/assimp/code/ScenePreprocessor.cpp)0
-rw-r--r--thirdparty/assimp/code/Common/ScenePreprocessor.h (renamed from thirdparty/assimp/code/ScenePreprocessor.h)0
-rw-r--r--thirdparty/assimp/code/Common/ScenePrivate.h (renamed from thirdparty/assimp/code/ScenePrivate.h)0
-rw-r--r--thirdparty/assimp/code/Common/SkeletonMeshBuilder.cpp (renamed from thirdparty/assimp/code/SkeletonMeshBuilder.cpp)0
-rw-r--r--thirdparty/assimp/code/Common/SpatialSort.cpp (renamed from thirdparty/assimp/code/SpatialSort.cpp)0
-rw-r--r--thirdparty/assimp/code/Common/SplitByBoneCountProcess.cpp (renamed from thirdparty/assimp/code/SplitByBoneCountProcess.cpp)0
-rw-r--r--thirdparty/assimp/code/Common/SplitByBoneCountProcess.h (renamed from thirdparty/assimp/code/SplitByBoneCountProcess.h)0
-rw-r--r--thirdparty/assimp/code/Common/StandardShapes.cpp (renamed from thirdparty/assimp/code/StandardShapes.cpp)0
-rw-r--r--thirdparty/assimp/code/Common/StdOStreamLogStream.h (renamed from thirdparty/assimp/code/StdOStreamLogStream.h)0
-rw-r--r--thirdparty/assimp/code/Common/Subdivision.cpp (renamed from thirdparty/assimp/code/Subdivision.cpp)7
-rw-r--r--thirdparty/assimp/code/Common/TargetAnimation.cpp (renamed from thirdparty/assimp/code/TargetAnimation.cpp)0
-rw-r--r--thirdparty/assimp/code/Common/TargetAnimation.h (renamed from thirdparty/assimp/code/TargetAnimation.h)0
-rw-r--r--thirdparty/assimp/code/Common/Version.cpp (renamed from thirdparty/assimp/code/Version.cpp)2
-rw-r--r--thirdparty/assimp/code/Common/VertexTriangleAdjacency.cpp (renamed from thirdparty/assimp/code/VertexTriangleAdjacency.cpp)0
-rw-r--r--thirdparty/assimp/code/Common/VertexTriangleAdjacency.h (renamed from thirdparty/assimp/code/VertexTriangleAdjacency.h)0
-rw-r--r--thirdparty/assimp/code/Common/Win32DebugLogStream.h (renamed from thirdparty/assimp/code/Win32DebugLogStream.h)0
-rw-r--r--thirdparty/assimp/code/Common/assbin_chunks.h196
-rw-r--r--thirdparty/assimp/code/Common/scene.cpp (renamed from thirdparty/assimp/code/scene.cpp)0
-rw-r--r--thirdparty/assimp/code/Common/simd.cpp (renamed from thirdparty/assimp/code/simd.cpp)0
-rw-r--r--thirdparty/assimp/code/Common/simd.h (renamed from thirdparty/assimp/code/simd.h)0
-rw-r--r--thirdparty/assimp/code/FBX/FBXAnimation.cpp (renamed from thirdparty/assimp/code/FBXAnimation.cpp)0
-rw-r--r--thirdparty/assimp/code/FBX/FBXBinaryTokenizer.cpp (renamed from thirdparty/assimp/code/FBXBinaryTokenizer.cpp)12
-rw-r--r--thirdparty/assimp/code/FBX/FBXCommon.h (renamed from thirdparty/assimp/code/FBXCommon.h)4
-rw-r--r--thirdparty/assimp/code/FBX/FBXCompileConfig.h (renamed from thirdparty/assimp/code/FBXCompileConfig.h)0
-rw-r--r--thirdparty/assimp/code/FBX/FBXConverter.cpp (renamed from thirdparty/assimp/code/FBXConverter.cpp)268
-rw-r--r--thirdparty/assimp/code/FBX/FBXConverter.h (renamed from thirdparty/assimp/code/FBXConverter.h)37
-rw-r--r--thirdparty/assimp/code/FBX/FBXDeformer.cpp (renamed from thirdparty/assimp/code/FBXDeformer.cpp)0
-rw-r--r--thirdparty/assimp/code/FBX/FBXDocument.cpp (renamed from thirdparty/assimp/code/FBXDocument.cpp)0
-rw-r--r--thirdparty/assimp/code/FBX/FBXDocument.h (renamed from thirdparty/assimp/code/FBXDocument.h)4
-rw-r--r--thirdparty/assimp/code/FBX/FBXDocumentUtil.cpp (renamed from thirdparty/assimp/code/FBXDocumentUtil.cpp)0
-rw-r--r--thirdparty/assimp/code/FBX/FBXDocumentUtil.h (renamed from thirdparty/assimp/code/FBXDocumentUtil.h)0
-rw-r--r--thirdparty/assimp/code/FBX/FBXExportNode.cpp (renamed from thirdparty/assimp/code/FBXExportNode.cpp)11
-rw-r--r--thirdparty/assimp/code/FBX/FBXExportNode.h (renamed from thirdparty/assimp/code/FBXExportNode.h)12
-rw-r--r--thirdparty/assimp/code/FBX/FBXExportProperty.cpp (renamed from thirdparty/assimp/code/FBXExportProperty.cpp)257
-rw-r--r--thirdparty/assimp/code/FBX/FBXExportProperty.h (renamed from thirdparty/assimp/code/FBXExportProperty.h)48
-rw-r--r--thirdparty/assimp/code/FBX/FBXExporter.cpp (renamed from thirdparty/assimp/code/FBXExporter.cpp)115
-rw-r--r--thirdparty/assimp/code/FBX/FBXExporter.h (renamed from thirdparty/assimp/code/FBXExporter.h)0
-rw-r--r--thirdparty/assimp/code/FBX/FBXImportSettings.h (renamed from thirdparty/assimp/code/FBXImportSettings.h)39
-rw-r--r--thirdparty/assimp/code/FBX/FBXImporter.cpp (renamed from thirdparty/assimp/code/FBXImporter.cpp)10
-rw-r--r--thirdparty/assimp/code/FBX/FBXImporter.h (renamed from thirdparty/assimp/code/FBXImporter.h)0
-rw-r--r--thirdparty/assimp/code/FBX/FBXMaterial.cpp (renamed from thirdparty/assimp/code/FBXMaterial.cpp)44
-rw-r--r--thirdparty/assimp/code/FBX/FBXMeshGeometry.cpp (renamed from thirdparty/assimp/code/FBXMeshGeometry.cpp)11
-rw-r--r--thirdparty/assimp/code/FBX/FBXMeshGeometry.h (renamed from thirdparty/assimp/code/FBXMeshGeometry.h)0
-rw-r--r--thirdparty/assimp/code/FBX/FBXModel.cpp (renamed from thirdparty/assimp/code/FBXModel.cpp)0
-rw-r--r--thirdparty/assimp/code/FBX/FBXNodeAttribute.cpp (renamed from thirdparty/assimp/code/FBXNodeAttribute.cpp)0
-rw-r--r--thirdparty/assimp/code/FBX/FBXParser.cpp (renamed from thirdparty/assimp/code/FBXParser.cpp)12
-rw-r--r--thirdparty/assimp/code/FBX/FBXParser.h (renamed from thirdparty/assimp/code/FBXParser.h)0
-rw-r--r--thirdparty/assimp/code/FBX/FBXProperties.cpp (renamed from thirdparty/assimp/code/FBXProperties.cpp)0
-rw-r--r--thirdparty/assimp/code/FBX/FBXProperties.h (renamed from thirdparty/assimp/code/FBXProperties.h)0
-rw-r--r--thirdparty/assimp/code/FBX/FBXTokenizer.cpp (renamed from thirdparty/assimp/code/FBXTokenizer.cpp)0
-rw-r--r--thirdparty/assimp/code/FBX/FBXTokenizer.h (renamed from thirdparty/assimp/code/FBXTokenizer.h)12
-rw-r--r--thirdparty/assimp/code/FBX/FBXUtil.cpp (renamed from thirdparty/assimp/code/FBXUtil.cpp)135
-rw-r--r--thirdparty/assimp/code/FBX/FBXUtil.h (renamed from thirdparty/assimp/code/FBXUtil.h)23
-rw-r--r--thirdparty/assimp/code/FIReader.cpp1834
-rw-r--r--thirdparty/assimp/code/MMD/MMDCpp14.h (renamed from thirdparty/assimp/code/MMDCpp14.h)0
-rw-r--r--thirdparty/assimp/code/MMD/MMDImporter.cpp (renamed from thirdparty/assimp/code/MMDImporter.cpp)12
-rw-r--r--thirdparty/assimp/code/MMD/MMDImporter.h (renamed from thirdparty/assimp/code/MMDImporter.h)0
-rw-r--r--thirdparty/assimp/code/MMD/MMDPmdParser.h (renamed from thirdparty/assimp/code/MMDPmdParser.h)0
-rw-r--r--thirdparty/assimp/code/MMD/MMDPmxParser.cpp (renamed from thirdparty/assimp/code/MMDPmxParser.cpp)6
-rw-r--r--thirdparty/assimp/code/MMD/MMDPmxParser.h (renamed from thirdparty/assimp/code/MMDPmxParser.h)0
-rw-r--r--thirdparty/assimp/code/MMD/MMDVmdParser.h (renamed from thirdparty/assimp/code/MMDVmdParser.h)0
-rw-r--r--thirdparty/assimp/code/Material/MaterialSystem.cpp (renamed from thirdparty/assimp/code/MaterialSystem.cpp)12
-rw-r--r--thirdparty/assimp/code/Material/MaterialSystem.h (renamed from thirdparty/assimp/code/MaterialSystem.h)0
-rw-r--r--thirdparty/assimp/code/PostProcessing/CalcTangentsProcess.cpp (renamed from thirdparty/assimp/code/CalcTangentsProcess.cpp)0
-rw-r--r--thirdparty/assimp/code/PostProcessing/CalcTangentsProcess.h (renamed from thirdparty/assimp/code/CalcTangentsProcess.h)4
-rw-r--r--thirdparty/assimp/code/PostProcessing/ComputeUVMappingProcess.cpp (renamed from thirdparty/assimp/code/ComputeUVMappingProcess.cpp)0
-rw-r--r--thirdparty/assimp/code/PostProcessing/ComputeUVMappingProcess.h (renamed from thirdparty/assimp/code/ComputeUVMappingProcess.h)3
-rw-r--r--thirdparty/assimp/code/PostProcessing/ConvertToLHProcess.cpp (renamed from thirdparty/assimp/code/ConvertToLHProcess.cpp)0
-rw-r--r--thirdparty/assimp/code/PostProcessing/ConvertToLHProcess.h (renamed from thirdparty/assimp/code/ConvertToLHProcess.h)3
-rw-r--r--thirdparty/assimp/code/PostProcessing/DeboneProcess.cpp (renamed from thirdparty/assimp/code/DeboneProcess.cpp)0
-rw-r--r--thirdparty/assimp/code/PostProcessing/DeboneProcess.h (renamed from thirdparty/assimp/code/DeboneProcess.h)17
-rw-r--r--thirdparty/assimp/code/PostProcessing/DropFaceNormalsProcess.cpp (renamed from thirdparty/assimp/code/DropFaceNormalsProcess.cpp)0
-rw-r--r--thirdparty/assimp/code/PostProcessing/DropFaceNormalsProcess.h (renamed from thirdparty/assimp/code/DropFaceNormalsProcess.h)11
-rw-r--r--thirdparty/assimp/code/PostProcessing/EmbedTexturesProcess.cpp (renamed from thirdparty/assimp/code/EmbedTexturesProcess.cpp)0
-rw-r--r--thirdparty/assimp/code/PostProcessing/EmbedTexturesProcess.h (renamed from thirdparty/assimp/code/EmbedTexturesProcess.h)2
-rw-r--r--thirdparty/assimp/code/PostProcessing/FindDegenerates.cpp (renamed from thirdparty/assimp/code/FindDegenerates.cpp)1
-rw-r--r--thirdparty/assimp/code/PostProcessing/FindDegenerates.h (renamed from thirdparty/assimp/code/FindDegenerates.h)3
-rw-r--r--thirdparty/assimp/code/PostProcessing/FindInstancesProcess.cpp (renamed from thirdparty/assimp/code/FindInstancesProcess.cpp)12
-rw-r--r--thirdparty/assimp/code/PostProcessing/FindInstancesProcess.h (renamed from thirdparty/assimp/code/FindInstancesProcess.h)4
-rw-r--r--thirdparty/assimp/code/PostProcessing/FindInvalidDataProcess.cpp (renamed from thirdparty/assimp/code/FindInvalidDataProcess.cpp)0
-rw-r--r--thirdparty/assimp/code/PostProcessing/FindInvalidDataProcess.h (renamed from thirdparty/assimp/code/FindInvalidDataProcess.h)3
-rw-r--r--thirdparty/assimp/code/PostProcessing/FixNormalsStep.cpp (renamed from thirdparty/assimp/code/FixNormalsStep.cpp)0
-rw-r--r--thirdparty/assimp/code/PostProcessing/FixNormalsStep.h (renamed from thirdparty/assimp/code/FixNormalsStep.h)2
-rw-r--r--thirdparty/assimp/code/PostProcessing/GenBoundingBoxesProcess.cpp115
-rw-r--r--thirdparty/assimp/code/PostProcessing/GenBoundingBoxesProcess.h76
-rw-r--r--thirdparty/assimp/code/PostProcessing/GenFaceNormalsProcess.cpp (renamed from thirdparty/assimp/code/GenFaceNormalsProcess.cpp)0
-rw-r--r--thirdparty/assimp/code/PostProcessing/GenFaceNormalsProcess.h (renamed from thirdparty/assimp/code/GenFaceNormalsProcess.h)2
-rw-r--r--thirdparty/assimp/code/PostProcessing/GenVertexNormalsProcess.cpp (renamed from thirdparty/assimp/code/GenVertexNormalsProcess.cpp)0
-rw-r--r--thirdparty/assimp/code/PostProcessing/GenVertexNormalsProcess.h (renamed from thirdparty/assimp/code/GenVertexNormalsProcess.h)18
-rw-r--r--thirdparty/assimp/code/PostProcessing/ImproveCacheLocality.cpp (renamed from thirdparty/assimp/code/ImproveCacheLocality.cpp)65
-rw-r--r--thirdparty/assimp/code/PostProcessing/ImproveCacheLocality.h (renamed from thirdparty/assimp/code/ImproveCacheLocality.h)7
-rw-r--r--thirdparty/assimp/code/PostProcessing/JoinVerticesProcess.cpp (renamed from thirdparty/assimp/code/JoinVerticesProcess.cpp)0
-rw-r--r--thirdparty/assimp/code/PostProcessing/JoinVerticesProcess.h (renamed from thirdparty/assimp/code/JoinVerticesProcess.h)10
-rw-r--r--thirdparty/assimp/code/PostProcessing/LimitBoneWeightsProcess.cpp (renamed from thirdparty/assimp/code/LimitBoneWeightsProcess.cpp)0
-rw-r--r--thirdparty/assimp/code/PostProcessing/LimitBoneWeightsProcess.h (renamed from thirdparty/assimp/code/LimitBoneWeightsProcess.h)34
-rw-r--r--thirdparty/assimp/code/PostProcessing/MakeVerboseFormat.cpp (renamed from thirdparty/assimp/code/MakeVerboseFormat.cpp)0
-rw-r--r--thirdparty/assimp/code/PostProcessing/MakeVerboseFormat.h (renamed from thirdparty/assimp/code/MakeVerboseFormat.h)3
-rw-r--r--thirdparty/assimp/code/PostProcessing/OptimizeGraph.cpp (renamed from thirdparty/assimp/code/OptimizeGraph.cpp)2
-rw-r--r--thirdparty/assimp/code/PostProcessing/OptimizeGraph.h (renamed from thirdparty/assimp/code/OptimizeGraph.h)27
-rw-r--r--thirdparty/assimp/code/PostProcessing/OptimizeMeshes.cpp (renamed from thirdparty/assimp/code/OptimizeMeshes.cpp)0
-rw-r--r--thirdparty/assimp/code/PostProcessing/OptimizeMeshes.h (renamed from thirdparty/assimp/code/OptimizeMeshes.h)10
-rw-r--r--thirdparty/assimp/code/PostProcessing/PretransformVertices.cpp (renamed from thirdparty/assimp/code/PretransformVertices.cpp)0
-rw-r--r--thirdparty/assimp/code/PostProcessing/PretransformVertices.h (renamed from thirdparty/assimp/code/PretransformVertices.h)15
-rw-r--r--thirdparty/assimp/code/PostProcessing/ProcessHelper.cpp (renamed from thirdparty/assimp/code/ProcessHelper.cpp)0
-rw-r--r--thirdparty/assimp/code/PostProcessing/ProcessHelper.h (renamed from thirdparty/assimp/code/ProcessHelper.h)2
-rw-r--r--thirdparty/assimp/code/PostProcessing/RemoveRedundantMaterials.cpp (renamed from thirdparty/assimp/code/RemoveRedundantMaterials.cpp)10
-rw-r--r--thirdparty/assimp/code/PostProcessing/RemoveRedundantMaterials.h (renamed from thirdparty/assimp/code/RemoveRedundantMaterials.h)18
-rw-r--r--thirdparty/assimp/code/PostProcessing/RemoveVCProcess.cpp (renamed from thirdparty/assimp/code/RemoveVCProcess.cpp)0
-rw-r--r--thirdparty/assimp/code/PostProcessing/RemoveVCProcess.h (renamed from thirdparty/assimp/code/RemoveVCProcess.h)3
-rw-r--r--thirdparty/assimp/code/PostProcessing/ScaleProcess.cpp (renamed from thirdparty/assimp/code/ScaleProcess.cpp)0
-rw-r--r--thirdparty/assimp/code/PostProcessing/ScaleProcess.h (renamed from thirdparty/assimp/code/ScaleProcess.h)2
-rw-r--r--thirdparty/assimp/code/PostProcessing/SortByPTypeProcess.cpp (renamed from thirdparty/assimp/code/SortByPTypeProcess.cpp)18
-rw-r--r--thirdparty/assimp/code/PostProcessing/SortByPTypeProcess.h (renamed from thirdparty/assimp/code/SortByPTypeProcess.h)11
-rw-r--r--thirdparty/assimp/code/PostProcessing/SplitLargeMeshes.cpp (renamed from thirdparty/assimp/code/SplitLargeMeshes.cpp)0
-rw-r--r--thirdparty/assimp/code/PostProcessing/SplitLargeMeshes.h (renamed from thirdparty/assimp/code/SplitLargeMeshes.h)9
-rw-r--r--thirdparty/assimp/code/PostProcessing/TextureTransform.cpp (renamed from thirdparty/assimp/code/TextureTransform.cpp)0
-rw-r--r--thirdparty/assimp/code/PostProcessing/TextureTransform.h (renamed from thirdparty/assimp/code/TextureTransform.h)2
-rw-r--r--thirdparty/assimp/code/PostProcessing/TriangulateProcess.cpp (renamed from thirdparty/assimp/code/TriangulateProcess.cpp)10
-rw-r--r--thirdparty/assimp/code/PostProcessing/TriangulateProcess.h (renamed from thirdparty/assimp/code/TriangulateProcess.h)8
-rw-r--r--thirdparty/assimp/code/PostProcessing/ValidateDataStructure.cpp (renamed from thirdparty/assimp/code/ValidateDataStructure.cpp)33
-rw-r--r--thirdparty/assimp/code/PostProcessing/ValidateDataStructure.h (renamed from thirdparty/assimp/code/ValidateDataStructure.h)3
-rw-r--r--thirdparty/assimp/code/RawLoader.cpp331
-rw-r--r--thirdparty/assimp/include/assimp/Exporter.hpp2
-rw-r--r--thirdparty/assimp/include/assimp/ParsingUtils.h3
-rw-r--r--thirdparty/assimp/include/assimp/aabb.h76
-rw-r--r--thirdparty/assimp/include/assimp/camera.h5
-rw-r--r--thirdparty/assimp/include/assimp/color4.inl4
-rw-r--r--thirdparty/assimp/include/assimp/config.h.in35
-rw-r--r--thirdparty/assimp/include/assimp/defs.h21
-rw-r--r--thirdparty/assimp/include/assimp/mesh.h11
-rw-r--r--thirdparty/assimp/include/assimp/postprocess.h13
-rw-r--r--thirdparty/assimp/include/assimp/scene.h9
-rw-r--r--thirdparty/freetype/include/freetype/freetype.h15
-rw-r--r--thirdparty/freetype/include/freetype/fterrors.h4
-rw-r--r--thirdparty/freetype/include/freetype/ftglyph.h2
-rw-r--r--thirdparty/freetype/include/freetype/ftimage.h16
-rw-r--r--thirdparty/freetype/include/freetype/ftmodapi.h2
-rw-r--r--thirdparty/freetype/include/freetype/ftoutln.h8
-rw-r--r--thirdparty/freetype/include/freetype/ftwinfnt.h2
-rw-r--r--thirdparty/freetype/include/freetype/internal/ftcalc.h2
-rw-r--r--thirdparty/freetype/include/freetype/internal/ftobjs.h6
-rw-r--r--thirdparty/freetype/include/freetype/internal/ftstream.h11
-rw-r--r--thirdparty/freetype/include/freetype/internal/fttrace.h1
-rw-r--r--thirdparty/freetype/include/freetype/internal/internal.h1
-rw-r--r--thirdparty/freetype/include/freetype/internal/psaux.h8
-rw-r--r--thirdparty/freetype/include/freetype/internal/services/svgldict.h4
-rw-r--r--thirdparty/freetype/include/freetype/internal/sfnt.h1
-rw-r--r--thirdparty/freetype/include/freetype/internal/t1types.h4
-rw-r--r--thirdparty/freetype/include/freetype/internal/tttypes.h83
-rw-r--r--thirdparty/freetype/include/freetype/internal/wofftypes.h112
-rw-r--r--thirdparty/freetype/src/autofit/afblue.c7
-rw-r--r--thirdparty/freetype/src/autofit/afblue.dat10
-rw-r--r--thirdparty/freetype/src/autofit/afblue.h139
-rw-r--r--thirdparty/freetype/src/autofit/afcjk.c5
-rw-r--r--thirdparty/freetype/src/autofit/afglobal.c11
-rw-r--r--thirdparty/freetype/src/autofit/aflatin.c58
-rw-r--r--thirdparty/freetype/src/autofit/afranges.c15
-rw-r--r--thirdparty/freetype/src/autofit/afscript.h6
-rw-r--r--thirdparty/freetype/src/autofit/afstyles.h7
-rw-r--r--thirdparty/freetype/src/base/ftbbox.c12
-rw-r--r--thirdparty/freetype/src/base/ftbitmap.c15
-rw-r--r--thirdparty/freetype/src/base/fterrors.c1
-rw-r--r--thirdparty/freetype/src/base/ftinit.c3
-rw-r--r--thirdparty/freetype/src/base/ftlcdfil.c12
-rw-r--r--thirdparty/freetype/src/base/ftobjs.c4
-rw-r--r--thirdparty/freetype/src/base/ftoutln.c13
-rw-r--r--thirdparty/freetype/src/base/ftstroke.c56
-rw-r--r--thirdparty/freetype/src/base/ftver.rc4
-rw-r--r--thirdparty/freetype/src/bdf/bdf.h6
-rw-r--r--thirdparty/freetype/src/bdf/bdfdrivr.c30
-rw-r--r--thirdparty/freetype/src/bdf/bdflib.c219
-rw-r--r--thirdparty/freetype/src/cache/rules.mk2
-rw-r--r--thirdparty/freetype/src/cff/cffdrivr.c4
-rw-r--r--thirdparty/freetype/src/cff/cffobjs.c2
-rw-r--r--thirdparty/freetype/src/cff/cffparse.c155
-rw-r--r--thirdparty/freetype/src/cff/cffparse.h13
-rw-r--r--thirdparty/freetype/src/gzip/ftgzip.c2
-rw-r--r--thirdparty/freetype/src/gzip/infblock.c5
-rw-r--r--thirdparty/freetype/src/gzip/infcodes.c4
-rw-r--r--thirdparty/freetype/src/gzip/inflate.c10
-rw-r--r--thirdparty/freetype/src/pcf/pcf.h3
-rw-r--r--thirdparty/freetype/src/pcf/pcfdrivr.c12
-rw-r--r--thirdparty/freetype/src/pcf/pcfread.c180
-rw-r--r--thirdparty/freetype/src/pfr/pfrobjs.c2
-rw-r--r--thirdparty/freetype/src/psaux/afmparse.c3
-rw-r--r--thirdparty/freetype/src/psaux/psfixed.h3
-rw-r--r--thirdparty/freetype/src/psaux/psfont.c6
-rw-r--r--thirdparty/freetype/src/psaux/psobjs.c8
-rw-r--r--thirdparty/freetype/src/psaux/psobjs.h8
-rw-r--r--thirdparty/freetype/src/raster/ftraster.c72
-rw-r--r--thirdparty/freetype/src/sfnt/rules.mk1
-rw-r--r--thirdparty/freetype/src/sfnt/sfdriver.c18
-rw-r--r--thirdparty/freetype/src/sfnt/sfnt.c1
-rw-r--r--thirdparty/freetype/src/sfnt/sfobjs.c399
-rw-r--r--thirdparty/freetype/src/sfnt/sfobjs.h2
-rw-r--r--thirdparty/freetype/src/sfnt/sfwoff.c434
-rw-r--r--thirdparty/freetype/src/sfnt/sfwoff.h41
-rw-r--r--thirdparty/freetype/src/sfnt/ttcmap.c5
-rw-r--r--thirdparty/freetype/src/sfnt/ttmtx.c6
-rw-r--r--thirdparty/freetype/src/smooth/ftgrays.c299
-rw-r--r--thirdparty/freetype/src/smooth/ftsmooth.c2
-rw-r--r--thirdparty/freetype/src/truetype/ttgload.c123
-rw-r--r--thirdparty/freetype/src/truetype/ttgxvar.c94
-rw-r--r--thirdparty/freetype/src/truetype/ttgxvar.h1
-rw-r--r--thirdparty/freetype/src/truetype/ttinterp.c391
-rw-r--r--thirdparty/freetype/src/truetype/ttobjs.c45
-rw-r--r--thirdparty/freetype/src/truetype/ttpload.c6
-rw-r--r--thirdparty/freetype/src/type1/t1driver.c4
-rw-r--r--thirdparty/freetype/src/type1/t1load.c31
-rw-r--r--thirdparty/freetype/src/type42/t42drivr.c4
-rw-r--r--thirdparty/freetype/src/type42/t42objs.c21
-rw-r--r--thirdparty/freetype/src/type42/t42parse.c13
-rw-r--r--thirdparty/glad/KHR/khrplatform.h12
-rw-r--r--thirdparty/glad/glad.c2
-rw-r--r--thirdparty/glad/glad/glad.h10
-rw-r--r--thirdparty/jpeg-compressor/jpgd.cpp55
-rw-r--r--thirdparty/mbedtls/include/mbedtls/aes.h4
-rw-r--r--thirdparty/mbedtls/include/mbedtls/aesni.h6
-rw-r--r--thirdparty/mbedtls/include/mbedtls/arc4.h4
-rw-r--r--thirdparty/mbedtls/include/mbedtls/asn1write.h13
-rw-r--r--thirdparty/mbedtls/include/mbedtls/base64.h9
-rw-r--r--thirdparty/mbedtls/include/mbedtls/bignum.h11
-rw-r--r--thirdparty/mbedtls/include/mbedtls/bn_mul.h8
-rw-r--r--thirdparty/mbedtls/include/mbedtls/camellia.h4
-rw-r--r--thirdparty/mbedtls/include/mbedtls/ccm.h6
-rw-r--r--thirdparty/mbedtls/include/mbedtls/certs.h240
-rw-r--r--thirdparty/mbedtls/include/mbedtls/cipher.h2
-rw-r--r--thirdparty/mbedtls/include/mbedtls/cmac.h6
-rw-r--r--thirdparty/mbedtls/include/mbedtls/compat-1.3.h6
-rw-r--r--thirdparty/mbedtls/include/mbedtls/config.h24
-rw-r--r--thirdparty/mbedtls/include/mbedtls/ctr_drbg.h10
-rw-r--r--thirdparty/mbedtls/include/mbedtls/des.h4
-rw-r--r--thirdparty/mbedtls/include/mbedtls/dhm.h3
-rw-r--r--thirdparty/mbedtls/include/mbedtls/ecdh.h6
-rw-r--r--thirdparty/mbedtls/include/mbedtls/ecdsa.h6
-rw-r--r--thirdparty/mbedtls/include/mbedtls/ecjpake.h5
-rw-r--r--thirdparty/mbedtls/include/mbedtls/ecp.h132
-rw-r--r--thirdparty/mbedtls/include/mbedtls/ecp_internal.h6
-rw-r--r--thirdparty/mbedtls/include/mbedtls/error.h6
-rw-r--r--thirdparty/mbedtls/include/mbedtls/gcm.h10
-rw-r--r--thirdparty/mbedtls/include/mbedtls/havege.h6
-rw-r--r--thirdparty/mbedtls/include/mbedtls/hkdf.h6
-rw-r--r--thirdparty/mbedtls/include/mbedtls/hmac_drbg.h6
-rw-r--r--thirdparty/mbedtls/include/mbedtls/md2.h4
-rw-r--r--thirdparty/mbedtls/include/mbedtls/md4.h4
-rw-r--r--thirdparty/mbedtls/include/mbedtls/md5.h4
-rw-r--r--thirdparty/mbedtls/include/mbedtls/net.h5
-rw-r--r--thirdparty/mbedtls/include/mbedtls/nist_kw.h6
-rw-r--r--thirdparty/mbedtls/include/mbedtls/padlock.h8
-rw-r--r--thirdparty/mbedtls/include/mbedtls/pem.h6
-rw-r--r--thirdparty/mbedtls/include/mbedtls/pkcs12.h6
-rw-r--r--thirdparty/mbedtls/include/mbedtls/pkcs5.h10
-rw-r--r--thirdparty/mbedtls/include/mbedtls/platform_util.h4
-rw-r--r--thirdparty/mbedtls/include/mbedtls/poly1305.h2
-rw-r--r--thirdparty/mbedtls/include/mbedtls/ripemd160.h4
-rw-r--r--thirdparty/mbedtls/include/mbedtls/rsa.h4
-rw-r--r--thirdparty/mbedtls/include/mbedtls/sha1.h4
-rw-r--r--thirdparty/mbedtls/include/mbedtls/sha256.h4
-rw-r--r--thirdparty/mbedtls/include/mbedtls/sha512.h5
-rw-r--r--thirdparty/mbedtls/include/mbedtls/ssl.h20
-rw-r--r--thirdparty/mbedtls/include/mbedtls/ssl_cache.h6
-rw-r--r--thirdparty/mbedtls/include/mbedtls/ssl_ciphersuites.h6
-rw-r--r--thirdparty/mbedtls/include/mbedtls/ssl_cookie.h6
-rw-r--r--thirdparty/mbedtls/include/mbedtls/ssl_internal.h6
-rw-r--r--thirdparty/mbedtls/include/mbedtls/ssl_ticket.h6
-rw-r--r--thirdparty/mbedtls/include/mbedtls/version.h8
-rw-r--r--thirdparty/mbedtls/include/mbedtls/x509.h4
-rw-r--r--thirdparty/mbedtls/include/mbedtls/x509_crt.h2
-rw-r--r--thirdparty/mbedtls/include/mbedtls/x509_csr.h8
-rw-r--r--thirdparty/mbedtls/include/mbedtls/xtea.h4
-rw-r--r--thirdparty/mbedtls/library/aes.c98
-rw-r--r--thirdparty/mbedtls/library/asn1write.c28
-rw-r--r--thirdparty/mbedtls/library/bignum.c191
-rw-r--r--thirdparty/mbedtls/library/ccm.c16
-rw-r--r--thirdparty/mbedtls/library/certs.c2040
-rw-r--r--thirdparty/mbedtls/library/chacha20.c10
-rw-r--r--thirdparty/mbedtls/library/debug.c44
-rw-r--r--thirdparty/mbedtls/library/des.c79
-rw-r--r--thirdparty/mbedtls/library/dhm.c16
-rw-r--r--thirdparty/mbedtls/library/ecdh.c27
-rw-r--r--thirdparty/mbedtls/library/ecdsa.c9
-rw-r--r--thirdparty/mbedtls/library/ecp.c20
-rw-r--r--thirdparty/mbedtls/library/ecp_curves.c60
-rw-r--r--thirdparty/mbedtls/library/entropy_poll.c29
-rw-r--r--thirdparty/mbedtls/library/havege.c2
-rw-r--r--thirdparty/mbedtls/library/md4.c30
-rw-r--r--thirdparty/mbedtls/library/md5.c21
-rw-r--r--thirdparty/mbedtls/library/oid.c53
-rw-r--r--thirdparty/mbedtls/library/poly1305.c8
-rw-r--r--thirdparty/mbedtls/library/ripemd160.c39
-rw-r--r--thirdparty/mbedtls/library/sha1.c36
-rw-r--r--thirdparty/mbedtls/library/sha256.c31
-rw-r--r--thirdparty/mbedtls/library/sha512.c21
-rw-r--r--thirdparty/mbedtls/library/ssl_ciphersuites.c57
-rw-r--r--thirdparty/mbedtls/library/version_features.c3
-rw-r--r--thirdparty/mbedtls/library/x509.c62
-rw-r--r--thirdparty/mbedtls/library/x509_crl.c10
-rw-r--r--thirdparty/mbedtls/library/x509_crt.c51
-rw-r--r--thirdparty/mbedtls/library/x509_csr.c15
-rw-r--r--thirdparty/mbedtls/library/x509write_crt.c47
-rw-r--r--thirdparty/mbedtls/library/x509write_csr.c36
-rw-r--r--thirdparty/misc/stb_vorbis.c11
-rw-r--r--thirdparty/pcre2/AUTHORS6
-rw-r--r--thirdparty/pcre2/LICENCE6
-rw-r--r--thirdparty/pcre2/src/config.h15
-rw-r--r--thirdparty/pcre2/src/pcre2.h108
-rw-r--r--thirdparty/pcre2/src/pcre2_auto_possess.c14
-rw-r--r--thirdparty/pcre2/src/pcre2_chartables.c18
-rw-r--r--thirdparty/pcre2/src/pcre2_compile.c678
-rw-r--r--thirdparty/pcre2/src/pcre2_context.c22
-rw-r--r--thirdparty/pcre2/src/pcre2_convert.c2
-rw-r--r--thirdparty/pcre2/src/pcre2_dfa_match.c71
-rw-r--r--thirdparty/pcre2/src/pcre2_error.c19
-rw-r--r--thirdparty/pcre2/src/pcre2_extuni.c4
-rw-r--r--thirdparty/pcre2/src/pcre2_internal.h257
-rw-r--r--thirdparty/pcre2/src/pcre2_intmodedep.h5
-rw-r--r--thirdparty/pcre2/src/pcre2_jit_compile.c2230
-rw-r--r--thirdparty/pcre2/src/pcre2_jit_match.c6
-rw-r--r--thirdparty/pcre2/src/pcre2_maketables.c26
-rw-r--r--thirdparty/pcre2/src/pcre2_match.c88
-rw-r--r--thirdparty/pcre2/src/pcre2_match_data.c8
-rw-r--r--thirdparty/pcre2/src/pcre2_script_run.c441
-rw-r--r--thirdparty/pcre2/src/pcre2_study.c16
-rw-r--r--thirdparty/pcre2/src/pcre2_substitute.c67
-rw-r--r--thirdparty/pcre2/src/pcre2_tables.c71
-rw-r--r--thirdparty/pcre2/src/pcre2_ucd.c7213
-rw-r--r--thirdparty/pcre2/src/pcre2_ucp.h1
-rw-r--r--thirdparty/pcre2/src/pcre2_xclass.c6
-rw-r--r--thirdparty/pcre2/src/sljit/sljitConfigInternal.h2
-rw-r--r--thirdparty/pcre2/src/sljit/sljitExecAllocator.c46
-rw-r--r--thirdparty/pcre2/src/sljit/sljitLir.c11
-rw-r--r--thirdparty/pcre2/src/sljit/sljitNativeARM_64.c20
-rw-r--r--thirdparty/pcre2/src/sljit/sljitNativeMIPS_32.c11
-rw-r--r--thirdparty/pcre2/src/sljit/sljitNativeMIPS_64.c13
-rw-r--r--thirdparty/pcre2/src/sljit/sljitNativeMIPS_common.c164
-rw-r--r--thirdparty/pcre2/src/sljit/sljitNativePPC_common.c2
-rw-r--r--thirdparty/tinyexr/tinyexr.h206
-rw-r--r--thirdparty/xatlas/xatlas.cpp11281
-rw-r--r--thirdparty/xatlas/xatlas.h334
-rw-r--r--thirdparty/zstd/common/compiler.h7
-rw-r--r--thirdparty/zstd/common/zstd_internal.h64
-rw-r--r--thirdparty/zstd/compress/zstd_compress.c292
-rw-r--r--thirdparty/zstd/compress/zstd_compress_internal.h104
-rw-r--r--thirdparty/zstd/compress/zstd_double_fast.c92
-rw-r--r--thirdparty/zstd/compress/zstd_fast.c49
-rw-r--r--thirdparty/zstd/compress/zstd_lazy.c15
-rw-r--r--thirdparty/zstd/compress/zstd_ldm.c2
-rw-r--r--thirdparty/zstd/compress/zstd_opt.c77
-rw-r--r--thirdparty/zstd/compress/zstdmt_compress.c25
-rw-r--r--thirdparty/zstd/compress/zstdmt_compress.h1
-rw-r--r--thirdparty/zstd/decompress/zstd_decompress.c21
-rw-r--r--thirdparty/zstd/decompress/zstd_decompress_block.c29
-rw-r--r--thirdparty/zstd/zstd.h74
380 files changed, 21675 insertions, 15451 deletions
diff --git a/thirdparty/README.md b/thirdparty/README.md
index dbdf9bbf4f..99f917dbc1 100644
--- a/thirdparty/README.md
+++ b/thirdparty/README.md
@@ -4,7 +4,7 @@
## assimp
- Upstream: http://github.com/assimp/assimp
-- Version: git (d3d98a7ec0c8d38e1952b46dfe53f7e9233dc92d)
+- Version: git (1d565b0aab5a2ee00462f18c5b8a81f6a5454a48)
- License: BSD-3-Clause
@@ -122,20 +122,20 @@ Use UI font variant if available, because it has tight vertical metrics and good
## freetype
- Upstream: https://www.freetype.org
-- Version: 2.10.0
+- Version: 2.10.1
- License: FreeType License (BSD-like)
Files extracted from upstream source:
-- the src/ folder, stripped of the `Jamfile` files
-- the include/ folder
+- the `src/` folder, stripped of the `Jamfile` files and the `tools` subfolder
+- the `include/` folder
- `docs/{FTL.TXT,LICENSE.TXT}`
## glad
- Upstream: https://github.com/Dav1dde/glad
-- Version: 0.1.29
+- Version: 0.1.31
- License: MIT
The files we package are automatically generated.
@@ -200,6 +200,7 @@ Important: Some files have Godot-made changes.
They are marked with `// -- GODOT start --` and `// -- GODOT end --`
comments.
+
## libtheora
- Upstream: https://www.theora.org
@@ -262,25 +263,13 @@ changes to ensure they build for Javascript/HTML5. Those
changes are marked with `// -- GODOT --` comments.
-## wslay
-
-- Upstream: https://github.com/tatsuhiro-t/wslay
-- Version: 1.1.0
-- License: MIT
-
-File extracted from upstream releaze tarball:
-
-- All `*.c` and `*.h` in `lib/` and `lib/includes/`
-- `wslay.h` has a small Godot addition to fix MSVC build.
- See `thirdparty/wslay/msvcfix.diff`
-
## mbedtls
- Upstream: https://tls.mbed.org/
-- Version: 2.16.0
+- Version: 2.16.2
- License: Apache 2.0
-File extracted from upstream release tarball `mbedtls-2.16.0-apache.tgz`:
+File extracted from upstream release tarball (`-apache.tgz` variant):
- All `*.h` from `include/mbedtls/` to `thirdparty/mbedtls/include/mbedtls/`
- All `*.c` from `library/` to `thirdparty/mbedtls/library/`
- Applied the patch in `thirdparty/mbedtls/1453.diff` (PR 1453).
@@ -391,7 +380,7 @@ Collection of single-file libraries used in Godot components.
* License: Public Domain (Unlicense) or MIT
- `stb_vorbis.c`
* Upstream: https://github.com/nothings/stb
- * Version: 1.15
+ * Version: 1.16
* License: Public Domain (Unlicense) or MIT
@@ -426,8 +415,8 @@ Files extracted from upstream source:
## pcre2
-- Upstream: http://www.pcre.org/
-- Version: 10.32
+- Upstream: http://www.pcre.org
+- Version: 10.33
- License: BSD-3-Clause
Files extracted from upstream source:
@@ -508,10 +497,23 @@ They can be reapplied using the patches included in the `vhacd`
folder.
+## wslay
+
+- Upstream: https://github.com/tatsuhiro-t/wslay
+- Version: 1.1.0
+- License: MIT
+
+File extracted from upstream release tarball:
+
+- All `*.c` and `*.h` in `lib/` and `lib/includes/`
+- `wslay.h` has a small Godot addition to fix MSVC build.
+ See `thirdparty/wslay/msvcfix.diff`
+
+
## xatlas
- Upstream: https://github.com/jpcy/xatlas
-- Version: git (b8ec29b, 2018)
+- Version: git (f65a664, 2019)
- License: MIT
Files extracted from upstream source:
@@ -536,7 +538,7 @@ Files extracted from upstream source:
## zstd
- Upstream: https://github.com/facebook/zstd
-- Version: 1.4.0
+- Version: 1.4.1
- License: BSD-3-Clause
Files extracted from upstream source:
diff --git a/thirdparty/assimp/assimp/config.h b/thirdparty/assimp/assimp/config.h
index 8b0634d28b..382a698268 100644
--- a/thirdparty/assimp/assimp/config.h
+++ b/thirdparty/assimp/assimp/config.h
@@ -647,6 +647,21 @@ enum aiComponent {
"AI_CONFIG_IMPORT_FBX_EMBEDDED_TEXTURES_LEGACY_NAMING"
// ---------------------------------------------------------------------------
+/** @brief Set wether the FBX importer shall not remove empty bones.
+ *
+ *
+ * Empty bone are often used to define connections for other models.
+ */
+#define AI_CONFIG_IMPORT_REMOVE_EMPTY_BONES \
+ "AI_CONFIG_IMPORT_REMOVE_EMPTY_BONES"
+
+// ---------------------------------------------------------------------------
+/** @brief Set wether the FBX importer shall convert the unit from cm to m.
+ */
+#define AI_CONFIG_FBX_CONVERT_TO_M \
+ "AI_CONFIG_FBX_CONVERT_TO_M"
+
+// ---------------------------------------------------------------------------
/** @brief Set the vertex animation keyframe to be imported
*
* ASSIMP does not support vertex keyframes (only bone animation is supported).
@@ -978,3 +993,4 @@ enum aiComponent {
/* #cmakedefine ASSIMP_DOUBLE_PRECISION 1 */
#endif // !! AI_CONFIG_H_INC
+
diff --git a/thirdparty/assimp/code/CApi/AssimpCExport.cpp b/thirdparty/assimp/code/CApi/AssimpCExport.cpp
new file mode 100644
index 0000000000..7557edcfc6
--- /dev/null
+++ b/thirdparty/assimp/code/CApi/AssimpCExport.cpp
@@ -0,0 +1,156 @@
+/*
+---------------------------------------------------------------------------
+Open Asset Import Library (assimp)
+---------------------------------------------------------------------------
+
+Copyright (c) 2006-2019, assimp team
+
+
+
+All rights reserved.
+
+Redistribution and use of this software in source and binary forms,
+with or without modification, are permitted provided that the following
+conditions are met:
+
+* Redistributions of source code must retain the above
+ copyright notice, this list of conditions and the
+ following disclaimer.
+
+* Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the
+ following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+* Neither the name of the assimp team, nor the names of its
+ contributors may be used to endorse or promote products
+ derived from this software without specific prior
+ written permission of the assimp team.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+---------------------------------------------------------------------------
+*/
+
+/** @file AssimpCExport.cpp
+Assimp C export interface. See Exporter.cpp for some notes.
+*/
+
+#ifndef ASSIMP_BUILD_NO_EXPORT
+
+#include "CInterfaceIOWrapper.h"
+#include <assimp/SceneCombiner.h>
+#include "Common/ScenePrivate.h"
+#include <assimp/Exporter.hpp>
+
+using namespace Assimp;
+
+// ------------------------------------------------------------------------------------------------
+ASSIMP_API size_t aiGetExportFormatCount(void)
+{
+ return Exporter().GetExportFormatCount();
+}
+
+// ------------------------------------------------------------------------------------------------
+ASSIMP_API const aiExportFormatDesc* aiGetExportFormatDescription( size_t index)
+{
+ // Note: this is valid as the index always pertains to a built-in exporter,
+ // for which the returned structure is guaranteed to be of static storage duration.
+ Exporter exporter;
+ const aiExportFormatDesc* orig( exporter.GetExportFormatDescription( index ) );
+ if (NULL == orig) {
+ return NULL;
+ }
+
+ aiExportFormatDesc *desc = new aiExportFormatDesc;
+ desc->description = new char[ strlen( orig->description ) + 1 ]();
+ ::strncpy( (char*) desc->description, orig->description, strlen( orig->description ) );
+ desc->fileExtension = new char[ strlen( orig->fileExtension ) + 1 ]();
+ ::strncpy( ( char* ) desc->fileExtension, orig->fileExtension, strlen( orig->fileExtension ) );
+ desc->id = new char[ strlen( orig->id ) + 1 ]();
+ ::strncpy( ( char* ) desc->id, orig->id, strlen( orig->id ) );
+
+ return desc;
+}
+
+// ------------------------------------------------------------------------------------------------
+ASSIMP_API void aiReleaseExportFormatDescription( const aiExportFormatDesc *desc ) {
+ if (NULL == desc) {
+ return;
+ }
+
+ delete [] desc->description;
+ delete [] desc->fileExtension;
+ delete [] desc->id;
+ delete desc;
+}
+
+// ------------------------------------------------------------------------------------------------
+ASSIMP_API void aiCopyScene(const aiScene* pIn, aiScene** pOut)
+{
+ if (!pOut || !pIn) {
+ return;
+ }
+
+ SceneCombiner::CopyScene(pOut,pIn,true);
+ ScenePriv(*pOut)->mIsCopy = true;
+}
+
+
+// ------------------------------------------------------------------------------------------------
+ASSIMP_API void aiFreeScene(const C_STRUCT aiScene* pIn)
+{
+ // note: aiReleaseImport() is also able to delete scene copies, but in addition
+ // it also handles scenes with import metadata.
+ delete pIn;
+}
+
+
+// ------------------------------------------------------------------------------------------------
+ASSIMP_API aiReturn aiExportScene( const aiScene* pScene, const char* pFormatId, const char* pFileName, unsigned int pPreprocessing )
+{
+ return ::aiExportSceneEx(pScene,pFormatId,pFileName,NULL,pPreprocessing);
+}
+
+
+// ------------------------------------------------------------------------------------------------
+ASSIMP_API aiReturn aiExportSceneEx( const aiScene* pScene, const char* pFormatId, const char* pFileName, aiFileIO* pIO, unsigned int pPreprocessing )
+{
+ Exporter exp;
+
+ if (pIO) {
+ exp.SetIOHandler(new CIOSystemWrapper(pIO));
+ }
+ return exp.Export(pScene,pFormatId,pFileName,pPreprocessing);
+}
+
+
+// ------------------------------------------------------------------------------------------------
+ASSIMP_API const C_STRUCT aiExportDataBlob* aiExportSceneToBlob( const aiScene* pScene, const char* pFormatId, unsigned int pPreprocessing )
+{
+ Exporter exp;
+ if (!exp.ExportToBlob(pScene,pFormatId,pPreprocessing)) {
+ return NULL;
+ }
+ const aiExportDataBlob* blob = exp.GetOrphanedBlob();
+ ai_assert(blob);
+
+ return blob;
+}
+
+// ------------------------------------------------------------------------------------------------
+ASSIMP_API C_STRUCT void aiReleaseExportBlob( const aiExportDataBlob* pData )
+{
+ delete pData;
+}
+
+#endif // !ASSIMP_BUILD_NO_EXPORT
diff --git a/thirdparty/assimp/code/CInterfaceIOWrapper.cpp b/thirdparty/assimp/code/CApi/CInterfaceIOWrapper.cpp
index 5a3a49565a..5a3a49565a 100644
--- a/thirdparty/assimp/code/CInterfaceIOWrapper.cpp
+++ b/thirdparty/assimp/code/CApi/CInterfaceIOWrapper.cpp
diff --git a/thirdparty/assimp/code/CInterfaceIOWrapper.h b/thirdparty/assimp/code/CApi/CInterfaceIOWrapper.h
index 2162320302..2162320302 100644
--- a/thirdparty/assimp/code/CInterfaceIOWrapper.h
+++ b/thirdparty/assimp/code/CApi/CInterfaceIOWrapper.h
diff --git a/thirdparty/assimp/code/Common/Assimp.cpp b/thirdparty/assimp/code/Common/Assimp.cpp
new file mode 100644
index 0000000000..178b2c01d0
--- /dev/null
+++ b/thirdparty/assimp/code/Common/Assimp.cpp
@@ -0,0 +1,695 @@
+/*
+---------------------------------------------------------------------------
+Open Asset Import Library (assimp)
+---------------------------------------------------------------------------
+
+Copyright (c) 2006-2019, assimp team
+
+
+
+All rights reserved.
+
+Redistribution and use of this software in source and binary forms,
+with or without modification, are permitted provided that the following
+conditions are met:
+
+* Redistributions of source code must retain the above
+ copyright notice, this list of conditions and the
+ following disclaimer.
+
+* Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the
+ following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+* Neither the name of the assimp team, nor the names of its
+ contributors may be used to endorse or promote products
+ derived from this software without specific prior
+ written permission of the assimp team.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+---------------------------------------------------------------------------
+*/
+/** @file Assimp.cpp
+ * @brief Implementation of the Plain-C API
+ */
+
+#include <assimp/cimport.h>
+#include <assimp/LogStream.hpp>
+#include <assimp/DefaultLogger.hpp>
+#include <assimp/Importer.hpp>
+#include <assimp/importerdesc.h>
+#include <assimp/scene.h>
+#include <assimp/GenericProperty.h>
+#include <assimp/Exceptional.h>
+#include <assimp/BaseImporter.h>
+
+#include "CApi/CInterfaceIOWrapper.h"
+#include "Importer.h"
+#include "ScenePrivate.h"
+
+#include <list>
+
+// ------------------------------------------------------------------------------------------------
+#ifndef ASSIMP_BUILD_SINGLETHREADED
+# include <thread>
+# include <mutex>
+#endif
+// ------------------------------------------------------------------------------------------------
+using namespace Assimp;
+
+namespace Assimp {
+ // underlying structure for aiPropertyStore
+ typedef BatchLoader::PropertyMap PropertyMap;
+
+ /** Stores the LogStream objects for all active C log streams */
+ struct mpred {
+ bool operator () (const aiLogStream& s0, const aiLogStream& s1) const {
+ return s0.callback<s1.callback&&s0.user<s1.user;
+ }
+ };
+ typedef std::map<aiLogStream, Assimp::LogStream*, mpred> LogStreamMap;
+
+ /** Stores the LogStream objects allocated by #aiGetPredefinedLogStream */
+ typedef std::list<Assimp::LogStream*> PredefLogStreamMap;
+
+ /** Local storage of all active log streams */
+ static LogStreamMap gActiveLogStreams;
+
+ /** Local storage of LogStreams allocated by #aiGetPredefinedLogStream */
+ static PredefLogStreamMap gPredefinedStreams;
+
+ /** Error message of the last failed import process */
+ static std::string gLastErrorString;
+
+ /** Verbose logging active or not? */
+ static aiBool gVerboseLogging = false;
+
+ /** will return all registered importers. */
+ void GetImporterInstanceList(std::vector< BaseImporter* >& out);
+
+ /** will delete all registered importers. */
+ void DeleteImporterInstanceList(std::vector< BaseImporter* >& out);
+} // namespace assimp
+
+
+#ifndef ASSIMP_BUILD_SINGLETHREADED
+/** Global mutex to manage the access to the log-stream map */
+static std::mutex gLogStreamMutex;
+#endif
+
+// ------------------------------------------------------------------------------------------------
+// Custom LogStream implementation for the C-API
+class LogToCallbackRedirector : public LogStream {
+public:
+ explicit LogToCallbackRedirector(const aiLogStream& s)
+ : stream (s) {
+ ai_assert(NULL != s.callback);
+ }
+
+ ~LogToCallbackRedirector() {
+#ifndef ASSIMP_BUILD_SINGLETHREADED
+ std::lock_guard<std::mutex> lock(gLogStreamMutex);
+#endif
+ // (HACK) Check whether the 'stream.user' pointer points to a
+ // custom LogStream allocated by #aiGetPredefinedLogStream.
+ // In this case, we need to delete it, too. Of course, this
+ // might cause strange problems, but the chance is quite low.
+
+ PredefLogStreamMap::iterator it = std::find(gPredefinedStreams.begin(),
+ gPredefinedStreams.end(), (Assimp::LogStream*)stream.user);
+
+ if (it != gPredefinedStreams.end()) {
+ delete *it;
+ gPredefinedStreams.erase(it);
+ }
+ }
+
+ /** @copydoc LogStream::write */
+ void write(const char* message) {
+ stream.callback(message,stream.user);
+ }
+
+private:
+ aiLogStream stream;
+};
+
+// ------------------------------------------------------------------------------------------------
+void ReportSceneNotFoundError() {
+ ASSIMP_LOG_ERROR("Unable to find the Assimp::Importer for this aiScene. "
+ "The C-API does not accept scenes produced by the C++ API and vice versa");
+
+ ai_assert(false);
+}
+
+// ------------------------------------------------------------------------------------------------
+// Reads the given file and returns its content.
+const aiScene* aiImportFile( const char* pFile, unsigned int pFlags) {
+ return aiImportFileEx(pFile,pFlags,NULL);
+}
+
+// ------------------------------------------------------------------------------------------------
+const aiScene* aiImportFileEx( const char* pFile, unsigned int pFlags, aiFileIO* pFS) {
+ return aiImportFileExWithProperties(pFile, pFlags, pFS, NULL);
+}
+
+// ------------------------------------------------------------------------------------------------
+const aiScene* aiImportFileExWithProperties( const char* pFile, unsigned int pFlags,
+ aiFileIO* pFS, const aiPropertyStore* props) {
+ ai_assert(NULL != pFile);
+
+ const aiScene* scene = NULL;
+ ASSIMP_BEGIN_EXCEPTION_REGION();
+
+ // create an Importer for this file
+ Assimp::Importer* imp = new Assimp::Importer();
+
+ // copy properties
+ if(props) {
+ const PropertyMap* pp = reinterpret_cast<const PropertyMap*>(props);
+ ImporterPimpl* pimpl = imp->Pimpl();
+ pimpl->mIntProperties = pp->ints;
+ pimpl->mFloatProperties = pp->floats;
+ pimpl->mStringProperties = pp->strings;
+ pimpl->mMatrixProperties = pp->matrices;
+ }
+ // setup a custom IO system if necessary
+ if (pFS) {
+ imp->SetIOHandler( new CIOSystemWrapper (pFS) );
+ }
+
+ // and have it read the file
+ scene = imp->ReadFile( pFile, pFlags);
+
+ // if succeeded, store the importer in the scene and keep it alive
+ if( scene) {
+ ScenePrivateData* priv = const_cast<ScenePrivateData*>( ScenePriv(scene) );
+ priv->mOrigImporter = imp;
+ } else {
+ // if failed, extract error code and destroy the import
+ gLastErrorString = imp->GetErrorString();
+ delete imp;
+ }
+
+ // return imported data. If the import failed the pointer is NULL anyways
+ ASSIMP_END_EXCEPTION_REGION(const aiScene*);
+
+ return scene;
+}
+
+// ------------------------------------------------------------------------------------------------
+const aiScene* aiImportFileFromMemory(
+ const char* pBuffer,
+ unsigned int pLength,
+ unsigned int pFlags,
+ const char* pHint)
+{
+ return aiImportFileFromMemoryWithProperties(pBuffer, pLength, pFlags, pHint, NULL);
+}
+
+// ------------------------------------------------------------------------------------------------
+const aiScene* aiImportFileFromMemoryWithProperties(
+ const char* pBuffer,
+ unsigned int pLength,
+ unsigned int pFlags,
+ const char* pHint,
+ const aiPropertyStore* props)
+{
+ ai_assert( NULL != pBuffer );
+ ai_assert( 0 != pLength );
+
+ const aiScene* scene = NULL;
+ ASSIMP_BEGIN_EXCEPTION_REGION();
+
+ // create an Importer for this file
+ Assimp::Importer* imp = new Assimp::Importer();
+
+ // copy properties
+ if(props) {
+ const PropertyMap* pp = reinterpret_cast<const PropertyMap*>(props);
+ ImporterPimpl* pimpl = imp->Pimpl();
+ pimpl->mIntProperties = pp->ints;
+ pimpl->mFloatProperties = pp->floats;
+ pimpl->mStringProperties = pp->strings;
+ pimpl->mMatrixProperties = pp->matrices;
+ }
+
+ // and have it read the file from the memory buffer
+ scene = imp->ReadFileFromMemory( pBuffer, pLength, pFlags,pHint);
+
+ // if succeeded, store the importer in the scene and keep it alive
+ if( scene) {
+ ScenePrivateData* priv = const_cast<ScenePrivateData*>( ScenePriv(scene) );
+ priv->mOrigImporter = imp;
+ }
+ else {
+ // if failed, extract error code and destroy the import
+ gLastErrorString = imp->GetErrorString();
+ delete imp;
+ }
+ // return imported data. If the import failed the pointer is NULL anyways
+ ASSIMP_END_EXCEPTION_REGION(const aiScene*);
+ return scene;
+}
+
+// ------------------------------------------------------------------------------------------------
+// Releases all resources associated with the given import process.
+void aiReleaseImport( const aiScene* pScene)
+{
+ if (!pScene) {
+ return;
+ }
+
+ ASSIMP_BEGIN_EXCEPTION_REGION();
+
+ // find the importer associated with this data
+ const ScenePrivateData* priv = ScenePriv(pScene);
+ if( !priv || !priv->mOrigImporter) {
+ delete pScene;
+ }
+ else {
+ // deleting the Importer also deletes the scene
+ // Note: the reason that this is not written as 'delete priv->mOrigImporter'
+ // is a suspected bug in gcc 4.4+ (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52339)
+ Importer* importer = priv->mOrigImporter;
+ delete importer;
+ }
+
+ ASSIMP_END_EXCEPTION_REGION(void);
+}
+
+// ------------------------------------------------------------------------------------------------
+ASSIMP_API const aiScene* aiApplyPostProcessing(const aiScene* pScene,
+ unsigned int pFlags)
+{
+ const aiScene* sc = NULL;
+
+
+ ASSIMP_BEGIN_EXCEPTION_REGION();
+
+ // find the importer associated with this data
+ const ScenePrivateData* priv = ScenePriv(pScene);
+ if( !priv || !priv->mOrigImporter) {
+ ReportSceneNotFoundError();
+ return NULL;
+ }
+
+ sc = priv->mOrigImporter->ApplyPostProcessing(pFlags);
+
+ if (!sc) {
+ aiReleaseImport(pScene);
+ return NULL;
+ }
+
+ ASSIMP_END_EXCEPTION_REGION(const aiScene*);
+ return sc;
+}
+
+// ------------------------------------------------------------------------------------------------
+ASSIMP_API const aiScene *aiApplyCustomizedPostProcessing( const aiScene *scene,
+ BaseProcess* process,
+ bool requestValidation ) {
+ const aiScene* sc( NULL );
+
+ ASSIMP_BEGIN_EXCEPTION_REGION();
+
+ // find the importer associated with this data
+ const ScenePrivateData* priv = ScenePriv( scene );
+ if ( NULL == priv || NULL == priv->mOrigImporter ) {
+ ReportSceneNotFoundError();
+ return NULL;
+ }
+
+ sc = priv->mOrigImporter->ApplyCustomizedPostProcessing( process, requestValidation );
+
+ if ( !sc ) {
+ aiReleaseImport( scene );
+ return NULL;
+ }
+
+ ASSIMP_END_EXCEPTION_REGION( const aiScene* );
+
+ return sc;
+}
+
+// ------------------------------------------------------------------------------------------------
+void CallbackToLogRedirector (const char* msg, char* dt)
+{
+ ai_assert( NULL != msg );
+ ai_assert( NULL != dt );
+ LogStream* s = (LogStream*)dt;
+
+ s->write(msg);
+}
+
+// ------------------------------------------------------------------------------------------------
+ASSIMP_API aiLogStream aiGetPredefinedLogStream(aiDefaultLogStream pStream,const char* file)
+{
+ aiLogStream sout;
+
+ ASSIMP_BEGIN_EXCEPTION_REGION();
+ LogStream* stream = LogStream::createDefaultStream(pStream,file);
+ if (!stream) {
+ sout.callback = NULL;
+ sout.user = NULL;
+ }
+ else {
+ sout.callback = &CallbackToLogRedirector;
+ sout.user = (char*)stream;
+ }
+ gPredefinedStreams.push_back(stream);
+ ASSIMP_END_EXCEPTION_REGION(aiLogStream);
+ return sout;
+}
+
+// ------------------------------------------------------------------------------------------------
+ASSIMP_API void aiAttachLogStream( const aiLogStream* stream )
+{
+ ASSIMP_BEGIN_EXCEPTION_REGION();
+
+#ifndef ASSIMP_BUILD_SINGLETHREADED
+ std::lock_guard<std::mutex> lock(gLogStreamMutex);
+#endif
+
+ LogStream* lg = new LogToCallbackRedirector(*stream);
+ gActiveLogStreams[*stream] = lg;
+
+ if (DefaultLogger::isNullLogger()) {
+ DefaultLogger::create(NULL,(gVerboseLogging == AI_TRUE ? Logger::VERBOSE : Logger::NORMAL));
+ }
+ DefaultLogger::get()->attachStream(lg);
+ ASSIMP_END_EXCEPTION_REGION(void);
+}
+
+// ------------------------------------------------------------------------------------------------
+ASSIMP_API aiReturn aiDetachLogStream( const aiLogStream* stream)
+{
+ ASSIMP_BEGIN_EXCEPTION_REGION();
+
+#ifndef ASSIMP_BUILD_SINGLETHREADED
+ std::lock_guard<std::mutex> lock(gLogStreamMutex);
+#endif
+ // find the log-stream associated with this data
+ LogStreamMap::iterator it = gActiveLogStreams.find( *stream);
+ // it should be there... else the user is playing fools with us
+ if( it == gActiveLogStreams.end()) {
+ return AI_FAILURE;
+ }
+ DefaultLogger::get()->detatchStream( it->second );
+ delete it->second;
+
+ gActiveLogStreams.erase( it);
+
+ if (gActiveLogStreams.empty()) {
+ DefaultLogger::kill();
+ }
+ ASSIMP_END_EXCEPTION_REGION(aiReturn);
+ return AI_SUCCESS;
+}
+
+// ------------------------------------------------------------------------------------------------
+ASSIMP_API void aiDetachAllLogStreams(void)
+{
+ ASSIMP_BEGIN_EXCEPTION_REGION();
+#ifndef ASSIMP_BUILD_SINGLETHREADED
+ std::lock_guard<std::mutex> lock(gLogStreamMutex);
+#endif
+ Logger *logger( DefaultLogger::get() );
+ if ( NULL == logger ) {
+ return;
+ }
+
+ for (LogStreamMap::iterator it = gActiveLogStreams.begin(); it != gActiveLogStreams.end(); ++it) {
+ logger->detatchStream( it->second );
+ delete it->second;
+ }
+ gActiveLogStreams.clear();
+ DefaultLogger::kill();
+
+ ASSIMP_END_EXCEPTION_REGION(void);
+}
+
+// ------------------------------------------------------------------------------------------------
+ASSIMP_API void aiEnableVerboseLogging(aiBool d)
+{
+ if (!DefaultLogger::isNullLogger()) {
+ DefaultLogger::get()->setLogSeverity((d == AI_TRUE ? Logger::VERBOSE : Logger::NORMAL));
+ }
+ gVerboseLogging = d;
+}
+
+// ------------------------------------------------------------------------------------------------
+// Returns the error text of the last failed import process.
+const char* aiGetErrorString()
+{
+ return gLastErrorString.c_str();
+}
+
+// -----------------------------------------------------------------------------------------------
+// Return the description of a importer given its index
+const aiImporterDesc* aiGetImportFormatDescription( size_t pIndex)
+{
+ return Importer().GetImporterInfo(pIndex);
+}
+
+// -----------------------------------------------------------------------------------------------
+// Return the number of importers
+size_t aiGetImportFormatCount(void)
+{
+ return Importer().GetImporterCount();
+}
+
+// ------------------------------------------------------------------------------------------------
+// Returns the error text of the last failed import process.
+aiBool aiIsExtensionSupported(const char* szExtension)
+{
+ ai_assert(NULL != szExtension);
+ aiBool candoit=AI_FALSE;
+ ASSIMP_BEGIN_EXCEPTION_REGION();
+
+ // FIXME: no need to create a temporary Importer instance just for that ..
+ Assimp::Importer tmp;
+ candoit = tmp.IsExtensionSupported(std::string(szExtension)) ? AI_TRUE : AI_FALSE;
+
+ ASSIMP_END_EXCEPTION_REGION(aiBool);
+ return candoit;
+}
+
+// ------------------------------------------------------------------------------------------------
+// Get a list of all file extensions supported by ASSIMP
+void aiGetExtensionList(aiString* szOut)
+{
+ ai_assert(NULL != szOut);
+ ASSIMP_BEGIN_EXCEPTION_REGION();
+
+ // FIXME: no need to create a temporary Importer instance just for that ..
+ Assimp::Importer tmp;
+ tmp.GetExtensionList(*szOut);
+
+ ASSIMP_END_EXCEPTION_REGION(void);
+}
+
+// ------------------------------------------------------------------------------------------------
+// Get the memory requirements for a particular import.
+void aiGetMemoryRequirements(const C_STRUCT aiScene* pIn,
+ C_STRUCT aiMemoryInfo* in)
+{
+ ASSIMP_BEGIN_EXCEPTION_REGION();
+
+ // find the importer associated with this data
+ const ScenePrivateData* priv = ScenePriv(pIn);
+ if( !priv || !priv->mOrigImporter) {
+ ReportSceneNotFoundError();
+ return;
+ }
+
+ return priv->mOrigImporter->GetMemoryRequirements(*in);
+ ASSIMP_END_EXCEPTION_REGION(void);
+}
+
+// ------------------------------------------------------------------------------------------------
+ASSIMP_API aiPropertyStore* aiCreatePropertyStore(void)
+{
+ return reinterpret_cast<aiPropertyStore*>( new PropertyMap() );
+}
+
+// ------------------------------------------------------------------------------------------------
+ASSIMP_API void aiReleasePropertyStore(aiPropertyStore* p)
+{
+ delete reinterpret_cast<PropertyMap*>(p);
+}
+
+// ------------------------------------------------------------------------------------------------
+// Importer::SetPropertyInteger
+ASSIMP_API void aiSetImportPropertyInteger(aiPropertyStore* p, const char* szName, int value)
+{
+ ASSIMP_BEGIN_EXCEPTION_REGION();
+ PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
+ SetGenericProperty<int>(pp->ints,szName,value);
+ ASSIMP_END_EXCEPTION_REGION(void);
+}
+
+// ------------------------------------------------------------------------------------------------
+// Importer::SetPropertyFloat
+ASSIMP_API void aiSetImportPropertyFloat(aiPropertyStore* p, const char* szName, ai_real value)
+{
+ ASSIMP_BEGIN_EXCEPTION_REGION();
+ PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
+ SetGenericProperty<ai_real>(pp->floats,szName,value);
+ ASSIMP_END_EXCEPTION_REGION(void);
+}
+
+// ------------------------------------------------------------------------------------------------
+// Importer::SetPropertyString
+ASSIMP_API void aiSetImportPropertyString(aiPropertyStore* p, const char* szName,
+ const C_STRUCT aiString* st)
+{
+ if (!st) {
+ return;
+ }
+ ASSIMP_BEGIN_EXCEPTION_REGION();
+ PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
+ SetGenericProperty<std::string>(pp->strings,szName,std::string(st->C_Str()));
+ ASSIMP_END_EXCEPTION_REGION(void);
+}
+
+// ------------------------------------------------------------------------------------------------
+// Importer::SetPropertyMatrix
+ASSIMP_API void aiSetImportPropertyMatrix(aiPropertyStore* p, const char* szName,
+ const C_STRUCT aiMatrix4x4* mat)
+{
+ if (!mat) {
+ return;
+ }
+ ASSIMP_BEGIN_EXCEPTION_REGION();
+ PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
+ SetGenericProperty<aiMatrix4x4>(pp->matrices,szName,*mat);
+ ASSIMP_END_EXCEPTION_REGION(void);
+}
+
+// ------------------------------------------------------------------------------------------------
+// Rotation matrix to quaternion
+ASSIMP_API void aiCreateQuaternionFromMatrix(aiQuaternion* quat,const aiMatrix3x3* mat)
+{
+ ai_assert( NULL != quat );
+ ai_assert( NULL != mat );
+ *quat = aiQuaternion(*mat);
+}
+
+// ------------------------------------------------------------------------------------------------
+// Matrix decomposition
+ASSIMP_API void aiDecomposeMatrix(const aiMatrix4x4* mat,aiVector3D* scaling,
+ aiQuaternion* rotation,
+ aiVector3D* position)
+{
+ ai_assert( NULL != rotation );
+ ai_assert( NULL != position );
+ ai_assert( NULL != scaling );
+ ai_assert( NULL != mat );
+ mat->Decompose(*scaling,*rotation,*position);
+}
+
+// ------------------------------------------------------------------------------------------------
+// Matrix transpose
+ASSIMP_API void aiTransposeMatrix3(aiMatrix3x3* mat)
+{
+ ai_assert(NULL != mat);
+ mat->Transpose();
+}
+
+// ------------------------------------------------------------------------------------------------
+ASSIMP_API void aiTransposeMatrix4(aiMatrix4x4* mat)
+{
+ ai_assert(NULL != mat);
+ mat->Transpose();
+}
+
+// ------------------------------------------------------------------------------------------------
+// Vector transformation
+ASSIMP_API void aiTransformVecByMatrix3(aiVector3D* vec,
+ const aiMatrix3x3* mat)
+{
+ ai_assert( NULL != mat );
+ ai_assert( NULL != vec);
+ *vec *= (*mat);
+}
+
+// ------------------------------------------------------------------------------------------------
+ASSIMP_API void aiTransformVecByMatrix4(aiVector3D* vec,
+ const aiMatrix4x4* mat)
+{
+ ai_assert( NULL != mat );
+ ai_assert( NULL != vec );
+
+ *vec *= (*mat);
+}
+
+// ------------------------------------------------------------------------------------------------
+// Matrix multiplication
+ASSIMP_API void aiMultiplyMatrix4(
+ aiMatrix4x4* dst,
+ const aiMatrix4x4* src)
+{
+ ai_assert( NULL != dst );
+ ai_assert( NULL != src );
+ *dst = (*dst) * (*src);
+}
+
+// ------------------------------------------------------------------------------------------------
+ASSIMP_API void aiMultiplyMatrix3(
+ aiMatrix3x3* dst,
+ const aiMatrix3x3* src)
+{
+ ai_assert( NULL != dst );
+ ai_assert( NULL != src );
+ *dst = (*dst) * (*src);
+}
+
+// ------------------------------------------------------------------------------------------------
+// Matrix identity
+ASSIMP_API void aiIdentityMatrix3(
+ aiMatrix3x3* mat)
+{
+ ai_assert(NULL != mat);
+ *mat = aiMatrix3x3();
+}
+
+// ------------------------------------------------------------------------------------------------
+ASSIMP_API void aiIdentityMatrix4(
+ aiMatrix4x4* mat)
+{
+ ai_assert(NULL != mat);
+ *mat = aiMatrix4x4();
+}
+
+// ------------------------------------------------------------------------------------------------
+ASSIMP_API C_STRUCT const aiImporterDesc* aiGetImporterDesc( const char *extension ) {
+ if( NULL == extension ) {
+ return NULL;
+ }
+ const aiImporterDesc *desc( NULL );
+ std::vector< BaseImporter* > out;
+ GetImporterInstanceList( out );
+ for( size_t i = 0; i < out.size(); ++i ) {
+ if( 0 == strncmp( out[ i ]->GetInfo()->mFileExtensions, extension, strlen( extension ) ) ) {
+ desc = out[ i ]->GetInfo();
+ break;
+ }
+ }
+
+ DeleteImporterInstanceList(out);
+
+ return desc;
+}
+
+// ------------------------------------------------------------------------------------------------
diff --git a/thirdparty/assimp/code/BaseImporter.cpp b/thirdparty/assimp/code/Common/BaseImporter.cpp
index 4803c6d6f2..0a5694aa0e 100644
--- a/thirdparty/assimp/code/BaseImporter.cpp
+++ b/thirdparty/assimp/code/Common/BaseImporter.cpp
@@ -320,7 +320,11 @@ std::string BaseImporter::GetExtension( const std::string& file ) {
return false;
}
-#include "../contrib/utf8cpp/source/utf8.h"
+#ifdef ASSIMP_USE_HUNTER
+# include <utf8/utf8.h>
+#else
+# include "../contrib/utf8cpp/source/utf8.h"
+#endif
// ------------------------------------------------------------------------------------------------
// Convert to UTF8 data
diff --git a/thirdparty/assimp/code/BaseProcess.cpp b/thirdparty/assimp/code/Common/BaseProcess.cpp
index 18872c3693..e247be418d 100644
--- a/thirdparty/assimp/code/BaseProcess.cpp
+++ b/thirdparty/assimp/code/Common/BaseProcess.cpp
@@ -89,7 +89,7 @@ void BaseProcess::ExecuteOnScene( Importer* pImp)
// and kill the partially imported data
delete pImp->Pimpl()->mScene;
- pImp->Pimpl()->mScene = NULL;
+ pImp->Pimpl()->mScene = nullptr;
}
}
diff --git a/thirdparty/assimp/code/BaseProcess.h b/thirdparty/assimp/code/Common/BaseProcess.h
index 4d5c7a76be..4d5c7a76be 100644
--- a/thirdparty/assimp/code/BaseProcess.h
+++ b/thirdparty/assimp/code/Common/BaseProcess.h
diff --git a/thirdparty/assimp/code/Bitmap.cpp b/thirdparty/assimp/code/Common/Bitmap.cpp
index b22b71ea9e..b22b71ea9e 100644
--- a/thirdparty/assimp/code/Bitmap.cpp
+++ b/thirdparty/assimp/code/Common/Bitmap.cpp
diff --git a/thirdparty/assimp/code/CreateAnimMesh.cpp b/thirdparty/assimp/code/Common/CreateAnimMesh.cpp
index 1a052849bb..98b60e5319 100644
--- a/thirdparty/assimp/code/CreateAnimMesh.cpp
+++ b/thirdparty/assimp/code/Common/CreateAnimMesh.cpp
@@ -47,10 +47,6 @@ namespace Assimp {
aiAnimMesh *aiCreateAnimMesh(const aiMesh *mesh)
{
aiAnimMesh *animesh = new aiAnimMesh;
- animesh->mVertices = NULL;
- animesh->mNormals = NULL;
- animesh->mTangents = NULL;
- animesh->mBitangents = NULL;
animesh->mNumVertices = mesh->mNumVertices;
if (mesh->mVertices) {
animesh->mVertices = new aiVector3D[animesh->mNumVertices];
diff --git a/thirdparty/assimp/code/DefaultIOStream.cpp b/thirdparty/assimp/code/Common/DefaultIOStream.cpp
index 1c100b6189..1c100b6189 100644
--- a/thirdparty/assimp/code/DefaultIOStream.cpp
+++ b/thirdparty/assimp/code/Common/DefaultIOStream.cpp
diff --git a/thirdparty/assimp/code/DefaultIOSystem.cpp b/thirdparty/assimp/code/Common/DefaultIOSystem.cpp
index d40b67de32..d40b67de32 100644
--- a/thirdparty/assimp/code/DefaultIOSystem.cpp
+++ b/thirdparty/assimp/code/Common/DefaultIOSystem.cpp
diff --git a/thirdparty/assimp/code/DefaultLogger.cpp b/thirdparty/assimp/code/Common/DefaultLogger.cpp
index de3528d2b4..de3528d2b4 100644
--- a/thirdparty/assimp/code/DefaultLogger.cpp
+++ b/thirdparty/assimp/code/Common/DefaultLogger.cpp
diff --git a/thirdparty/assimp/code/DefaultProgressHandler.h b/thirdparty/assimp/code/Common/DefaultProgressHandler.h
index bd2cce00be..bd2cce00be 100644
--- a/thirdparty/assimp/code/DefaultProgressHandler.h
+++ b/thirdparty/assimp/code/Common/DefaultProgressHandler.h
diff --git a/thirdparty/assimp/code/Exporter.cpp b/thirdparty/assimp/code/Common/Exporter.cpp
index 8848e87f5b..090b561ae0 100644
--- a/thirdparty/assimp/code/Exporter.cpp
+++ b/thirdparty/assimp/code/Common/Exporter.cpp
@@ -61,15 +61,16 @@ Here we implement only the C++ interface (Assimp::Exporter).
#include <assimp/mesh.h>
#include <assimp/postprocess.h>
#include <assimp/scene.h>
-
-#include "DefaultProgressHandler.h"
-#include "BaseProcess.h"
-#include "JoinVerticesProcess.h"
-#include "MakeVerboseFormat.h"
-#include "ConvertToLHProcess.h"
-#include "PretransformVertices.h"
#include <assimp/Exceptional.h>
-#include "ScenePrivate.h"
+
+#include "Common/DefaultProgressHandler.h"
+#include "Common/BaseProcess.h"
+#include "Common/ScenePrivate.h"
+#include "PostProcessing/CalcTangentsProcess.h"
+#include "PostProcessing/MakeVerboseFormat.h"
+#include "PostProcessing/JoinVerticesProcess.h"
+#include "PostProcessing/ConvertToLHProcess.h"
+#include "PostProcessing/PretransformVertices.h"
#include <memory>
@@ -101,6 +102,7 @@ void ExportSceneX3D(const char*, IOSystem*, const aiScene*, const ExportProperti
void ExportSceneFBX(const char*, IOSystem*, const aiScene*, const ExportProperties*);
void ExportSceneFBXA(const char*, IOSystem*, const aiScene*, const ExportProperties*);
void ExportScene3MF( const char*, IOSystem*, const aiScene*, const ExportProperties* );
+void ExportAssimp2Json(const char* , IOSystem*, const aiScene* , const Assimp::ExportProperties*);
// ------------------------------------------------------------------------------------------------
// global array of all export formats which Assimp supports in its current build
@@ -161,11 +163,11 @@ Exporter::ExportFormatEntry gExporters[] =
#endif
#ifndef ASSIMP_BUILD_NO_ASSBIN_EXPORTER
- Exporter::ExportFormatEntry( "assbin", "Assimp Binary", "assbin" , &ExportSceneAssbin, 0 ),
+ Exporter::ExportFormatEntry( "assbin", "Assimp Binary File", "assbin" , &ExportSceneAssbin, 0 ),
#endif
#ifndef ASSIMP_BUILD_NO_ASSXML_EXPORTER
- Exporter::ExportFormatEntry( "assxml", "Assxml Document", "assxml" , &ExportSceneAssxml, 0 ),
+ Exporter::ExportFormatEntry( "assxml", "Assimp XML Document", "assxml" , &ExportSceneAssxml, 0 ),
#endif
#ifndef ASSIMP_BUILD_NO_X3D_EXPORTER
@@ -178,7 +180,11 @@ Exporter::ExportFormatEntry gExporters[] =
#endif
#ifndef ASSIMP_BUILD_NO_3MF_EXPORTER
- Exporter::ExportFormatEntry( "3mf", "The 3MF-File-Format", "3mf", &ExportScene3MF, 0 )
+ Exporter::ExportFormatEntry( "3mf", "The 3MF-File-Format", "3mf", &ExportScene3MF, 0 ),
+#endif
+
+#ifndef ASSIMP_BUILD_NO_ASSJSON_EXPORTER
+ Exporter::ExportFormatEntry( "assjson", "Assimp JSON Document", "json", &ExportAssimp2Json, 0)
#endif
};
@@ -288,7 +294,7 @@ void Exporter::SetProgressHandler(ProgressHandler* pHandler) {
// ------------------------------------------------------------------------------------------------
const aiExportDataBlob* Exporter::ExportToBlob( const aiScene* pScene, const char* pFormatId,
- unsigned int, const ExportProperties* /*pProperties*/ ) {
+ unsigned int pPreprocessing, const ExportProperties* pProperties) {
if (pimpl->blob) {
delete pimpl->blob;
pimpl->blob = nullptr;
@@ -298,7 +304,7 @@ const aiExportDataBlob* Exporter::ExportToBlob( const aiScene* pScene, const cha
BlobIOSystem* blobio = new BlobIOSystem();
pimpl->mIOSystem = std::shared_ptr<IOSystem>( blobio );
- if (AI_SUCCESS != Export(pScene,pFormatId,blobio->GetMagicFileName())) {
+ if (AI_SUCCESS != Export(pScene,pFormatId,blobio->GetMagicFileName(), pPreprocessing, pProperties)) {
pimpl->mIOSystem = old;
return nullptr;
}
diff --git a/thirdparty/assimp/code/FileLogStream.h b/thirdparty/assimp/code/Common/FileLogStream.h
index 740c503192..740c503192 100644
--- a/thirdparty/assimp/code/FileLogStream.h
+++ b/thirdparty/assimp/code/Common/FileLogStream.h
diff --git a/thirdparty/assimp/code/FileSystemFilter.h b/thirdparty/assimp/code/Common/FileSystemFilter.h
index 9923cdbdd3..9923cdbdd3 100644
--- a/thirdparty/assimp/code/FileSystemFilter.h
+++ b/thirdparty/assimp/code/Common/FileSystemFilter.h
diff --git a/thirdparty/assimp/code/Common/IFF.h b/thirdparty/assimp/code/Common/IFF.h
new file mode 100644
index 0000000000..91d7d48289
--- /dev/null
+++ b/thirdparty/assimp/code/Common/IFF.h
@@ -0,0 +1,102 @@
+// Definitions for the Interchange File Format (IFF)
+// Alexander Gessler, 2006
+// Adapted to Assimp August 2008
+
+#ifndef AI_IFF_H_INCLUDED
+#define AI_IFF_H_INCLUDED
+
+#include <assimp/ByteSwapper.h>
+
+namespace Assimp {
+namespace IFF {
+
+/////////////////////////////////////////////////////////////////////////////////
+//! Describes an IFF chunk header
+/////////////////////////////////////////////////////////////////////////////////
+struct ChunkHeader
+{
+ //! Type of the chunk header - FourCC
+ uint32_t type;
+
+ //! Length of the chunk data, in bytes
+ uint32_t length;
+};
+
+
+/////////////////////////////////////////////////////////////////////////////////
+//! Describes an IFF sub chunk header
+/////////////////////////////////////////////////////////////////////////////////
+struct SubChunkHeader
+{
+ //! Type of the chunk header - FourCC
+ uint32_t type;
+
+ //! Length of the chunk data, in bytes
+ uint16_t length;
+};
+
+
+#define AI_IFF_FOURCC(a,b,c,d) ((uint32_t) (((uint8_t)a << 24u) | \
+ ((uint8_t)b << 16u) | ((uint8_t)c << 8u) | ((uint8_t)d)))
+
+
+#define AI_IFF_FOURCC_FORM AI_IFF_FOURCC('F','O','R','M')
+
+
+/////////////////////////////////////////////////////////////////////////////////
+//! Load a chunk header
+//! @param outFile Pointer to the file data - points to the chunk data afterwards
+//! @return Copy of the chunk header
+/////////////////////////////////////////////////////////////////////////////////
+inline ChunkHeader LoadChunk(uint8_t*& outFile)
+{
+ ChunkHeader head;
+ ::memcpy(&head.type, outFile, 4);
+ outFile += 4;
+ ::memcpy(&head.length, outFile, 4);
+ outFile += 4;
+ AI_LSWAP4(head.length);
+ AI_LSWAP4(head.type);
+ return head;
+}
+
+/////////////////////////////////////////////////////////////////////////////////
+//! Load a sub chunk header
+//! @param outFile Pointer to the file data - points to the chunk data afterwards
+//! @return Copy of the sub chunk header
+/////////////////////////////////////////////////////////////////////////////////
+inline SubChunkHeader LoadSubChunk(uint8_t*& outFile)
+{
+ SubChunkHeader head;
+ ::memcpy(&head.type, outFile, 4);
+ outFile += 4;
+ ::memcpy(&head.length, outFile, 2);
+ outFile += 2;
+ AI_LSWAP2(head.length);
+ AI_LSWAP4(head.type);
+ return head;
+}
+
+/////////////////////////////////////////////////////////////////////////////////
+//! Read the file header and return the type of the file and its size
+//! @param outFile Pointer to the file data. The buffer must at
+//! least be 12 bytes large.
+//! @param fileType Receives the type of the file
+//! @return 0 if everything was OK, otherwise an error message
+/////////////////////////////////////////////////////////////////////////////////
+inline const char* ReadHeader(uint8_t* outFile, uint32_t& fileType)
+{
+ ChunkHeader head = LoadChunk(outFile);
+ if(AI_IFF_FOURCC_FORM != head.type)
+ {
+ return "The file is not an IFF file: FORM chunk is missing";
+ }
+ ::memcpy(&fileType, outFile, 4);
+ AI_LSWAP4(fileType);
+ return 0;
+}
+
+
+}}
+
+#endif // !! AI_IFF_H_INCLUDED
diff --git a/thirdparty/assimp/code/Importer.cpp b/thirdparty/assimp/code/Common/Importer.cpp
index 65b16471cc..91b50859a0 100644
--- a/thirdparty/assimp/code/Importer.cpp
+++ b/thirdparty/assimp/code/Common/Importer.cpp
@@ -64,15 +64,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// ------------------------------------------------------------------------------------------------
// Internal headers
// ------------------------------------------------------------------------------------------------
-#include "Importer.h"
-#include <assimp/BaseImporter.h>
-#include "BaseProcess.h"
+#include "Common/Importer.h"
+#include "Common/BaseProcess.h"
+#include "Common/DefaultProgressHandler.h"
+#include "PostProcessing/ProcessHelper.h"
+#include "Common/ScenePreprocessor.h"
+#include "Common/ScenePrivate.h"
-#include "DefaultProgressHandler.h"
+#include <assimp/BaseImporter.h>
#include <assimp/GenericProperty.h>
-#include "ProcessHelper.h"
-#include "ScenePreprocessor.h"
-#include "ScenePrivate.h"
#include <assimp/MemoryIOWrapper.h>
#include <assimp/Profiler.h>
#include <assimp/TinyFormatter.h>
@@ -86,7 +86,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/DefaultIOSystem.h>
#ifndef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
-# include "ValidateDataStructure.h"
+# include "PostProcessing/ValidateDataStructure.h"
#endif
using namespace Assimp::Profiling;
@@ -590,10 +590,12 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags)
// Find an worker class which can handle the file
BaseImporter* imp = NULL;
+ SetPropertyInteger("importerIndex", -1);
for( unsigned int a = 0; a < pimpl->mImporter.size(); a++) {
if( pimpl->mImporter[a]->CanRead( pFile, pimpl->mIOHandler, false)) {
imp = pimpl->mImporter[a];
+ SetPropertyInteger("importerIndex", a);
break;
}
}
@@ -606,6 +608,7 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags)
for( unsigned int a = 0; a < pimpl->mImporter.size(); a++) {
if( pimpl->mImporter[a]->CanRead( pFile, pimpl->mIOHandler, true)) {
imp = pimpl->mImporter[a];
+ SetPropertyInteger("importerIndex", a);
break;
}
}
diff --git a/thirdparty/assimp/code/Importer.h b/thirdparty/assimp/code/Common/Importer.h
index a439d99c2f..a439d99c2f 100644
--- a/thirdparty/assimp/code/Importer.h
+++ b/thirdparty/assimp/code/Common/Importer.h
diff --git a/thirdparty/assimp/code/ImporterRegistry.cpp b/thirdparty/assimp/code/Common/ImporterRegistry.cpp
index 747815fa6f..32ac3b4168 100644
--- a/thirdparty/assimp/code/ImporterRegistry.cpp
+++ b/thirdparty/assimp/code/Common/ImporterRegistry.cpp
@@ -56,146 +56,146 @@ corresponding preprocessor flag to selectively disable formats.
// (include_new_importers_here)
// ------------------------------------------------------------------------------------------------
#ifndef ASSIMP_BUILD_NO_X_IMPORTER
-# include "XFileImporter.h"
+# include "X/XFileImporter.h"
#endif
#ifndef ASSIMP_BUILD_NO_AMF_IMPORTER
-# include "AMFImporter.hpp"
+# include "AMF/AMFImporter.hpp"
#endif
#ifndef ASSIMP_BUILD_NO_3DS_IMPORTER
-# include "3DSLoader.h"
+# include "3DS/3DSLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_MD3_IMPORTER
-# include "MD3Loader.h"
+# include "MD3/MD3Loader.h"
#endif
#ifndef ASSIMP_BUILD_NO_MDL_IMPORTER
-# include "MDLLoader.h"
+# include "MDL/MDLLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_MD2_IMPORTER
-# include "MD2Loader.h"
+# include "MD2/MD2Loader.h"
#endif
#ifndef ASSIMP_BUILD_NO_PLY_IMPORTER
-# include "PlyLoader.h"
+# include "Ply/PlyLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_ASE_IMPORTER
-# include "ASELoader.h"
+# include "ASE/ASELoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_OBJ_IMPORTER
-# include "ObjFileImporter.h"
+# include "Obj/ObjFileImporter.h"
#endif
#ifndef ASSIMP_BUILD_NO_HMP_IMPORTER
-# include "HMPLoader.h"
+# include "HMP/HMPLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_SMD_IMPORTER
-# include "SMDLoader.h"
+# include "SMD/SMDLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_MDC_IMPORTER
-# include "MDCLoader.h"
+# include "MDC/MDCLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_MD5_IMPORTER
-# include "MD5Loader.h"
+# include "MD5/MD5Loader.h"
#endif
#ifndef ASSIMP_BUILD_NO_STL_IMPORTER
-# include "STLLoader.h"
+# include "STL/STLLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_LWO_IMPORTER
-# include "LWOLoader.h"
+# include "LWO/LWOLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_DXF_IMPORTER
-# include "DXFLoader.h"
+# include "DXF/DXFLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_NFF_IMPORTER
-# include "NFFLoader.h"
+# include "NFF/NFFLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_RAW_IMPORTER
-# include "RawLoader.h"
+# include "Raw/RawLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_SIB_IMPORTER
-# include "SIBImporter.h"
+# include "SIB/SIBImporter.h"
#endif
#ifndef ASSIMP_BUILD_NO_OFF_IMPORTER
-# include "OFFLoader.h"
+# include "OFF/OFFLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_AC_IMPORTER
-# include "ACLoader.h"
+# include "AC/ACLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_BVH_IMPORTER
-# include "BVHLoader.h"
+# include "BVH/BVHLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_IRRMESH_IMPORTER
-# include "IRRMeshLoader.h"
+# include "Irr/IRRMeshLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_IRR_IMPORTER
-# include "IRRLoader.h"
+# include "Irr/IRRLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_Q3D_IMPORTER
-# include "Q3DLoader.h"
+# include "Q3D/Q3DLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_B3D_IMPORTER
-# include "B3DImporter.h"
+# include "B3D/B3DImporter.h"
#endif
#ifndef ASSIMP_BUILD_NO_COLLADA_IMPORTER
-# include "ColladaLoader.h"
+# include "Collada/ColladaLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_TERRAGEN_IMPORTER
-# include "TerragenLoader.h"
+# include "Terragen/TerragenLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_CSM_IMPORTER
-# include "CSMLoader.h"
+# include "CSM/CSMLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_3D_IMPORTER
-# include "UnrealLoader.h"
+# include "Unreal/UnrealLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_LWS_IMPORTER
-# include "LWSLoader.h"
+# include "LWS/LWSLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_OGRE_IMPORTER
-# include "OgreImporter.h"
+# include "Ogre/OgreImporter.h"
#endif
#ifndef ASSIMP_BUILD_NO_OPENGEX_IMPORTER
-# include "OpenGEXImporter.h"
+# include "OpenGEX/OpenGEXImporter.h"
#endif
#ifndef ASSIMP_BUILD_NO_MS3D_IMPORTER
-# include "MS3DLoader.h"
+# include "MS3D/MS3DLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_COB_IMPORTER
-# include "COBLoader.h"
+# include "COB/COBLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_BLEND_IMPORTER
-# include "BlenderLoader.h"
+# include "Blender/BlenderLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_Q3BSP_IMPORTER
-# include "Q3BSPFileImporter.h"
+# include "Q3BSP/Q3BSPFileImporter.h"
#endif
#ifndef ASSIMP_BUILD_NO_NDO_IMPORTER
-# include "NDOLoader.h"
+# include "NDO/NDOLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_IFC_IMPORTER
# include "Importer/IFC/IFCLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_XGL_IMPORTER
-# include "XGLLoader.h"
+# include "XGL/XGLLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_FBX_IMPORTER
-# include "FBXImporter.h"
+# include "FBX/FBXImporter.h"
#endif
#ifndef ASSIMP_BUILD_NO_ASSBIN_IMPORTER
-# include "AssbinLoader.h"
+# include "Assbin/AssbinLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER
-# include "glTFImporter.h"
-# include "glTF2Importer.h"
+# include "glTF/glTFImporter.h"
+# include "glTF2/glTF2Importer.h"
#endif
#ifndef ASSIMP_BUILD_NO_C4D_IMPORTER
-# include "C4DImporter.h"
+# include "C4D/C4DImporter.h"
#endif
#ifndef ASSIMP_BUILD_NO_3MF_IMPORTER
-# include "D3MFImporter.h"
+# include "3MF/D3MFImporter.h"
#endif
#ifndef ASSIMP_BUILD_NO_X3D_IMPORTER
-# include "X3DImporter.hpp"
+# include "X3D/X3DImporter.hpp"
#endif
#ifndef ASSIMP_BUILD_NO_MMD_IMPORTER
-# include "MMDImporter.h"
+# include "MMD/MMDImporter.h"
#endif
#ifndef ASSIMP_BUILD_NO_STEP_IMPORTER
# include "Importer/StepFile/StepFileImporter.h"
@@ -364,7 +364,7 @@ void GetImporterInstanceList(std::vector< BaseImporter* >& out)
void DeleteImporterInstanceList(std::vector< BaseImporter* >& deleteList){
for(size_t i= 0; i<deleteList.size();++i){
delete deleteList[i];
- deleteList[i]=NULL;
+ deleteList[i]=nullptr;
}//for
}
diff --git a/thirdparty/assimp/code/PolyTools.h b/thirdparty/assimp/code/Common/PolyTools.h
index fbbda0e7d1..fbbda0e7d1 100644
--- a/thirdparty/assimp/code/PolyTools.h
+++ b/thirdparty/assimp/code/Common/PolyTools.h
diff --git a/thirdparty/assimp/code/PostStepRegistry.cpp b/thirdparty/assimp/code/Common/PostStepRegistry.cpp
index 15b4a28843..ef58f8ddfd 100644
--- a/thirdparty/assimp/code/PostStepRegistry.cpp
+++ b/thirdparty/assimp/code/Common/PostStepRegistry.cpp
@@ -48,89 +48,93 @@ directly (unless you are adding new steps), instead use the
corresponding preprocessor flag to selectively disable steps.
*/
-#include "ProcessHelper.h"
+#include "PostProcessing/ProcessHelper.h"
#ifndef ASSIMP_BUILD_NO_CALCTANGENTS_PROCESS
-# include "CalcTangentsProcess.h"
+# include "PostProcessing/CalcTangentsProcess.h"
#endif
#ifndef ASSIMP_BUILD_NO_JOINVERTICES_PROCESS
-# include "JoinVerticesProcess.h"
+# include "PostProcessing/JoinVerticesProcess.h"
#endif
#if !(defined ASSIMP_BUILD_NO_MAKELEFTHANDED_PROCESS && defined ASSIMP_BUILD_NO_FLIPUVS_PROCESS && defined ASSIMP_BUILD_NO_FLIPWINDINGORDER_PROCESS)
-# include "ConvertToLHProcess.h"
+# include "PostProcessing/ConvertToLHProcess.h"
#endif
#ifndef ASSIMP_BUILD_NO_TRIANGULATE_PROCESS
-# include "TriangulateProcess.h"
+# include "PostProcessing/TriangulateProcess.h"
#endif
#ifndef ASSIMP_BUILD_NO_DROPFACENORMALS_PROCESS
-# include "DropFaceNormalsProcess.h"
+# include "PostProcessing/DropFaceNormalsProcess.h"
#endif
#ifndef ASSIMP_BUILD_NO_GENFACENORMALS_PROCESS
-# include "GenFaceNormalsProcess.h"
+# include "PostProcessing/GenFaceNormalsProcess.h"
#endif
#ifndef ASSIMP_BUILD_NO_GENVERTEXNORMALS_PROCESS
-# include "GenVertexNormalsProcess.h"
+# include "PostProcessing/GenVertexNormalsProcess.h"
#endif
#ifndef ASSIMP_BUILD_NO_REMOVEVC_PROCESS
-# include "RemoveVCProcess.h"
+# include "PostProcessing/RemoveVCProcess.h"
#endif
#ifndef ASSIMP_BUILD_NO_SPLITLARGEMESHES_PROCESS
-# include "SplitLargeMeshes.h"
+# include "PostProcessing/SplitLargeMeshes.h"
#endif
#ifndef ASSIMP_BUILD_NO_PRETRANSFORMVERTICES_PROCESS
-# include "PretransformVertices.h"
+# include "PostProcessing/PretransformVertices.h"
#endif
#ifndef ASSIMP_BUILD_NO_LIMITBONEWEIGHTS_PROCESS
-# include "LimitBoneWeightsProcess.h"
+# include "PostProcessing/LimitBoneWeightsProcess.h"
#endif
#ifndef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
-# include "ValidateDataStructure.h"
+# include "PostProcessing/ValidateDataStructure.h"
#endif
#ifndef ASSIMP_BUILD_NO_IMPROVECACHELOCALITY_PROCESS
-# include "ImproveCacheLocality.h"
+# include "PostProcessing/ImproveCacheLocality.h"
#endif
#ifndef ASSIMP_BUILD_NO_FIXINFACINGNORMALS_PROCESS
-# include "FixNormalsStep.h"
+# include "PostProcessing/FixNormalsStep.h"
#endif
#ifndef ASSIMP_BUILD_NO_REMOVE_REDUNDANTMATERIALS_PROCESS
-# include "RemoveRedundantMaterials.h"
+# include "PostProcessing/RemoveRedundantMaterials.h"
#endif
#if (!defined ASSIMP_BUILD_NO_EMBEDTEXTURES_PROCESS)
-# include "EmbedTexturesProcess.h"
+# include "PostProcessing/EmbedTexturesProcess.h"
#endif
#ifndef ASSIMP_BUILD_NO_FINDINVALIDDATA_PROCESS
-# include "FindInvalidDataProcess.h"
+# include "PostProcessing/FindInvalidDataProcess.h"
#endif
#ifndef ASSIMP_BUILD_NO_FINDDEGENERATES_PROCESS
-# include "FindDegenerates.h"
+# include "PostProcessing/FindDegenerates.h"
#endif
#ifndef ASSIMP_BUILD_NO_SORTBYPTYPE_PROCESS
-# include "SortByPTypeProcess.h"
+# include "PostProcessing/SortByPTypeProcess.h"
#endif
#ifndef ASSIMP_BUILD_NO_GENUVCOORDS_PROCESS
-# include "ComputeUVMappingProcess.h"
+# include "PostProcessing/ComputeUVMappingProcess.h"
#endif
#ifndef ASSIMP_BUILD_NO_TRANSFORMTEXCOORDS_PROCESS
-# include "TextureTransform.h"
+# include "PostProcessing/TextureTransform.h"
#endif
#ifndef ASSIMP_BUILD_NO_FINDINSTANCES_PROCESS
-# include "FindInstancesProcess.h"
+# include "PostProcessing/FindInstancesProcess.h"
#endif
#ifndef ASSIMP_BUILD_NO_OPTIMIZEMESHES_PROCESS
-# include "OptimizeMeshes.h"
+# include "PostProcessing/OptimizeMeshes.h"
#endif
#ifndef ASSIMP_BUILD_NO_OPTIMIZEGRAPH_PROCESS
-# include "OptimizeGraph.h"
+# include "PostProcessing/OptimizeGraph.h"
#endif
#ifndef ASSIMP_BUILD_NO_SPLITBYBONECOUNT_PROCESS
-# include "SplitByBoneCountProcess.h"
+# include "Common/SplitByBoneCountProcess.h"
#endif
#ifndef ASSIMP_BUILD_NO_DEBONE_PROCESS
-# include "DeboneProcess.h"
+# include "PostProcessing/DeboneProcess.h"
#endif
#if (!defined ASSIMP_BUILD_NO_GLOBALSCALE_PROCESS)
-# include "ScaleProcess.h"
+# include "PostProcessing/ScaleProcess.h"
#endif
+#if (!defined ASSIMP_BUILD_NO_GENBOUNDINGBOXES_PROCESS)
+# include "PostProcessing/GenBoundingBoxesProcess.h"
+#endif
+
namespace Assimp {
@@ -246,6 +250,9 @@ void GetPostProcessingStepInstanceList(std::vector< BaseProcess* >& out)
#if (!defined ASSIMP_BUILD_NO_IMPROVECACHELOCALITY_PROCESS)
out.push_back( new ImproveCacheLocalityProcess());
#endif
+#if (!defined ASSIMP_BUILD_NO_GENBOUNDINGBOXES_PROCESS)
+ out.push_back(new GenBoundingBoxesProcess);
+#endif
}
}
diff --git a/thirdparty/assimp/code/RemoveComments.cpp b/thirdparty/assimp/code/Common/RemoveComments.cpp
index 91700a7699..91700a7699 100644
--- a/thirdparty/assimp/code/RemoveComments.cpp
+++ b/thirdparty/assimp/code/Common/RemoveComments.cpp
diff --git a/thirdparty/assimp/code/SGSpatialSort.cpp b/thirdparty/assimp/code/Common/SGSpatialSort.cpp
index 120070b0aa..120070b0aa 100644
--- a/thirdparty/assimp/code/SGSpatialSort.cpp
+++ b/thirdparty/assimp/code/Common/SGSpatialSort.cpp
diff --git a/thirdparty/assimp/code/SceneCombiner.cpp b/thirdparty/assimp/code/Common/SceneCombiner.cpp
index e445bd7434..e445bd7434 100644
--- a/thirdparty/assimp/code/SceneCombiner.cpp
+++ b/thirdparty/assimp/code/Common/SceneCombiner.cpp
diff --git a/thirdparty/assimp/code/ScenePreprocessor.cpp b/thirdparty/assimp/code/Common/ScenePreprocessor.cpp
index 432a3d7666..432a3d7666 100644
--- a/thirdparty/assimp/code/ScenePreprocessor.cpp
+++ b/thirdparty/assimp/code/Common/ScenePreprocessor.cpp
diff --git a/thirdparty/assimp/code/ScenePreprocessor.h b/thirdparty/assimp/code/Common/ScenePreprocessor.h
index 3f4c8d7c3f..3f4c8d7c3f 100644
--- a/thirdparty/assimp/code/ScenePreprocessor.h
+++ b/thirdparty/assimp/code/Common/ScenePreprocessor.h
diff --git a/thirdparty/assimp/code/ScenePrivate.h b/thirdparty/assimp/code/Common/ScenePrivate.h
index f336aafc9a..f336aafc9a 100644
--- a/thirdparty/assimp/code/ScenePrivate.h
+++ b/thirdparty/assimp/code/Common/ScenePrivate.h
diff --git a/thirdparty/assimp/code/SkeletonMeshBuilder.cpp b/thirdparty/assimp/code/Common/SkeletonMeshBuilder.cpp
index 06cfe034e9..06cfe034e9 100644
--- a/thirdparty/assimp/code/SkeletonMeshBuilder.cpp
+++ b/thirdparty/assimp/code/Common/SkeletonMeshBuilder.cpp
diff --git a/thirdparty/assimp/code/SpatialSort.cpp b/thirdparty/assimp/code/Common/SpatialSort.cpp
index a4f3a4e4b8..a4f3a4e4b8 100644
--- a/thirdparty/assimp/code/SpatialSort.cpp
+++ b/thirdparty/assimp/code/Common/SpatialSort.cpp
diff --git a/thirdparty/assimp/code/SplitByBoneCountProcess.cpp b/thirdparty/assimp/code/Common/SplitByBoneCountProcess.cpp
index 2ef66a9afc..2ef66a9afc 100644
--- a/thirdparty/assimp/code/SplitByBoneCountProcess.cpp
+++ b/thirdparty/assimp/code/Common/SplitByBoneCountProcess.cpp
diff --git a/thirdparty/assimp/code/SplitByBoneCountProcess.h b/thirdparty/assimp/code/Common/SplitByBoneCountProcess.h
index 6c904a9df4..6c904a9df4 100644
--- a/thirdparty/assimp/code/SplitByBoneCountProcess.h
+++ b/thirdparty/assimp/code/Common/SplitByBoneCountProcess.h
diff --git a/thirdparty/assimp/code/StandardShapes.cpp b/thirdparty/assimp/code/Common/StandardShapes.cpp
index 2e5100130f..2e5100130f 100644
--- a/thirdparty/assimp/code/StandardShapes.cpp
+++ b/thirdparty/assimp/code/Common/StandardShapes.cpp
diff --git a/thirdparty/assimp/code/StdOStreamLogStream.h b/thirdparty/assimp/code/Common/StdOStreamLogStream.h
index 893e261a2b..893e261a2b 100644
--- a/thirdparty/assimp/code/StdOStreamLogStream.h
+++ b/thirdparty/assimp/code/Common/StdOStreamLogStream.h
diff --git a/thirdparty/assimp/code/Subdivision.cpp b/thirdparty/assimp/code/Common/Subdivision.cpp
index 19db223a55..60c54939f5 100644
--- a/thirdparty/assimp/code/Subdivision.cpp
+++ b/thirdparty/assimp/code/Common/Subdivision.cpp
@@ -43,9 +43,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/Subdivision.h>
#include <assimp/SceneCombiner.h>
#include <assimp/SpatialSort.h>
-#include "ProcessHelper.h"
#include <assimp/Vertex.h>
#include <assimp/ai_assert.h>
+
+#include "PostProcessing/ProcessHelper.h"
+
#include <stdio.h>
using namespace Assimp;
@@ -56,8 +58,7 @@ void mydummy() {}
* implementation is basing on recursive refinement. Directly evaluating the result is also
* possible and much quicker, but it depends on lengthy matrix lookup tables. */
// ------------------------------------------------------------------------------------------------
-class CatmullClarkSubdivider : public Subdivider
-{
+class CatmullClarkSubdivider : public Subdivider {
public:
void Subdivide (aiMesh* mesh, aiMesh*& out, unsigned int num, bool discard_input);
void Subdivide (aiMesh** smesh, size_t nmesh,
diff --git a/thirdparty/assimp/code/TargetAnimation.cpp b/thirdparty/assimp/code/Common/TargetAnimation.cpp
index b8062499ff..b8062499ff 100644
--- a/thirdparty/assimp/code/TargetAnimation.cpp
+++ b/thirdparty/assimp/code/Common/TargetAnimation.cpp
diff --git a/thirdparty/assimp/code/TargetAnimation.h b/thirdparty/assimp/code/Common/TargetAnimation.h
index 91634ab5aa..91634ab5aa 100644
--- a/thirdparty/assimp/code/TargetAnimation.h
+++ b/thirdparty/assimp/code/Common/TargetAnimation.h
diff --git a/thirdparty/assimp/code/Version.cpp b/thirdparty/assimp/code/Common/Version.cpp
index 0381037ff1..cc94340ac8 100644
--- a/thirdparty/assimp/code/Version.cpp
+++ b/thirdparty/assimp/code/Common/Version.cpp
@@ -134,7 +134,7 @@ ASSIMP_API aiScene::aiScene()
, mCameras(nullptr)
, mMetaData(nullptr)
, mPrivate(new Assimp::ScenePrivateData()) {
- // empty
+ // empty
}
// ------------------------------------------------------------------------------------------------
diff --git a/thirdparty/assimp/code/VertexTriangleAdjacency.cpp b/thirdparty/assimp/code/Common/VertexTriangleAdjacency.cpp
index 7cfd1a3505..7cfd1a3505 100644
--- a/thirdparty/assimp/code/VertexTriangleAdjacency.cpp
+++ b/thirdparty/assimp/code/Common/VertexTriangleAdjacency.cpp
diff --git a/thirdparty/assimp/code/VertexTriangleAdjacency.h b/thirdparty/assimp/code/Common/VertexTriangleAdjacency.h
index f3be47612d..f3be47612d 100644
--- a/thirdparty/assimp/code/VertexTriangleAdjacency.h
+++ b/thirdparty/assimp/code/Common/VertexTriangleAdjacency.h
diff --git a/thirdparty/assimp/code/Win32DebugLogStream.h b/thirdparty/assimp/code/Common/Win32DebugLogStream.h
index a6063a261e..a6063a261e 100644
--- a/thirdparty/assimp/code/Win32DebugLogStream.h
+++ b/thirdparty/assimp/code/Common/Win32DebugLogStream.h
diff --git a/thirdparty/assimp/code/Common/assbin_chunks.h b/thirdparty/assimp/code/Common/assbin_chunks.h
new file mode 100644
index 0000000000..15e4af5e7d
--- /dev/null
+++ b/thirdparty/assimp/code/Common/assbin_chunks.h
@@ -0,0 +1,196 @@
+#ifndef INCLUDED_ASSBIN_CHUNKS_H
+#define INCLUDED_ASSBIN_CHUNKS_H
+
+#define ASSBIN_VERSION_MAJOR 1
+#define ASSBIN_VERSION_MINOR 0
+
+/**
+@page assfile .ASS File formats
+
+@section over Overview
+Assimp provides its own interchange format, which is intended to applications which need
+to serialize 3D-models and to reload them quickly. Assimp's file formats are designed to
+be read by Assimp itself. They encode additional information needed by Assimp to optimize
+its postprocessing pipeline. If you once apply specific steps to a scene, then save it
+and reread it from an ASS format using the same post processing settings, they won't
+be executed again.
+
+The format comes in two flavours: XML and binary - both of them hold a complete dump of
+the 'aiScene' data structure returned by the APIs. The focus for the binary format
+(<tt>.assbin</tt>) is fast loading. Optional deflate compression helps reduce file size. The XML
+flavour, <tt>.assxml</tt> or simply .xml, is just a plain-to-xml conversion of aiScene.
+
+ASSBIN is Assimp's binary interchange format. assimp_cmd (<tt>&lt;root&gt;/tools/assimp_cmd</tt>) is able to
+write it and the core library provides a loader for it.
+
+@section assxml XML File format
+
+The format is pretty much self-explanatory due to its similarity to the in-memory aiScene structure.
+With few exceptions, C structures are wrapped in XML elements.
+
+The DTD for ASSXML can be found in <tt>&lt;root&gt;/doc/AssXML_Scheme.xml</tt>. Or have look
+at the output files generated by assimp_cmd.
+
+@section assbin Binary file format
+
+The ASSBIN file format is composed of chunks to represent the hierarchical aiScene data structure.
+This makes the format extensible and allows backward-compatibility with future data structure
+versions. The <tt>&lt;root&gt;/code/assbin_chunks.h</tt> header contains some magic constants
+for use by stand-alone ASSBIN loaders. Also, Assimp's own file writer can be found
+in <tt>&lt;root&gt;/tools/assimp_cmd/WriteDumb.cpp</tt> (yes, the 'b' is no typo ...).
+
+@verbatim
+
+-------------------------------------------------------------------------------
+1. File structure:
+-------------------------------------------------------------------------------
+
+----------------------
+| Header (512 bytes) |
+----------------------
+| Variable chunks |
+----------------------
+
+-------------------------------------------------------------------------------
+2. Definitions:
+-------------------------------------------------------------------------------
+
+integer is four bytes wide, stored in little-endian byte order.
+short is two bytes wide, stored in little-endian byte order.
+byte is a single byte.
+string is an integer n followed by n UTF-8 characters, not terminated by zero
+float is an IEEE 754 single-precision floating-point value
+double is an IEEE 754 double-precision floating-point value
+t[n] is an array of n elements of type t
+
+-------------------------------------------------------------------------------
+2. Header:
+-------------------------------------------------------------------------------
+
+byte[44] Magic identification string for ASSBIN files.
+ 'ASSIMP.binary'
+
+integer Major version of the Assimp library which wrote the file
+integer Minor version of the Assimp library which wrote the file
+ match these against ASSBIN_VERSION_MAJOR and ASSBIN_VERSION_MINOR
+
+integer SVN revision of the Assimp library (intended for our internal
+ debugging - if you write Ass files from your own APPs, set this value to 0.
+integer Assimp compile flags
+
+short 0 for normal files, 1 for shortened dumps for regression tests
+ these should have the file extension assbin.regress
+
+short 1 if the data after the header is compressed with the DEFLATE algorithm,
+ 0 for uncompressed files.
+ For compressed files, the first integer after the header is
+ always the uncompressed data size
+
+byte[256] Zero-terminated source file name, UTF-8
+byte[128] Zero-terminated command line parameters passed to assimp_cmd, UTF-8
+
+byte[64] Reserved for future use
+---> Total length: 512 bytes
+
+-------------------------------------------------------------------------------
+3. Chunks:
+-------------------------------------------------------------------------------
+
+integer Magic chunk ID (ASSBIN_CHUNK_XXX)
+integer Chunk data length, in bytes
+ (unknown chunks are possible, a good reader skips over them)
+ (chunk-data-length does not include the first two integers)
+
+byte[n] chunk-data-length bytes of data, depending on the chunk type
+
+Chunks can contain nested chunks. Nested chunks are ALWAYS at the end of the chunk,
+their size is included in chunk-data-length.
+
+The chunk layout for all ASSIMP data structures is derived from their C declarations.
+The general 'rule' to get from Assimp headers to the serialized layout is:
+
+ 1. POD members (i.e. aiMesh::mPrimitiveTypes, aiMesh::mNumVertices),
+ in order of declaration.
+
+ 2. Array-members (aiMesh::mFaces, aiMesh::mVertices, aiBone::mWeights),
+ in order of declaration.
+
+ 2. Object array members (i.e aiMesh::mBones, aiScene::mMeshes) are stored in
+ subchunks directly following the data written in 1.) and 2.)
+
+
+ Of course, there are some exceptions to this general order:
+
+[[aiScene]]
+
+ - The root node holding the scene structure is naturally stored in
+ a ASSBIN_CHUNK_AINODE subchunk following 1.) and 2.) (which is
+ empty for aiScene).
+
+[[aiMesh]]
+
+ - mTextureCoords and mNumUVComponents are serialized as follows:
+
+ [number of used uv channels times]
+ integer mNumUVComponents[n]
+ float mTextureCoords[n][3]
+
+ -> more than AI_MAX_TEXCOORD_CHANNELS can be stored. This allows Assimp
+ builds with different settings for AI_MAX_TEXCOORD_CHANNELS to exchange
+ data.
+ -> the on-disk format always uses 3 floats to write UV coordinates.
+ If mNumUVComponents[0] is 1, the corresponding mTextureCoords array
+ consists of 3 floats.
+
+ - The array member block of aiMesh is prefixed with an integer that specifies
+ the kinds of vertex components actually present in the mesh. This is a
+ bitwise combination of the ASSBIN_MESH_HAS_xxx constants.
+
+[[aiFace]]
+
+ - mNumIndices is stored as short
+ - mIndices are written as short, if aiMesh::mNumVertices<65536
+
+[[aiNode]]
+
+ - mParent is omitted
+
+[[aiLight]]
+
+ - mAttenuationXXX not written if aiLight::mType == aiLightSource_DIRECTIONAL
+ - mAngleXXX not written if aiLight::mType != aiLightSource_SPOT
+
+[[aiMaterial]]
+
+ - mNumAllocated is omitted, for obvious reasons :-)
+
+
+ @endverbatim*/
+
+
+#define ASSBIN_HEADER_LENGTH 512
+
+// these are the magic chunk identifiers for the binary ASS file format
+#define ASSBIN_CHUNK_AICAMERA 0x1234
+#define ASSBIN_CHUNK_AILIGHT 0x1235
+#define ASSBIN_CHUNK_AITEXTURE 0x1236
+#define ASSBIN_CHUNK_AIMESH 0x1237
+#define ASSBIN_CHUNK_AINODEANIM 0x1238
+#define ASSBIN_CHUNK_AISCENE 0x1239
+#define ASSBIN_CHUNK_AIBONE 0x123a
+#define ASSBIN_CHUNK_AIANIMATION 0x123b
+#define ASSBIN_CHUNK_AINODE 0x123c
+#define ASSBIN_CHUNK_AIMATERIAL 0x123d
+#define ASSBIN_CHUNK_AIMATERIALPROPERTY 0x123e
+
+#define ASSBIN_MESH_HAS_POSITIONS 0x1
+#define ASSBIN_MESH_HAS_NORMALS 0x2
+#define ASSBIN_MESH_HAS_TANGENTS_AND_BITANGENTS 0x4
+#define ASSBIN_MESH_HAS_TEXCOORD_BASE 0x100
+#define ASSBIN_MESH_HAS_COLOR_BASE 0x10000
+
+#define ASSBIN_MESH_HAS_TEXCOORD(n) (ASSBIN_MESH_HAS_TEXCOORD_BASE << n)
+#define ASSBIN_MESH_HAS_COLOR(n) (ASSBIN_MESH_HAS_COLOR_BASE << n)
+
+
+#endif // INCLUDED_ASSBIN_CHUNKS_H
diff --git a/thirdparty/assimp/code/scene.cpp b/thirdparty/assimp/code/Common/scene.cpp
index 2acb348d81..2acb348d81 100644
--- a/thirdparty/assimp/code/scene.cpp
+++ b/thirdparty/assimp/code/Common/scene.cpp
diff --git a/thirdparty/assimp/code/simd.cpp b/thirdparty/assimp/code/Common/simd.cpp
index 04615f408e..04615f408e 100644
--- a/thirdparty/assimp/code/simd.cpp
+++ b/thirdparty/assimp/code/Common/simd.cpp
diff --git a/thirdparty/assimp/code/simd.h b/thirdparty/assimp/code/Common/simd.h
index 3eecdd4581..3eecdd4581 100644
--- a/thirdparty/assimp/code/simd.h
+++ b/thirdparty/assimp/code/Common/simd.h
diff --git a/thirdparty/assimp/code/FBXAnimation.cpp b/thirdparty/assimp/code/FBX/FBXAnimation.cpp
index 874914431b..874914431b 100644
--- a/thirdparty/assimp/code/FBXAnimation.cpp
+++ b/thirdparty/assimp/code/FBX/FBXAnimation.cpp
diff --git a/thirdparty/assimp/code/FBXBinaryTokenizer.cpp b/thirdparty/assimp/code/FBX/FBXBinaryTokenizer.cpp
index 7138df4315..a4a2bc8e79 100644
--- a/thirdparty/assimp/code/FBXBinaryTokenizer.cpp
+++ b/thirdparty/assimp/code/FBX/FBXBinaryTokenizer.cpp
@@ -98,7 +98,7 @@ namespace FBX {
// return (flags & to_check) != 0;
//}
// ------------------------------------------------------------------------------------------------
-Token::Token(const char* sbegin, const char* send, TokenType type, unsigned int offset)
+Token::Token(const char* sbegin, const char* send, TokenType type, size_t offset)
:
#ifdef DEBUG
contents(sbegin, static_cast<size_t>(send-sbegin)),
@@ -122,18 +122,18 @@ namespace {
// ------------------------------------------------------------------------------------------------
// signal tokenization error, this is always unrecoverable. Throws DeadlyImportError.
-AI_WONT_RETURN void TokenizeError(const std::string& message, unsigned int offset) AI_WONT_RETURN_SUFFIX;
-AI_WONT_RETURN void TokenizeError(const std::string& message, unsigned int offset)
+AI_WONT_RETURN void TokenizeError(const std::string& message, size_t offset) AI_WONT_RETURN_SUFFIX;
+AI_WONT_RETURN void TokenizeError(const std::string& message, size_t offset)
{
throw DeadlyImportError(Util::AddOffset("FBX-Tokenize",message,offset));
}
// ------------------------------------------------------------------------------------------------
-uint32_t Offset(const char* begin, const char* cursor) {
+size_t Offset(const char* begin, const char* cursor) {
ai_assert(begin <= cursor);
- return static_cast<unsigned int>(cursor - begin);
+ return cursor - begin;
}
// ------------------------------------------------------------------------------------------------
@@ -424,7 +424,7 @@ bool ReadScope(TokenList& output_tokens, const char* input, const char*& cursor,
// ------------------------------------------------------------------------------------------------
// TODO: Test FBX Binary files newer than the 7500 version to check if the 64 bits address behaviour is consistent
-void TokenizeBinary(TokenList& output_tokens, const char* input, unsigned int length)
+void TokenizeBinary(TokenList& output_tokens, const char* input, size_t length)
{
ai_assert(input);
diff --git a/thirdparty/assimp/code/FBXCommon.h b/thirdparty/assimp/code/FBX/FBXCommon.h
index fcb20a5cad..e516449130 100644
--- a/thirdparty/assimp/code/FBXCommon.h
+++ b/thirdparty/assimp/code/FBX/FBXCommon.h
@@ -47,7 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef ASSIMP_BUILD_NO_FBX_EXPORTER
-
+namespace Assimp {
namespace FBX
{
const std::string NULL_RECORD = { // 13 null bytes
@@ -80,7 +80,7 @@ namespace FBX
TransformInheritance_MAX // end-of-enum sentinel
};
}
-
+}
#endif // ASSIMP_BUILD_NO_FBX_EXPORTER
#endif // AI_FBXCOMMON_H_INC
diff --git a/thirdparty/assimp/code/FBXCompileConfig.h b/thirdparty/assimp/code/FBX/FBXCompileConfig.h
index 3a3841fa5b..3a3841fa5b 100644
--- a/thirdparty/assimp/code/FBXCompileConfig.h
+++ b/thirdparty/assimp/code/FBX/FBXCompileConfig.h
diff --git a/thirdparty/assimp/code/FBXConverter.cpp b/thirdparty/assimp/code/FBX/FBXConverter.cpp
index 09ae06a64f..9f940d3226 100644
--- a/thirdparty/assimp/code/FBXConverter.cpp
+++ b/thirdparty/assimp/code/FBX/FBXConverter.cpp
@@ -67,6 +67,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <sstream>
#include <iomanip>
+
namespace Assimp {
namespace FBX {
@@ -76,20 +77,21 @@ namespace Assimp {
#define CONVERT_FBX_TIME(time) static_cast<double>(time) / 46186158000L
- FBXConverter::FBXConverter(aiScene* out, const Document& doc)
- : defaultMaterialIndex()
- , lights()
- , cameras()
- , textures()
- , materials_converted()
- , textures_converted()
- , meshes_converted()
- , node_anim_chain_bits()
- , mNodeNameInstances()
- , mNodeNames()
- , anim_fps()
- , out(out)
- , doc(doc) {
+ FBXConverter::FBXConverter(aiScene* out, const Document& doc, bool removeEmptyBones, FbxUnit unit )
+ : defaultMaterialIndex()
+ , lights()
+ , cameras()
+ , textures()
+ , materials_converted()
+ , textures_converted()
+ , meshes_converted()
+ , node_anim_chain_bits()
+ , mNodeNames()
+ , anim_fps()
+ , out(out)
+ , doc(doc)
+ , mRemoveEmptyBones( removeEmptyBones )
+ , mCurrentUnit(FbxUnit::cm) {
// animations need to be converted first since this will
// populate the node_anim_chain_bits map, which is needed
// to determine which nodes need to be generated.
@@ -117,6 +119,7 @@ namespace Assimp {
ConvertGlobalSettings();
TransferDataToScene();
+ ConvertToUnitScale(unit);
// if we didn't read any meshes set the AI_SCENE_FLAGS_INCOMPLETE
// to make sure the scene passes assimp's validation. FBX files
@@ -138,12 +141,46 @@ namespace Assimp {
void FBXConverter::ConvertRootNode() {
out->mRootNode = new aiNode();
- out->mRootNode->mName.Set("RootNode");
+ std::string unique_name;
+ GetUniqueName("RootNode", unique_name);
+ out->mRootNode->mName.Set(unique_name);
// root has ID 0
ConvertNodes(0L, *out->mRootNode);
}
+ static std::string getAncestorBaseName(const aiNode* node)
+ {
+ const char* nodeName = nullptr;
+ size_t length = 0;
+ while (node && (!nodeName || length == 0))
+ {
+ nodeName = node->mName.C_Str();
+ length = node->mName.length;
+ node = node->mParent;
+ }
+
+ if (!nodeName || length == 0)
+ {
+ return {};
+ }
+ // could be std::string_view if c++17 available
+ return std::string(nodeName, length);
+ }
+
+ // Make unique name
+ std::string FBXConverter::MakeUniqueNodeName(const Model* const model, const aiNode& parent)
+ {
+ std::string original_name = FixNodeName(model->Name());
+ if (original_name.empty())
+ {
+ original_name = getAncestorBaseName(&parent);
+ }
+ std::string unique_name;
+ GetUniqueName(original_name, unique_name);
+ return unique_name;
+ }
+
void FBXConverter::ConvertNodes(uint64_t id, aiNode& parent, const aiMatrix4x4& parent_transform) {
const std::vector<const Connection*>& conns = doc.GetConnectionsByDestinationSequenced(id, "Model");
@@ -175,35 +212,18 @@ namespace Assimp {
aiMatrix4x4 new_abs_transform = parent_transform;
+ std::string unique_name = MakeUniqueNodeName(model, parent);
+
// even though there is only a single input node, the design of
// assimp (or rather: the complicated transformation chain that
// is employed by fbx) means that we may need multiple aiNode's
// to represent a fbx node's transformation.
- GenerateTransformationNodeChain(*model, nodes_chain, post_nodes_chain);
+ const bool need_additional_node = GenerateTransformationNodeChain(*model, unique_name, nodes_chain, post_nodes_chain);
ai_assert(nodes_chain.size());
- std::string original_name = FixNodeName(model->Name());
-
- // check if any of the nodes in the chain has the name the fbx node
- // is supposed to have. If there is none, add another node to
- // preserve the name - people might have scripts etc. that rely
- // on specific node names.
- aiNode* name_carrier = NULL;
- for (aiNode* prenode : nodes_chain) {
- if (!strcmp(prenode->mName.C_Str(), original_name.c_str())) {
- name_carrier = prenode;
- break;
- }
- }
-
- if (!name_carrier) {
- std::string old_original_name = original_name;
- GetUniqueName(old_original_name, original_name);
- nodes_chain.push_back(new aiNode(original_name));
- }
- else {
- original_name = nodes_chain.back()->mName.C_Str();
+ if (need_additional_node) {
+ nodes_chain.push_back(new aiNode(unique_name));
}
//setup metadata on newest node
@@ -265,11 +285,11 @@ namespace Assimp {
ConvertNodes(model->ID(), *last_parent, new_abs_transform);
if (doc.Settings().readLights) {
- ConvertLights(*model, original_name);
+ ConvertLights(*model, unique_name);
}
if (doc.Settings().readCameras) {
- ConvertCameras(*model, original_name);
+ ConvertCameras(*model, unique_name);
}
nodes.push_back(nodes_chain.front());
@@ -387,6 +407,7 @@ namespace Assimp {
break;
default:
ai_assert(false);
+ break;
}
}
@@ -399,11 +420,6 @@ namespace Assimp {
out_camera->mAspect = cam.AspectWidth() / cam.AspectHeight();
- //cameras are defined along positive x direction
- /*out_camera->mPosition = cam.Position();
- out_camera->mLookAt = (cam.InterestPosition() - out_camera->mPosition).Normalize();
- out_camera->mUp = cam.UpVector();*/
-
out_camera->mPosition = aiVector3D(0.0f);
out_camera->mLookAt = aiVector3D(1.0f, 0.0f, 0.0f);
out_camera->mUp = aiVector3D(0.0f, 1.0f, 0.0f);
@@ -421,21 +437,16 @@ namespace Assimp {
void FBXConverter::GetUniqueName(const std::string &name, std::string &uniqueName)
{
uniqueName = name;
- int i = 0;
- auto it = mNodeNameInstances.find(name); // duplicate node name instance count
- if (it != mNodeNameInstances.end())
+ auto it_pair = mNodeNames.insert({ name, 0 }); // duplicate node name instance count
+ unsigned int& i = it_pair.first->second;
+ while (!it_pair.second)
{
- i = it->second;
- while (mNodeNames.find(uniqueName) != mNodeNames.end())
- {
- i++;
- std::stringstream ext;
- ext << name << std::setfill('0') << std::setw(3) << i;
- uniqueName = ext.str();
- }
+ i++;
+ std::ostringstream ext;
+ ext << name << std::setfill('0') << std::setw(3) << i;
+ uniqueName = ext.str();
+ it_pair = mNodeNames.insert({ uniqueName, 0 });
}
- mNodeNameInstances[name] = i;
- mNodeNames.insert(uniqueName);
}
const char* FBXConverter::NameTransformationComp(TransformationComp comp) {
@@ -651,8 +662,7 @@ namespace Assimp {
if ((v - all_ones).SquareLength() > zero_epsilon) {
return true;
}
- }
- else if (ok) {
+ } else if (ok) {
if (v.SquareLength() > zero_epsilon) {
return true;
}
@@ -667,7 +677,7 @@ namespace Assimp {
return name + std::string(MAGIC_NODE_TAG) + "_" + NameTransformationComp(comp);
}
- void FBXConverter::GenerateTransformationNodeChain(const Model& model, std::vector<aiNode*>& output_nodes,
+ bool FBXConverter::GenerateTransformationNodeChain(const Model& model, const std::string& name, std::vector<aiNode*>& output_nodes,
std::vector<aiNode*>& post_output_nodes) {
const PropertyTable& props = model.Props();
const Model::RotOrder rot = model.RotationOrder();
@@ -782,8 +792,6 @@ namespace Assimp {
// not be guaranteed.
ai_assert(NeedsComplexTransformationChain(model) == is_complex);
- std::string name = FixNodeName(model.Name());
-
// now, if we have more than just Translation, Scaling and Rotation,
// we need to generate a full node chain to accommodate for assimp's
// lack to express pivots and offsets.
@@ -825,20 +833,20 @@ namespace Assimp {
}
ai_assert(output_nodes.size());
- return;
+ return true;
}
// else, we can just multiply the matrices together
aiNode* nd = new aiNode();
output_nodes.push_back(nd);
- std::string uniqueName;
- GetUniqueName(name, uniqueName);
- nd->mName.Set(uniqueName);
+ // name passed to the method is already unique
+ nd->mName.Set(name);
for (const auto &transform : chain) {
nd->mTransformation = nd->mTransformation * transform;
}
+ return false;
}
void FBXConverter::SetupNodeMetadata(const Model& model, aiNode& nd)
@@ -977,7 +985,9 @@ namespace Assimp {
unsigned int epcount = 0;
for (unsigned i = 0; i < indices.size(); i++)
{
- if (indices[i] < 0) epcount++;
+ if (indices[i] < 0) {
+ epcount++;
+ }
}
unsigned int pcount = static_cast<unsigned int>( indices.size() );
unsigned int scount = out_mesh->mNumFaces = pcount - epcount;
@@ -1237,10 +1247,10 @@ namespace Assimp {
ai_assert(count_faces);
ai_assert(count_vertices);
- // mapping from output indices to DOM indexing, needed to resolve weights
+ // mapping from output indices to DOM indexing, needed to resolve weights or blendshapes
std::vector<unsigned int> reverseMapping;
-
- if (process_weights) {
+ std::map<unsigned int, unsigned int> translateIndexMap;
+ if (process_weights || mesh.GetBlendShapes().size() > 0) {
reverseMapping.resize(count_vertices);
}
@@ -1347,6 +1357,7 @@ namespace Assimp {
if (reverseMapping.size()) {
reverseMapping[cursor] = in_cursor;
+ translateIndexMap[in_cursor] = cursor;
}
out_mesh->mVertices[cursor] = vertices[in_cursor];
@@ -1378,6 +1389,50 @@ namespace Assimp {
ConvertWeights(out_mesh, model, mesh, node_global_transform, index, &reverseMapping);
}
+ std::vector<aiAnimMesh*> animMeshes;
+ for (const BlendShape* blendShape : mesh.GetBlendShapes()) {
+ for (const BlendShapeChannel* blendShapeChannel : blendShape->BlendShapeChannels()) {
+ const std::vector<const ShapeGeometry*>& shapeGeometries = blendShapeChannel->GetShapeGeometries();
+ for (size_t i = 0; i < shapeGeometries.size(); i++) {
+ aiAnimMesh* animMesh = aiCreateAnimMesh(out_mesh);
+ const ShapeGeometry* shapeGeometry = shapeGeometries.at(i);
+ const std::vector<aiVector3D>& vertices = shapeGeometry->GetVertices();
+ const std::vector<aiVector3D>& normals = shapeGeometry->GetNormals();
+ const std::vector<unsigned int>& indices = shapeGeometry->GetIndices();
+ animMesh->mName.Set(FixAnimMeshName(shapeGeometry->Name()));
+ for (size_t j = 0; j < indices.size(); j++) {
+ unsigned int index = indices.at(j);
+ aiVector3D vertex = vertices.at(j);
+ aiVector3D normal = normals.at(j);
+ unsigned int count = 0;
+ const unsigned int* outIndices = mesh.ToOutputVertexIndex(index, count);
+ for (unsigned int k = 0; k < count; k++) {
+ unsigned int outIndex = outIndices[k];
+ if (translateIndexMap.find(outIndex) == translateIndexMap.end())
+ continue;
+ unsigned int index = translateIndexMap[outIndex];
+ animMesh->mVertices[index] += vertex;
+ if (animMesh->mNormals != nullptr) {
+ animMesh->mNormals[index] += normal;
+ animMesh->mNormals[index].NormalizeSafe();
+ }
+ }
+ }
+ animMesh->mWeight = shapeGeometries.size() > 1 ? blendShapeChannel->DeformPercent() / 100.0f : 1.0f;
+ animMeshes.push_back(animMesh);
+ }
+ }
+ }
+
+ const size_t numAnimMeshes = animMeshes.size();
+ if (numAnimMeshes > 0) {
+ out_mesh->mNumAnimMeshes = static_cast<unsigned int>(numAnimMeshes);
+ out_mesh->mAnimMeshes = new aiAnimMesh*[numAnimMeshes];
+ for (size_t i = 0; i < numAnimMeshes; i++) {
+ out_mesh->mAnimMeshes[i] = animMeshes.at(i);
+ }
+ }
+
return static_cast<unsigned int>(meshes.size() - 1);
}
@@ -1407,7 +1462,7 @@ namespace Assimp {
const WeightIndexArray& indices = cluster->GetIndices();
- if (indices.empty()) {
+ if (indices.empty() && mRemoveEmptyBones ) {
continue;
}
@@ -1439,13 +1494,11 @@ namespace Assimp {
if (index_out_indices.back() == no_index_sentinel) {
index_out_indices.back() = out_indices.size();
-
}
if (no_mat_check) {
out_indices.push_back(out_idx[i]);
- }
- else {
+ } else {
// this extra lookup is in O(logn), so the entire algorithm becomes O(nlogn)
const std::vector<unsigned int>::iterator it = std::lower_bound(
outputVertStartIndices->begin(),
@@ -1461,11 +1514,11 @@ namespace Assimp {
}
}
}
-
+
// if we found at least one, generate the output bones
// XXX this could be heavily simplified by collecting the bone
// data in a single step.
- if (ok) {
+ if (ok && mRemoveEmptyBones) {
ConvertCluster(bones, model, *cluster, out_indices, index_out_indices,
count_out_indices, node_global_transform);
}
@@ -1596,6 +1649,13 @@ namespace Assimp {
out_mat->AddProperty(&str, AI_MATKEY_NAME);
}
+ // Set the shading mode as best we can: The FBX specification only mentions Lambert and Phong, and only Phong is mentioned in Assimp's aiShadingMode enum.
+ if (material.GetShadingModel() == "phong")
+ {
+ aiShadingMode shadingMode = aiShadingMode_Phong;
+ out_mat->AddProperty<aiShadingMode>(&shadingMode, 1, AI_MATKEY_SHADING_MODEL);
+ }
+
// shading stuff and colors
SetShadingPropertiesCommon(out_mat, props);
SetShadingPropertiesRaw( out_mat, props, material.Textures(), mesh );
@@ -1621,7 +1681,7 @@ namespace Assimp {
out_tex->pcData = reinterpret_cast<aiTexel*>(const_cast<Video&>(video).RelinquishContent());
// try to extract a hint from the file extension
- const std::string& filename = video.FileName().empty() ? video.RelativeFilename() : video.FileName();
+ const std::string& filename = video.RelativeFilename().empty() ? video.FileName() : video.RelativeFilename();
std::string ext = BaseImporter::GetExtension(filename);
if (ext == "jpeg") {
@@ -1632,7 +1692,7 @@ namespace Assimp {
memcpy(out_tex->achFormatHint, ext.c_str(), ext.size());
}
- out_tex->mFilename.Set(video.FileName().c_str());
+ out_tex->mFilename.Set(filename.c_str());
return static_cast<unsigned int>(textures.size() - 1);
}
@@ -1678,9 +1738,8 @@ namespace Assimp {
}
void FBXConverter::TrySetTextureProperties(aiMaterial* out_mat, const TextureMap& textures,
- const std::string& propName,
- aiTextureType target, const MeshGeometry* const mesh)
- {
+ const std::string& propName,
+ aiTextureType target, const MeshGeometry* const mesh) {
TextureMap::const_iterator it = textures.find(propName);
if (it == textures.end()) {
return;
@@ -3407,8 +3466,9 @@ void FBXConverter::SetShadingPropertiesRaw(aiMaterial* out_mat, const PropertyTa
na->mNumScalingKeys = static_cast<unsigned int>(keys.size());
na->mScalingKeys = new aiVectorKey[keys.size()];
- if (keys.size() > 0)
+ if (keys.size() > 0) {
InterpolateKeys(na->mScalingKeys, keys, inputs, aiVector3D(1.0f, 1.0f, 1.0f), maxTime, minTime);
+ }
}
void FBXConverter::ConvertTranslationKeys(aiNodeAnim* na, const std::vector<const AnimationCurveNode*>& nodes,
@@ -3472,6 +3532,46 @@ void FBXConverter::SetShadingPropertiesRaw(aiMaterial* out_mat, const PropertyTa
out->mMetaData->Set(14, "CustomFrameRate", doc.GlobalSettings().CustomFrameRate());
}
+ void FBXConverter::ConvertToUnitScale( FbxUnit unit ) {
+ if (mCurrentUnit == unit) {
+ return;
+ }
+
+ ai_real scale = 1.0;
+ if (mCurrentUnit == FbxUnit::cm) {
+ if (unit == FbxUnit::m) {
+ scale = (ai_real)0.01;
+ } else if (unit == FbxUnit::km) {
+ scale = (ai_real)0.00001;
+ }
+ } else if (mCurrentUnit == FbxUnit::m) {
+ if (unit == FbxUnit::cm) {
+ scale = (ai_real)100.0;
+ } else if (unit == FbxUnit::km) {
+ scale = (ai_real)0.001;
+ }
+ } else if (mCurrentUnit == FbxUnit::km) {
+ if (unit == FbxUnit::cm) {
+ scale = (ai_real)100000.0;
+ } else if (unit == FbxUnit::m) {
+ scale = (ai_real)1000.0;
+ }
+ }
+
+ for (auto mesh : meshes) {
+ if (nullptr == mesh) {
+ continue;
+ }
+
+ if (mesh->HasPositions()) {
+ for (unsigned int i = 0; i < mesh->mNumVertices; ++i) {
+ aiVector3D &pos = mesh->mVertices[i];
+ pos *= scale;
+ }
+ }
+ }
+ }
+
void FBXConverter::TransferDataToScene()
{
ai_assert(!out->mMeshes);
@@ -3525,9 +3625,9 @@ void FBXConverter::SetShadingPropertiesRaw(aiMaterial* out_mat, const PropertyTa
}
// ------------------------------------------------------------------------------------------------
- void ConvertToAssimpScene(aiScene* out, const Document& doc)
+ void ConvertToAssimpScene(aiScene* out, const Document& doc, bool removeEmptyBones, FbxUnit unit)
{
- FBXConverter converter(out, doc);
+ FBXConverter converter(out, doc, removeEmptyBones, unit);
}
} // !FBX
diff --git a/thirdparty/assimp/code/FBXConverter.h b/thirdparty/assimp/code/FBX/FBXConverter.h
index 50637468b9..17a7bc56b7 100644
--- a/thirdparty/assimp/code/FBXConverter.h
+++ b/thirdparty/assimp/code/FBX/FBXConverter.h
@@ -52,6 +52,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "FBXUtil.h"
#include "FBXProperties.h"
#include "FBXImporter.h"
+
#include <assimp/anim.h>
#include <assimp/material.h>
#include <assimp/light.h>
@@ -76,12 +77,22 @@ namespace FBX {
class Document;
+enum class FbxUnit {
+ cm = 0,
+ m,
+ km,
+ NumUnits,
+
+ Undefined
+};
+
/**
* Convert a FBX #Document to #aiScene
* @param out Empty scene to be populated
- * @param doc Parsed FBX document
+ * @param doc Parsed FBX document
+ * @param removeEmptyBones Will remove bones, which do not have any references to vertices.
*/
-void ConvertToAssimpScene(aiScene* out, const Document& doc);
+void ConvertToAssimpScene(aiScene* out, const Document& doc, bool removeEmptyBones, FbxUnit unit);
/** Dummy class to encapsulate the conversion process */
class FBXConverter {
@@ -112,7 +123,7 @@ public:
};
public:
- FBXConverter(aiScene* out, const Document& doc);
+ FBXConverter(aiScene* out, const Document& doc, bool removeEmptyBones, FbxUnit unit);
~FBXConverter();
private:
@@ -145,6 +156,11 @@ private:
const char* NameTransformationComp(TransformationComp comp);
// ------------------------------------------------------------------------------------------------
+ // Returns an unique name for a node or traverses up a hierarchy until a non-empty name is found and
+ // then makes this name unique
+ std::string MakeUniqueNodeName(const Model* const model, const aiNode& parent);
+
+ // ------------------------------------------------------------------------------------------------
// note: this returns the REAL fbx property names
const char* NameTransformationCompProperty(TransformationComp comp);
@@ -167,7 +183,7 @@ private:
/**
* note: memory for output_nodes will be managed by the caller
*/
- void GenerateTransformationNodeChain(const Model& model, std::vector<aiNode*>& output_nodes, std::vector<aiNode*>& post_output_nodes);
+ bool GenerateTransformationNodeChain(const Model& model, const std::string& name, std::vector<aiNode*>& output_nodes, std::vector<aiNode*>& post_output_nodes);
// ------------------------------------------------------------------------------------------------
void SetupNodeMetadata(const Model& model, aiNode& nd);
@@ -415,6 +431,10 @@ private:
void ConvertGlobalSettings();
// ------------------------------------------------------------------------------------------------
+ // Will perform the conversion from a given unit to the requested unit.
+ void ConvertToUnitScale(FbxUnit unit);
+
+ // ------------------------------------------------------------------------------------------------
// copy generated meshes, animations, lights, cameras and textures to the output scene
void TransferDataToScene();
@@ -443,16 +463,17 @@ private:
NodeAnimBitMap node_anim_chain_bits;
// number of nodes with the same name
- using NodeAnimNameMap = std::unordered_map<std::string, unsigned int>;
- NodeAnimNameMap mNodeNameInstances;
-
- using NodeNameCache = std::unordered_set<std::string>;
+ using NodeNameCache = std::unordered_map<std::string, unsigned int>;
NodeNameCache mNodeNames;
double anim_fps;
aiScene* const out;
const FBX::Document& doc;
+
+ bool mRemoveEmptyBones;
+
+ FbxUnit mCurrentUnit;
};
}
diff --git a/thirdparty/assimp/code/FBXDeformer.cpp b/thirdparty/assimp/code/FBX/FBXDeformer.cpp
index 6927553450..6927553450 100644
--- a/thirdparty/assimp/code/FBXDeformer.cpp
+++ b/thirdparty/assimp/code/FBX/FBXDeformer.cpp
diff --git a/thirdparty/assimp/code/FBXDocument.cpp b/thirdparty/assimp/code/FBX/FBXDocument.cpp
index 1af08fe6d8..1af08fe6d8 100644
--- a/thirdparty/assimp/code/FBXDocument.cpp
+++ b/thirdparty/assimp/code/FBX/FBXDocument.cpp
diff --git a/thirdparty/assimp/code/FBXDocument.h b/thirdparty/assimp/code/FBX/FBXDocument.h
index c849defdcd..18e5c38f13 100644
--- a/thirdparty/assimp/code/FBXDocument.h
+++ b/thirdparty/assimp/code/FBX/FBXDocument.h
@@ -627,7 +627,7 @@ public:
return content;
}
- uint32_t ContentLength() const {
+ uint64_t ContentLength() const {
return contentLength;
}
@@ -643,7 +643,7 @@ private:
std::string fileName;
std::shared_ptr<const PropertyTable> props;
- uint32_t contentLength;
+ uint64_t contentLength;
uint8_t* content;
};
diff --git a/thirdparty/assimp/code/FBXDocumentUtil.cpp b/thirdparty/assimp/code/FBX/FBXDocumentUtil.cpp
index f84691479a..f84691479a 100644
--- a/thirdparty/assimp/code/FBXDocumentUtil.cpp
+++ b/thirdparty/assimp/code/FBX/FBXDocumentUtil.cpp
diff --git a/thirdparty/assimp/code/FBXDocumentUtil.h b/thirdparty/assimp/code/FBX/FBXDocumentUtil.h
index 2450109e59..2450109e59 100644
--- a/thirdparty/assimp/code/FBXDocumentUtil.h
+++ b/thirdparty/assimp/code/FBX/FBXDocumentUtil.h
diff --git a/thirdparty/assimp/code/FBXExportNode.cpp b/thirdparty/assimp/code/FBX/FBXExportNode.cpp
index e5215466a1..06c89cee46 100644
--- a/thirdparty/assimp/code/FBXExportNode.cpp
+++ b/thirdparty/assimp/code/FBX/FBXExportNode.cpp
@@ -54,6 +54,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <sstream> // ostringstream
#include <memory> // shared_ptr
+namespace Assimp {
// AddP70<type> helpers... there's no usable pattern here,
// so all are defined as separate functions.
// Even "animatable" properties are often completely different
@@ -252,7 +253,8 @@ void FBX::Node::DumpChildren(
} else {
std::ostringstream ss;
DumpChildrenAscii(ss, indent);
- s.PutString(ss.str());
+ if (ss.tellp() > 0)
+ s.PutString(ss.str());
}
}
@@ -266,7 +268,8 @@ void FBX::Node::End(
} else {
std::ostringstream ss;
EndAscii(ss, indent, has_children);
- s.PutString(ss.str());
+ if (ss.tellp() > 0)
+ s.PutString(ss.str());
}
}
@@ -367,7 +370,7 @@ void FBX::Node::EndBinary(
bool has_children
) {
// if there were children, add a null record
- if (has_children) { s.PutString(FBX::NULL_RECORD); }
+ if (has_children) { s.PutString(Assimp::FBX::NULL_RECORD); }
// now go back and write initial pos
this->end_pos = s.Tell();
@@ -563,6 +566,6 @@ void FBX::Node::WritePropertyNode(
FBX::Node::WritePropertyNodeAscii(name, v, s, indent);
}
}
-
+}
#endif // ASSIMP_BUILD_NO_FBX_EXPORTER
#endif // ASSIMP_BUILD_NO_EXPORT
diff --git a/thirdparty/assimp/code/FBXExportNode.h b/thirdparty/assimp/code/FBX/FBXExportNode.h
index e1ebc36969..ef3bc781a4 100644
--- a/thirdparty/assimp/code/FBXExportNode.h
+++ b/thirdparty/assimp/code/FBX/FBXExportNode.h
@@ -54,16 +54,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string>
#include <vector>
+namespace Assimp {
namespace FBX {
class Node;
}
-class FBX::Node
-{
-public: // public data members
+class FBX::Node {
+public:
// TODO: accessors
std::string name; // node name
- std::vector<FBX::Property> properties; // node properties
+ std::vector<FBX::FBXExportProperty> properties; // node properties
std::vector<FBX::Node> children; // child nodes
// some nodes always pretend they have children...
@@ -214,7 +214,7 @@ public: // static member functions
Assimp::StreamWriterLE& s,
bool binary, int indent
) {
- FBX::Property p(value);
+ FBX::FBXExportProperty p(value);
FBX::Node node(name, p);
node.Dump(s, binary, indent);
}
@@ -264,7 +264,7 @@ private: // static helper functions
);
};
-
+}
#endif // ASSIMP_BUILD_NO_FBX_EXPORTER
diff --git a/thirdparty/assimp/code/FBXExportProperty.cpp b/thirdparty/assimp/code/FBX/FBXExportProperty.cpp
index 9981d6b1c6..f8593e6295 100644
--- a/thirdparty/assimp/code/FBXExportProperty.cpp
+++ b/thirdparty/assimp/code/FBX/FBXExportProperty.cpp
@@ -52,187 +52,210 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <locale>
#include <sstream> // ostringstream
+namespace Assimp {
+namespace FBX {
// constructors for single element properties
-FBX::Property::Property(bool v)
- : type('C'), data(1)
-{
- data = {uint8_t(v)};
+FBXExportProperty::FBXExportProperty(bool v)
+: type('C')
+, data(1) {
+ data = {
+ uint8_t(v)
+ };
}
-FBX::Property::Property(int16_t v) : type('Y'), data(2)
-{
+FBXExportProperty::FBXExportProperty(int16_t v)
+: type('Y')
+, data(2) {
uint8_t* d = data.data();
(reinterpret_cast<int16_t*>(d))[0] = v;
}
-FBX::Property::Property(int32_t v) : type('I'), data(4)
-{
+FBXExportProperty::FBXExportProperty(int32_t v)
+: type('I')
+, data(4) {
uint8_t* d = data.data();
(reinterpret_cast<int32_t*>(d))[0] = v;
}
-FBX::Property::Property(float v) : type('F'), data(4)
-{
+FBXExportProperty::FBXExportProperty(float v)
+: type('F')
+, data(4) {
uint8_t* d = data.data();
(reinterpret_cast<float*>(d))[0] = v;
}
-FBX::Property::Property(double v) : type('D'), data(8)
-{
+FBXExportProperty::FBXExportProperty(double v)
+: type('D')
+, data(8) {
uint8_t* d = data.data();
(reinterpret_cast<double*>(d))[0] = v;
}
-FBX::Property::Property(int64_t v) : type('L'), data(8)
-{
+FBXExportProperty::FBXExportProperty(int64_t v)
+: type('L')
+, data(8) {
uint8_t* d = data.data();
(reinterpret_cast<int64_t*>(d))[0] = v;
}
-
// constructors for array-type properties
-FBX::Property::Property(const char* c, bool raw)
- : Property(std::string(c), raw)
-{}
+FBXExportProperty::FBXExportProperty(const char* c, bool raw)
+: FBXExportProperty(std::string(c), raw) {
+ // empty
+}
// strings can either be saved as "raw" (R) data, or "string" (S) data
-FBX::Property::Property(const std::string& s, bool raw)
- : type(raw ? 'R' : 'S'), data(s.size())
-{
+FBXExportProperty::FBXExportProperty(const std::string& s, bool raw)
+: type(raw ? 'R' : 'S')
+, data(s.size()) {
for (size_t i = 0; i < s.size(); ++i) {
data[i] = uint8_t(s[i]);
}
}
-FBX::Property::Property(const std::vector<uint8_t>& r)
- : type('R'), data(r)
-{}
+FBXExportProperty::FBXExportProperty(const std::vector<uint8_t>& r)
+: type('R')
+, data(r) {
+ // empty
+}
-FBX::Property::Property(const std::vector<int32_t>& va)
- : type('i'), data(4*va.size())
-{
+FBXExportProperty::FBXExportProperty(const std::vector<int32_t>& va)
+: type('i')
+, data(4 * va.size() ) {
int32_t* d = reinterpret_cast<int32_t*>(data.data());
- for (size_t i = 0; i < va.size(); ++i) { d[i] = va[i]; }
+ for (size_t i = 0; i < va.size(); ++i) {
+ d[i] = va[i];
+ }
}
-FBX::Property::Property(const std::vector<int64_t>& va)
- : type('l'), data(8*va.size())
-{
+FBXExportProperty::FBXExportProperty(const std::vector<int64_t>& va)
+: type('l')
+, data(8 * va.size()) {
int64_t* d = reinterpret_cast<int64_t*>(data.data());
- for (size_t i = 0; i < va.size(); ++i) { d[i] = va[i]; }
+ for (size_t i = 0; i < va.size(); ++i) {
+ d[i] = va[i];
+ }
}
-FBX::Property::Property(const std::vector<float>& va)
- : type('f'), data(4*va.size())
-{
+FBXExportProperty::FBXExportProperty(const std::vector<float>& va)
+: type('f')
+, data(4 * va.size()) {
float* d = reinterpret_cast<float*>(data.data());
- for (size_t i = 0; i < va.size(); ++i) { d[i] = va[i]; }
+ for (size_t i = 0; i < va.size(); ++i) {
+ d[i] = va[i];
+ }
}
-FBX::Property::Property(const std::vector<double>& va)
- : type('d'), data(8*va.size())
-{
+FBXExportProperty::FBXExportProperty(const std::vector<double>& va)
+: type('d')
+, data(8 * va.size()) {
double* d = reinterpret_cast<double*>(data.data());
- for (size_t i = 0; i < va.size(); ++i) { d[i] = va[i]; }
+ for (size_t i = 0; i < va.size(); ++i) {
+ d[i] = va[i];
+ }
}
-FBX::Property::Property(const aiMatrix4x4& vm)
- : type('d'), data(8*16)
-{
+FBXExportProperty::FBXExportProperty(const aiMatrix4x4& vm)
+: type('d')
+, data(8 * 16) {
double* d = reinterpret_cast<double*>(data.data());
for (unsigned int c = 0; c < 4; ++c) {
for (unsigned int r = 0; r < 4; ++r) {
- d[4*c+r] = vm[r][c];
+ d[4 * c + r] = vm[r][c];
}
}
}
// public member functions
-size_t FBX::Property::size()
-{
+size_t FBXExportProperty::size() {
switch (type) {
- case 'C': case 'Y': case 'I': case 'F': case 'D': case 'L':
- return data.size() + 1;
- case 'S': case 'R':
- return data.size() + 5;
- case 'i': case 'd':
- return data.size() + 13;
- default:
- throw DeadlyExportError("Requested size on property of unknown type");
+ case 'C':
+ case 'Y':
+ case 'I':
+ case 'F':
+ case 'D':
+ case 'L':
+ return data.size() + 1;
+ case 'S':
+ case 'R':
+ return data.size() + 5;
+ case 'i':
+ case 'd':
+ return data.size() + 13;
+ default:
+ throw DeadlyExportError("Requested size on property of unknown type");
}
}
-void FBX::Property::DumpBinary(Assimp::StreamWriterLE &s)
-{
+void FBXExportProperty::DumpBinary(Assimp::StreamWriterLE& s) {
s.PutU1(type);
uint8_t* d = data.data();
size_t N;
switch (type) {
- case 'C': s.PutU1(*(reinterpret_cast<uint8_t*>(d))); return;
- case 'Y': s.PutI2(*(reinterpret_cast<int16_t*>(d))); return;
- case 'I': s.PutI4(*(reinterpret_cast<int32_t*>(d))); return;
- case 'F': s.PutF4(*(reinterpret_cast<float*>(d))); return;
- case 'D': s.PutF8(*(reinterpret_cast<double*>(d))); return;
- case 'L': s.PutI8(*(reinterpret_cast<int64_t*>(d))); return;
- case 'S':
- case 'R':
- s.PutU4(uint32_t(data.size()));
- for (size_t i = 0; i < data.size(); ++i) { s.PutU1(data[i]); }
- return;
- case 'i':
- N = data.size() / 4;
- s.PutU4(uint32_t(N)); // number of elements
- s.PutU4(0); // no encoding (1 would be zip-compressed)
- // TODO: compress if large?
- s.PutU4(uint32_t(data.size())); // data size
- for (size_t i = 0; i < N; ++i) {
- s.PutI4((reinterpret_cast<int32_t*>(d))[i]);
- }
- return;
- case 'l':
- N = data.size() / 8;
- s.PutU4(uint32_t(N)); // number of elements
- s.PutU4(0); // no encoding (1 would be zip-compressed)
- // TODO: compress if large?
- s.PutU4(uint32_t(data.size())); // data size
- for (size_t i = 0; i < N; ++i) {
- s.PutI8((reinterpret_cast<int64_t*>(d))[i]);
- }
- return;
- case 'f':
- N = data.size() / 4;
- s.PutU4(uint32_t(N)); // number of elements
- s.PutU4(0); // no encoding (1 would be zip-compressed)
- // TODO: compress if large?
- s.PutU4(uint32_t(data.size())); // data size
- for (size_t i = 0; i < N; ++i) {
- s.PutF4((reinterpret_cast<float*>(d))[i]);
- }
- return;
- case 'd':
- N = data.size() / 8;
- s.PutU4(uint32_t(N)); // number of elements
- s.PutU4(0); // no encoding (1 would be zip-compressed)
- // TODO: compress if large?
- s.PutU4(uint32_t(data.size())); // data size
- for (size_t i = 0; i < N; ++i) {
- s.PutF8((reinterpret_cast<double*>(d))[i]);
- }
- return;
- default:
- std::ostringstream err;
- err << "Tried to dump property with invalid type '";
- err << type << "'!";
- throw DeadlyExportError(err.str());
+ case 'C': s.PutU1(*(reinterpret_cast<uint8_t*>(d))); return;
+ case 'Y': s.PutI2(*(reinterpret_cast<int16_t*>(d))); return;
+ case 'I': s.PutI4(*(reinterpret_cast<int32_t*>(d))); return;
+ case 'F': s.PutF4(*(reinterpret_cast<float*>(d))); return;
+ case 'D': s.PutF8(*(reinterpret_cast<double*>(d))); return;
+ case 'L': s.PutI8(*(reinterpret_cast<int64_t*>(d))); return;
+ case 'S':
+ case 'R':
+ s.PutU4(uint32_t(data.size()));
+ for (size_t i = 0; i < data.size(); ++i) { s.PutU1(data[i]); }
+ return;
+ case 'i':
+ N = data.size() / 4;
+ s.PutU4(uint32_t(N)); // number of elements
+ s.PutU4(0); // no encoding (1 would be zip-compressed)
+ // TODO: compress if large?
+ s.PutU4(uint32_t(data.size())); // data size
+ for (size_t i = 0; i < N; ++i) {
+ s.PutI4((reinterpret_cast<int32_t*>(d))[i]);
+ }
+ return;
+ case 'l':
+ N = data.size() / 8;
+ s.PutU4(uint32_t(N)); // number of elements
+ s.PutU4(0); // no encoding (1 would be zip-compressed)
+ // TODO: compress if large?
+ s.PutU4(uint32_t(data.size())); // data size
+ for (size_t i = 0; i < N; ++i) {
+ s.PutI8((reinterpret_cast<int64_t*>(d))[i]);
+ }
+ return;
+ case 'f':
+ N = data.size() / 4;
+ s.PutU4(uint32_t(N)); // number of elements
+ s.PutU4(0); // no encoding (1 would be zip-compressed)
+ // TODO: compress if large?
+ s.PutU4(uint32_t(data.size())); // data size
+ for (size_t i = 0; i < N; ++i) {
+ s.PutF4((reinterpret_cast<float*>(d))[i]);
+ }
+ return;
+ case 'd':
+ N = data.size() / 8;
+ s.PutU4(uint32_t(N)); // number of elements
+ s.PutU4(0); // no encoding (1 would be zip-compressed)
+ // TODO: compress if large?
+ s.PutU4(uint32_t(data.size())); // data size
+ for (size_t i = 0; i < N; ++i) {
+ s.PutF8((reinterpret_cast<double*>(d))[i]);
+ }
+ return;
+ default:
+ std::ostringstream err;
+ err << "Tried to dump property with invalid type '";
+ err << type << "'!";
+ throw DeadlyExportError(err.str());
}
}
-void FBX::Property::DumpAscii(Assimp::StreamWriterLE &outstream, int indent)
-{
+void FBXExportProperty::DumpAscii(Assimp::StreamWriterLE& outstream, int indent) {
std::ostringstream ss;
ss.imbue(std::locale::classic());
ss.precision(15); // this seems to match official FBX SDK exports
@@ -240,8 +263,7 @@ void FBX::Property::DumpAscii(Assimp::StreamWriterLE &outstream, int indent)
outstream.PutString(ss.str());
}
-void FBX::Property::DumpAscii(std::ostream& s, int indent)
-{
+void FBXExportProperty::DumpAscii(std::ostream& s, int indent) {
// no writing type... or anything. just shove it into the stream.
uint8_t* d = data.data();
size_t N;
@@ -360,5 +382,8 @@ void FBX::Property::DumpAscii(std::ostream& s, int indent)
}
}
+} // Namespace FBX
+} // Namespace Assimp
+
#endif // ASSIMP_BUILD_NO_FBX_EXPORTER
#endif // ASSIMP_BUILD_NO_EXPORT
diff --git a/thirdparty/assimp/code/FBXExportProperty.h b/thirdparty/assimp/code/FBX/FBXExportProperty.h
index 9c9d37c362..d692fe6ee3 100644
--- a/thirdparty/assimp/code/FBXExportProperty.h
+++ b/thirdparty/assimp/code/FBX/FBXExportProperty.h
@@ -47,7 +47,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef ASSIMP_BUILD_NO_FBX_EXPORTER
-
#include <assimp/types.h> // aiMatrix4x4
#include <assimp/StreamWriter.h> // StreamWriterLE
@@ -56,11 +55,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <ostream>
#include <type_traits> // is_void
+namespace Assimp {
namespace FBX {
- class Property;
-}
-/** FBX::Property
+/** @brief FBX::Property
*
* Holds a value of any of FBX's recognized types,
* each represented by a particular one-character code.
@@ -78,35 +76,34 @@ namespace FBX {
* S : string (array of 1-byte char)
* R : raw data (array of bytes)
*/
-class FBX::Property
-{
+class FBXExportProperty {
public:
// constructors for basic types.
// all explicit to avoid accidental typecasting
- explicit Property(bool v);
+ explicit FBXExportProperty(bool v);
// TODO: determine if there is actually a byte type,
// or if this always means <bool>. 'C' seems to imply <char>,
// so possibly the above was intended to represent both.
- explicit Property(int16_t v);
- explicit Property(int32_t v);
- explicit Property(float v);
- explicit Property(double v);
- explicit Property(int64_t v);
+ explicit FBXExportProperty(int16_t v);
+ explicit FBXExportProperty(int32_t v);
+ explicit FBXExportProperty(float v);
+ explicit FBXExportProperty(double v);
+ explicit FBXExportProperty(int64_t v);
// strings can either be stored as 'R' (raw) or 'S' (string) type
- explicit Property(const char* c, bool raw=false);
- explicit Property(const std::string& s, bool raw=false);
- explicit Property(const std::vector<uint8_t>& r);
- explicit Property(const std::vector<int32_t>& va);
- explicit Property(const std::vector<int64_t>& va);
- explicit Property(const std::vector<double>& va);
- explicit Property(const std::vector<float>& va);
- explicit Property(const aiMatrix4x4& vm);
+ explicit FBXExportProperty(const char* c, bool raw = false);
+ explicit FBXExportProperty(const std::string& s, bool raw = false);
+ explicit FBXExportProperty(const std::vector<uint8_t>& r);
+ explicit FBXExportProperty(const std::vector<int32_t>& va);
+ explicit FBXExportProperty(const std::vector<int64_t>& va);
+ explicit FBXExportProperty(const std::vector<double>& va);
+ explicit FBXExportProperty(const std::vector<float>& va);
+ explicit FBXExportProperty(const aiMatrix4x4& vm);
// this will catch any type not defined above,
// so that we don't accidentally convert something we don't want.
// for example (const char*) --> (bool)... seriously wtf C++
template <class T>
- explicit Property(T v) : type('X') {
+ explicit FBXExportProperty(T v) : type('X') {
static_assert(std::is_void<T>::value, "TRIED TO CREATE FBX PROPERTY WITH UNSUPPORTED TYPE, CHECK YOUR PROPERTY INSTANTIATION");
} // note: no line wrap so it appears verbatim on the compiler error
@@ -114,9 +111,9 @@ public:
size_t size();
// write this property node as binary data to the given stream
- void DumpBinary(Assimp::StreamWriterLE &s);
- void DumpAscii(Assimp::StreamWriterLE &s, int indent=0);
- void DumpAscii(std::ostream &s, int indent=0);
+ void DumpBinary(Assimp::StreamWriterLE& s);
+ void DumpAscii(Assimp::StreamWriterLE& s, int indent = 0);
+ void DumpAscii(std::ostream& s, int indent = 0);
// note: make sure the ostream is in classic "C" locale
private:
@@ -124,6 +121,9 @@ private:
std::vector<uint8_t> data;
};
+} // Namespace FBX
+} // Namespace Assimp
+
#endif // ASSIMP_BUILD_NO_FBX_EXPORTER
#endif // AI_FBXEXPORTPROPERTY_H_INC
diff --git a/thirdparty/assimp/code/FBXExporter.cpp b/thirdparty/assimp/code/FBX/FBXExporter.cpp
index acb1227144..153e676506 100644
--- a/thirdparty/assimp/code/FBXExporter.cpp
+++ b/thirdparty/assimp/code/FBX/FBXExporter.cpp
@@ -45,6 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "FBXExportNode.h"
#include "FBXExportProperty.h"
#include "FBXCommon.h"
+#include "FBXUtil.h"
#include <assimp/version.h> // aiGetVersion
#include <assimp/IOSystem.hpp>
@@ -73,7 +74,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
const ai_real DEG = ai_real( 57.29577951308232087679815481 ); // degrees per radian
+using namespace Assimp;
+using namespace Assimp::FBX;
+
// some constants that we'll use for writing metadata
+namespace Assimp {
namespace FBX {
const std::string EXPORT_VERSION_STR = "7.4.0";
const uint32_t EXPORT_VERSION_INT = 7400; // 7.4 == 2014/2015
@@ -92,11 +97,6 @@ namespace FBX {
";------------------------------------------------------------------";
}
-using namespace Assimp;
-using namespace FBX;
-
-namespace Assimp {
-
// ---------------------------------------------------------------------
// Worker function for exporting a scene to binary FBX.
// Prototyped and registered in Exporter.cpp
@@ -121,6 +121,7 @@ namespace Assimp {
IOSystem* pIOSystem,
const aiScene* pScene,
const ExportProperties* pProperties
+
){
// initialize the exporter
FBXExporter exporter(pScene, pProperties);
@@ -1218,6 +1219,16 @@ void FBXExporter::WriteObjects ()
layer.AddChild(le);
layer.Dump(outstream, binary, indent);
+ for(unsigned int lr = 1; lr < m->GetNumUVChannels(); ++ lr)
+ {
+ FBX::Node layerExtra("Layer", int32_t(1));
+ layerExtra.AddChild("Version", int32_t(100));
+ FBX::Node leExtra("LayerElement");
+ leExtra.AddChild("Type", "LayerElementUV");
+ leExtra.AddChild("TypedIndex", int32_t(lr));
+ layerExtra.AddChild(leExtra);
+ layerExtra.Dump(outstream, binary, indent);
+ }
// finish the node record
indent = 1;
n.End(outstream, binary, indent, true);
@@ -1393,10 +1404,6 @@ void FBXExporter::WriteObjects ()
// FbxVideo - stores images used by textures.
for (const auto &it : uid_by_image) {
- if (it.first.compare(0, 1, "*") == 0) {
- // TODO: embedded textures
- continue;
- }
FBX::Node n("Video");
const int64_t& uid = it.second;
const std::string name = ""; // TODO: ... name???
@@ -1406,7 +1413,33 @@ void FBXExporter::WriteObjects ()
// TODO: get full path... relative path... etc... ugh...
// for now just use the same path for everything,
// and hopefully one of them will work out.
- const std::string& path = it.first;
+ std::string path = it.first;
+ // try get embedded texture
+ const aiTexture* embedded_texture = mScene->GetEmbeddedTexture(it.first.c_str());
+ if (embedded_texture != nullptr) {
+ // change the path (use original filename, if available. If name is empty, concatenate texture index with file extension)
+ std::stringstream newPath;
+ if (embedded_texture->mFilename.length > 0) {
+ newPath << embedded_texture->mFilename.C_Str();
+ } else if (embedded_texture->achFormatHint[0]) {
+ int texture_index = std::stoi(path.substr(1, path.size() - 1));
+ newPath << texture_index << "." << embedded_texture->achFormatHint;
+ }
+ path = newPath.str();
+ // embed the texture
+ size_t texture_size = static_cast<size_t>(embedded_texture->mWidth * std::max(embedded_texture->mHeight, 1u));
+ if (binary) {
+ // embed texture as binary data
+ std::vector<uint8_t> tex_data;
+ tex_data.resize(texture_size);
+ memcpy(&tex_data[0], (char*)embedded_texture->pcData, texture_size);
+ n.AddChild("Content", tex_data);
+ } else {
+ // embed texture in base64 encoding
+ std::string encoded_texture = FBX::Util::EncodeBase64((char*)embedded_texture->pcData, texture_size);
+ n.AddChild("Content", encoded_texture);
+ }
+ }
p.AddP70("Path", "KString", "XRefUrl", "", path);
n.AddChild(p);
n.AddChild("UseMipMap", int32_t(0));
@@ -1419,17 +1452,17 @@ void FBXExporter::WriteObjects ()
// referenced by material_index/texture_type pairs.
std::map<std::pair<size_t,size_t>,int64_t> texture_uids;
const std::map<aiTextureType,std::string> prop_name_by_tt = {
- {aiTextureType_DIFFUSE, "DiffuseColor"},
- {aiTextureType_SPECULAR, "SpecularColor"},
- {aiTextureType_AMBIENT, "AmbientColor"},
- {aiTextureType_EMISSIVE, "EmissiveColor"},
- {aiTextureType_HEIGHT, "Bump"},
- {aiTextureType_NORMALS, "NormalMap"},
- {aiTextureType_SHININESS, "ShininessExponent"},
- {aiTextureType_OPACITY, "TransparentColor"},
+ {aiTextureType_DIFFUSE, "DiffuseColor"},
+ {aiTextureType_SPECULAR, "SpecularColor"},
+ {aiTextureType_AMBIENT, "AmbientColor"},
+ {aiTextureType_EMISSIVE, "EmissiveColor"},
+ {aiTextureType_HEIGHT, "Bump"},
+ {aiTextureType_NORMALS, "NormalMap"},
+ {aiTextureType_SHININESS, "ShininessExponent"},
+ {aiTextureType_OPACITY, "TransparentColor"},
{aiTextureType_DISPLACEMENT, "DisplacementColor"},
//{aiTextureType_LIGHTMAP, "???"},
- {aiTextureType_REFLECTION, "ReflectionColor"}
+ {aiTextureType_REFLECTION, "ReflectionColor"}
//{aiTextureType_UNKNOWN, ""}
};
for (size_t i = 0; i < mScene->mNumMaterials; ++i) {
@@ -1575,19 +1608,41 @@ void FBXExporter::WriteObjects ()
// one sticky point is that the number of vertices may not match,
// because assimp splits vertices by normal, uv, etc.
+ // functor for aiNode sorting
+ struct SortNodeByName
+ {
+ bool operator()(const aiNode *lhs, const aiNode *rhs) const
+ {
+ return strcmp(lhs->mName.C_Str(), rhs->mName.C_Str()) < 0;
+ }
+ };
+
// first we should mark the skeleton for each mesh.
// the skeleton must include not only the aiBones,
// but also all their parent nodes.
// anything that affects the position of any bone node must be included.
- std::vector<std::set<const aiNode*>> skeleton_by_mesh(mScene->mNumMeshes);
+ // Use SorNodeByName to make sure the exported result will be the same across all systems
+ // Otherwise the aiNodes of the skeleton would be sorted based on the pointer address, which isn't consistent
+ std::vector<std::set<const aiNode*, SortNodeByName>> skeleton_by_mesh(mScene->mNumMeshes);
// at the same time we can build a list of all the skeleton nodes,
// which will be used later to mark them as type "limbNode".
std::unordered_set<const aiNode*> limbnodes;
+
+ //actual bone nodes in fbx, without parenting-up
+ std::unordered_set<std::string> setAllBoneNamesInScene;
+ for(unsigned int m = 0; m < mScene->mNumMeshes; ++ m)
+ {
+ aiMesh* pMesh = mScene->mMeshes[m];
+ for(unsigned int b = 0; b < pMesh->mNumBones; ++ b)
+ setAllBoneNamesInScene.insert(pMesh->mBones[b]->mName.data);
+ }
+ aiMatrix4x4 mxTransIdentity;
+
// and a map of nodes by bone name, as finding them is annoying.
std::map<std::string,aiNode*> node_by_bone;
for (size_t mi = 0; mi < mScene->mNumMeshes; ++mi) {
const aiMesh* m = mScene->mMeshes[mi];
- std::set<const aiNode*> skeleton;
+ std::set<const aiNode*, SortNodeByName> skeleton;
for (size_t bi =0; bi < m->mNumBones; ++bi) {
const aiBone* b = m->mBones[bi];
const std::string name(b->mName.C_Str());
@@ -1626,6 +1681,11 @@ void FBXExporter::WriteObjects ()
if (node_name.find(MAGIC_NODE_TAG) != std::string::npos) {
continue;
}
+ //not a bone in scene && no effect in transform
+ if(setAllBoneNamesInScene.find(node_name)==setAllBoneNamesInScene.end()
+ && parent->mTransformation == mxTransIdentity) {
+ continue;
+ }
// otherwise check if this is the root of the skeleton
bool end = false;
// is the mesh part of this node?
@@ -1728,7 +1788,7 @@ void FBXExporter::WriteObjects ()
aiMatrix4x4 mesh_xform = get_world_transform(mesh_node, mScene);
// now make a subdeformer for each bone in the skeleton
- const std::set<const aiNode*> &skeleton = skeleton_by_mesh[mi];
+ const std::set<const aiNode*, SortNodeByName> skeleton= skeleton_by_mesh[mi];
for (const aiNode* bone_node : skeleton) {
// if there's a bone for this node, find it
const aiBone* b = nullptr;
@@ -1790,7 +1850,10 @@ void FBXExporter::WriteObjects ()
// this should be the same as the bone's mOffsetMatrix.
// if it's not the same, the skeleton isn't in the bind pose.
- const float epsilon = 1e-4f; // some error is to be expected
+ float epsilon = 1e-4f; // some error is to be expected
+ float epsilon_custom = mProperties->GetPropertyFloat("BINDPOSE_EPSILON", -1);
+ if(epsilon_custom > 0)
+ epsilon = epsilon_custom;
bool bone_xform_okay = true;
if (b && ! tr.Equal(b->mOffsetMatrix, epsilon)) {
not_in_bind_pose.insert(b);
@@ -2237,8 +2300,8 @@ void FBXExporter::WriteModelNode(
// not sure what these are for,
// but they seem to be omnipresent
- m.AddChild("Shading", Property(true));
- m.AddChild("Culling", Property("CullingOff"));
+ m.AddChild("Shading", FBXExportProperty(true));
+ m.AddChild("Culling", FBXExportProperty("CullingOff"));
m.Dump(outstream, binary, 1);
}
@@ -2351,7 +2414,7 @@ void FBXExporter::WriteModelNodes(
na.AddProperties(
node_attribute_uid, FBX::SEPARATOR + "NodeAttribute", "LimbNode"
);
- na.AddChild("TypeFlags", Property("Skeleton"));
+ na.AddChild("TypeFlags", FBXExportProperty("Skeleton"));
na.Dump(outstream, binary, 1);
// and connect them
connections.emplace_back("C", "OO", node_attribute_uid, node_uid);
diff --git a/thirdparty/assimp/code/FBXExporter.h b/thirdparty/assimp/code/FBX/FBXExporter.h
index 71fb55c57f..71fb55c57f 100644
--- a/thirdparty/assimp/code/FBXExporter.h
+++ b/thirdparty/assimp/code/FBX/FBXExporter.h
diff --git a/thirdparty/assimp/code/FBXImportSettings.h b/thirdparty/assimp/code/FBX/FBXImportSettings.h
index d5e1c20608..1a4c80f8b2 100644
--- a/thirdparty/assimp/code/FBXImportSettings.h
+++ b/thirdparty/assimp/code/FBX/FBXImportSettings.h
@@ -53,19 +53,22 @@ namespace FBX {
struct ImportSettings
{
ImportSettings()
- : strictMode(true)
- , readAllLayers(true)
- , readAllMaterials(false)
- , readMaterials(true)
- , readTextures(true)
- , readCameras(true)
- , readLights(true)
- , readAnimations(true)
- , readWeights(true)
- , preservePivots(true)
- , optimizeEmptyAnimationCurves(true)
- , useLegacyEmbeddedTextureNaming(false)
- {}
+ : strictMode(true)
+ , readAllLayers(true)
+ , readAllMaterials(false)
+ , readMaterials(true)
+ , readTextures(true)
+ , readCameras(true)
+ , readLights(true)
+ , readAnimations(true)
+ , readWeights(true)
+ , preservePivots(true)
+ , optimizeEmptyAnimationCurves(true)
+ , useLegacyEmbeddedTextureNaming(false)
+ , removeEmptyBones( true )
+ , convertToMeters( false ) {
+ // empty
+ }
/** enable strict mode:
@@ -141,8 +144,16 @@ struct ImportSettings
bool optimizeEmptyAnimationCurves;
/** use legacy naming for embedded textures eg: (*0, *1, *2)
- **/
+ */
bool useLegacyEmbeddedTextureNaming;
+
+ /** Empty bones shall be removed
+ */
+ bool removeEmptyBones;
+
+ /** Set to true to perform a conversion from cm to meter after the import
+ */
+ bool convertToMeters;
};
diff --git a/thirdparty/assimp/code/FBXImporter.cpp b/thirdparty/assimp/code/FBX/FBXImporter.cpp
index 2cc8bffc29..ec8bbd2b47 100644
--- a/thirdparty/assimp/code/FBXImporter.cpp
+++ b/thirdparty/assimp/code/FBX/FBXImporter.cpp
@@ -140,6 +140,8 @@ void FBXImporter::SetupProperties(const Importer* pImp)
settings.preservePivots = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_PRESERVE_PIVOTS, true);
settings.optimizeEmptyAnimationCurves = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_OPTIMIZE_EMPTY_ANIMATION_CURVES, true);
settings.useLegacyEmbeddedTextureNaming = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_EMBEDDED_TEXTURES_LEGACY_NAMING, false);
+ settings.removeEmptyBones = pImp->GetPropertyBool(AI_CONFIG_IMPORT_REMOVE_EMPTY_BONES, true);
+ settings.convertToMeters = pImp->GetPropertyBool(AI_CONFIG_FBX_CONVERT_TO_M, false);
}
// ------------------------------------------------------------------------------------------------
@@ -170,7 +172,7 @@ void FBXImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS
bool is_binary = false;
if (!strncmp(begin,"Kaydara FBX Binary",18)) {
is_binary = true;
- TokenizeBinary(tokens,begin,static_cast<unsigned int>(contents.size()));
+ TokenizeBinary(tokens,begin,contents.size());
}
else {
Tokenize(tokens,begin);
@@ -183,8 +185,12 @@ void FBXImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS
// take the raw parse-tree and convert it to a FBX DOM
Document doc(parser,settings);
+ FbxUnit unit(FbxUnit::cm);
+ if (settings.convertToMeters) {
+ unit = FbxUnit::m;
+ }
// convert the FBX DOM to aiScene
- ConvertToAssimpScene(pScene,doc);
+ ConvertToAssimpScene(pScene,doc, settings.removeEmptyBones, unit);
std::for_each(tokens.begin(),tokens.end(),Util::delete_fun<Token>());
}
diff --git a/thirdparty/assimp/code/FBXImporter.h b/thirdparty/assimp/code/FBX/FBXImporter.h
index c365b2cddf..c365b2cddf 100644
--- a/thirdparty/assimp/code/FBXImporter.h
+++ b/thirdparty/assimp/code/FBX/FBXImporter.h
diff --git a/thirdparty/assimp/code/FBXMaterial.cpp b/thirdparty/assimp/code/FBX/FBXMaterial.cpp
index f16f134404..f43a8b84b0 100644
--- a/thirdparty/assimp/code/FBXMaterial.cpp
+++ b/thirdparty/assimp/code/FBX/FBXMaterial.cpp
@@ -316,7 +316,7 @@ Video::Video(uint64_t id, const Element& element, const Document& doc, const std
relativeFileName = ParseTokenAsString(GetRequiredToken(*RelativeFilename,0));
}
- if(Content) {
+ if(Content && !Content->Tokens().empty()) {
//this field is omitted when the embedded texture is already loaded, let's ignore if it's not found
try {
const Token& token = GetRequiredToken(*Content, 0);
@@ -326,16 +326,40 @@ Video::Video(uint64_t id, const Element& element, const Document& doc, const std
DOMError("embedded content is not surrounded by quotation marks", &element);
}
else {
- const char* encodedData = data + 1;
- size_t encodedDataLen = static_cast<size_t>(token.end() - token.begin());
- // search for last quotation mark
- while (encodedDataLen > 1 && encodedData[encodedDataLen] != '"')
- encodedDataLen--;
- if (encodedDataLen % 4 != 0) {
- DOMError("embedded content is invalid, needs to be in base64", &element);
+ size_t targetLength = 0;
+ auto numTokens = Content->Tokens().size();
+ // First time compute size (it could be large like 64Gb and it is good to allocate it once)
+ for (uint32_t tokenIdx = 0; tokenIdx < numTokens; ++tokenIdx)
+ {
+ const Token& dataToken = GetRequiredToken(*Content, tokenIdx);
+ size_t tokenLength = dataToken.end() - dataToken.begin() - 2; // ignore double quotes
+ const char* base64data = dataToken.begin() + 1;
+ const size_t outLength = Util::ComputeDecodedSizeBase64(base64data, tokenLength);
+ if (outLength == 0)
+ {
+ DOMError("Corrupted embedded content found", &element);
+ }
+ targetLength += outLength;
}
- else {
- contentLength = Util::DecodeBase64(encodedData, encodedDataLen, content);
+ if (targetLength == 0)
+ {
+ DOMError("Corrupted embedded content found", &element);
+ }
+ content = new uint8_t[targetLength];
+ contentLength = static_cast<uint64_t>(targetLength);
+ size_t dst_offset = 0;
+ for (uint32_t tokenIdx = 0; tokenIdx < numTokens; ++tokenIdx)
+ {
+ const Token& dataToken = GetRequiredToken(*Content, tokenIdx);
+ size_t tokenLength = dataToken.end() - dataToken.begin() - 2; // ignore double quotes
+ const char* base64data = dataToken.begin() + 1;
+ dst_offset += Util::DecodeBase64(base64data, tokenLength, content + dst_offset, targetLength - dst_offset);
+ }
+ if (targetLength != dst_offset)
+ {
+ delete[] content;
+ contentLength = 0;
+ DOMError("Corrupted embedded content found", &element);
}
}
}
diff --git a/thirdparty/assimp/code/FBXMeshGeometry.cpp b/thirdparty/assimp/code/FBX/FBXMeshGeometry.cpp
index d75476b826..44a0264ca0 100644
--- a/thirdparty/assimp/code/FBXMeshGeometry.cpp
+++ b/thirdparty/assimp/code/FBX/FBXMeshGeometry.cpp
@@ -568,15 +568,15 @@ void MeshGeometry::ReadVertexDataColors(std::vector<aiColor4D>& colors_out, cons
}
// ------------------------------------------------------------------------------------------------
-static const std::string TangentIndexToken = "TangentIndex";
-static const std::string TangentsIndexToken = "TangentsIndex";
+static const char *TangentIndexToken = "TangentIndex";
+static const char *TangentsIndexToken = "TangentsIndex";
void MeshGeometry::ReadVertexDataTangents(std::vector<aiVector3D>& tangents_out, const Scope& source,
const std::string& MappingInformationType,
const std::string& ReferenceInformationType)
{
const char * str = source.Elements().count( "Tangents" ) > 0 ? "Tangents" : "Tangent";
- const char * strIdx = source.Elements().count( "Tangents" ) > 0 ? TangentsIndexToken.c_str() : TangentIndexToken.c_str();
+ const char * strIdx = source.Elements().count( "Tangents" ) > 0 ? TangentsIndexToken : TangentIndexToken;
ResolveVertexDataArray(tangents_out,source,MappingInformationType,ReferenceInformationType,
str,
strIdx,
@@ -630,10 +630,11 @@ void MeshGeometry::ReadVertexDataMaterials(std::vector<int>& materials_out, cons
materials_out.clear();
}
- m_materials.assign(m_vertices.size(),materials_out[0]);
+ materials_out.resize(m_vertices.size());
+ std::fill(materials_out.begin(), materials_out.end(), materials_out.at(0));
}
else if (MappingInformationType == "ByPolygon" && ReferenceInformationType == "IndexToDirect") {
- m_materials.resize(face_count);
+ materials_out.resize(face_count);
if(materials_out.size() != face_count) {
FBXImporter::LogError(Formatter::format("length of input data unexpected for ByPolygon mapping: ")
diff --git a/thirdparty/assimp/code/FBXMeshGeometry.h b/thirdparty/assimp/code/FBX/FBXMeshGeometry.h
index d6d4512177..d6d4512177 100644
--- a/thirdparty/assimp/code/FBXMeshGeometry.h
+++ b/thirdparty/assimp/code/FBX/FBXMeshGeometry.h
diff --git a/thirdparty/assimp/code/FBXModel.cpp b/thirdparty/assimp/code/FBX/FBXModel.cpp
index 589af36ac7..589af36ac7 100644
--- a/thirdparty/assimp/code/FBXModel.cpp
+++ b/thirdparty/assimp/code/FBX/FBXModel.cpp
diff --git a/thirdparty/assimp/code/FBXNodeAttribute.cpp b/thirdparty/assimp/code/FBX/FBXNodeAttribute.cpp
index b72e5637ee..b72e5637ee 100644
--- a/thirdparty/assimp/code/FBXNodeAttribute.cpp
+++ b/thirdparty/assimp/code/FBX/FBXNodeAttribute.cpp
diff --git a/thirdparty/assimp/code/FBXParser.cpp b/thirdparty/assimp/code/FBX/FBXParser.cpp
index b255c47347..4a9346040d 100644
--- a/thirdparty/assimp/code/FBXParser.cpp
+++ b/thirdparty/assimp/code/FBX/FBXParser.cpp
@@ -117,7 +117,7 @@ namespace FBX {
Element::Element(const Token& key_token, Parser& parser)
: key_token(key_token)
{
- TokenPtr n = NULL;
+ TokenPtr n = nullptr;
do {
n = parser.AdvanceToNextToken();
if(!n) {
@@ -643,9 +643,9 @@ void ParseVectorDataArray(std::vector<aiVector3D>& out, const Element& el)
if (type == 'd') {
const double* d = reinterpret_cast<const double*>(&buff[0]);
for (unsigned int i = 0; i < count3; ++i, d += 3) {
- out.push_back(aiVector3D(static_cast<float>(d[0]),
- static_cast<float>(d[1]),
- static_cast<float>(d[2])));
+ out.push_back(aiVector3D(static_cast<ai_real>(d[0]),
+ static_cast<ai_real>(d[1]),
+ static_cast<ai_real>(d[2])));
}
// for debugging
/*for ( size_t i = 0; i < out.size(); i++ ) {
@@ -963,7 +963,6 @@ void ParseVectorDataArray(std::vector<float>& out, const Element& el)
}
}
-
// ------------------------------------------------------------------------------------------------
// read an array of uints
void ParseVectorDataArray(std::vector<unsigned int>& out, const Element& el)
@@ -1280,7 +1279,6 @@ float ParseTokenAsFloat(const Token& t)
return i;
}
-
// ------------------------------------------------------------------------------------------------
// wrapper around ParseTokenAsInt() with ParseError handling
int ParseTokenAsInt(const Token& t)
@@ -1293,8 +1291,6 @@ int ParseTokenAsInt(const Token& t)
return i;
}
-
-
// ------------------------------------------------------------------------------------------------
// wrapper around ParseTokenAsInt64() with ParseError handling
int64_t ParseTokenAsInt64(const Token& t)
diff --git a/thirdparty/assimp/code/FBXParser.h b/thirdparty/assimp/code/FBX/FBXParser.h
index 7b0cf72039..7b0cf72039 100644
--- a/thirdparty/assimp/code/FBXParser.h
+++ b/thirdparty/assimp/code/FBX/FBXParser.h
diff --git a/thirdparty/assimp/code/FBXProperties.cpp b/thirdparty/assimp/code/FBX/FBXProperties.cpp
index 8d7036b6a9..8d7036b6a9 100644
--- a/thirdparty/assimp/code/FBXProperties.cpp
+++ b/thirdparty/assimp/code/FBX/FBXProperties.cpp
diff --git a/thirdparty/assimp/code/FBXProperties.h b/thirdparty/assimp/code/FBX/FBXProperties.h
index 58755542fc..58755542fc 100644
--- a/thirdparty/assimp/code/FBXProperties.h
+++ b/thirdparty/assimp/code/FBX/FBXProperties.h
diff --git a/thirdparty/assimp/code/FBXTokenizer.cpp b/thirdparty/assimp/code/FBX/FBXTokenizer.cpp
index 252cce3557..252cce3557 100644
--- a/thirdparty/assimp/code/FBXTokenizer.cpp
+++ b/thirdparty/assimp/code/FBX/FBXTokenizer.cpp
diff --git a/thirdparty/assimp/code/FBXTokenizer.h b/thirdparty/assimp/code/FBX/FBXTokenizer.h
index 2af29743f4..afa588a470 100644
--- a/thirdparty/assimp/code/FBXTokenizer.h
+++ b/thirdparty/assimp/code/FBX/FBXTokenizer.h
@@ -93,7 +93,7 @@ public:
Token(const char* sbegin, const char* send, TokenType type, unsigned int line, unsigned int column);
/** construct a binary token */
- Token(const char* sbegin, const char* send, TokenType type, unsigned int offset);
+ Token(const char* sbegin, const char* send, TokenType type, size_t offset);
~Token();
@@ -118,14 +118,14 @@ public:
return type;
}
- unsigned int Offset() const {
+ size_t Offset() const {
ai_assert(IsBinary());
return offset;
}
unsigned int Line() const {
ai_assert(!IsBinary());
- return line;
+ return static_cast<unsigned int>(line);
}
unsigned int Column() const {
@@ -147,8 +147,8 @@ private:
const TokenType type;
union {
- const unsigned int line;
- unsigned int offset;
+ size_t line;
+ size_t offset;
};
const unsigned int column;
};
@@ -178,7 +178,7 @@ void Tokenize(TokenList& output_tokens, const char* input);
* @param input_buffer Binary input buffer to be processed.
* @param length Length of input buffer, in bytes. There is no 0-terminal.
* @throw DeadlyImportError if something goes wrong */
-void TokenizeBinary(TokenList& output_tokens, const char* input, unsigned int length);
+void TokenizeBinary(TokenList& output_tokens, const char* input, size_t length);
} // ! FBX
diff --git a/thirdparty/assimp/code/FBXUtil.cpp b/thirdparty/assimp/code/FBX/FBXUtil.cpp
index fb483161b2..c10e057c8c 100644
--- a/thirdparty/assimp/code/FBXUtil.cpp
+++ b/thirdparty/assimp/code/FBX/FBXUtil.cpp
@@ -86,7 +86,7 @@ const char* TokenTypeString(TokenType t)
// ------------------------------------------------------------------------------------------------
-std::string AddOffset(const std::string& prefix, const std::string& text, unsigned int offset)
+std::string AddOffset(const std::string& prefix, const std::string& text, size_t offset)
{
return static_cast<std::string>( (Formatter::format() << prefix << " (offset 0x" << std::hex << offset << ") " << text) );
}
@@ -114,47 +114,126 @@ std::string AddTokenText(const std::string& prefix, const std::string& text, con
text) );
}
+// Generated by this formula: T["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[i]] = i;
static const uint8_t base64DecodeTable[128] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 63,
- 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 64, 0, 0,
- 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0,
- 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63,
+ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255, 255, 255, 255, 255,
+ 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 255, 255, 255, 255, 255,
+ 255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
+ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 255, 255, 255, 255, 255
};
uint8_t DecodeBase64(char ch)
{
- return base64DecodeTable[size_t(ch)];
+ const auto idx = static_cast<uint8_t>(ch);
+ if (idx > 127)
+ return 255;
+ return base64DecodeTable[idx];
}
-size_t DecodeBase64(const char* in, size_t inLength, uint8_t*& out)
+size_t ComputeDecodedSizeBase64(const char* in, size_t inLength)
{
- if (inLength < 4) {
- out = 0;
+ if (inLength < 2)
+ {
+ return 0;
+ }
+ const size_t equals = size_t(in[inLength - 1] == '=') + size_t(in[inLength - 2] == '=');
+ const size_t full_length = (inLength * 3) >> 2; // div by 4
+ if (full_length < equals)
+ {
+ return 0;
+ }
+ return full_length - equals;
+}
+
+size_t DecodeBase64(const char* in, size_t inLength, uint8_t* out, size_t maxOutLength)
+{
+ if (maxOutLength == 0 || inLength < 2) {
return 0;
}
+ const size_t realLength = inLength - size_t(in[inLength - 1] == '=') - size_t(in[inLength - 2] == '=');
+ size_t dst_offset = 0;
+ int val = 0, valb = -8;
+ for (size_t src_offset = 0; src_offset < realLength; ++src_offset)
+ {
+ const uint8_t table_value = Util::DecodeBase64(in[src_offset]);
+ if (table_value == 255)
+ {
+ return 0;
+ }
+ val = (val << 6) + table_value;
+ valb += 6;
+ if (valb >= 0)
+ {
+ out[dst_offset++] = static_cast<uint8_t>((val >> valb) & 0xFF);
+ valb -= 8;
+ val &= 0xFFF;
+ }
+ }
+ return dst_offset;
+}
- const size_t outLength = (inLength * 3) / 4;
- out = new uint8_t[outLength];
- memset(out, 0, outLength);
+static const char to_base64_string[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+char EncodeBase64(char byte)
+{
+ return to_base64_string[(size_t)byte];
+}
- size_t i = 0;
- size_t j = 0;
- for (i = 0; i < inLength - 4; i += 4)
+/** Encodes a block of 4 bytes to base64 encoding
+*
+* @param bytes Bytes to encode.
+* @param out_string String to write encoded values to.
+* @param string_pos Position in out_string.*/
+void EncodeByteBlock(const char* bytes, std::string& out_string, size_t string_pos)
+{
+ char b0 = (bytes[0] & 0xFC) >> 2;
+ char b1 = (bytes[0] & 0x03) << 4 | ((bytes[1] & 0xF0) >> 4);
+ char b2 = (bytes[1] & 0x0F) << 2 | ((bytes[2] & 0xC0) >> 6);
+ char b3 = (bytes[2] & 0x3F);
+
+ out_string[string_pos + 0] = EncodeBase64(b0);
+ out_string[string_pos + 1] = EncodeBase64(b1);
+ out_string[string_pos + 2] = EncodeBase64(b2);
+ out_string[string_pos + 3] = EncodeBase64(b3);
+}
+
+std::string EncodeBase64(const char* data, size_t length)
+{
+ // calculate extra bytes needed to get a multiple of 3
+ size_t extraBytes = 3 - length % 3;
+
+ // number of base64 bytes
+ size_t encodedBytes = 4 * (length + extraBytes) / 3;
+
+ std::string encoded_string(encodedBytes, '=');
+
+ // read blocks of 3 bytes
+ for (size_t ib3 = 0; ib3 < length / 3; ib3++)
{
- uint8_t b0 = Util::DecodeBase64(in[i]);
- uint8_t b1 = Util::DecodeBase64(in[i + 1]);
- uint8_t b2 = Util::DecodeBase64(in[i + 2]);
- uint8_t b3 = Util::DecodeBase64(in[i + 3]);
-
- out[j++] = (uint8_t)((b0 << 2) | (b1 >> 4));
- out[j++] = (uint8_t)((b1 << 4) | (b2 >> 2));
- out[j++] = (uint8_t)((b2 << 6) | b3);
+ const size_t iByte = ib3 * 3;
+ const size_t iEncodedByte = ib3 * 4;
+ const char* currData = &data[iByte];
+
+ EncodeByteBlock(currData, encoded_string, iEncodedByte);
+ }
+
+ // if size of data is not a multiple of 3, also encode the final bytes (and add zeros where needed)
+ if (extraBytes > 0)
+ {
+ char finalBytes[4] = { 0,0,0,0 };
+ memcpy(&finalBytes[0], &data[length - length % 3], length % 3);
+
+ const size_t iEncodedByte = encodedBytes - 4;
+ EncodeByteBlock(&finalBytes[0], encoded_string, iEncodedByte);
+
+ // add '=' at the end
+ for (size_t i = 0; i < 4 * extraBytes / 3; i++)
+ encoded_string[encodedBytes - i - 1] = '=';
}
- return outLength;
+ return encoded_string;
}
} // !Util
diff --git a/thirdparty/assimp/code/FBXUtil.h b/thirdparty/assimp/code/FBX/FBXUtil.h
index 6890e015ba..b634418858 100644
--- a/thirdparty/assimp/code/FBXUtil.h
+++ b/thirdparty/assimp/code/FBX/FBXUtil.h
@@ -78,7 +78,7 @@ const char* TokenTypeString(TokenType t);
* @param line Line index, 1-based
* @param column Column index, 1-based
* @return A string of the following format: {prefix} (offset 0x{offset}) {text}*/
-std::string AddOffset(const std::string& prefix, const std::string& text, unsigned int offset);
+std::string AddOffset(const std::string& prefix, const std::string& text, size_t offset);
/** Format log/error messages using a given line location in the source file.
@@ -105,13 +105,30 @@ std::string AddTokenText(const std::string& prefix, const std::string& text, con
* @return decoded byte value*/
uint8_t DecodeBase64(char ch);
+/** Compute decoded size of a Base64-encoded string
+*
+* @param in Characters to decode.
+* @param inLength Number of characters to decode.
+* @return size of the decoded data (number of bytes)*/
+size_t ComputeDecodedSizeBase64(const char* in, size_t inLength);
+
/** Decode a Base64-encoded string
*
* @param in Characters to decode.
* @param inLength Number of characters to decode.
-* @param out Reference to pointer where we will store the decoded data.
+* @param out Pointer where we will store the decoded data.
+* @param maxOutLength Size of output buffer.
* @return size of the decoded data (number of bytes)*/
-size_t DecodeBase64(const char* in, size_t inLength, uint8_t*& out);
+size_t DecodeBase64(const char* in, size_t inLength, uint8_t* out, size_t maxOutLength);
+
+char EncodeBase64(char byte);
+
+/** Encode bytes in base64-encoding
+*
+* @param data Binary data to encode.
+* @param inLength Number of bytes to encode.
+* @return base64-encoded string*/
+std::string EncodeBase64(const char* data, size_t length);
}
}
diff --git a/thirdparty/assimp/code/FIReader.cpp b/thirdparty/assimp/code/FIReader.cpp
deleted file mode 100644
index 2116316ca3..0000000000
--- a/thirdparty/assimp/code/FIReader.cpp
+++ /dev/null
@@ -1,1834 +0,0 @@
-/*
-Open Asset Import Library (assimp)
-----------------------------------------------------------------------
-
-Copyright (c) 2006-2019, assimp team
-
-
-All rights reserved.
-
-Redistribution and use of this software in source and binary forms,
-with or without modification, are permitted provided that the
-following conditions are met:
-
-* Redistributions of source code must retain the above
-copyright notice, this list of conditions and the
-following disclaimer.
-
-* Redistributions in binary form must reproduce the above
-copyright notice, this list of conditions and the
-following disclaimer in the documentation and/or other
-materials provided with the distribution.
-
-* Neither the name of the assimp team, nor the names of its
-contributors may be used to endorse or promote products
-derived from this software without specific prior
-written permission of the assimp team.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-----------------------------------------------------------------------
-*/
-/// \file FIReader.cpp
-/// \brief Reader for Fast Infoset encoded binary XML files.
-/// \date 2017
-/// \author Patrick Daehne
-
-#ifndef ASSIMP_BUILD_NO_X3D_IMPORTER
-
-#include "FIReader.hpp"
-#include <assimp/StringUtils.h>
-
-// Workaround for issue #1361
-// https://github.com/assimp/assimp/issues/1361
-#ifdef __ANDROID__
-# define _GLIBCXX_USE_C99 1
-#endif
-
-#include <assimp/Exceptional.h>
-#include <assimp/IOStream.hpp>
-#include <assimp/types.h>
-#include <assimp/MemoryIOWrapper.h>
-#include <assimp/irrXMLWrapper.h>
-#include "../contrib/utf8cpp/source/utf8.h"
-#include <assimp/fast_atof.h>
-#include <stack>
-#include <map>
-#include <iostream>
-#include <sstream>
-#include <iomanip>
-
-namespace Assimp {
-
-static const std::string parseErrorMessage = "Fast Infoset parse error";
-
-static const char *xmlDeclarations[] = {
- "<?xml encoding='finf'?>",
- "<?xml encoding='finf' standalone='yes'?>",
- "<?xml encoding='finf' standalone='no'?>",
- "<?xml version='1.0' encoding='finf'?>",
- "<?xml version='1.0' encoding='finf' standalone='yes'?>",
- "<?xml version='1.0' encoding='finf' standalone='no'?>",
- "<?xml version='1.1' encoding='finf'?>",
- "<?xml version='1.1' encoding='finf' standalone='yes'?>",
- "<?xml version='1.1' encoding='finf' standalone='no'?>"
-};
-
-static size_t parseMagic(const uint8_t *data, const uint8_t *dataEnd) {
- if (dataEnd - data < 4) {
- return 0;
- }
- uint32_t magic = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
- switch (magic) {
- case 0xe0000001:
- return 4;
- case 0x3c3f786d: // "<?xm"
- {
- size_t xmlDeclarationsLength = sizeof(xmlDeclarations) / sizeof(xmlDeclarations[0]);
- for (size_t i = 0; i < xmlDeclarationsLength; ++i) {
- auto xmlDeclaration = xmlDeclarations[i];
- ptrdiff_t xmlDeclarationLength = strlen(xmlDeclaration);
- if ((dataEnd - data >= xmlDeclarationLength) && (memcmp(xmlDeclaration, data, xmlDeclarationLength) == 0)) {
- data += xmlDeclarationLength;
- if (dataEnd - data < 4) {
- return 0;
- }
- magic = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
- return magic == 0xe0000001 ? xmlDeclarationLength + 4 : 0;
- }
- }
- return 0;
- }
- default:
- return 0;
- }
-}
-
-static std::string parseUTF8String(const uint8_t *data, size_t len) {
- return std::string((char*)data, len);
-}
-
-static std::string parseUTF16String(const uint8_t *data, size_t len) {
- if (len & 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- size_t numShorts = len / 2;
- std::vector<short> utf16;
- utf16.reserve(numShorts);
- for (size_t i = 0; i < numShorts; ++i) {
- short v = (data[0] << 8) | data[1];
- utf16.push_back(v);
- data += 2;
- }
- std::string result;
- utf8::utf16to8(utf16.begin(), utf16.end(), back_inserter(result));
- return result;
-}
-
-struct FIStringValueImpl: public FIStringValue {
- inline FIStringValueImpl(std::string &&value_) { value = std::move(value_); }
- virtual const std::string &toString() const /*override*/ { return value; }
-};
-
-std::shared_ptr<FIStringValue> FIStringValue::create(std::string &&value) {
- return std::make_shared<FIStringValueImpl>(std::move(value));
-}
-
-struct FIHexValueImpl: public FIHexValue {
- mutable std::string strValue;
- mutable bool strValueValid;
- inline FIHexValueImpl(std::vector<uint8_t> &&value_): strValueValid(false) { value = std::move(value_); }
- virtual const std::string &toString() const /*override*/ {
- if (!strValueValid) {
- strValueValid = true;
- std::ostringstream os;
- os << std::hex << std::uppercase << std::setfill('0');
- std::for_each(value.begin(), value.end(), [&](uint8_t c) { os << std::setw(2) << static_cast<int>(c); });
- strValue = os.str();
- }
- return strValue;
- };
-};
-
-std::shared_ptr<FIHexValue> FIHexValue::create(std::vector<uint8_t> &&value) {
- return std::make_shared<FIHexValueImpl>(std::move(value));
-}
-
-struct FIBase64ValueImpl: public FIBase64Value {
- mutable std::string strValue;
- mutable bool strValueValid;
- inline FIBase64ValueImpl(std::vector<uint8_t> &&value_): strValueValid(false) { value = std::move(value_); }
- virtual const std::string &toString() const /*override*/ {
- if (!strValueValid) {
- strValueValid = true;
- std::ostringstream os;
- uint8_t c1 = 0, c2;
- int imod3 = 0;
- std::vector<uint8_t>::size_type valueSize = value.size();
- for (std::vector<uint8_t>::size_type i = 0; i < valueSize; ++i) {
- c2 = value[i];
- switch (imod3) {
- case 0:
- os << basis_64[c2 >> 2];
- imod3 = 1;
- break;
- case 1:
- os << basis_64[((c1 & 0x03) << 4) | ((c2 & 0xf0) >> 4)];
- imod3 = 2;
- break;
- case 2:
- os << basis_64[((c1 & 0x0f) << 2) | ((c2 & 0xc0) >> 6)] << basis_64[c2 & 0x3f];
- imod3 = 0;
- break;
- }
- c1 = c2;
- }
- switch (imod3) {
- case 1:
- os << basis_64[(c1 & 0x03) << 4] << "==";
- break;
- case 2:
- os << basis_64[(c1 & 0x0f) << 2] << '=';
- break;
- }
- strValue = os.str();
- }
- return strValue;
- };
- static const char basis_64[];
-};
-
-const char FIBase64ValueImpl::basis_64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
-std::shared_ptr<FIBase64Value> FIBase64Value::create(std::vector<uint8_t> &&value) {
- return std::make_shared<FIBase64ValueImpl>(std::move(value));
-}
-
-struct FIShortValueImpl: public FIShortValue {
- mutable std::string strValue;
- mutable bool strValueValid;
- inline FIShortValueImpl(std::vector<int16_t> &&value_): strValueValid(false) { value = std::move(value_); }
- virtual const std::string &toString() const /*override*/ {
- if (!strValueValid) {
- strValueValid = true;
- std::ostringstream os;
- int n = 0;
- std::for_each(value.begin(), value.end(), [&](int16_t s) { if (++n > 1) os << ' '; os << s; });
- strValue = os.str();
- }
- return strValue;
- }
-};
-
-std::shared_ptr<FIShortValue> FIShortValue::create(std::vector<int16_t> &&value) {
- return std::make_shared<FIShortValueImpl>(std::move(value));
-}
-
-struct FIIntValueImpl: public FIIntValue {
- mutable std::string strValue;
- mutable bool strValueValid;
- inline FIIntValueImpl(std::vector<int32_t> &&value_): strValueValid(false) { value = std::move(value_); }
- virtual const std::string &toString() const /*override*/ {
- if (!strValueValid) {
- strValueValid = true;
- std::ostringstream os;
- int n = 0;
- std::for_each(value.begin(), value.end(), [&](int32_t i) { if (++n > 1) os << ' '; os << i; });
- strValue = os.str();
- }
- return strValue;
- };
-};
-
-std::shared_ptr<FIIntValue> FIIntValue::create(std::vector<int32_t> &&value) {
- return std::make_shared<FIIntValueImpl>(std::move(value));
-}
-
-struct FILongValueImpl: public FILongValue {
- mutable std::string strValue;
- mutable bool strValueValid;
- inline FILongValueImpl(std::vector<int64_t> &&value_): strValueValid(false) { value = std::move(value_); }
- virtual const std::string &toString() const /*override*/ {
- if (!strValueValid) {
- strValueValid = true;
- std::ostringstream os;
- int n = 0;
- std::for_each(value.begin(), value.end(), [&](int64_t l) { if (++n > 1) os << ' '; os << l; });
- strValue = os.str();
- }
- return strValue;
- };
-};
-
-std::shared_ptr<FILongValue> FILongValue::create(std::vector<int64_t> &&value) {
- return std::make_shared<FILongValueImpl>(std::move(value));
-}
-
-struct FIBoolValueImpl: public FIBoolValue {
- mutable std::string strValue;
- mutable bool strValueValid;
- inline FIBoolValueImpl(std::vector<bool> &&value_): strValueValid(false) { value = std::move(value_); }
- virtual const std::string &toString() const /*override*/ {
- if (!strValueValid) {
- strValueValid = true;
- std::ostringstream os;
- os << std::boolalpha;
- int n = 0;
- std::for_each(value.begin(), value.end(), [&](bool b) { if (++n > 1) os << ' '; os << b; });
- strValue = os.str();
- }
- return strValue;
- };
-};
-
-std::shared_ptr<FIBoolValue> FIBoolValue::create(std::vector<bool> &&value) {
- return std::make_shared<FIBoolValueImpl>(std::move(value));
-}
-
-struct FIFloatValueImpl: public FIFloatValue {
- mutable std::string strValue;
- mutable bool strValueValid;
- inline FIFloatValueImpl(std::vector<float> &&value_): strValueValid(false) { value = std::move(value_); }
- virtual const std::string &toString() const /*override*/ {
- if (!strValueValid) {
- strValueValid = true;
- std::ostringstream os;
- int n = 0;
- std::for_each(value.begin(), value.end(), [&](float f) { if (++n > 1) os << ' '; os << f; });
- strValue = os.str();
- }
- return strValue;
- }
-};
-
-std::shared_ptr<FIFloatValue> FIFloatValue::create(std::vector<float> &&value) {
- return std::make_shared<FIFloatValueImpl>(std::move(value));
-}
-
-struct FIDoubleValueImpl: public FIDoubleValue {
- mutable std::string strValue;
- mutable bool strValueValid;
- inline FIDoubleValueImpl(std::vector<double> &&value_): strValueValid(false) { value = std::move(value_); }
- virtual const std::string &toString() const /*override*/ {
- if (!strValueValid) {
- strValueValid = true;
- std::ostringstream os;
- int n = 0;
- std::for_each(value.begin(), value.end(), [&](double d) { if (++n > 1) os << ' '; os << d; });
- strValue = os.str();
- }
- return strValue;
- }
-};
-
-std::shared_ptr<FIDoubleValue> FIDoubleValue::create(std::vector<double> &&value) {
- return std::make_shared<FIDoubleValueImpl>(std::move(value));
-}
-
-struct FIUUIDValueImpl: public FIUUIDValue {
- mutable std::string strValue;
- mutable bool strValueValid;
- inline FIUUIDValueImpl(std::vector<uint8_t> &&value_): strValueValid(false) { value = std::move(value_); }
- virtual const std::string &toString() const /*override*/ {
- if (!strValueValid) {
- strValueValid = true;
- std::ostringstream os;
- os << std::hex << std::uppercase << std::setfill('0');
- std::vector<uint8_t>::size_type valueSize = value.size();
- for (std::vector<uint8_t>::size_type i = 0; i < valueSize; ++i) {
- switch (i & 15) {
- case 0:
- if (i > 0) {
- os << ' ';
- }
- os << std::setw(2) << static_cast<int>(value[i]);
- break;
- case 4:
- case 6:
- case 8:
- case 10:
- os << '-';
- // intentionally fall through!
- case 1:
- case 2:
- case 3:
- case 5:
- case 7:
- case 9:
- case 11:
- case 12:
- case 13:
- case 14:
- case 15:
- os << std::setw(2) << static_cast<int>(value[i]);
- break;
- }
- }
- strValue = os.str();
- }
- return strValue;
- };
-};
-
-std::shared_ptr<FIUUIDValue> FIUUIDValue::create(std::vector<uint8_t> &&value) {
- return std::make_shared<FIUUIDValueImpl>(std::move(value));
-}
-
-struct FICDATAValueImpl: public FICDATAValue {
- inline FICDATAValueImpl(std::string &&value_) { value = std::move(value_); }
- virtual const std::string &toString() const /*override*/ { return value; }
-};
-
-std::shared_ptr<FICDATAValue> FICDATAValue::create(std::string &&value) {
- return std::make_shared<FICDATAValueImpl>(std::move(value));
-}
-
-struct FIHexDecoder: public FIDecoder {
- virtual std::shared_ptr<const FIValue> decode(const uint8_t *data, size_t len) /*override*/ {
- return FIHexValue::create(std::vector<uint8_t>(data, data + len));
- }
-};
-
-struct FIBase64Decoder: public FIDecoder {
- virtual std::shared_ptr<const FIValue> decode(const uint8_t *data, size_t len) /*override*/ {
- return FIBase64Value::create(std::vector<uint8_t>(data, data + len));
- }
-};
-
-struct FIShortDecoder: public FIDecoder {
- virtual std::shared_ptr<const FIValue> decode(const uint8_t *data, size_t len) /*override*/ {
- if (len & 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- std::vector<int16_t> value;
- size_t numShorts = len / 2;
- value.reserve(numShorts);
- for (size_t i = 0; i < numShorts; ++i) {
- int16_t v = (data[0] << 8) | data[1];
- value.push_back(v);
- data += 2;
- }
- return FIShortValue::create(std::move(value));
- }
-};
-
-struct FIIntDecoder: public FIDecoder {
- virtual std::shared_ptr<const FIValue> decode(const uint8_t *data, size_t len) /*override*/ {
- if (len & 3) {
- throw DeadlyImportError(parseErrorMessage);
- }
- std::vector<int32_t> value;
- size_t numInts = len / 4;
- value.reserve(numInts);
- for (size_t i = 0; i < numInts; ++i) {
- int32_t v = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
- value.push_back(v);
- data += 4;
- }
- return FIIntValue::create(std::move(value));
- }
-};
-
-struct FILongDecoder: public FIDecoder {
- virtual std::shared_ptr<const FIValue> decode(const uint8_t *data, size_t len) /*override*/ {
- if (len & 7) {
- throw DeadlyImportError(parseErrorMessage);
- }
- std::vector<int64_t> value;
- size_t numLongs = len / 8;
- value.reserve(numLongs);
- for (size_t i = 0; i < numLongs; ++i) {
- int64_t b0 = data[0], b1 = data[1], b2 = data[2], b3 = data[3], b4 = data[4], b5 = data[5], b6 = data[6], b7 = data[7];
- int64_t v = (b0 << 56) | (b1 << 48) | (b2 << 40) | (b3 << 32) | (b4 << 24) | (b5 << 16) | (b6 << 8) | b7;
- value.push_back(v);
- data += 8;
- }
- return FILongValue::create(std::move(value));
- }
-};
-
-struct FIBoolDecoder: public FIDecoder {
- virtual std::shared_ptr<const FIValue> decode(const uint8_t *data, size_t len) /*override*/ {
- if (len < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- std::vector<bool> value;
- uint8_t b = *data++;
- size_t unusedBits = b >> 4;
- size_t numBools = (len * 8) - 4 - unusedBits;
- value.reserve(numBools);
- uint8_t mask = 1 << 3;
- for (size_t i = 0; i < numBools; ++i) {
- if (!mask) {
- mask = 1 << 7;
- b = *data++;
- }
- value.push_back((b & mask) != 0);
- }
- return FIBoolValue::create(std::move(value));
- }
-};
-
-struct FIFloatDecoder: public FIDecoder {
- virtual std::shared_ptr<const FIValue> decode(const uint8_t *data, size_t len) /*override*/ {
- if (len & 3) {
- throw DeadlyImportError(parseErrorMessage);
- }
- std::vector<float> value;
- size_t numFloats = len / 4;
- value.reserve(numFloats);
- for (size_t i = 0; i < numFloats; ++i) {
- int v = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
- float f;
- memcpy(&f, &v, 4);
- value.push_back(f);
- data += 4;
- }
- return FIFloatValue::create(std::move(value));
- }
-};
-
-struct FIDoubleDecoder: public FIDecoder {
- virtual std::shared_ptr<const FIValue> decode(const uint8_t *data, size_t len) /*override*/ {
- if (len & 7) {
- throw DeadlyImportError(parseErrorMessage);
- }
- std::vector<double> value;
- size_t numDoubles = len / 8;
- value.reserve(numDoubles);
- for (size_t i = 0; i < numDoubles; ++i) {
- long long b0 = data[0], b1 = data[1], b2 = data[2], b3 = data[3], b4 = data[4], b5 = data[5], b6 = data[6], b7 = data[7];
- long long v = (b0 << 56) | (b1 << 48) | (b2 << 40) | (b3 << 32) | (b4 << 24) | (b5 << 16) | (b6 << 8) | b7;
- double f;
- memcpy(&f, &v, 8);
- value.push_back(f);
- data += 8;
- }
- return FIDoubleValue::create(std::move(value));
- }
-};
-
-struct FIUUIDDecoder: public FIDecoder {
- virtual std::shared_ptr<const FIValue> decode(const uint8_t *data, size_t len) /*override*/ {
- if (len & 15) {
- throw DeadlyImportError(parseErrorMessage);
- }
- return FIUUIDValue::create(std::vector<uint8_t>(data, data + len));
- }
-};
-
-struct FICDATADecoder: public FIDecoder {
- virtual std::shared_ptr<const FIValue> decode(const uint8_t *data, size_t len) /*override*/ {
- return FICDATAValue::create(parseUTF8String(data, len));
- }
-};
-
-class CFIReaderImpl: public FIReader {
-public:
-
- CFIReaderImpl(std::unique_ptr<uint8_t[]> data_, size_t size):
- data(std::move(data_)), dataP(data.get()), dataEnd(data.get() + size), currentNodeType(irr::io::EXN_NONE),
- emptyElement(false), headerPending(true), terminatorPending(false)
- {}
-
- virtual ~CFIReaderImpl() {}
-
- virtual bool read() /*override*/ {
- if (headerPending) {
- headerPending = false;
- parseHeader();
- }
- if (terminatorPending) {
- terminatorPending = false;
- if (elementStack.empty()) {
- return false;
- }
- else {
- nodeName = elementStack.top();
- elementStack.pop();
- currentNodeType = nodeName.empty() ? irr::io::EXN_UNKNOWN : irr::io::EXN_ELEMENT_END;
- return true;
- }
- }
- if (dataP >= dataEnd) {
- return false;
- }
- uint8_t b = *dataP;
- if (b < 0x80) { // Element (C.2.11.2, C.3.7.2)
- // C.3
- parseElement();
- return true;
- }
- else if (b < 0xc0) { // Characters (C.3.7.5)
- // C.7
- auto chars = parseNonIdentifyingStringOrIndex3(vocabulary.charactersTable);
- nodeName = chars->toString();
- currentNodeType = irr::io::EXN_TEXT;
- return true;
- }
- else if (b < 0xe0) {
- if ((b & 0xfc) == 0xc4) { // DTD (C.2.11.5)
- // C.9
- ++dataP;
- if (b & 0x02) {
- /*const std::string &systemID =*/ parseIdentifyingStringOrIndex(vocabulary.otherURITable);
- }
- if (b & 0x01) {
- /*const std::string &publicID =*/ parseIdentifyingStringOrIndex(vocabulary.otherURITable);
- }
- elementStack.push(EmptyString);
- currentNodeType = irr::io::EXN_UNKNOWN;
- return true;
- }
- else if ((b & 0xfc) == 0xc8) { // Unexpanded entity reference (C.3.7.4)
- // C.6
- ++dataP;
- /*const std::string &name =*/ parseIdentifyingStringOrIndex(vocabulary.otherNCNameTable);
- if (b & 0x02) {
- /*const std::string &systemID =*/ parseIdentifyingStringOrIndex(vocabulary.otherURITable);
- }
- if (b & 0x01) {
- /*const std::string &publicID =*/ parseIdentifyingStringOrIndex(vocabulary.otherURITable);
- }
- currentNodeType = irr::io::EXN_UNKNOWN;
- return true;
- }
- }
- else if (b < 0xf0) {
- if (b == 0xe1) { // Processing instruction (C.2.11.3, C.3.7.3)
- // C.5
- ++dataP;
- /*const std::string &target =*/ parseIdentifyingStringOrIndex(vocabulary.otherNCNameTable);
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- /*std::shared_ptr<const FIValue> data =*/ parseNonIdentifyingStringOrIndex1(vocabulary.otherStringTable);
- currentNodeType = irr::io::EXN_UNKNOWN;
- return true;
- }
- else if (b == 0xe2) { // Comment (C.2.11.4, C.3.7.6)
- // C.8
- ++dataP;
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- std::shared_ptr<const FIValue> comment = parseNonIdentifyingStringOrIndex1(vocabulary.otherStringTable);
- nodeName = comment->toString();
- currentNodeType = irr::io::EXN_COMMENT;
- return true;
- }
- }
- else { // Terminator (C.2.12, C.3.8)
- ++dataP;
- if (b == 0xff) {
- terminatorPending = true;
- }
- if (elementStack.empty()) {
- return false;
- }
- else {
- nodeName = elementStack.top();
- elementStack.pop();
- currentNodeType = nodeName.empty() ? irr::io::EXN_UNKNOWN : irr::io::EXN_ELEMENT_END;
- return true;
- }
- }
- throw DeadlyImportError(parseErrorMessage);
- }
-
- virtual irr::io::EXML_NODE getNodeType() const /*override*/ {
- return currentNodeType;
- }
-
- virtual int getAttributeCount() const /*override*/ {
- return static_cast<int>(attributes.size());
- }
-
- virtual const char* getAttributeName(int idx) const /*override*/ {
- if (idx < 0 || idx >= (int)attributes.size()) {
- return nullptr;
- }
- return attributes[idx].name.c_str();
- }
-
- virtual const char* getAttributeValue(int idx) const /*override*/ {
- if (idx < 0 || idx >= (int)attributes.size()) {
- return nullptr;
- }
- return attributes[idx].value->toString().c_str();
- }
-
- virtual const char* getAttributeValue(const char* name) const /*override*/ {
- const Attribute* attr = getAttributeByName(name);
- if (!attr) {
- return nullptr;
- }
- return attr->value->toString().c_str();
- }
-
- virtual const char* getAttributeValueSafe(const char* name) const /*override*/ {
- const Attribute* attr = getAttributeByName(name);
- if (!attr) {
- return EmptyString.c_str();
- }
- return attr->value->toString().c_str();
- }
-
- virtual int getAttributeValueAsInt(const char* name) const /*override*/ {
- const Attribute* attr = getAttributeByName(name);
- if (!attr) {
- return 0;
- }
- std::shared_ptr<const FIIntValue> intValue = std::dynamic_pointer_cast<const FIIntValue>(attr->value);
- if (intValue) {
- return intValue->value.size() == 1 ? intValue->value.front() : 0;
- }
- return atoi(attr->value->toString().c_str());
- }
-
- virtual int getAttributeValueAsInt(int idx) const /*override*/ {
- if (idx < 0 || idx >= (int)attributes.size()) {
- return 0;
- }
- std::shared_ptr<const FIIntValue> intValue = std::dynamic_pointer_cast<const FIIntValue>(attributes[idx].value);
- if (intValue) {
- return intValue->value.size() == 1 ? intValue->value.front() : 0;
- }
- return atoi(attributes[idx].value->toString().c_str());
- }
-
- virtual float getAttributeValueAsFloat(const char* name) const /*override*/ {
- const Attribute* attr = getAttributeByName(name);
- if (!attr) {
- return 0;
- }
- std::shared_ptr<const FIFloatValue> floatValue = std::dynamic_pointer_cast<const FIFloatValue>(attr->value);
- if (floatValue) {
- return floatValue->value.size() == 1 ? floatValue->value.front() : 0;
- }
-
- return fast_atof(attr->value->toString().c_str());
- }
-
- virtual float getAttributeValueAsFloat(int idx) const /*override*/ {
- if (idx < 0 || idx >= (int)attributes.size()) {
- return 0;
- }
- std::shared_ptr<const FIFloatValue> floatValue = std::dynamic_pointer_cast<const FIFloatValue>(attributes[idx].value);
- if (floatValue) {
- return floatValue->value.size() == 1 ? floatValue->value.front() : 0;
- }
- return fast_atof(attributes[idx].value->toString().c_str());
- }
-
- virtual const char* getNodeName() const /*override*/ {
- return nodeName.c_str();
- }
-
- virtual const char* getNodeData() const /*override*/ {
- return nodeName.c_str();
- }
-
- virtual bool isEmptyElement() const /*override*/ {
- return emptyElement;
- }
-
- virtual irr::io::ETEXT_FORMAT getSourceFormat() const /*override*/ {
- return irr::io::ETF_UTF8;
- }
-
- virtual irr::io::ETEXT_FORMAT getParserFormat() const /*override*/ {
- return irr::io::ETF_UTF8;
- }
-
- virtual std::shared_ptr<const FIValue> getAttributeEncodedValue(int idx) const /*override*/ {
- if (idx < 0 || idx >= (int)attributes.size()) {
- return nullptr;
- }
- return attributes[idx].value;
- }
-
- virtual std::shared_ptr<const FIValue> getAttributeEncodedValue(const char* name) const /*override*/ {
- const Attribute* attr = getAttributeByName(name);
- if (!attr) {
- return nullptr;
- }
- return attr->value;
- }
-
- virtual void registerDecoder(const std::string &algorithmUri, std::unique_ptr<FIDecoder> decoder) /*override*/ {
- decoderMap[algorithmUri] = std::move(decoder);
- }
-
- virtual void registerVocabulary(const std::string &vocabularyUri, const FIVocabulary *vocabulary) /*override*/ {
- vocabularyMap[vocabularyUri] = vocabulary;
- }
-
-private:
-
- struct QName {
- std::string prefix;
- std::string uri;
- std::string name;
- inline QName() {}
- inline QName(const FIQName &qname): prefix(qname.prefix ? qname.prefix : ""), uri(qname.uri ? qname.uri : ""), name(qname.name) {}
- };
-
- struct Attribute {
- QName qname;
- std::string name;
- std::shared_ptr<const FIValue> value;
- };
-
- struct Vocabulary {
- std::vector<std::string> restrictedAlphabetTable;
- std::vector<std::string> encodingAlgorithmTable;
- std::vector<std::string> prefixTable;
- std::vector<std::string> namespaceNameTable;
- std::vector<std::string> localNameTable;
- std::vector<std::string> otherNCNameTable;
- std::vector<std::string> otherURITable;
- std::vector<std::shared_ptr<const FIValue>> attributeValueTable;
- std::vector<std::shared_ptr<const FIValue>> charactersTable;
- std::vector<std::shared_ptr<const FIValue>> otherStringTable;
- std::vector<QName> elementNameTable;
- std::vector<QName> attributeNameTable;
- Vocabulary() {
- prefixTable.push_back("xml");
- namespaceNameTable.push_back("http://www.w3.org/XML/1998/namespace");
- }
- };
-
- const Attribute* getAttributeByName(const char* name) const {
- if (!name) {
- return 0;
- }
- std::string n = name;
- for (int i=0; i<(int)attributes.size(); ++i) {
- if (attributes[i].name == n) {
- return &attributes[i];
- }
- }
- return 0;
- }
-
- size_t parseInt2() { // C.25
- uint8_t b = *dataP++;
- if (!(b & 0x40)) { // x0...... (C.25.2)
- return b & 0x3f;
- }
- else if ((b & 0x60) == 0x40) { // x10..... ........ (C.25.3)
- if (dataEnd - dataP > 0) {
- return (((b & 0x1f) << 8) | *dataP++) + 0x40;
- }
- }
- else if ((b & 0x70) == 0x60) { // x110.... ........ ........ (C.25.4)
- if (dataEnd - dataP > 1) {
- size_t result = (((b & 0x0f) << 16) | (dataP[0] << 8) | dataP[1]) + 0x2040;
- dataP += 2;
- return result;
- }
- }
- throw DeadlyImportError(parseErrorMessage);
- }
-
- size_t parseInt3() { // C.27
- uint8_t b = *dataP++;
- if (!(b & 0x20)) { // xx0..... (C.27.2)
- return b & 0x1f;
- }
- else if ((b & 0x38) == 0x20) { // xx100... ........ (C.27.3)
- if (dataEnd - dataP > 0) {
- return (((b & 0x07) << 8) | *dataP++) + 0x20;
- }
- }
- else if ((b & 0x38) == 0x28) { // xx101... ........ ........ (C.27.4)
- if (dataEnd - dataP > 1) {
- size_t result = (((b & 0x07) << 16) | (dataP[0] << 8) | dataP[1]) + 0x820;
- dataP += 2;
- return result;
- }
- }
- else if ((b & 0x3f) == 0x30) { // xx110000 0000.... ........ ........ (C.27.5)
- if ((dataEnd - dataP > 2) && !(dataP[0] & 0xf0)) {
- size_t result = (((dataP[0] & 0x0f) << 16) | (dataP[1] << 8) | dataP[2]) + 0x80820;
- dataP += 3;
- return result;
- }
- }
- throw DeadlyImportError(parseErrorMessage);
- }
-
- size_t parseInt4() { // C.28
- uint8_t b = *dataP++;
- if (!(b & 0x10)) { // xxx0.... (C.28.2)
- return b & 0x0f;
- }
- else if ((b & 0x1c) == 0x10) { // xxx100.. ........ (C.28.3)
- if (dataEnd - dataP > 0) {
- return (((b & 0x03) << 8) | *dataP++) + 0x10;
- }
- }
- else if ((b & 0x1c) == 0x14) { // xxx101.. ........ ........ (C.28.4)
- if (dataEnd - dataP > 1) {
- size_t result = (((b & 0x03) << 16) | (dataP[0] << 8) | dataP[1]) + 0x410;
- dataP += 2;
- return result;
- }
- }
- else if ((b & 0x1f) == 0x18) { // xxx11000 0000.... ........ ........ (C.28.5)
- if ((dataEnd - dataP > 2) && !(dataP[0] & 0xf0)) {
- size_t result = (((dataP[0] & 0x0f) << 16) | (dataP[1] << 8) | dataP[2]) + 0x40410;
- dataP += 3;
- return result;
- }
- }
- throw DeadlyImportError(parseErrorMessage);
- }
-
- size_t parseSequenceLen() { // C.21
- if (dataEnd - dataP > 0) {
- uint8_t b = *dataP++;
- if (b < 0x80) { // 0....... (C.21.2)
- return b;
- }
- else if ((b & 0xf0) == 0x80) { // 1000.... ........ ........ (C.21.3)
- if (dataEnd - dataP > 1) {
- size_t result = (((b & 0x0f) << 16) | (dataP[0] << 8) | dataP[1]) + 0x80;
- dataP += 2;
- return result;
- }
- }
- }
- throw DeadlyImportError(parseErrorMessage);
- }
-
- std::string parseNonEmptyOctetString2() { // C.22
- // Parse the length of the string
- uint8_t b = *dataP++ & 0x7f;
- size_t len;
- if (!(b & 0x40)) { // x0...... (C.22.3.1)
- len = b + 1;
- }
- else if (b == 0x40) { // x1000000 ........ (C.22.3.2)
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- len = *dataP++ + 0x41;
- }
- else if (b == 0x60) { // x1100000 ........ ........ ........ ........ (C.22.3.3)
- if (dataEnd - dataP < 4) {
- throw DeadlyImportError(parseErrorMessage);
- }
- len = ((dataP[0] << 24) | (dataP[1] << 16) | (dataP[2] << 8) | dataP[3]) + 0x141;
- dataP += 4;
- }
- else {
- throw DeadlyImportError(parseErrorMessage);
- }
-
- // Parse the string (C.22.4)
- if (dataEnd - dataP < static_cast<ptrdiff_t>(len)) {
- throw DeadlyImportError(parseErrorMessage);
- }
- std::string s = parseUTF8String(dataP, len);
- dataP += len;
-
- return s;
- }
-
- size_t parseNonEmptyOctetString5Length() { // C.23
- // Parse the length of the string
- size_t b = *dataP++ & 0x0f;
- if (!(b & 0x08)) { // xxxx0... (C.23.3.1)
- return b + 1;
- }
- else if (b == 0x08) { // xxxx1000 ........ (C.23.3.2)
- if (dataEnd - dataP > 0) {
- return *dataP++ + 0x09;
- }
- }
- else if (b == 0x0c) { // xxxx1100 ........ ........ ........ ........ (C.23.3.3)
- if (dataEnd - dataP > 3) {
- size_t result = ((dataP[0] << 24) | (dataP[1] << 16) | (dataP[2] << 8) | dataP[3]) + 0x109;
- dataP += 4;
- return result;
- }
- }
- throw DeadlyImportError(parseErrorMessage);
- }
-
- size_t parseNonEmptyOctetString7Length() { // C.24
- // Parse the length of the string
- size_t b = *dataP++ & 0x03;
- if (!(b & 0x02)) { // xxxxxx0. (C.24.3.1)
- return b + 1;
- }
- else if (b == 0x02) { // xxxxxx10 ........ (C.24.3.2)
- if (dataEnd - dataP > 0) {
- return *dataP++ + 0x3;
- }
- }
- else if (b == 0x03) { // xxxxxx11 ........ ........ ........ ........ (C.24.3.3)
- if (dataEnd - dataP > 3) {
- size_t result = ((dataP[0] << 24) | (dataP[1] << 16) | (dataP[2] << 8) | dataP[3]) + 0x103;
- dataP += 4;
- return result;
- }
- }
- throw DeadlyImportError(parseErrorMessage);
- }
-
- std::shared_ptr<const FIValue> parseEncodedData(size_t index, size_t len) {
- if (index < 32) {
- FIDecoder *decoder = defaultDecoder[index];
- if (!decoder) {
- throw DeadlyImportError("Invalid encoding algorithm index " + to_string(index));
- }
- return decoder->decode(dataP, len);
- }
- else {
- if (index - 32 >= vocabulary.encodingAlgorithmTable.size()) {
- throw DeadlyImportError("Invalid encoding algorithm index " + to_string(index));
- }
- std::string uri = vocabulary.encodingAlgorithmTable[index - 32];
- auto it = decoderMap.find(uri);
- if (it == decoderMap.end()) {
- throw DeadlyImportError("Unsupported encoding algorithm " + uri);
- }
- else {
- return it->second->decode(dataP, len);
- }
- }
- }
-
- std::shared_ptr<const FIValue> parseRestrictedAlphabet(size_t index, size_t len) {
- std::string alphabet;
- if (index < 16) {
- switch (index) {
- case 0: // numeric
- alphabet = "0123456789-+.e ";
- break;
- case 1: // date and time
- alphabet = "0123456789-:TZ ";
- break;
- default:
- throw DeadlyImportError("Invalid restricted alphabet index " + to_string(index));
- }
- }
- else {
- if (index - 16 >= vocabulary.restrictedAlphabetTable.size()) {
- throw DeadlyImportError("Invalid restricted alphabet index " + to_string(index));
- }
- alphabet = vocabulary.restrictedAlphabetTable[index - 16];
- }
- std::vector<uint32_t> alphabetUTF32;
- utf8::utf8to32(alphabet.begin(), alphabet.end(), back_inserter(alphabetUTF32));
- std::string::size_type alphabetLength = alphabetUTF32.size();
- if (alphabetLength < 2) {
- throw DeadlyImportError("Invalid restricted alphabet length " + to_string(alphabetLength));
- }
- std::string::size_type bitsPerCharacter = 1;
- while ((1ull << bitsPerCharacter) <= alphabetLength) {
- ++bitsPerCharacter;
- }
- size_t bitsAvail = 0;
- uint8_t mask = (1 << bitsPerCharacter) - 1;
- uint32_t bits = 0;
- std::string s;
- for (size_t i = 0; i < len; ++i) {
- bits = (bits << 8) | dataP[i];
- bitsAvail += 8;
- while (bitsAvail >= bitsPerCharacter) {
- bitsAvail -= bitsPerCharacter;
- size_t charIndex = (bits >> bitsAvail) & mask;
- if (charIndex < alphabetLength) {
- s.push_back(alphabetUTF32[charIndex]);
- }
- else if (charIndex != mask) {
- throw DeadlyImportError(parseErrorMessage);
- }
- }
- }
- return FIStringValue::create(std::move(s));
- }
-
- std::shared_ptr<const FIValue> parseEncodedCharacterString3() { // C.19
- std::shared_ptr<const FIValue> result;
- size_t len;
- uint8_t b = *dataP;
- if (b & 0x20) {
- ++dataP;
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- size_t index = ((b & 0x0f) << 4) | ((*dataP & 0xf0) >> 4); // C.29
- len = parseNonEmptyOctetString5Length();
- if (dataEnd - dataP < static_cast<ptrdiff_t>(len)) {
- throw DeadlyImportError(parseErrorMessage);
- }
- if (b & 0x10) {
- // encoding algorithm (C.19.3.4)
- result = parseEncodedData(index, len);
- }
- else {
- // Restricted alphabet (C.19.3.3)
- result = parseRestrictedAlphabet(index, len);
- }
- }
- else {
- len = parseNonEmptyOctetString5Length();
- if (dataEnd - dataP < static_cast<ptrdiff_t>(len)) {
- throw DeadlyImportError(parseErrorMessage);
- }
- if (b & 0x10) {
- // UTF-16 (C.19.3.2)
- if (len & 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- result = FIStringValue::create(parseUTF16String(dataP, len));
- }
- else {
- // UTF-8 (C.19.3.1)
- result = FIStringValue::create(parseUTF8String(dataP, len));
- }
- }
- dataP += len;
- return result;
- }
-
- std::shared_ptr<const FIValue> parseEncodedCharacterString5() { // C.20
- std::shared_ptr<const FIValue> result;
- size_t len;
- uint8_t b = *dataP;
- if (b & 0x08) {
- ++dataP;
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- size_t index = ((b & 0x03) << 6) | ((*dataP & 0xfc) >> 2); /* C.29 */
- len = parseNonEmptyOctetString7Length();
- if (dataEnd - dataP < static_cast<ptrdiff_t>(len)) {
- throw DeadlyImportError(parseErrorMessage);
- }
- if (b & 0x04) {
- // encoding algorithm (C.20.3.4)
- result = parseEncodedData(index, len);
- }
- else {
- // Restricted alphabet (C.20.3.3)
- result = parseRestrictedAlphabet(index, len);
- }
- }
- else {
- len = parseNonEmptyOctetString7Length();
- if (dataEnd - dataP < static_cast<ptrdiff_t>(len)) {
- throw DeadlyImportError(parseErrorMessage);
- }
- if (b & 0x04) {
- // UTF-16 (C.20.3.2)
- if (len & 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- result = FIStringValue::create(parseUTF16String(dataP, len));
- }
- else {
- // UTF-8 (C.20.3.1)
- result = FIStringValue::create(parseUTF8String(dataP, len));
- }
- }
- dataP += len;
- return result;
- }
-
- const std::string &parseIdentifyingStringOrIndex(std::vector<std::string> &stringTable) { // C.13
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- uint8_t b = *dataP;
- if (b & 0x80) {
- // We have an index (C.13.4)
- size_t index = parseInt2();
- if (index >= stringTable.size()) {
- throw DeadlyImportError(parseErrorMessage);
- }
- return stringTable[index];
- }
- else {
- // We have a string (C.13.3)
- stringTable.push_back(parseNonEmptyOctetString2());
- return stringTable.back();
- }
- }
-
- QName parseNameSurrogate() { // C.16
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- uint8_t b = *dataP++;
- if (b & 0xfc) { // Padding '000000' C.2.5.5
- throw DeadlyImportError(parseErrorMessage);
- }
- QName result;
- size_t index;
- if (b & 0x02) { // prefix (C.16.3)
- if ((dataEnd - dataP < 1) || (*dataP & 0x80)) {
- throw DeadlyImportError(parseErrorMessage);
- }
- index = parseInt2();
- if (index >= vocabulary.prefixTable.size()) {
- throw DeadlyImportError(parseErrorMessage);
- }
- result.prefix = vocabulary.prefixTable[index];
- }
- if (b & 0x01) { // namespace-name (C.16.4)
- if ((dataEnd - dataP < 1) || (*dataP & 0x80)) {
- throw DeadlyImportError(parseErrorMessage);
- }
- index = parseInt2();
- if (index >= vocabulary.namespaceNameTable.size()) {
- throw DeadlyImportError(parseErrorMessage);
- }
- result.uri = vocabulary.namespaceNameTable[index];
- }
- // local-name
- if ((dataEnd - dataP < 1) || (*dataP & 0x80)) {
- throw DeadlyImportError(parseErrorMessage);
- }
- index = parseInt2();
- if (index >= vocabulary.localNameTable.size()) {
- throw DeadlyImportError(parseErrorMessage);
- }
- result.name = vocabulary.localNameTable[index];
- return result;
- }
-
- const QName &parseQualifiedNameOrIndex2(std::vector<QName> &qNameTable) { // C.17
- uint8_t b = *dataP;
- if ((b & 0x7c) == 0x78) { // x11110..
- // We have a literal (C.17.3)
- ++dataP;
- QName result;
- // prefix (C.17.3.1)
- result.prefix = b & 0x02 ? parseIdentifyingStringOrIndex(vocabulary.prefixTable) : std::string();
- // namespace-name (C.17.3.1)
- result.uri = b & 0x01 ? parseIdentifyingStringOrIndex(vocabulary.namespaceNameTable) : std::string();
- // local-name
- result.name = parseIdentifyingStringOrIndex(vocabulary.localNameTable);
- qNameTable.push_back(result);
- return qNameTable.back();
- }
- else {
- // We have an index (C.17.4)
- size_t index = parseInt2();
- if (index >= qNameTable.size()) {
- throw DeadlyImportError(parseErrorMessage);
- }
- return qNameTable[index];
- }
- }
-
- const QName &parseQualifiedNameOrIndex3(std::vector<QName> &qNameTable) { // C.18
- uint8_t b = *dataP;
- if ((b & 0x3c) == 0x3c) { // xx1111..
- // We have a literal (C.18.3)
- ++dataP;
- QName result;
- // prefix (C.18.3.1)
- result.prefix = b & 0x02 ? parseIdentifyingStringOrIndex(vocabulary.prefixTable) : std::string();
- // namespace-name (C.18.3.1)
- result.uri = b & 0x01 ? parseIdentifyingStringOrIndex(vocabulary.namespaceNameTable) : std::string();
- // local-name
- result.name = parseIdentifyingStringOrIndex(vocabulary.localNameTable);
- qNameTable.push_back(result);
- return qNameTable.back();
- }
- else {
- // We have an index (C.18.4)
- size_t index = parseInt3();
- if (index >= qNameTable.size()) {
- throw DeadlyImportError(parseErrorMessage);
- }
- return qNameTable[index];
- }
- }
-
- std::shared_ptr<const FIValue> parseNonIdentifyingStringOrIndex1(std::vector<std::shared_ptr<const FIValue>> &valueTable) { // C.14
- uint8_t b = *dataP;
- if (b == 0xff) { // C.26.2
- // empty string
- ++dataP;
- return EmptyFIString;
- }
- else if (b & 0x80) { // C.14.4
- // We have an index
- size_t index = parseInt2();
- if (index >= valueTable.size()) {
- throw DeadlyImportError(parseErrorMessage);
- }
- return valueTable[index];
- }
- else { // C.14.3
- // We have a literal
- std::shared_ptr<const FIValue> result = parseEncodedCharacterString3();
- if (b & 0x40) { // C.14.3.1
- valueTable.push_back(result);
- }
- return result;
- }
- }
-
- std::shared_ptr<const FIValue> parseNonIdentifyingStringOrIndex3(std::vector<std::shared_ptr<const FIValue>> &valueTable) { // C.15
- uint8_t b = *dataP;
- if (b & 0x20) { // C.15.4
- // We have an index
- size_t index = parseInt4();
- if (index >= valueTable.size()) {
- throw DeadlyImportError(parseErrorMessage);
- }
- return valueTable[index];
- }
- else { // C.15.3
- // We have a literal
- std::shared_ptr<const FIValue> result = parseEncodedCharacterString5();
- if (b & 0x10) { // C.15.3.1
- valueTable.push_back(result);
- }
- return result;
- }
- }
-
- void parseElement() {
- // C.3
-
- attributes.clear();
-
- uint8_t b = *dataP;
- bool hasAttributes = (b & 0x40) != 0; // C.3.3
- if ((b & 0x3f) == 0x38) { // C.3.4.1
- // Parse namespaces
- ++dataP;
- for (;;) {
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- b = *dataP++;
- if (b == 0xf0) { // C.3.4.3
- break;
- }
- if ((b & 0xfc) != 0xcc) { // C.3.4.2
- throw DeadlyImportError(parseErrorMessage);
- }
- // C.12
- Attribute attr;
- attr.qname.prefix = "xmlns";
- attr.qname.name = b & 0x02 ? parseIdentifyingStringOrIndex(vocabulary.prefixTable) : std::string();
- attr.qname.uri = b & 0x01 ? parseIdentifyingStringOrIndex(vocabulary.namespaceNameTable) : std::string();
- attr.name = attr.qname.name.empty() ? "xmlns" : "xmlns:" + attr.qname.name;
- attr.value = FIStringValue::create(std::string(attr.qname.uri));
- attributes.push_back(attr);
- }
- if ((dataEnd - dataP < 1) || (*dataP & 0xc0)) {
- throw DeadlyImportError(parseErrorMessage);
- }
- }
-
- // Parse Element name (C.3.5)
- const QName &elemName = parseQualifiedNameOrIndex3(vocabulary.elementNameTable);
- nodeName = elemName.prefix.empty() ? elemName.name : elemName.prefix + ':' + elemName.name;
-
- if (hasAttributes) {
- for (;;) {
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- b = *dataP;
- if (b < 0x80) { // C.3.6.1
- // C.4
- Attribute attr;
- attr.qname = parseQualifiedNameOrIndex2(vocabulary.attributeNameTable);
- attr.name = attr.qname.prefix.empty() ? attr.qname.name : attr.qname.prefix + ':' + attr.qname.name;
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- attr.value = parseNonIdentifyingStringOrIndex1(vocabulary.attributeValueTable);
- attributes.push_back(attr);
- }
- else {
- if ((b & 0xf0) != 0xf0) { // C.3.6.2
- throw DeadlyImportError(parseErrorMessage);
- }
- emptyElement = b == 0xff; // C.3.6.2, C.3.8
- ++dataP;
- break;
- }
- }
- }
- else {
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- b = *dataP;
- switch (b) {
- case 0xff:
- terminatorPending = true;
- // Intentionally fall through
- case 0xf0:
- emptyElement = true;
- ++dataP;
- break;
- default:
- emptyElement = false;
- }
- }
- if (!emptyElement) {
- elementStack.push(nodeName);
- }
-
- currentNodeType = irr::io::EXN_ELEMENT;
- }
-
- void parseHeader() {
- // Parse header (C.1.3)
- size_t magicSize = parseMagic(dataP, dataEnd);
- if (!magicSize) {
- throw DeadlyImportError(parseErrorMessage);
- }
- dataP += magicSize;
- // C.2.3
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- uint8_t b = *dataP++;
- if (b & 0x40) {
- // Parse additional data (C.2.4)
- size_t len = parseSequenceLen();
- for (size_t i = 0; i < len; ++i) {
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- /*std::string id =*/ parseNonEmptyOctetString2();
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- /*std::string data =*/ parseNonEmptyOctetString2();
- }
- }
- if (b & 0x20) {
- // Parse initial vocabulary (C.2.5)
- if (dataEnd - dataP < 2) {
- throw DeadlyImportError(parseErrorMessage);
- }
- uint16_t b1 = (dataP[0] << 8) | dataP[1];
- dataP += 2;
- if (b1 & 0x1000) {
- // External vocabulary (C.2.5.2)
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- std::string uri = parseNonEmptyOctetString2();
- auto it = vocabularyMap.find(uri);
- if (it == vocabularyMap.end()) {
- throw DeadlyImportError("Unknown vocabulary " + uri);
- }
- const FIVocabulary *externalVocabulary = it->second;
- if (externalVocabulary->restrictedAlphabetTable) {
- std::copy(externalVocabulary->restrictedAlphabetTable, externalVocabulary->restrictedAlphabetTable + externalVocabulary->restrictedAlphabetTableSize, std::back_inserter(vocabulary.restrictedAlphabetTable));
- }
- if (externalVocabulary->encodingAlgorithmTable) {
- std::copy(externalVocabulary->encodingAlgorithmTable, externalVocabulary->encodingAlgorithmTable + externalVocabulary->encodingAlgorithmTableSize, std::back_inserter(vocabulary.encodingAlgorithmTable));
- }
- if (externalVocabulary->prefixTable) {
- std::copy(externalVocabulary->prefixTable, externalVocabulary->prefixTable + externalVocabulary->prefixTableSize, std::back_inserter(vocabulary.prefixTable));
- }
- if (externalVocabulary->namespaceNameTable) {
- std::copy(externalVocabulary->namespaceNameTable, externalVocabulary->namespaceNameTable + externalVocabulary->namespaceNameTableSize, std::back_inserter(vocabulary.namespaceNameTable));
- }
- if (externalVocabulary->localNameTable) {
- std::copy(externalVocabulary->localNameTable, externalVocabulary->localNameTable + externalVocabulary->localNameTableSize, std::back_inserter(vocabulary.localNameTable));
- }
- if (externalVocabulary->otherNCNameTable) {
- std::copy(externalVocabulary->otherNCNameTable, externalVocabulary->otherNCNameTable + externalVocabulary->otherNCNameTableSize, std::back_inserter(vocabulary.otherNCNameTable));
- }
- if (externalVocabulary->otherURITable) {
- std::copy(externalVocabulary->otherURITable, externalVocabulary->otherURITable + externalVocabulary->otherURITableSize, std::back_inserter(vocabulary.otherURITable));
- }
- if (externalVocabulary->attributeValueTable) {
- std::copy(externalVocabulary->attributeValueTable, externalVocabulary->attributeValueTable + externalVocabulary->attributeValueTableSize, std::back_inserter(vocabulary.attributeValueTable));
- }
- if (externalVocabulary->charactersTable) {
- std::copy(externalVocabulary->charactersTable, externalVocabulary->charactersTable + externalVocabulary->charactersTableSize, std::back_inserter(vocabulary.charactersTable));
- }
- if (externalVocabulary->otherStringTable) {
- std::copy(externalVocabulary->otherStringTable, externalVocabulary->otherStringTable + externalVocabulary->otherStringTableSize, std::back_inserter(vocabulary.otherStringTable));
- }
- if (externalVocabulary->elementNameTable) {
- std::copy(externalVocabulary->elementNameTable, externalVocabulary->elementNameTable + externalVocabulary->elementNameTableSize, std::back_inserter(vocabulary.elementNameTable));
- }
- if (externalVocabulary->attributeNameTable) {
- std::copy(externalVocabulary->attributeNameTable, externalVocabulary->attributeNameTable + externalVocabulary->attributeNameTableSize, std::back_inserter(vocabulary.attributeNameTable));
- }
- }
- if (b1 & 0x0800) {
- // Parse restricted alphabets (C.2.5.3)
- for (size_t len = parseSequenceLen(); len > 0; --len) {
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- vocabulary.restrictedAlphabetTable.push_back(parseNonEmptyOctetString2());
- }
- }
- if (b1 & 0x0400) {
- // Parse encoding algorithms (C.2.5.3)
- for (size_t len = parseSequenceLen(); len > 0; --len) {
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- vocabulary.encodingAlgorithmTable.push_back(parseNonEmptyOctetString2());
- }
- }
- if (b1 & 0x0200) {
- // Parse prefixes (C.2.5.3)
- for (size_t len = parseSequenceLen(); len > 0; --len) {
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- vocabulary.prefixTable.push_back(parseNonEmptyOctetString2());
- }
- }
- if (b1 & 0x0100) {
- // Parse namespace names (C.2.5.3)
- for (size_t len = parseSequenceLen(); len > 0; --len) {
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- vocabulary.namespaceNameTable.push_back(parseNonEmptyOctetString2());
- }
- }
- if (b1 & 0x0080) {
- // Parse local names (C.2.5.3)
- for (size_t len = parseSequenceLen(); len > 0; --len) {
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- vocabulary.localNameTable.push_back(parseNonEmptyOctetString2());
- }
- }
- if (b1 & 0x0040) {
- // Parse other ncnames (C.2.5.3)
- for (size_t len = parseSequenceLen(); len > 0; --len) {
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- vocabulary.otherNCNameTable.push_back(parseNonEmptyOctetString2());
- }
- }
- if (b1 & 0x0020) {
- // Parse other uris (C.2.5.3)
- for (size_t len = parseSequenceLen(); len > 0; --len) {
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- vocabulary.otherURITable.push_back(parseNonEmptyOctetString2());
- }
- }
- if (b1 & 0x0010) {
- // Parse attribute values (C.2.5.4)
- for (size_t len = parseSequenceLen(); len > 0; --len) {
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- vocabulary.attributeValueTable.push_back(parseEncodedCharacterString3());
- }
- }
- if (b1 & 0x0008) {
- // Parse content character chunks (C.2.5.4)
- for (size_t len = parseSequenceLen(); len > 0; --len) {
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- vocabulary.charactersTable.push_back(parseEncodedCharacterString3());
- }
- }
- if (b1 & 0x0004) {
- // Parse other strings (C.2.5.4)
- for (size_t len = parseSequenceLen(); len > 0; --len) {
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- vocabulary.otherStringTable.push_back(parseEncodedCharacterString3());
- }
- }
- if (b1 & 0x0002) {
- // Parse element name surrogates (C.2.5.5)
- for (size_t len = parseSequenceLen(); len > 0; --len) {
- vocabulary.elementNameTable.push_back(parseNameSurrogate());
- }
- }
- if (b1 & 0x0001) {
- // Parse attribute name surrogates (C.2.5.5)
- for (size_t len = parseSequenceLen(); len > 0; --len) {
- vocabulary.attributeNameTable.push_back(parseNameSurrogate());
- }
- }
- }
- if (b & 0x10) {
- // Parse notations (C.2.6)
- for (;;) {
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- uint8_t b1 = *dataP++;
- if (b1 == 0xf0) {
- break;
- }
- if ((b1 & 0xfc) != 0xc0) {
- throw DeadlyImportError(parseErrorMessage);
- }
- /* C.11 */
- /*const std::string &name =*/ parseIdentifyingStringOrIndex(vocabulary.otherNCNameTable);
- if (b1 & 0x02) {
- /*const std::string &systemId =*/ parseIdentifyingStringOrIndex(vocabulary.otherURITable);
- }
- if (b1 & 0x01) {
- /*const std::string &publicId =*/ parseIdentifyingStringOrIndex(vocabulary.otherURITable);
- }
- }
- }
- if (b & 0x08) {
- // Parse unparsed entities (C.2.7)
- for (;;) {
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- uint8_t b1 = *dataP++;
- if (b1 == 0xf0) {
- break;
- }
- if ((b1 & 0xfe) != 0xd0) {
- throw DeadlyImportError(parseErrorMessage);
- }
- /* C.10 */
- /*const std::string &name =*/ parseIdentifyingStringOrIndex(vocabulary.otherNCNameTable);
- /*const std::string &systemId =*/ parseIdentifyingStringOrIndex(vocabulary.otherURITable);
- if (b1 & 0x01) {
- /*const std::string &publicId =*/ parseIdentifyingStringOrIndex(vocabulary.otherURITable);
- }
- /*const std::string &notationName =*/ parseIdentifyingStringOrIndex(vocabulary.otherNCNameTable);
- }
- }
- if (b & 0x04) {
- // Parse character encoding scheme (C.2.8)
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- /*std::string characterEncodingScheme =*/ parseNonEmptyOctetString2();
- }
- if (b & 0x02) {
- // Parse standalone flag (C.2.9)
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- uint8_t b1 = *dataP++;
- if (b1 & 0xfe) {
- throw DeadlyImportError(parseErrorMessage);
- }
- //bool standalone = b1 & 0x01;
- }
- if (b & 0x01) {
- // Parse version (C.2.10)
- if (dataEnd - dataP < 1) {
- throw DeadlyImportError(parseErrorMessage);
- }
- /*std::shared_ptr<const FIValue> version =*/ parseNonIdentifyingStringOrIndex1(vocabulary.otherStringTable);
- }
- }
-
- std::unique_ptr<uint8_t[]> data;
- uint8_t *dataP, *dataEnd;
- irr::io::EXML_NODE currentNodeType;
- bool emptyElement;
- bool headerPending;
- bool terminatorPending;
- Vocabulary vocabulary;
- std::vector<Attribute> attributes;
- std::stack<std::string> elementStack;
- std::string nodeName;
- std::map<std::string, std::unique_ptr<FIDecoder>> decoderMap;
- std::map<std::string, const FIVocabulary*> vocabularyMap;
-
- static const std::string EmptyString;
- static std::shared_ptr<const FIValue> EmptyFIString;
-
- static FIHexDecoder hexDecoder;
- static FIBase64Decoder base64Decoder;
- static FIShortDecoder shortDecoder;
- static FIIntDecoder intDecoder;
- static FILongDecoder longDecoder;
- static FIBoolDecoder boolDecoder;
- static FIFloatDecoder floatDecoder;
- static FIDoubleDecoder doubleDecoder;
- static FIUUIDDecoder uuidDecoder;
- static FICDATADecoder cdataDecoder;
- static FIDecoder *defaultDecoder[32];
-};
-
-const std::string CFIReaderImpl::EmptyString;
-std::shared_ptr<const FIValue> CFIReaderImpl::EmptyFIString = FIStringValue::create(std::string());
-
-FIHexDecoder CFIReaderImpl::hexDecoder;
-FIBase64Decoder CFIReaderImpl::base64Decoder;
-FIShortDecoder CFIReaderImpl::shortDecoder;
-FIIntDecoder CFIReaderImpl::intDecoder;
-FILongDecoder CFIReaderImpl::longDecoder;
-FIBoolDecoder CFIReaderImpl::boolDecoder;
-FIFloatDecoder CFIReaderImpl::floatDecoder;
-FIDoubleDecoder CFIReaderImpl::doubleDecoder;
-FIUUIDDecoder CFIReaderImpl::uuidDecoder;
-FICDATADecoder CFIReaderImpl::cdataDecoder;
-
-FIDecoder *CFIReaderImpl::defaultDecoder[32] = {
- &hexDecoder,
- &base64Decoder,
- &shortDecoder,
- &intDecoder,
- &longDecoder,
- &boolDecoder,
- &floatDecoder,
- &doubleDecoder,
- &uuidDecoder,
- &cdataDecoder
-};
-
-class CXMLReaderImpl : public FIReader
-{
-public:
-
- //! Constructor
- CXMLReaderImpl(std::unique_ptr<irr::io::IIrrXMLReader<char, irr::io::IXMLBase>> reader_)
- : reader(std::move(reader_))
- {}
-
- virtual ~CXMLReaderImpl() {}
-
- virtual bool read() /*override*/ {
- return reader->read();
- }
-
- virtual irr::io::EXML_NODE getNodeType() const /*override*/ {
- return reader->getNodeType();
- }
-
- virtual int getAttributeCount() const /*override*/ {
- return reader->getAttributeCount();
- }
-
- virtual const char* getAttributeName(int idx) const /*override*/ {
- return reader->getAttributeName(idx);
- }
-
- virtual const char* getAttributeValue(int idx) const /*override*/ {
- return reader->getAttributeValue(idx);
- }
-
- virtual const char* getAttributeValue(const char* name) const /*override*/ {
- return reader->getAttributeValue(name);
- }
-
- virtual const char* getAttributeValueSafe(const char* name) const /*override*/ {
- return reader->getAttributeValueSafe(name);
- }
-
- virtual int getAttributeValueAsInt(const char* name) const /*override*/ {
- return reader->getAttributeValueAsInt(name);
- }
-
- virtual int getAttributeValueAsInt(int idx) const /*override*/ {
- return reader->getAttributeValueAsInt(idx);
- }
-
- virtual float getAttributeValueAsFloat(const char* name) const /*override*/ {
- return reader->getAttributeValueAsFloat(name);
- }
-
- virtual float getAttributeValueAsFloat(int idx) const /*override*/ {
- return reader->getAttributeValueAsFloat(idx);
- }
-
- virtual const char* getNodeName() const /*override*/ {
- return reader->getNodeName();
- }
-
- virtual const char* getNodeData() const /*override*/ {
- return reader->getNodeData();
- }
-
- virtual bool isEmptyElement() const /*override*/ {
- return reader->isEmptyElement();
- }
-
- virtual irr::io::ETEXT_FORMAT getSourceFormat() const /*override*/ {
- return reader->getSourceFormat();
- }
-
- virtual irr::io::ETEXT_FORMAT getParserFormat() const /*override*/ {
- return reader->getParserFormat();
- }
-
- virtual std::shared_ptr<const FIValue> getAttributeEncodedValue(int /*idx*/) const /*override*/ {
- return nullptr;
- }
-
- virtual std::shared_ptr<const FIValue> getAttributeEncodedValue(const char* /*name*/) const /*override*/ {
- return nullptr;
- }
-
- virtual void registerDecoder(const std::string & /*algorithmUri*/, std::unique_ptr<FIDecoder> /*decoder*/) /*override*/ {}
-
-
- virtual void registerVocabulary(const std::string &/*vocabularyUri*/, const FIVocabulary * /*vocabulary*/) /*override*/ {}
-
-private:
-
- std::unique_ptr<irr::io::IIrrXMLReader<char, irr::io::IXMLBase>> reader;
-};
-
-static std::unique_ptr<uint8_t[]> readFile(IOStream *stream, size_t &size, bool &isFI) {
- size = stream->FileSize();
- std::unique_ptr<uint8_t[]> data = std::unique_ptr<uint8_t[]>(new uint8_t[size]);
- if (stream->Read(data.get(), size, 1) != 1) {
- size = 0;
- data.reset();
- }
- isFI = parseMagic(data.get(), data.get() + size) > 0;
- return data;
-}
-
-std::unique_ptr<FIReader> FIReader::create(IOStream *stream)
-{
- size_t size;
- bool isFI;
- auto data = readFile(stream, size, isFI);
- if (isFI) {
- return std::unique_ptr<FIReader>(new CFIReaderImpl(std::move(data), size));
- }
- else {
- auto memios = std::unique_ptr<MemoryIOStream>(new MemoryIOStream(data.release(), size, true));
- auto callback = std::unique_ptr<CIrrXML_IOStreamReader>(new CIrrXML_IOStreamReader(memios.get()));
- return std::unique_ptr<FIReader>(new CXMLReaderImpl(std::unique_ptr<irr::io::IIrrXMLReader<char, irr::io::IXMLBase>>(createIrrXMLReader(callback.get()))));
- }
-}
-
-}// namespace Assimp
-
-#endif // !ASSIMP_BUILD_NO_X3D_IMPORTER
diff --git a/thirdparty/assimp/code/MMDCpp14.h b/thirdparty/assimp/code/MMD/MMDCpp14.h
index 638b0bfd2f..638b0bfd2f 100644
--- a/thirdparty/assimp/code/MMDCpp14.h
+++ b/thirdparty/assimp/code/MMD/MMDCpp14.h
diff --git a/thirdparty/assimp/code/MMDImporter.cpp b/thirdparty/assimp/code/MMD/MMDImporter.cpp
index 84b9e35a6b..e7744e4cd0 100644
--- a/thirdparty/assimp/code/MMDImporter.cpp
+++ b/thirdparty/assimp/code/MMD/MMDImporter.cpp
@@ -41,15 +41,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef ASSIMP_BUILD_NO_MMD_IMPORTER
-#include "MMDImporter.h"
-#include "MMDPmdParser.h"
-#include "MMDPmxParser.h"
-#include "MMDVmdParser.h"
-#include "ConvertToLHProcess.h"
+#include "MMD/MMDImporter.h"
+#include "MMD/MMDPmdParser.h"
+#include "MMD/MMDPmxParser.h"
+#include "MMD/MMDVmdParser.h"
+#include "PostProcessing/ConvertToLHProcess.h"
+
#include <assimp/DefaultIOSystem.h>
#include <assimp/Importer.hpp>
#include <assimp/ai_assert.h>
#include <assimp/scene.h>
+
#include <fstream>
#include <iomanip>
#include <memory>
diff --git a/thirdparty/assimp/code/MMDImporter.h b/thirdparty/assimp/code/MMD/MMDImporter.h
index 4ee94eeb00..4ee94eeb00 100644
--- a/thirdparty/assimp/code/MMDImporter.h
+++ b/thirdparty/assimp/code/MMD/MMDImporter.h
diff --git a/thirdparty/assimp/code/MMDPmdParser.h b/thirdparty/assimp/code/MMD/MMDPmdParser.h
index d2f2224aa1..d2f2224aa1 100644
--- a/thirdparty/assimp/code/MMDPmdParser.h
+++ b/thirdparty/assimp/code/MMD/MMDPmdParser.h
diff --git a/thirdparty/assimp/code/MMDPmxParser.cpp b/thirdparty/assimp/code/MMD/MMDPmxParser.cpp
index 7425ceac22..80f0986dd7 100644
--- a/thirdparty/assimp/code/MMDPmxParser.cpp
+++ b/thirdparty/assimp/code/MMD/MMDPmxParser.cpp
@@ -42,7 +42,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <utility>
#include "MMDPmxParser.h"
#include <assimp/StringUtils.h>
-#include "../contrib/utf8cpp/source/utf8.h"
+#ifdef ASSIMP_USE_HUNTER
+# include <utf8/utf8.h>
+#else
+# include "../contrib/utf8cpp/source/utf8.h"
+#endif
#include <assimp/Exceptional.h>
namespace pmx
diff --git a/thirdparty/assimp/code/MMDPmxParser.h b/thirdparty/assimp/code/MMD/MMDPmxParser.h
index cf523a1298..cf523a1298 100644
--- a/thirdparty/assimp/code/MMDPmxParser.h
+++ b/thirdparty/assimp/code/MMD/MMDPmxParser.h
diff --git a/thirdparty/assimp/code/MMDVmdParser.h b/thirdparty/assimp/code/MMD/MMDVmdParser.h
index 947c3a2422..947c3a2422 100644
--- a/thirdparty/assimp/code/MMDVmdParser.h
+++ b/thirdparty/assimp/code/MMD/MMDVmdParser.h
diff --git a/thirdparty/assimp/code/MaterialSystem.cpp b/thirdparty/assimp/code/Material/MaterialSystem.cpp
index 03d5a18a34..d0b39093b6 100644
--- a/thirdparty/assimp/code/MaterialSystem.cpp
+++ b/thirdparty/assimp/code/Material/MaterialSystem.cpp
@@ -96,12 +96,12 @@ aiReturn aiGetMaterialFloatArray(const aiMaterial* pMat,
ai_real* pOut,
unsigned int* pMax)
{
- ai_assert( pOut != NULL );
- ai_assert( pMat != NULL );
+ ai_assert( pOut != nullptr );
+ ai_assert( pMat != nullptr );
const aiMaterialProperty* prop;
aiGetMaterialProperty(pMat,pKey,type,index, (const aiMaterialProperty**) &prop);
- if (!prop) {
+ if ( nullptr == prop) {
return AI_FAILURE;
}
@@ -112,9 +112,11 @@ aiReturn aiGetMaterialFloatArray(const aiMaterial* pMat,
if (pMax) {
iWrite = std::min(*pMax,iWrite); ;
}
- for (unsigned int a = 0; a < iWrite;++a) {
- pOut[a] = static_cast<ai_real> ( reinterpret_cast<float*>(prop->mData)[a] );
+
+ for (unsigned int a = 0; a < iWrite; ++a) {
+ pOut[ a ] = static_cast<ai_real> ( reinterpret_cast<float*>(prop->mData)[a] );
}
+
if (pMax) {
*pMax = iWrite;
}
diff --git a/thirdparty/assimp/code/MaterialSystem.h b/thirdparty/assimp/code/Material/MaterialSystem.h
index 67d53578cb..67d53578cb 100644
--- a/thirdparty/assimp/code/MaterialSystem.h
+++ b/thirdparty/assimp/code/Material/MaterialSystem.h
diff --git a/thirdparty/assimp/code/CalcTangentsProcess.cpp b/thirdparty/assimp/code/PostProcessing/CalcTangentsProcess.cpp
index b30f39c274..b30f39c274 100644
--- a/thirdparty/assimp/code/CalcTangentsProcess.cpp
+++ b/thirdparty/assimp/code/PostProcessing/CalcTangentsProcess.cpp
diff --git a/thirdparty/assimp/code/CalcTangentsProcess.h b/thirdparty/assimp/code/PostProcessing/CalcTangentsProcess.h
index 18775abcc7..3568a624f8 100644
--- a/thirdparty/assimp/code/CalcTangentsProcess.h
+++ b/thirdparty/assimp/code/PostProcessing/CalcTangentsProcess.h
@@ -42,11 +42,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/** @file Defines a post processing step to calculate tangents and
- bitangents on all imported meshes.*/
+ bi-tangents on all imported meshes.*/
#ifndef AI_CALCTANGENTSPROCESS_H_INC
#define AI_CALCTANGENTSPROCESS_H_INC
-#include "BaseProcess.h"
+#include "Common/BaseProcess.h"
struct aiMesh;
diff --git a/thirdparty/assimp/code/ComputeUVMappingProcess.cpp b/thirdparty/assimp/code/PostProcessing/ComputeUVMappingProcess.cpp
index bb571a551b..bb571a551b 100644
--- a/thirdparty/assimp/code/ComputeUVMappingProcess.cpp
+++ b/thirdparty/assimp/code/PostProcessing/ComputeUVMappingProcess.cpp
diff --git a/thirdparty/assimp/code/ComputeUVMappingProcess.h b/thirdparty/assimp/code/PostProcessing/ComputeUVMappingProcess.h
index 24f6bb7218..a6d36e06ea 100644
--- a/thirdparty/assimp/code/ComputeUVMappingProcess.h
+++ b/thirdparty/assimp/code/PostProcessing/ComputeUVMappingProcess.h
@@ -45,7 +45,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_COMPUTEUVMAPPING_H_INC
#define AI_COMPUTEUVMAPPING_H_INC
-#include "BaseProcess.h"
+#include "Common/BaseProcess.h"
+
#include <assimp/mesh.h>
#include <assimp/material.h>
#include <assimp/types.h>
diff --git a/thirdparty/assimp/code/ConvertToLHProcess.cpp b/thirdparty/assimp/code/PostProcessing/ConvertToLHProcess.cpp
index b7cd4f0bc6..b7cd4f0bc6 100644
--- a/thirdparty/assimp/code/ConvertToLHProcess.cpp
+++ b/thirdparty/assimp/code/PostProcessing/ConvertToLHProcess.cpp
diff --git a/thirdparty/assimp/code/ConvertToLHProcess.h b/thirdparty/assimp/code/PostProcessing/ConvertToLHProcess.h
index 63351568d0..f32b91fc39 100644
--- a/thirdparty/assimp/code/ConvertToLHProcess.h
+++ b/thirdparty/assimp/code/PostProcessing/ConvertToLHProcess.h
@@ -52,7 +52,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define AI_CONVERTTOLHPROCESS_H_INC
#include <assimp/types.h>
-#include "BaseProcess.h"
+
+#include "Common/BaseProcess.h"
struct aiMesh;
struct aiNodeAnim;
diff --git a/thirdparty/assimp/code/DeboneProcess.cpp b/thirdparty/assimp/code/PostProcessing/DeboneProcess.cpp
index 83b8336bc9..83b8336bc9 100644
--- a/thirdparty/assimp/code/DeboneProcess.cpp
+++ b/thirdparty/assimp/code/PostProcessing/DeboneProcess.cpp
diff --git a/thirdparty/assimp/code/DeboneProcess.h b/thirdparty/assimp/code/PostProcessing/DeboneProcess.h
index ba77aba70e..8b64c2acc6 100644
--- a/thirdparty/assimp/code/DeboneProcess.h
+++ b/thirdparty/assimp/code/PostProcessing/DeboneProcess.h
@@ -44,17 +44,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_DEBONEPROCESS_H_INC
#define AI_DEBONEPROCESS_H_INC
-#include <vector>
-#include <utility>
-#include "BaseProcess.h"
+#include "Common/BaseProcess.h"
#include <assimp/mesh.h>
#include <assimp/scene.h>
+#include <vector>
+#include <utility>
+
+#// Forward declarations
class DeboneTest;
-namespace Assimp
-{
+namespace Assimp {
#if (!defined AI_DEBONE_THRESHOLD)
# define AI_DEBONE_THRESHOLD 1.0f
@@ -66,14 +67,11 @@ namespace Assimp
* the bone are split from the mesh. The split off (new) mesh is boneless. At any
* point in time, bones without affect upon a given mesh are to be removed.
*/
-class DeboneProcess : public BaseProcess
-{
+class DeboneProcess : public BaseProcess {
public:
-
DeboneProcess();
~DeboneProcess();
-public:
// -------------------------------------------------------------------
/** Returns whether the processing step is present in the given flag.
* @param pFlags The processing flags the importer was called with.
@@ -91,7 +89,6 @@ public:
void SetupProperties(const Importer* pImp);
protected:
-
// -------------------------------------------------------------------
/** Executes the post processing step on the given imported data.
* At the moment a process is not supposed to fail.
diff --git a/thirdparty/assimp/code/DropFaceNormalsProcess.cpp b/thirdparty/assimp/code/PostProcessing/DropFaceNormalsProcess.cpp
index b11615bb82..b11615bb82 100644
--- a/thirdparty/assimp/code/DropFaceNormalsProcess.cpp
+++ b/thirdparty/assimp/code/PostProcessing/DropFaceNormalsProcess.cpp
diff --git a/thirdparty/assimp/code/DropFaceNormalsProcess.h b/thirdparty/assimp/code/PostProcessing/DropFaceNormalsProcess.h
index 0d116663b7..c710c5a5ee 100644
--- a/thirdparty/assimp/code/DropFaceNormalsProcess.h
+++ b/thirdparty/assimp/code/PostProcessing/DropFaceNormalsProcess.h
@@ -44,23 +44,20 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_DROPFACENORMALPROCESS_H_INC
#define AI_DROPFACENORMALPROCESS_H_INC
-#include "BaseProcess.h"
+#include "Common/BaseProcess.h"
+
#include <assimp/mesh.h>
-namespace Assimp
-{
+namespace Assimp {
// ---------------------------------------------------------------------------
/** The DropFaceNormalsProcess computes face normals for all faces of all meshes
*/
-class ASSIMP_API_WINONLY DropFaceNormalsProcess : public BaseProcess
-{
+class ASSIMP_API_WINONLY DropFaceNormalsProcess : public BaseProcess {
public:
-
DropFaceNormalsProcess();
~DropFaceNormalsProcess();
-public:
// -------------------------------------------------------------------
/** Returns whether the processing step is present in the given flag field.
* @param pFlags The processing flags the importer was called with. A bitwise
diff --git a/thirdparty/assimp/code/EmbedTexturesProcess.cpp b/thirdparty/assimp/code/PostProcessing/EmbedTexturesProcess.cpp
index 739382a057..739382a057 100644
--- a/thirdparty/assimp/code/EmbedTexturesProcess.cpp
+++ b/thirdparty/assimp/code/PostProcessing/EmbedTexturesProcess.cpp
diff --git a/thirdparty/assimp/code/EmbedTexturesProcess.h b/thirdparty/assimp/code/PostProcessing/EmbedTexturesProcess.h
index cdf40bef74..3c4b2eab4e 100644
--- a/thirdparty/assimp/code/EmbedTexturesProcess.h
+++ b/thirdparty/assimp/code/PostProcessing/EmbedTexturesProcess.h
@@ -42,7 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once
-#include "BaseProcess.h"
+#include "Common/BaseProcess.h"
#include <string>
diff --git a/thirdparty/assimp/code/FindDegenerates.cpp b/thirdparty/assimp/code/PostProcessing/FindDegenerates.cpp
index 365f5d7447..50fac46dba 100644
--- a/thirdparty/assimp/code/FindDegenerates.cpp
+++ b/thirdparty/assimp/code/PostProcessing/FindDegenerates.cpp
@@ -228,6 +228,7 @@ bool FindDegeneratesProcess::ExecuteOnMesh( aiMesh* mesh) {
if ( area < 1e-6 ) {
if ( mConfigRemoveDegenerates ) {
remove_me[ a ] = true;
+ ++deg;
goto evil_jump_outside;
}
diff --git a/thirdparty/assimp/code/FindDegenerates.h b/thirdparty/assimp/code/PostProcessing/FindDegenerates.h
index 880f5f16a2..7a15e77cf1 100644
--- a/thirdparty/assimp/code/FindDegenerates.h
+++ b/thirdparty/assimp/code/PostProcessing/FindDegenerates.h
@@ -45,7 +45,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_FINDDEGENERATESPROCESS_H_INC
#define AI_FINDDEGENERATESPROCESS_H_INC
-#include "BaseProcess.h"
+#include "Common/BaseProcess.h"
+
#include <assimp/mesh.h>
class FindDegeneratesProcessTest;
diff --git a/thirdparty/assimp/code/FindInstancesProcess.cpp b/thirdparty/assimp/code/PostProcessing/FindInstancesProcess.cpp
index be1138116e..64907458a1 100644
--- a/thirdparty/assimp/code/FindInstancesProcess.cpp
+++ b/thirdparty/assimp/code/PostProcessing/FindInstancesProcess.cpp
@@ -137,6 +137,11 @@ void FindInstancesProcess::Execute( aiScene* pScene)
aiMesh* inst = pScene->mMeshes[i];
hashes[i] = GetMeshHash(inst);
+ // Find an appropriate epsilon
+ // to compare position differences against
+ float epsilon = ComputePositionEpsilon(inst);
+ epsilon *= epsilon;
+
for (int a = i-1; a >= 0; --a) {
if (hashes[i] == hashes[a])
{
@@ -154,12 +159,7 @@ void FindInstancesProcess::Execute( aiScene* pScene)
orig->mPrimitiveTypes != inst->mPrimitiveTypes)
continue;
- // up to now the meshes are equal. find an appropriate
- // epsilon to compare position differences against
- float epsilon = ComputePositionEpsilon(inst);
- epsilon *= epsilon;
-
- // now compare vertex positions, normals,
+ // up to now the meshes are equal. Now compare vertex positions, normals,
// tangents and bitangents using this epsilon.
if (orig->HasPositions()) {
if(!CompareArrays(orig->mVertices,inst->mVertices,orig->mNumVertices,epsilon))
diff --git a/thirdparty/assimp/code/FindInstancesProcess.h b/thirdparty/assimp/code/PostProcessing/FindInstancesProcess.h
index ab4a371c71..64b838d7cc 100644
--- a/thirdparty/assimp/code/FindInstancesProcess.h
+++ b/thirdparty/assimp/code/PostProcessing/FindInstancesProcess.h
@@ -46,8 +46,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_FINDINSTANCES_H_INC
#define AI_FINDINSTANCES_H_INC
-#include "BaseProcess.h"
-#include "ProcessHelper.h"
+#include "Common/BaseProcess.h"
+#include "PostProcessing/ProcessHelper.h"
class FindInstancesProcessTest;
namespace Assimp {
diff --git a/thirdparty/assimp/code/FindInvalidDataProcess.cpp b/thirdparty/assimp/code/PostProcessing/FindInvalidDataProcess.cpp
index 433f042448..433f042448 100644
--- a/thirdparty/assimp/code/FindInvalidDataProcess.cpp
+++ b/thirdparty/assimp/code/PostProcessing/FindInvalidDataProcess.cpp
diff --git a/thirdparty/assimp/code/FindInvalidDataProcess.h b/thirdparty/assimp/code/PostProcessing/FindInvalidDataProcess.h
index 8504fb7b1f..ce7375f34f 100644
--- a/thirdparty/assimp/code/FindInvalidDataProcess.h
+++ b/thirdparty/assimp/code/PostProcessing/FindInvalidDataProcess.h
@@ -46,7 +46,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_FINDINVALIDDATA_H_INC
#define AI_FINDINVALIDDATA_H_INC
-#include "BaseProcess.h"
+#include "Common/BaseProcess.h"
+
#include <assimp/types.h>
#include <assimp/anim.h>
diff --git a/thirdparty/assimp/code/FixNormalsStep.cpp b/thirdparty/assimp/code/PostProcessing/FixNormalsStep.cpp
index bbbe6899b4..bbbe6899b4 100644
--- a/thirdparty/assimp/code/FixNormalsStep.cpp
+++ b/thirdparty/assimp/code/PostProcessing/FixNormalsStep.cpp
diff --git a/thirdparty/assimp/code/FixNormalsStep.h b/thirdparty/assimp/code/PostProcessing/FixNormalsStep.h
index 6be27faef6..f60ce596a4 100644
--- a/thirdparty/assimp/code/FixNormalsStep.h
+++ b/thirdparty/assimp/code/PostProcessing/FixNormalsStep.h
@@ -45,7 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_FIXNORMALSPROCESS_H_INC
#define AI_FIXNORMALSPROCESS_H_INC
-#include "BaseProcess.h"
+#include "Common/BaseProcess.h"
struct aiMesh;
diff --git a/thirdparty/assimp/code/PostProcessing/GenBoundingBoxesProcess.cpp b/thirdparty/assimp/code/PostProcessing/GenBoundingBoxesProcess.cpp
new file mode 100644
index 0000000000..c013454fc3
--- /dev/null
+++ b/thirdparty/assimp/code/PostProcessing/GenBoundingBoxesProcess.cpp
@@ -0,0 +1,115 @@
+/*
+---------------------------------------------------------------------------
+Open Asset Import Library (assimp)
+---------------------------------------------------------------------------
+
+Copyright (c) 2006-2019, assimp team
+
+All rights reserved.
+
+Redistribution and use of this software in source and binary forms,
+with or without modification, are permitted provided that the following
+conditions are met:
+
+* Redistributions of source code must retain the above
+ copyright notice, this list of conditions and the
+ following disclaimer.
+
+* Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the
+ following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+* Neither the name of the assimp team, nor the names of its
+ contributors may be used to endorse or promote products
+ derived from this software without specific prior
+ written permission of the assimp team.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+---------------------------------------------------------------------------
+*/
+
+#ifndef ASSIMP_BUILD_NO_GENBOUNDINGBOXES_PROCESS
+
+#include "PostProcessing/GenBoundingBoxesProcess.h"
+
+#include <assimp/postprocess.h>
+#include <assimp/scene.h>
+
+namespace Assimp {
+
+GenBoundingBoxesProcess::GenBoundingBoxesProcess()
+: BaseProcess() {
+
+}
+
+GenBoundingBoxesProcess::~GenBoundingBoxesProcess() {
+ // empty
+}
+
+bool GenBoundingBoxesProcess::IsActive(unsigned int pFlags) const {
+ return 0 != ( pFlags & aiProcess_GenBoundingBoxes );
+}
+
+void checkMesh(aiMesh* mesh, aiVector3D& min, aiVector3D& max) {
+ ai_assert(nullptr != mesh);
+
+ if (0 == mesh->mNumVertices) {
+ return;
+ }
+
+ for (unsigned int i = 0; i < mesh->mNumVertices; ++i) {
+ const aiVector3D &pos = mesh->mVertices[i];
+ if (pos.x < min.x) {
+ min.x = pos.x;
+ }
+ if (pos.y < min.y) {
+ min.y = pos.y;
+ }
+ if (pos.z < min.z) {
+ min.z = pos.z;
+ }
+
+ if (pos.x > max.x) {
+ max.x = pos.x;
+ }
+ if (pos.y > max.y) {
+ max.y = pos.y;
+ }
+ if (pos.z > max.z) {
+ max.z = pos.z;
+ }
+ }
+}
+
+void GenBoundingBoxesProcess::Execute(aiScene* pScene) {
+ if (nullptr == pScene) {
+ return;
+ }
+
+ for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
+ aiMesh* mesh = pScene->mMeshes[i];
+ if (nullptr == mesh) {
+ continue;
+ }
+
+ aiVector3D min(999999, 999999, 999999), max(-999999, -999999, -999999);
+ checkMesh(mesh, min, max);
+ mesh->mAABB.mMin = min;
+ mesh->mAABB.mMax = max;
+ }
+}
+
+} // Namespace Assimp
+
+#endif // ASSIMP_BUILD_NO_GENBOUNDINGBOXES_PROCESS
diff --git a/thirdparty/assimp/code/PostProcessing/GenBoundingBoxesProcess.h b/thirdparty/assimp/code/PostProcessing/GenBoundingBoxesProcess.h
new file mode 100644
index 0000000000..4b43c82a42
--- /dev/null
+++ b/thirdparty/assimp/code/PostProcessing/GenBoundingBoxesProcess.h
@@ -0,0 +1,76 @@
+/*
+---------------------------------------------------------------------------
+Open Asset Import Library (assimp)
+---------------------------------------------------------------------------
+
+Copyright (c) 2006-2019, assimp team
+
+All rights reserved.
+
+Redistribution and use of this software in source and binary forms,
+with or without modification, are permitted provided that the following
+conditions are met:
+
+* Redistributions of source code must retain the above
+ copyright notice, this list of conditions and the
+ following disclaimer.
+
+* Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the
+ following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+* Neither the name of the assimp team, nor the names of its
+ contributors may be used to endorse or promote products
+ derived from this software without specific prior
+ written permission of the assimp team.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+---------------------------------------------------------------------------
+*/
+
+/** @file Defines a post-processing step to generate Axis-aligned bounding
+ * volumes for all meshes.
+ */
+
+#pragma once
+
+#ifndef AI_GENBOUNDINGBOXESPROCESS_H_INC
+#define AI_GENBOUNDINGBOXESPROCESS_H_INC
+
+#ifndef ASSIMP_BUILD_NO_GENBOUNDINGBOXES_PROCESS
+
+#include "Common/BaseProcess.h"
+
+namespace Assimp {
+
+/** Post-processing process to find axis-aligned bounding volumes for amm meshes
+ * used in a scene
+ */
+class ASSIMP_API GenBoundingBoxesProcess : public BaseProcess {
+public:
+ /// The class constructor.
+ GenBoundingBoxesProcess();
+ /// The class destructor.
+ ~GenBoundingBoxesProcess();
+ /// Will return true, if aiProcess_GenBoundingBoxes is defined.
+ bool IsActive(unsigned int pFlags) const override;
+ /// The execution callback.
+ void Execute(aiScene* pScene) override;
+};
+
+} // Namespace Assimp
+
+#endif // #ifndef ASSIMP_BUILD_NO_GENBOUNDINGBOXES_PROCESS
+
+#endif // AI_GENBOUNDINGBOXESPROCESS_H_INC
diff --git a/thirdparty/assimp/code/GenFaceNormalsProcess.cpp b/thirdparty/assimp/code/PostProcessing/GenFaceNormalsProcess.cpp
index 028334dec7..028334dec7 100644
--- a/thirdparty/assimp/code/GenFaceNormalsProcess.cpp
+++ b/thirdparty/assimp/code/PostProcessing/GenFaceNormalsProcess.cpp
diff --git a/thirdparty/assimp/code/GenFaceNormalsProcess.h b/thirdparty/assimp/code/PostProcessing/GenFaceNormalsProcess.h
index c80ec9fddc..c641fd6353 100644
--- a/thirdparty/assimp/code/GenFaceNormalsProcess.h
+++ b/thirdparty/assimp/code/PostProcessing/GenFaceNormalsProcess.h
@@ -44,7 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_GENFACENORMALPROCESS_H_INC
#define AI_GENFACENORMALPROCESS_H_INC
-#include "BaseProcess.h"
+#include "Common/BaseProcess.h"
#include <assimp/mesh.h>
namespace Assimp
diff --git a/thirdparty/assimp/code/GenVertexNormalsProcess.cpp b/thirdparty/assimp/code/PostProcessing/GenVertexNormalsProcess.cpp
index 3f6c2f86bd..3f6c2f86bd 100644
--- a/thirdparty/assimp/code/GenVertexNormalsProcess.cpp
+++ b/thirdparty/assimp/code/PostProcessing/GenVertexNormalsProcess.cpp
diff --git a/thirdparty/assimp/code/GenVertexNormalsProcess.h b/thirdparty/assimp/code/PostProcessing/GenVertexNormalsProcess.h
index 9142ad26f5..2ceee17e85 100644
--- a/thirdparty/assimp/code/GenVertexNormalsProcess.h
+++ b/thirdparty/assimp/code/PostProcessing/GenVertexNormalsProcess.h
@@ -45,24 +45,24 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_GENVERTEXNORMALPROCESS_H_INC
#define AI_GENVERTEXNORMALPROCESS_H_INC
-#include "BaseProcess.h"
+#include "Common/assbin_chunks.h"
+#include "Common/BaseProcess.h"
+
#include <assimp/mesh.h>
+// Forward declarations
class GenNormalsTest;
namespace Assimp {
// ---------------------------------------------------------------------------
-/** The GenFaceNormalsProcess computes vertex normals for all vertizes
+/** The GenFaceNormalsProcess computes vertex normals for all vertices
*/
-class ASSIMP_API GenVertexNormalsProcess : public BaseProcess
-{
+class ASSIMP_API GenVertexNormalsProcess : public BaseProcess {
public:
-
GenVertexNormalsProcess();
~GenVertexNormalsProcess();
-public:
// -------------------------------------------------------------------
/** Returns whether the processing step is present in the given flag.
* @param pFlags The processing flags the importer was called with.
@@ -88,13 +88,10 @@ public:
// setter for configMaxAngle
- inline void SetMaxSmoothAngle(ai_real f)
- {
+ inline void SetMaxSmoothAngle(ai_real f) {
configMaxAngle =f;
}
-public:
-
// -------------------------------------------------------------------
/** Computes normals for a specific mesh
* @param pcMesh Mesh
@@ -104,7 +101,6 @@ public:
bool GenMeshVertexNormals (aiMesh* pcMesh, unsigned int meshIndex);
private:
-
/** Configuration option: maximum smoothing angle, in radians*/
ai_real configMaxAngle;
mutable bool force_ = false;
diff --git a/thirdparty/assimp/code/ImproveCacheLocality.cpp b/thirdparty/assimp/code/PostProcessing/ImproveCacheLocality.cpp
index ace9d95ff8..d0a016fa42 100644
--- a/thirdparty/assimp/code/ImproveCacheLocality.cpp
+++ b/thirdparty/assimp/code/PostProcessing/ImproveCacheLocality.cpp
@@ -45,14 +45,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* <br>
* The algorithm is roughly basing on this paper:
* http://www.cs.princeton.edu/gfx/pubs/Sander_2007_%3ETR/tipsy.pdf
- * .. although overdraw rduction isn't implemented yet ...
+ * .. although overdraw reduction isn't implemented yet ...
*/
-
-
// internal headers
-#include "ImproveCacheLocality.h"
-#include "VertexTriangleAdjacency.h"
+#include "PostProcessing/ImproveCacheLocality.h"
+#include "Common/VertexTriangleAdjacency.h"
+
#include <assimp/StringUtils.h>
#include <assimp/postprocess.h>
#include <assimp/scene.h>
@@ -64,36 +63,33 @@ using namespace Assimp;
// ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer
-ImproveCacheLocalityProcess::ImproveCacheLocalityProcess() {
- configCacheDepth = PP_ICL_PTCACHE_SIZE;
+ImproveCacheLocalityProcess::ImproveCacheLocalityProcess()
+: mConfigCacheDepth(PP_ICL_PTCACHE_SIZE) {
+ // empty
}
// ------------------------------------------------------------------------------------------------
// Destructor, private as well
-ImproveCacheLocalityProcess::~ImproveCacheLocalityProcess()
-{
+ImproveCacheLocalityProcess::~ImproveCacheLocalityProcess() {
// nothing to do here
}
// ------------------------------------------------------------------------------------------------
// Returns whether the processing step is present in the given flag field.
-bool ImproveCacheLocalityProcess::IsActive( unsigned int pFlags) const
-{
+bool ImproveCacheLocalityProcess::IsActive( unsigned int pFlags) const {
return (pFlags & aiProcess_ImproveCacheLocality) != 0;
}
// ------------------------------------------------------------------------------------------------
// Setup configuration
-void ImproveCacheLocalityProcess::SetupProperties(const Importer* pImp)
-{
+void ImproveCacheLocalityProcess::SetupProperties(const Importer* pImp) {
// AI_CONFIG_PP_ICL_PTCACHE_SIZE controls the target cache size for the optimizer
- configCacheDepth = pImp->GetPropertyInteger(AI_CONFIG_PP_ICL_PTCACHE_SIZE,PP_ICL_PTCACHE_SIZE);
+ mConfigCacheDepth = pImp->GetPropertyInteger(AI_CONFIG_PP_ICL_PTCACHE_SIZE,PP_ICL_PTCACHE_SIZE);
}
// ------------------------------------------------------------------------------------------------
// Executes the post processing step on the given imported data.
-void ImproveCacheLocalityProcess::Execute( aiScene* pScene)
-{
+void ImproveCacheLocalityProcess::Execute( aiScene* pScene) {
if (!pScene->mNumMeshes) {
ASSIMP_LOG_DEBUG("ImproveCacheLocalityProcess skipped; there are no meshes");
return;
@@ -103,7 +99,7 @@ void ImproveCacheLocalityProcess::Execute( aiScene* pScene)
float out = 0.f;
unsigned int numf = 0, numm = 0;
- for( unsigned int a = 0; a < pScene->mNumMeshes; a++){
+ for( unsigned int a = 0; a < pScene->mNumMeshes; ++a ){
const float res = ProcessMesh( pScene->mMeshes[a],a);
if (res) {
numf += pScene->mMeshes[a]->mNumFaces;
@@ -121,44 +117,41 @@ void ImproveCacheLocalityProcess::Execute( aiScene* pScene)
// ------------------------------------------------------------------------------------------------
// Improves the cache coherency of a specific mesh
-float ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshNum)
-{
+ai_real ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshNum) {
// TODO: rewrite this to use std::vector or boost::shared_array
- ai_assert(NULL != pMesh);
+ ai_assert(nullptr != pMesh);
// Check whether the input data is valid
// - there must be vertices and faces
// - all faces must be triangulated or we can't operate on them
if (!pMesh->HasFaces() || !pMesh->HasPositions())
- return 0.f;
+ return static_cast<ai_real>(0.f);
if (pMesh->mPrimitiveTypes != aiPrimitiveType_TRIANGLE) {
ASSIMP_LOG_ERROR("This algorithm works on triangle meshes only");
- return 0.f;
+ return static_cast<ai_real>(0.f);
}
- if(pMesh->mNumVertices <= configCacheDepth) {
- return 0.f;
+ if(pMesh->mNumVertices <= mConfigCacheDepth) {
+ return static_cast<ai_real>(0.f);
}
- float fACMR = 3.f;
+ ai_real fACMR = 3.f;
const aiFace* const pcEnd = pMesh->mFaces+pMesh->mNumFaces;
// Input ACMR is for logging purposes only
if (!DefaultLogger::isNullLogger()) {
- unsigned int* piFIFOStack = new unsigned int[configCacheDepth];
- memset(piFIFOStack,0xff,configCacheDepth*sizeof(unsigned int));
+ unsigned int* piFIFOStack = new unsigned int[mConfigCacheDepth];
+ memset(piFIFOStack,0xff,mConfigCacheDepth*sizeof(unsigned int));
unsigned int* piCur = piFIFOStack;
- const unsigned int* const piCurEnd = piFIFOStack + configCacheDepth;
+ const unsigned int* const piCurEnd = piFIFOStack + mConfigCacheDepth;
// count the number of cache misses
unsigned int iCacheMisses = 0;
for (const aiFace* pcFace = pMesh->mFaces;pcFace != pcEnd;++pcFace) {
-
for (unsigned int qq = 0; qq < 3;++qq) {
bool bInCache = false;
-
for (unsigned int* pp = piFIFOStack;pp < piCurEnd;++pp) {
if (*pp == pcFace->mIndices[qq]) {
// the vertex is in cache
@@ -176,7 +169,7 @@ float ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int mesh
}
}
delete[] piFIFOStack;
- fACMR = (float)iCacheMisses / pMesh->mNumFaces;
+ fACMR = (ai_real) iCacheMisses / pMesh->mNumFaces;
if (3.0 == fACMR) {
char szBuff[128]; // should be sufficiently large in every case
@@ -185,7 +178,7 @@ float ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int mesh
// smaller than 3.0 ...
ai_snprintf(szBuff,128,"Mesh %u: Not suitable for vcache optimization",meshNum);
ASSIMP_LOG_WARN(szBuff);
- return 0.f;
+ return static_cast<ai_real>(0.f);
}
}
@@ -258,7 +251,7 @@ float ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int mesh
int ivdx = 0;
int ics = 1;
- int iStampCnt = configCacheDepth+1;
+ int iStampCnt = mConfigCacheDepth+1;
while (ivdx >= 0) {
unsigned int icnt = piNumTriPtrNoModify[ivdx];
@@ -294,7 +287,7 @@ float ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int mesh
*piCSIter++ = dp;
// if the vertex is not yet in cache, set its cache count
- if (iStampCnt-piCachingStamps[dp] > configCacheDepth) {
+ if (iStampCnt-piCachingStamps[dp] > mConfigCacheDepth) {
piCachingStamps[dp] = iStampCnt++;
++iCacheMisses;
}
@@ -319,7 +312,7 @@ float ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int mesh
// will the vertex be in cache, even after fanning occurs?
unsigned int tmp;
- if ((tmp = iStampCnt-piCachingStamps[dp]) + 2*piNumTriPtr[dp] <= configCacheDepth) {
+ if ((tmp = iStampCnt-piCachingStamps[dp]) + 2*piNumTriPtr[dp] <= mConfigCacheDepth) {
priority = tmp;
}
@@ -356,7 +349,7 @@ float ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int mesh
}
}
}
- float fACMR2 = 0.0f;
+ ai_real fACMR2 = 0.0f;
if (!DefaultLogger::isNullLogger()) {
fACMR2 = (float)iCacheMisses / pMesh->mNumFaces;
diff --git a/thirdparty/assimp/code/ImproveCacheLocality.h b/thirdparty/assimp/code/PostProcessing/ImproveCacheLocality.h
index 1b29ee0d6e..de25ecd9fb 100644
--- a/thirdparty/assimp/code/ImproveCacheLocality.h
+++ b/thirdparty/assimp/code/PostProcessing/ImproveCacheLocality.h
@@ -45,7 +45,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_IMPROVECACHELOCALITY_H_INC
#define AI_IMPROVECACHELOCALITY_H_INC
-#include "BaseProcess.h"
+#include "Common/BaseProcess.h"
+
#include <assimp/types.h>
struct aiMesh;
@@ -87,12 +88,12 @@ protected:
* @param pMesh The mesh to process.
* @param meshNum Index of the mesh to process
*/
- float ProcessMesh( aiMesh* pMesh, unsigned int meshNum);
+ ai_real ProcessMesh( aiMesh* pMesh, unsigned int meshNum);
private:
//! Configuration parameter: specifies the size of the cache to
//! optimize the vertex data for.
- unsigned int configCacheDepth;
+ unsigned int mConfigCacheDepth;
};
} // end of namespace Assimp
diff --git a/thirdparty/assimp/code/JoinVerticesProcess.cpp b/thirdparty/assimp/code/PostProcessing/JoinVerticesProcess.cpp
index 914ec05b46..914ec05b46 100644
--- a/thirdparty/assimp/code/JoinVerticesProcess.cpp
+++ b/thirdparty/assimp/code/PostProcessing/JoinVerticesProcess.cpp
diff --git a/thirdparty/assimp/code/JoinVerticesProcess.h b/thirdparty/assimp/code/PostProcessing/JoinVerticesProcess.h
index 66fa362de2..e017ae62db 100644
--- a/thirdparty/assimp/code/JoinVerticesProcess.h
+++ b/thirdparty/assimp/code/PostProcessing/JoinVerticesProcess.h
@@ -45,7 +45,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_JOINVERTICESPROCESS_H_INC
#define AI_JOINVERTICESPROCESS_H_INC
-#include "BaseProcess.h"
+#include "Common/BaseProcess.h"
+
#include <assimp/types.h>
struct aiMesh;
@@ -61,13 +62,11 @@ namespace Assimp
* erases all but one of the copies. This usually reduces the number of vertices
* in a mesh by a serious amount and is the standard form to render a mesh.
*/
-class ASSIMP_API JoinVerticesProcess : public BaseProcess
-{
+class ASSIMP_API JoinVerticesProcess : public BaseProcess {
public:
JoinVerticesProcess();
~JoinVerticesProcess();
-public:
// -------------------------------------------------------------------
/** Returns whether the processing step is present in the given flag field.
* @param pFlags The processing flags the importer was called with. A bitwise
@@ -83,15 +82,12 @@ public:
*/
void Execute( aiScene* pScene);
-public:
// -------------------------------------------------------------------
/** Unites identical vertices in the given mesh.
* @param pMesh The mesh to process.
* @param meshIndex Index of the mesh to process
*/
int ProcessMesh( aiMesh* pMesh, unsigned int meshIndex);
-
-private:
};
} // end of namespace Assimp
diff --git a/thirdparty/assimp/code/LimitBoneWeightsProcess.cpp b/thirdparty/assimp/code/PostProcessing/LimitBoneWeightsProcess.cpp
index d560f19287..d560f19287 100644
--- a/thirdparty/assimp/code/LimitBoneWeightsProcess.cpp
+++ b/thirdparty/assimp/code/PostProcessing/LimitBoneWeightsProcess.cpp
diff --git a/thirdparty/assimp/code/LimitBoneWeightsProcess.h b/thirdparty/assimp/code/PostProcessing/LimitBoneWeightsProcess.h
index 3602fd8edf..73c2a68d53 100644
--- a/thirdparty/assimp/code/LimitBoneWeightsProcess.h
+++ b/thirdparty/assimp/code/PostProcessing/LimitBoneWeightsProcess.h
@@ -44,14 +44,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_LIMITBONEWEIGHTSPROCESS_H_INC
#define AI_LIMITBONEWEIGHTSPROCESS_H_INC
-#include "BaseProcess.h"
+#include "Common/BaseProcess.h"
+// Forward declarations
struct aiMesh;
class LimitBoneWeightsTest;
-namespace Assimp
-{
+namespace Assimp {
// NOTE: If you change these limits, don't forget to change the
// corresponding values in all Assimp ports
@@ -72,14 +72,11 @@ namespace Assimp
* The other weights on this bone are then renormalized to assure the sum weight
* to be 1.
*/
-class ASSIMP_API LimitBoneWeightsProcess : public BaseProcess
-{
+class ASSIMP_API LimitBoneWeightsProcess : public BaseProcess {
public:
-
LimitBoneWeightsProcess();
~LimitBoneWeightsProcess();
-public:
// -------------------------------------------------------------------
/** Returns whether the processing step is present in the given flag.
* @param pFlags The processing flags the importer was called with.
@@ -96,8 +93,6 @@ public:
*/
void SetupProperties(const Importer* pImp);
-public:
-
// -------------------------------------------------------------------
/** Limits the bone weight count for all vertices in the given mesh.
* @param pMesh The mesh to process.
@@ -111,34 +106,29 @@ public:
*/
void Execute( aiScene* pScene);
-
-public:
-
// -------------------------------------------------------------------
/** Describes a bone weight on a vertex */
- struct Weight
- {
+ struct Weight {
unsigned int mBone; ///< Index of the bone
float mWeight; ///< Weight of that bone on this vertex
Weight() AI_NO_EXCEPT
: mBone(0)
- , mWeight(0.0f)
- { }
+ , mWeight(0.0f) {
+ // empty
+ }
Weight( unsigned int pBone, float pWeight)
- {
- mBone = pBone;
- mWeight = pWeight;
+ : mBone(pBone)
+ , mWeight(pWeight) {
+ // empty
}
/** Comparison operator to sort bone weights by descending weight */
- bool operator < (const Weight& pWeight) const
- {
+ bool operator < (const Weight& pWeight) const {
return mWeight > pWeight.mWeight;
}
};
-public:
/** Maximum number of bones influencing any single vertex. */
unsigned int mMaxWeights;
};
diff --git a/thirdparty/assimp/code/MakeVerboseFormat.cpp b/thirdparty/assimp/code/PostProcessing/MakeVerboseFormat.cpp
index 50ff5ed93d..50ff5ed93d 100644
--- a/thirdparty/assimp/code/MakeVerboseFormat.cpp
+++ b/thirdparty/assimp/code/PostProcessing/MakeVerboseFormat.cpp
diff --git a/thirdparty/assimp/code/MakeVerboseFormat.h b/thirdparty/assimp/code/PostProcessing/MakeVerboseFormat.h
index d12db63ae1..1adf8e2f69 100644
--- a/thirdparty/assimp/code/MakeVerboseFormat.h
+++ b/thirdparty/assimp/code/PostProcessing/MakeVerboseFormat.h
@@ -46,7 +46,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_MAKEVERBOSEFORMAT_H_INC
#define AI_MAKEVERBOSEFORMAT_H_INC
-#include "BaseProcess.h"
+#include "Common/BaseProcess.h"
+
struct aiMesh;
namespace Assimp {
diff --git a/thirdparty/assimp/code/OptimizeGraph.cpp b/thirdparty/assimp/code/PostProcessing/OptimizeGraph.cpp
index add9ab79e1..5db51f58b6 100644
--- a/thirdparty/assimp/code/OptimizeGraph.cpp
+++ b/thirdparty/assimp/code/PostProcessing/OptimizeGraph.cpp
@@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2019, assimp team
-
-
All rights reserved.
Redistribution and use of this software in source and binary forms,
diff --git a/thirdparty/assimp/code/OptimizeGraph.h b/thirdparty/assimp/code/PostProcessing/OptimizeGraph.h
index e5bbed7679..82cc5db3fe 100644
--- a/thirdparty/assimp/code/OptimizeGraph.h
+++ b/thirdparty/assimp/code/PostProcessing/OptimizeGraph.h
@@ -46,13 +46,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_OPTIMIZEGRAPHPROCESS_H_INC
#define AI_OPTIMIZEGRAPHPROCESS_H_INC
-#include "BaseProcess.h"
-#include "ProcessHelper.h"
+#include "Common/BaseProcess.h"
+#include "PostProcessing/ProcessHelper.h"
+
#include <assimp/types.h>
+
#include <set>
+// Forward declarations
struct aiMesh;
+
class OptimizeGraphProcessTest;
+
namespace Assimp {
// -----------------------------------------------------------------------------
@@ -64,14 +69,11 @@ namespace Assimp {
* @see aiProcess_OptimizeGraph for a detailed description of the
* algorithm being applied.
*/
-class OptimizeGraphProcess : public BaseProcess
-{
+class OptimizeGraphProcess : public BaseProcess {
public:
-
OptimizeGraphProcess();
~OptimizeGraphProcess();
-public:
// -------------------------------------------------------------------
bool IsActive( unsigned int pFlags) const;
@@ -81,14 +83,12 @@ public:
// -------------------------------------------------------------------
void SetupProperties(const Importer* pImp);
-
// -------------------------------------------------------------------
/** @brief Add a list of node names to be locked and not modified.
* @param in List of nodes. See #AI_CONFIG_PP_OG_EXCLUDE_LIST for
* format explanations.
*/
- inline void AddLockedNodeList(std::string& in)
- {
+ inline void AddLockedNodeList(std::string& in) {
ConvertListToStrings (in,locked_nodes);
}
@@ -96,8 +96,7 @@ public:
/** @brief Add another node to be locked and not modified.
* @param name Name to be locked
*/
- inline void AddLockedNode(std::string& name)
- {
+ inline void AddLockedNode(std::string& name) {
locked_nodes.push_back(name);
}
@@ -105,25 +104,21 @@ public:
/** @brief Remove a node from the list of locked nodes.
* @param name Name to be unlocked
*/
- inline void RemoveLockedNode(std::string& name)
- {
+ inline void RemoveLockedNode(std::string& name) {
locked_nodes.remove(name);
}
protected:
-
void CollectNewChildren(aiNode* nd, std::list<aiNode*>& nodes);
void FindInstancedMeshes (aiNode* pNode);
private:
-
#ifdef AI_OG_USE_HASHING
typedef std::set<unsigned int> LockedSetType;
#else
typedef std::set<std::string> LockedSetType;
#endif
-
//! Scene we're working with
aiScene* mScene;
diff --git a/thirdparty/assimp/code/OptimizeMeshes.cpp b/thirdparty/assimp/code/PostProcessing/OptimizeMeshes.cpp
index 3f6765f6ca..3f6765f6ca 100644
--- a/thirdparty/assimp/code/OptimizeMeshes.cpp
+++ b/thirdparty/assimp/code/PostProcessing/OptimizeMeshes.cpp
diff --git a/thirdparty/assimp/code/OptimizeMeshes.h b/thirdparty/assimp/code/PostProcessing/OptimizeMeshes.h
index 9f46f349b4..dec4ab52de 100644
--- a/thirdparty/assimp/code/OptimizeMeshes.h
+++ b/thirdparty/assimp/code/PostProcessing/OptimizeMeshes.h
@@ -46,8 +46,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_OPTIMIZEMESHESPROCESS_H_INC
#define AI_OPTIMIZEMESHESPROCESS_H_INC
-#include "BaseProcess.h"
+#include "Common/BaseProcess.h"
+
#include <assimp/types.h>
+
#include <vector>
struct aiMesh;
@@ -64,16 +66,14 @@ namespace Assimp {
*
* @note Instanced meshes are currently not processed.
*/
-class OptimizeMeshesProcess : public BaseProcess
-{
+class OptimizeMeshesProcess : public BaseProcess {
public:
/// @brief The class constructor.
OptimizeMeshesProcess();
- /// @brief The class destcructor,
+ /// @brief The class destructor.
~OptimizeMeshesProcess();
-
/** @brief Internal utility to store additional mesh info
*/
struct MeshInfo {
diff --git a/thirdparty/assimp/code/PretransformVertices.cpp b/thirdparty/assimp/code/PostProcessing/PretransformVertices.cpp
index 52001a0578..52001a0578 100644
--- a/thirdparty/assimp/code/PretransformVertices.cpp
+++ b/thirdparty/assimp/code/PostProcessing/PretransformVertices.cpp
diff --git a/thirdparty/assimp/code/PretransformVertices.h b/thirdparty/assimp/code/PostProcessing/PretransformVertices.h
index b7329af130..b2982951e0 100644
--- a/thirdparty/assimp/code/PretransformVertices.h
+++ b/thirdparty/assimp/code/PostProcessing/PretransformVertices.h
@@ -47,13 +47,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_PRETRANSFORMVERTICES_H_INC
#define AI_PRETRANSFORMVERTICES_H_INC
-#include "BaseProcess.h"
+#include "Common/BaseProcess.h"
+
#include <assimp/mesh.h>
+
#include <list>
#include <vector>
+// Forward declarations
struct aiNode;
+
class PretransformVerticesTest;
+
namespace Assimp {
// ---------------------------------------------------------------------------
@@ -80,10 +85,10 @@ public:
// -------------------------------------------------------------------
/** @brief Toggle the 'keep hierarchy' option
- * @param d hm ... difficult to guess what this means, hu!?
+ * @param keep true for keep configuration.
*/
- void KeepHierarchy(bool d) {
- configKeepHierarchy = d;
+ void KeepHierarchy(bool keep) {
+ configKeepHierarchy = keep;
}
// -------------------------------------------------------------------
@@ -148,8 +153,6 @@ private:
// Build reference counters for all meshes
void BuildMeshRefCountArray(aiNode* nd, unsigned int * refs);
-
-
//! Configuration option: keep scene hierarchy as long as possible
bool configKeepHierarchy;
bool configNormalize;
diff --git a/thirdparty/assimp/code/ProcessHelper.cpp b/thirdparty/assimp/code/PostProcessing/ProcessHelper.cpp
index 59869fdff7..59869fdff7 100644
--- a/thirdparty/assimp/code/ProcessHelper.cpp
+++ b/thirdparty/assimp/code/PostProcessing/ProcessHelper.cpp
diff --git a/thirdparty/assimp/code/ProcessHelper.h b/thirdparty/assimp/code/PostProcessing/ProcessHelper.h
index c59f3217bf..0afcc41420 100644
--- a/thirdparty/assimp/code/ProcessHelper.h
+++ b/thirdparty/assimp/code/PostProcessing/ProcessHelper.h
@@ -51,7 +51,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/scene.h>
#include <assimp/SpatialSort.h>
-#include "BaseProcess.h"
+#include "Common/BaseProcess.h"
#include <assimp/ParsingUtils.h>
#include <list>
diff --git a/thirdparty/assimp/code/RemoveRedundantMaterials.cpp b/thirdparty/assimp/code/PostProcessing/RemoveRedundantMaterials.cpp
index 632bdca3fe..49ec8f5c47 100644
--- a/thirdparty/assimp/code/RemoveRedundantMaterials.cpp
+++ b/thirdparty/assimp/code/PostProcessing/RemoveRedundantMaterials.cpp
@@ -49,7 +49,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "RemoveRedundantMaterials.h"
#include <assimp/ParsingUtils.h>
#include "ProcessHelper.h"
-#include "MaterialSystem.h"
+#include "Material/MaterialSystem.h"
#include <stdio.h>
using namespace Assimp;
@@ -57,7 +57,7 @@ using namespace Assimp;
// ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer
RemoveRedundantMatsProcess::RemoveRedundantMatsProcess()
-: configFixedMaterials() {
+: mConfigFixedMaterials() {
// nothing to do here
}
@@ -80,7 +80,7 @@ bool RemoveRedundantMatsProcess::IsActive( unsigned int pFlags) const
void RemoveRedundantMatsProcess::SetupProperties(const Importer* pImp)
{
// Get value of AI_CONFIG_PP_RRM_EXCLUDE_LIST
- configFixedMaterials = pImp->GetPropertyString(AI_CONFIG_PP_RRM_EXCLUDE_LIST,"");
+ mConfigFixedMaterials = pImp->GetPropertyString(AI_CONFIG_PP_RRM_EXCLUDE_LIST,"");
}
// ------------------------------------------------------------------------------------------------
@@ -100,10 +100,10 @@ void RemoveRedundantMatsProcess::Execute( aiScene* pScene)
// If a list of materials to be excluded was given, match the list with
// our imported materials and 'salt' all positive matches to ensure that
// we get unique hashes later.
- if (configFixedMaterials.length()) {
+ if (mConfigFixedMaterials.length()) {
std::list<std::string> strings;
- ConvertListToStrings(configFixedMaterials,strings);
+ ConvertListToStrings(mConfigFixedMaterials,strings);
for (unsigned int i = 0; i < pScene->mNumMaterials;++i) {
aiMaterial* mat = pScene->mMaterials[i];
diff --git a/thirdparty/assimp/code/RemoveRedundantMaterials.h b/thirdparty/assimp/code/PostProcessing/RemoveRedundantMaterials.h
index dbd4d44cc0..1f32a0abfb 100644
--- a/thirdparty/assimp/code/RemoveRedundantMaterials.h
+++ b/thirdparty/assimp/code/PostProcessing/RemoveRedundantMaterials.h
@@ -46,7 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_REMOVEREDUNDANTMATERIALS_H_INC
#define AI_REMOVEREDUNDANTMATERIALS_H_INC
-#include "BaseProcess.h"
+#include "Common/BaseProcess.h"
#include <assimp/mesh.h>
class RemoveRedundantMatsTest;
@@ -57,8 +57,7 @@ namespace Assimp {
/** RemoveRedundantMatsProcess: Post-processing step to remove redundant
* materials from the imported scene.
*/
-class ASSIMP_API RemoveRedundantMatsProcess : public BaseProcess
-{
+class ASSIMP_API RemoveRedundantMatsProcess : public BaseProcess {
public:
/// The default class constructor.
RemoveRedundantMatsProcess();
@@ -66,7 +65,6 @@ public:
/// The class destructor.
~RemoveRedundantMatsProcess();
-public:
// -------------------------------------------------------------------
// Check whether step is active
bool IsActive( unsigned int pFlags) const;
@@ -79,27 +77,25 @@ public:
// Setup import settings
void SetupProperties(const Importer* pImp);
-
// -------------------------------------------------------------------
- /** @brief Set list of fixed (unmutable) materials
+ /** @brief Set list of fixed (inmutable) materials
* @param fixed See #AI_CONFIG_PP_RRM_EXCLUDE_LIST
*/
void SetFixedMaterialsString(const std::string& fixed = "") {
- configFixedMaterials = fixed;
+ mConfigFixedMaterials = fixed;
}
// -------------------------------------------------------------------
- /** @brief Get list of fixed (unmutable) materials
+ /** @brief Get list of fixed (inmutable) materials
* @return See #AI_CONFIG_PP_RRM_EXCLUDE_LIST
*/
const std::string& GetFixedMaterialsString() const {
- return configFixedMaterials;
+ return mConfigFixedMaterials;
}
private:
-
//! Configuration option: list of all fixed materials
- std::string configFixedMaterials;
+ std::string mConfigFixedMaterials;
};
} // end of namespace Assimp
diff --git a/thirdparty/assimp/code/RemoveVCProcess.cpp b/thirdparty/assimp/code/PostProcessing/RemoveVCProcess.cpp
index 99fd47a3aa..99fd47a3aa 100644
--- a/thirdparty/assimp/code/RemoveVCProcess.cpp
+++ b/thirdparty/assimp/code/PostProcessing/RemoveVCProcess.cpp
diff --git a/thirdparty/assimp/code/RemoveVCProcess.h b/thirdparty/assimp/code/PostProcessing/RemoveVCProcess.h
index 617d7b9b20..7bb21a8330 100644
--- a/thirdparty/assimp/code/RemoveVCProcess.h
+++ b/thirdparty/assimp/code/PostProcessing/RemoveVCProcess.h
@@ -44,7 +44,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_REMOVEVCPROCESS_H_INCLUDED
#define AI_REMOVEVCPROCESS_H_INCLUDED
-#include "BaseProcess.h"
+#include "Common/BaseProcess.h"
+
#include <assimp/mesh.h>
class RemoveVCProcessTest;
diff --git a/thirdparty/assimp/code/ScaleProcess.cpp b/thirdparty/assimp/code/PostProcessing/ScaleProcess.cpp
index 6d458c4b11..6d458c4b11 100644
--- a/thirdparty/assimp/code/ScaleProcess.cpp
+++ b/thirdparty/assimp/code/PostProcessing/ScaleProcess.cpp
diff --git a/thirdparty/assimp/code/ScaleProcess.h b/thirdparty/assimp/code/PostProcessing/ScaleProcess.h
index 55146ae064..2567378759 100644
--- a/thirdparty/assimp/code/ScaleProcess.h
+++ b/thirdparty/assimp/code/PostProcessing/ScaleProcess.h
@@ -41,7 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
-#include "BaseProcess.h"
+#include "Common/BaseProcess.h"
struct aiNode;
diff --git a/thirdparty/assimp/code/SortByPTypeProcess.cpp b/thirdparty/assimp/code/PostProcessing/SortByPTypeProcess.cpp
index 2e0cc54004..be8405a17b 100644
--- a/thirdparty/assimp/code/SortByPTypeProcess.cpp
+++ b/thirdparty/assimp/code/PostProcessing/SortByPTypeProcess.cpp
@@ -57,8 +57,8 @@ using namespace Assimp;
// ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer
SortByPTypeProcess::SortByPTypeProcess()
-{
- configRemoveMeshes = 0;
+: mConfigRemoveMeshes( 0 ) {
+ // empty
}
// ------------------------------------------------------------------------------------------------
@@ -78,7 +78,7 @@ bool SortByPTypeProcess::IsActive( unsigned int pFlags) const
// ------------------------------------------------------------------------------------------------
void SortByPTypeProcess::SetupProperties(const Importer* pImp)
{
- configRemoveMeshes = pImp->GetPropertyInteger(AI_CONFIG_PP_SBP_REMOVE,0);
+ mConfigRemoveMeshes = pImp->GetPropertyInteger(AI_CONFIG_PP_SBP_REMOVE,0);
}
// ------------------------------------------------------------------------------------------------
@@ -172,7 +172,7 @@ void SortByPTypeProcess::Execute( aiScene* pScene) {
}
if (1 == num) {
- if (!(configRemoveMeshes & mesh->mPrimitiveTypes)) {
+ if (!(mConfigRemoveMeshes & mesh->mPrimitiveTypes)) {
*meshIdx = static_cast<unsigned int>( outMeshes.size() );
outMeshes.push_back(mesh);
} else {
@@ -206,7 +206,7 @@ void SortByPTypeProcess::Execute( aiScene* pScene) {
VertexWeightTable* avw = ComputeVertexBoneWeightTable(mesh);
for (unsigned int real = 0; real < 4; ++real,++meshIdx)
{
- if ( !aiNumPerPType[real] || configRemoveMeshes & (1u << real))
+ if ( !aiNumPerPType[real] || mConfigRemoveMeshes & (1u << real))
{
continue;
}
@@ -392,10 +392,10 @@ void SortByPTypeProcess::Execute( aiScene* pScene) {
{
char buffer[1024];
::ai_snprintf(buffer,1024,"Points: %u%s, Lines: %u%s, Triangles: %u%s, Polygons: %u%s (Meshes, X = removed)",
- aiNumMeshesPerPType[0], ((configRemoveMeshes & aiPrimitiveType_POINT) ? "X" : ""),
- aiNumMeshesPerPType[1], ((configRemoveMeshes & aiPrimitiveType_LINE) ? "X" : ""),
- aiNumMeshesPerPType[2], ((configRemoveMeshes & aiPrimitiveType_TRIANGLE) ? "X" : ""),
- aiNumMeshesPerPType[3], ((configRemoveMeshes & aiPrimitiveType_POLYGON) ? "X" : ""));
+ aiNumMeshesPerPType[0], ((mConfigRemoveMeshes & aiPrimitiveType_POINT) ? "X" : ""),
+ aiNumMeshesPerPType[1], ((mConfigRemoveMeshes & aiPrimitiveType_LINE) ? "X" : ""),
+ aiNumMeshesPerPType[2], ((mConfigRemoveMeshes & aiPrimitiveType_TRIANGLE) ? "X" : ""),
+ aiNumMeshesPerPType[3], ((mConfigRemoveMeshes & aiPrimitiveType_POLYGON) ? "X" : ""));
ASSIMP_LOG_INFO(buffer);
ASSIMP_LOG_DEBUG("SortByPTypeProcess finished");
}
diff --git a/thirdparty/assimp/code/SortByPTypeProcess.h b/thirdparty/assimp/code/PostProcessing/SortByPTypeProcess.h
index c9d9924d8f..1d7ccfc152 100644
--- a/thirdparty/assimp/code/SortByPTypeProcess.h
+++ b/thirdparty/assimp/code/PostProcessing/SortByPTypeProcess.h
@@ -45,10 +45,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_SORTBYPTYPEPROCESS_H_INC
#define AI_SORTBYPTYPEPROCESS_H_INC
-#include "BaseProcess.h"
+#include "Common/BaseProcess.h"
#include <assimp/mesh.h>
class SortByPTypeProcessTest;
+
namespace Assimp {
@@ -57,14 +58,11 @@ namespace Assimp {
* A mesh with 5 lines, 3 points and 145 triangles would be split in 3
* submeshes.
*/
-class ASSIMP_API SortByPTypeProcess : public BaseProcess
-{
+class ASSIMP_API SortByPTypeProcess : public BaseProcess {
public:
-
SortByPTypeProcess();
~SortByPTypeProcess();
-public:
// -------------------------------------------------------------------
bool IsActive( unsigned int pFlags) const;
@@ -75,8 +73,7 @@ public:
void SetupProperties(const Importer* pImp);
private:
-
- int configRemoveMeshes;
+ int mConfigRemoveMeshes;
};
diff --git a/thirdparty/assimp/code/SplitLargeMeshes.cpp b/thirdparty/assimp/code/PostProcessing/SplitLargeMeshes.cpp
index 1797b28d5a..1797b28d5a 100644
--- a/thirdparty/assimp/code/SplitLargeMeshes.cpp
+++ b/thirdparty/assimp/code/PostProcessing/SplitLargeMeshes.cpp
diff --git a/thirdparty/assimp/code/SplitLargeMeshes.h b/thirdparty/assimp/code/PostProcessing/SplitLargeMeshes.h
index 77f089ce7e..3f90576ea9 100644
--- a/thirdparty/assimp/code/SplitLargeMeshes.h
+++ b/thirdparty/assimp/code/PostProcessing/SplitLargeMeshes.h
@@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2019, assimp team
-
All rights reserved.
Redistribution and use of this software in source and binary forms,
@@ -40,21 +39,21 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------
*/
-/** @file Defines a post processing step to split large meshes into submeshes
+/** @file Defines a post processing step to split large meshes into sub-meshes
*/
#ifndef AI_SPLITLARGEMESHES_H_INC
#define AI_SPLITLARGEMESHES_H_INC
#include <vector>
-#include "BaseProcess.h"
+#include "Common/BaseProcess.h"
#include <assimp/mesh.h>
#include <assimp/scene.h>
+// Forward declarations
class SplitLargeMeshesTest;
-namespace Assimp
-{
+namespace Assimp {
class SplitLargeMeshesProcess_Triangle;
class SplitLargeMeshesProcess_Vertex;
diff --git a/thirdparty/assimp/code/TextureTransform.cpp b/thirdparty/assimp/code/PostProcessing/TextureTransform.cpp
index 8ae2ba7218..8ae2ba7218 100644
--- a/thirdparty/assimp/code/TextureTransform.cpp
+++ b/thirdparty/assimp/code/PostProcessing/TextureTransform.cpp
diff --git a/thirdparty/assimp/code/TextureTransform.h b/thirdparty/assimp/code/PostProcessing/TextureTransform.h
index c556ff5d8c..2a5d623d7f 100644
--- a/thirdparty/assimp/code/TextureTransform.h
+++ b/thirdparty/assimp/code/PostProcessing/TextureTransform.h
@@ -45,7 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define AI_TEXTURE_TRANSFORM_H_INCLUDED
#include <assimp/BaseImporter.h>
-#include "BaseProcess.h"
+#include "Common/BaseProcess.h"
#include <assimp/material.h>
#include <list>
diff --git a/thirdparty/assimp/code/TriangulateProcess.cpp b/thirdparty/assimp/code/PostProcessing/TriangulateProcess.cpp
index 0f68f47ddb..1040836bbe 100644
--- a/thirdparty/assimp/code/TriangulateProcess.cpp
+++ b/thirdparty/assimp/code/PostProcessing/TriangulateProcess.cpp
@@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2019, assimp team
-
-
All rights reserved.
Redistribution and use of this software in source and binary forms,
@@ -60,9 +58,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* a file
*/
#ifndef ASSIMP_BUILD_NO_TRIANGULATE_PROCESS
-#include "TriangulateProcess.h"
-#include "ProcessHelper.h"
-#include "PolyTools.h"
+
+#include "PostProcessing/TriangulateProcess.h"
+#include "PostProcessing/ProcessHelper.h"
+#include "Common/PolyTools.h"
+
#include <memory>
//#define AI_BUILD_TRIANGULATE_COLOR_FACE_WINDING
diff --git a/thirdparty/assimp/code/TriangulateProcess.h b/thirdparty/assimp/code/PostProcessing/TriangulateProcess.h
index 47bd2115ad..916b5103dd 100644
--- a/thirdparty/assimp/code/TriangulateProcess.h
+++ b/thirdparty/assimp/code/PostProcessing/TriangulateProcess.h
@@ -46,7 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_TRIANGULATEPROCESS_H_INC
#define AI_TRIANGULATEPROCESS_H_INC
-#include "BaseProcess.h"
+#include "Common/BaseProcess.h"
struct aiMesh;
@@ -59,14 +59,11 @@ namespace Assimp {
* into triangles. You usually want this to happen because the graphics cards
* need their data as triangles.
*/
-class ASSIMP_API TriangulateProcess : public BaseProcess
-{
+class ASSIMP_API TriangulateProcess : public BaseProcess {
public:
-
TriangulateProcess();
~TriangulateProcess();
-public:
// -------------------------------------------------------------------
/** Returns whether the processing step is present in the given flag field.
* @param pFlags The processing flags the importer was called with. A bitwise
@@ -82,7 +79,6 @@ public:
*/
void Execute( aiScene* pScene);
-public:
// -------------------------------------------------------------------
/** Triangulates the given mesh.
* @param pMesh The mesh to triangulate.
diff --git a/thirdparty/assimp/code/ValidateDataStructure.cpp b/thirdparty/assimp/code/PostProcessing/ValidateDataStructure.cpp
index 657b0361b7..712fd6943d 100644
--- a/thirdparty/assimp/code/ValidateDataStructure.cpp
+++ b/thirdparty/assimp/code/PostProcessing/ValidateDataStructure.cpp
@@ -46,8 +46,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* the data structure returned by Assimp.
*/
-
-
// internal headers
#include "ValidateDataStructure.h"
#include <assimp/BaseImporter.h>
@@ -110,8 +108,8 @@ void ValidateDSProcess::ReportWarning(const char* msg,...)
}
// ------------------------------------------------------------------------------------------------
-inline int HasNameMatch(const aiString& in, aiNode* node)
-{
+inline
+int HasNameMatch(const aiString& in, aiNode* node) {
int result = (node->mName == in ? 1 : 0 );
for (unsigned int i = 0; i < node->mNumChildren;++i) {
result += HasNameMatch(in,node->mChildren[i]);
@@ -121,9 +119,8 @@ inline int HasNameMatch(const aiString& in, aiNode* node)
// ------------------------------------------------------------------------------------------------
template <typename T>
-inline void ValidateDSProcess::DoValidation(T** parray, unsigned int size,
- const char* firstName, const char* secondName)
-{
+inline
+void ValidateDSProcess::DoValidation(T** parray, unsigned int size, const char* firstName, const char* secondName) {
// validate all entries
if (size)
{
@@ -181,7 +178,8 @@ inline void ValidateDSProcess::DoValidationEx(T** parray, unsigned int size,
// ------------------------------------------------------------------------------------------------
template <typename T>
inline
-void ValidateDSProcess::DoValidationWithNameCheck(T** array, unsigned int size, const char* firstName, const char* secondName) {
+void ValidateDSProcess::DoValidationWithNameCheck(T** array, unsigned int size, const char* firstName,
+ const char* secondName) {
// validate all entries
DoValidationEx(array,size,firstName,secondName);
@@ -201,9 +199,8 @@ void ValidateDSProcess::DoValidationWithNameCheck(T** array, unsigned int size,
// ------------------------------------------------------------------------------------------------
// Executes the post processing step on the given imported data.
-void ValidateDSProcess::Execute( aiScene* pScene)
-{
- this->mScene = pScene;
+void ValidateDSProcess::Execute( aiScene* pScene) {
+ mScene = pScene;
ASSIMP_LOG_DEBUG("ValidateDataStructureProcess begin");
// validate the node graph of the scene
@@ -516,13 +513,11 @@ void ValidateDSProcess::Validate( const aiMesh* pMesh)
}
// ------------------------------------------------------------------------------------------------
-void ValidateDSProcess::Validate( const aiMesh* pMesh,
- const aiBone* pBone,float* afSum)
-{
+void ValidateDSProcess::Validate( const aiMesh* pMesh, const aiBone* pBone,float* afSum) {
this->Validate(&pBone->mName);
if (!pBone->mNumWeights) {
- ReportError("aiBone::mNumWeights is zero");
+ //ReportError("aiBone::mNumWeights is zero");
}
// check whether all vertices affected by this bone are valid
@@ -563,9 +558,6 @@ void ValidateDSProcess::Validate( const aiAnimation* pAnimation)
else {
ReportError("aiAnimation::mNumChannels is 0. At least one node animation channel must be there.");
}
-
- // Animation duration is allowed to be zero in cases where the anim contains only a single key frame.
- // if (!pAnimation->mDuration)this->ReportError("aiAnimation::mDuration is zero");
}
// ------------------------------------------------------------------------------------------------
@@ -746,8 +738,9 @@ void ValidateDSProcess::Validate( const aiMaterial* pMaterial)
"AI_MATKEY_SHININESS_STRENGTH key is 0.0");
}
break;
- default: ;
- };
+ default:
+ break;
+ }
}
if (AI_SUCCESS == aiGetMaterialFloat( pMaterial,AI_MATKEY_OPACITY,&fTemp) && (!fTemp || fTemp > 1.01)) {
diff --git a/thirdparty/assimp/code/ValidateDataStructure.h b/thirdparty/assimp/code/PostProcessing/ValidateDataStructure.h
index bd21e88545..0b891ef414 100644
--- a/thirdparty/assimp/code/ValidateDataStructure.h
+++ b/thirdparty/assimp/code/PostProcessing/ValidateDataStructure.h
@@ -48,7 +48,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/types.h>
#include <assimp/material.h>
-#include "BaseProcess.h"
+
+#include "Common/BaseProcess.h"
struct aiBone;
struct aiMesh;
diff --git a/thirdparty/assimp/code/RawLoader.cpp b/thirdparty/assimp/code/RawLoader.cpp
deleted file mode 100644
index d0da247e47..0000000000
--- a/thirdparty/assimp/code/RawLoader.cpp
+++ /dev/null
@@ -1,331 +0,0 @@
-/*
----------------------------------------------------------------------------
-Open Asset Import Library (assimp)
----------------------------------------------------------------------------
-
-Copyright (c) 2006-2019, assimp team
-
-
-
-All rights reserved.
-
-Redistribution and use of this software in source and binary forms,
-with or without modification, are permitted provided that the following
-conditions are met:
-
-* Redistributions of source code must retain the above
- copyright notice, this list of conditions and the
- following disclaimer.
-
-* Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the
- following disclaimer in the documentation and/or other
- materials provided with the distribution.
-
-* Neither the name of the assimp team, nor the names of its
- contributors may be used to endorse or promote products
- derived from this software without specific prior
- written permission of the assimp team.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------------
-*/
-
-/** @file RawLoader.cpp
- * @brief Implementation of the RAW importer class
- */
-
-
-#ifndef ASSIMP_BUILD_NO_RAW_IMPORTER
-
-// internal headers
-#include "RawLoader.h"
-#include <assimp/ParsingUtils.h>
-#include <assimp/fast_atof.h>
-#include <memory>
-#include <assimp/IOSystem.hpp>
-#include <assimp/DefaultLogger.hpp>
-#include <assimp/scene.h>
-#include <assimp/importerdesc.h>
-
-using namespace Assimp;
-
-static const aiImporterDesc desc = {
- "Raw Importer",
- "",
- "",
- "",
- aiImporterFlags_SupportTextFlavour,
- 0,
- 0,
- 0,
- 0,
- "raw"
-};
-
-// ------------------------------------------------------------------------------------------------
-// Constructor to be privately used by Importer
-RAWImporter::RAWImporter()
-{}
-
-// ------------------------------------------------------------------------------------------------
-// Destructor, private as well
-RAWImporter::~RAWImporter()
-{}
-
-// ------------------------------------------------------------------------------------------------
-// Returns whether the class can handle the format of the given file.
-bool RAWImporter::CanRead( const std::string& pFile, IOSystem* /*pIOHandler*/, bool /*checkSig*/) const
-{
- return SimpleExtensionCheck(pFile,"raw");
-}
-
-// ------------------------------------------------------------------------------------------------
-const aiImporterDesc* RAWImporter::GetInfo () const
-{
- return &desc;
-}
-
-// ------------------------------------------------------------------------------------------------
-// Imports the given file into the given scene structure.
-void RAWImporter::InternReadFile( const std::string& pFile,
- aiScene* pScene, IOSystem* pIOHandler)
-{
- std::unique_ptr<IOStream> file( pIOHandler->Open( pFile, "rb"));
-
- // Check whether we can read from the file
- if( file.get() == NULL) {
- throw DeadlyImportError( "Failed to open RAW file " + pFile + ".");
- }
-
- // allocate storage and copy the contents of the file to a memory buffer
- // (terminate it with zero)
- std::vector<char> mBuffer2;
- TextFileToBuffer(file.get(),mBuffer2);
- const char* buffer = &mBuffer2[0];
-
- // list of groups loaded from the file
- std::vector< GroupInformation > outGroups(1,GroupInformation("<default>"));
- std::vector< GroupInformation >::iterator curGroup = outGroups.begin();
-
- // now read all lines
- char line[4096];
- while (GetNextLine(buffer,line))
- {
- // if the line starts with a non-numeric identifier, it marks
- // the beginning of a new group
- const char* sz = line;SkipSpaces(&sz);
- if (IsLineEnd(*sz))continue;
- if (!IsNumeric(*sz))
- {
- const char* sz2 = sz;
- while (!IsSpaceOrNewLine(*sz2))++sz2;
- const unsigned int length = (unsigned int)(sz2-sz);
-
- // find an existing group with this name
- for (std::vector< GroupInformation >::iterator it = outGroups.begin(), end = outGroups.end();
- it != end;++it)
- {
- if (length == (*it).name.length() && !::strcmp(sz,(*it).name.c_str()))
- {
- curGroup = it;sz2 = NULL;
- break;
- }
- }
- if (sz2)
- {
- outGroups.push_back(GroupInformation(std::string(sz,length)));
- curGroup = outGroups.end()-1;
- }
- }
- else
- {
- // there can be maximally 12 floats plus an extra texture file name
- float data[12];
- unsigned int num;
- for (num = 0; num < 12;++num)
- {
- if(!SkipSpaces(&sz) || !IsNumeric(*sz))break;
- sz = fast_atoreal_move<float>(sz,data[num]);
- }
- if (num != 12 && num != 9)
- {
- ASSIMP_LOG_ERROR("A line may have either 9 or 12 floats and an optional texture");
- continue;
- }
-
- MeshInformation* output = NULL;
-
- const char* sz2 = sz;
- unsigned int length;
- if (!IsLineEnd(*sz))
- {
- while (!IsSpaceOrNewLine(*sz2))++sz2;
- length = (unsigned int)(sz2-sz);
- }
- else if (9 == num)
- {
- sz = "%default%";
- length = 9;
- }
- else
- {
- sz = "";
- length = 0;
- }
-
- // search in the list of meshes whether we have one with this texture
- for (auto &mesh : (*curGroup).meshes)
- {
- if (length == mesh.name.length() && (length ? !::strcmp(sz, mesh.name.c_str()) : true))
- {
- output = &mesh;
- break;
- }
- }
- // if we don't have the mesh, create it
- if (!output)
- {
- (*curGroup).meshes.push_back(MeshInformation(std::string(sz,length)));
- output = &((*curGroup).meshes.back());
- }
- if (12 == num)
- {
- aiColor4D v(data[0],data[1],data[2],1.0f);
- output->colors.push_back(v);
- output->colors.push_back(v);
- output->colors.push_back(v);
-
- output->vertices.push_back(aiVector3D(data[3],data[4],data[5]));
- output->vertices.push_back(aiVector3D(data[6],data[7],data[8]));
- output->vertices.push_back(aiVector3D(data[9],data[10],data[11]));
- }
- else
- {
- output->vertices.push_back(aiVector3D(data[0],data[1],data[2]));
- output->vertices.push_back(aiVector3D(data[3],data[4],data[5]));
- output->vertices.push_back(aiVector3D(data[6],data[7],data[8]));
- }
- }
- }
-
- pScene->mRootNode = new aiNode();
- pScene->mRootNode->mName.Set("<RawRoot>");
-
- // count the number of valid groups
- // (meshes can't be empty)
- for (auto & outGroup : outGroups)
- {
- if (!outGroup.meshes.empty())
- {
- ++pScene->mRootNode->mNumChildren;
- pScene->mNumMeshes += (unsigned int) outGroup.meshes.size();
- }
- }
-
- if (!pScene->mNumMeshes)
- {
- throw DeadlyImportError("RAW: No meshes loaded. The file seems to be corrupt or empty.");
- }
-
- pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];
- aiNode** cc;
- if (1 == pScene->mRootNode->mNumChildren)
- {
- cc = &pScene->mRootNode;
- pScene->mRootNode->mNumChildren = 0;
- } else {
- cc = new aiNode*[pScene->mRootNode->mNumChildren];
- memset(cc, 0, sizeof(aiNode*) * pScene->mRootNode->mNumChildren);
- pScene->mRootNode->mChildren = cc;
- }
-
- pScene->mNumMaterials = pScene->mNumMeshes;
- aiMaterial** mats = pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials];
-
- unsigned int meshIdx = 0;
- for (auto & outGroup : outGroups)
- {
- if (outGroup.meshes.empty())continue;
-
- aiNode* node;
- if (pScene->mRootNode->mNumChildren)
- {
- node = *cc = new aiNode();
- node->mParent = pScene->mRootNode;
- }
- else node = *cc;
- node->mName.Set(outGroup.name);
-
- // add all meshes
- node->mNumMeshes = (unsigned int) outGroup.meshes.size();
- unsigned int* pi = node->mMeshes = new unsigned int[ node->mNumMeshes ];
- for (std::vector< MeshInformation >::iterator it2 = outGroup.meshes.begin(),
- end2 = outGroup.meshes.end(); it2 != end2; ++it2)
- {
- ai_assert(!(*it2).vertices.empty());
-
- // allocate the mesh
- *pi++ = meshIdx;
- aiMesh* mesh = pScene->mMeshes[meshIdx] = new aiMesh();
- mesh->mMaterialIndex = meshIdx++;
-
- mesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
-
- // allocate storage for the vertex components and copy them
- mesh->mNumVertices = (unsigned int)(*it2).vertices.size();
- mesh->mVertices = new aiVector3D[ mesh->mNumVertices ];
- ::memcpy(mesh->mVertices,&(*it2).vertices[0],sizeof(aiVector3D)*mesh->mNumVertices);
-
- if ((*it2).colors.size())
- {
- ai_assert((*it2).colors.size() == mesh->mNumVertices);
-
- mesh->mColors[0] = new aiColor4D[ mesh->mNumVertices ];
- ::memcpy(mesh->mColors[0],&(*it2).colors[0],sizeof(aiColor4D)*mesh->mNumVertices);
- }
-
- // generate triangles
- ai_assert(0 == mesh->mNumVertices % 3);
- aiFace* fc = mesh->mFaces = new aiFace[ mesh->mNumFaces = mesh->mNumVertices/3 ];
- aiFace* const fcEnd = fc + mesh->mNumFaces;
- unsigned int n = 0;
- while (fc != fcEnd)
- {
- aiFace& f = *fc++;
- f.mIndices = new unsigned int[f.mNumIndices = 3];
- for (unsigned int m = 0; m < 3;++m)
- f.mIndices[m] = n++;
- }
-
- // generate a material for the mesh
- aiMaterial* mat = new aiMaterial();
-
- aiColor4D clr(1.0f,1.0f,1.0f,1.0f);
- if ("%default%" == (*it2).name) // a gray default material
- {
- clr.r = clr.g = clr.b = 0.6f;
- }
- else if ((*it2).name.length() > 0) // a texture
- {
- aiString s;
- s.Set((*it2).name);
- mat->AddProperty(&s,AI_MATKEY_TEXTURE_DIFFUSE(0));
- }
- mat->AddProperty<aiColor4D>(&clr,1,AI_MATKEY_COLOR_DIFFUSE);
- *mats++ = mat;
- }
- }
-}
-
-#endif // !! ASSIMP_BUILD_NO_RAW_IMPORTER
diff --git a/thirdparty/assimp/include/assimp/Exporter.hpp b/thirdparty/assimp/include/assimp/Exporter.hpp
index bf0096e7e9..ea0303e804 100644
--- a/thirdparty/assimp/include/assimp/Exporter.hpp
+++ b/thirdparty/assimp/include/assimp/Exporter.hpp
@@ -190,7 +190,7 @@ public:
* @note Use aiCopyScene() to get a modifiable copy of a previously
* imported scene. */
const aiExportDataBlob* ExportToBlob(const aiScene* pScene, const char* pFormatId,
- unsigned int pPreprocessing = 0u, const ExportProperties* = nullptr);
+ unsigned int pPreprocessing = 0u, const ExportProperties* pProperties = nullptr);
const aiExportDataBlob* ExportToBlob( const aiScene* pScene, const std::string& pFormatId,
unsigned int pPreprocessing = 0u, const ExportProperties* pProperties = nullptr);
diff --git a/thirdparty/assimp/include/assimp/ParsingUtils.h b/thirdparty/assimp/include/assimp/ParsingUtils.h
index ca30ce13b0..6b9574fc67 100644
--- a/thirdparty/assimp/include/assimp/ParsingUtils.h
+++ b/thirdparty/assimp/include/assimp/ParsingUtils.h
@@ -196,8 +196,7 @@ bool GetNextLine( const char_t*& buffer, char_t out[ BufferSize ] ) {
// ---------------------------------------------------------------------------------
template <class char_t>
-AI_FORCE_INLINE bool IsNumeric( char_t in)
-{
+AI_FORCE_INLINE bool IsNumeric( char_t in) {
return ( in >= '0' && in <= '9' ) || '-' == in || '+' == in;
}
diff --git a/thirdparty/assimp/include/assimp/aabb.h b/thirdparty/assimp/include/assimp/aabb.h
new file mode 100644
index 0000000000..a20f317424
--- /dev/null
+++ b/thirdparty/assimp/include/assimp/aabb.h
@@ -0,0 +1,76 @@
+/*
+---------------------------------------------------------------------------
+Open Asset Import Library (assimp)
+---------------------------------------------------------------------------
+
+Copyright (c) 2006-2019, assimp team
+
+
+
+All rights reserved.
+
+Redistribution and use of this software in source and binary forms,
+with or without modification, are permitted provided that the following
+conditions are met:
+
+* Redistributions of source code must retain the above
+copyright notice, this list of conditions and the
+following disclaimer.
+
+* Redistributions in binary form must reproduce the above
+copyright notice, this list of conditions and the
+following disclaimer in the documentation and/or other
+materials provided with the distribution.
+
+* Neither the name of the assimp team, nor the names of its
+contributors may be used to endorse or promote products
+derived from this software without specific prior
+written permission of the assimp team.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+---------------------------------------------------------------------------
+*/
+
+#pragma once
+#ifndef AI_AABB_H_INC
+#define AI_AABB_H_INC
+
+#include <assimp/vector3.h>
+
+struct aiAABB {
+ C_STRUCT aiVector3D mMin;
+ C_STRUCT aiVector3D mMax;
+
+#ifdef __cplusplus
+
+ aiAABB()
+ : mMin()
+ , mMax() {
+ // empty
+ }
+
+ aiAABB(const aiVector3D &min, const aiVector3D &max )
+ : mMin(min)
+ , mMax(max) {
+ // empty
+ }
+
+ ~aiAABB() {
+ // empty
+ }
+
+#endif
+};
+
+
+#endif
diff --git a/thirdparty/assimp/include/assimp/camera.h b/thirdparty/assimp/include/assimp/camera.h
index 99daf69934..e573eea5d1 100644
--- a/thirdparty/assimp/include/assimp/camera.h
+++ b/thirdparty/assimp/include/assimp/camera.h
@@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2019, assimp team
-
-
All rights reserved.
Redistribution and use of this software in source and binary forms,
@@ -60,7 +58,7 @@ extern "C" {
*
* Cameras have a representation in the node graph and can be animated.
* An important aspect is that the camera itself is also part of the
- * scenegraph. This means, any values such as the look-at vector are not
+ * scene-graph. This means, any values such as the look-at vector are not
* *absolute*, they're <b>relative</b> to the coordinate system defined
* by the node which corresponds to the camera. This allows for camera
* animations. For static cameras parameters like the 'look-at' or 'up' vectors
@@ -162,7 +160,6 @@ struct aiCamera
*/
float mClipPlaneFar;
-
/** Screen aspect ratio.
*
* This is the ration between the width and the height of the
diff --git a/thirdparty/assimp/include/assimp/color4.inl b/thirdparty/assimp/include/assimp/color4.inl
index 3192d55f39..afa53dcb5b 100644
--- a/thirdparty/assimp/include/assimp/color4.inl
+++ b/thirdparty/assimp/include/assimp/color4.inl
@@ -85,6 +85,8 @@ AI_FORCE_INLINE TReal aiColor4t<TReal>::operator[](unsigned int i) const {
return g;
case 2:
return b;
+ case 3:
+ return a;
default:
break;
}
@@ -100,6 +102,8 @@ AI_FORCE_INLINE TReal& aiColor4t<TReal>::operator[](unsigned int i) {
return g;
case 2:
return b;
+ case 3:
+ return a;
default:
break;
}
diff --git a/thirdparty/assimp/include/assimp/config.h.in b/thirdparty/assimp/include/assimp/config.h.in
index a37ff0b8c8..d08b929a10 100644
--- a/thirdparty/assimp/include/assimp/config.h.in
+++ b/thirdparty/assimp/include/assimp/config.h.in
@@ -142,7 +142,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/** @brief Specifies the maximum angle that may be between two vertex tangents
* that their tangents and bi-tangents are smoothed.
*
- * This applies to the CalcTangentSpace-Step. The angle is specified
+ * This applies to the CalcTangentSpace-Step. TFvhe angle is specified
* in degrees. The maximum value is 175.
* Property type: float. Default value: 45 degrees
*/
@@ -651,13 +651,28 @@ enum aiComponent
// ---------------------------------------------------------------------------
/** @brief Set whether the fbx importer will use the legacy embedded texture naming.
-*
-* The default value is false (0)
-* Property type: bool
-*/
+ *
+ * The default value is false (0)
+ * Property type: bool
+ */
#define AI_CONFIG_IMPORT_FBX_EMBEDDED_TEXTURES_LEGACY_NAMING \
"AI_CONFIG_IMPORT_FBX_EMBEDDED_TEXTURES_LEGACY_NAMING"
-
+
+// ---------------------------------------------------------------------------
+/** @brief Set wether the importer shall not remove empty bones.
+ *
+ * Empty bone are often used to define connections for other models.
+ */
+#define AI_CONFIG_IMPORT_REMOVE_EMPTY_BONES \
+ "AI_CONFIG_IMPORT_REMOVE_EMPTY_BONES"
+
+
+// ---------------------------------------------------------------------------
+/** @brief Set wether the FBX importer shall convert the unit from cm to m.
+ */
+#define AI_CONFIG_FBX_CONVERT_TO_M \
+ "AI_CONFIG_FBX_CONVERT_TO_M"
+
// ---------------------------------------------------------------------------
/** @brief Set the vertex animation keyframe to be imported
*
@@ -966,8 +981,12 @@ enum aiComponent
#define AI_CONFIG_EXPORT_XFILE_64BIT "EXPORT_XFILE_64BIT"
-/**
- *
+/** @brief Specifies whether the assimp export shall be able to export point clouds
+ *
+ * When this flag is not defined the render data has to contain valid faces.
+ * Point clouds are only a collection of vertices which have nor spatial organization
+ * by a face and the validation process will remove them. Enabling this feature will
+ * switch off the flag and enable the functionality to export pure point clouds.
*/
#define AI_CONFIG_EXPORT_POINT_CLOUDS "EXPORT_POINT_CLOUDS"
diff --git a/thirdparty/assimp/include/assimp/defs.h b/thirdparty/assimp/include/assimp/defs.h
index 4a177e3c3e..05a5e3fd4b 100644
--- a/thirdparty/assimp/include/assimp/defs.h
+++ b/thirdparty/assimp/include/assimp/defs.h
@@ -122,7 +122,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* OPTIMIZEANIMS
* OPTIMIZEGRAPH
* GENENTITYMESHES
- * FIXTEXTUREPATHS */
+ * FIXTEXTUREPATHS
+ * GENBOUNDINGBOXES */
//////////////////////////////////////////////////////////////////////////
#ifdef _MSC_VER
@@ -214,10 +215,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endif
#if (defined(__BORLANDC__) || defined (__BCPLUSPLUS__))
-#error Currently, Borland is unsupported. Feel free to port Assimp.
-
-// "W8059 Packgröße der Struktur geändert"
-
+# error Currently, Borland is unsupported. Feel free to port Assimp.
#endif
@@ -243,10 +241,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
typedef double ai_real;
typedef signed long long int ai_int;
typedef unsigned long long int ai_uint;
+#ifndef ASSIMP_AI_REAL_TEXT_PRECISION
+#define ASSIMP_AI_REAL_TEXT_PRECISION 16
+#endif // ASSIMP_AI_REAL_TEXT_PRECISION
#else // ASSIMP_DOUBLE_PRECISION
typedef float ai_real;
typedef signed int ai_int;
typedef unsigned int ai_uint;
+#ifndef ASSIMP_AI_REAL_TEXT_PRECISION
+#define ASSIMP_AI_REAL_TEXT_PRECISION 8
+#endif // ASSIMP_AI_REAL_TEXT_PRECISION
#endif // ASSIMP_DOUBLE_PRECISION
//////////////////////////////////////////////////////////////////////////
@@ -267,6 +271,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define AI_DEG_TO_RAD(x) ((x)*(ai_real)0.0174532925)
#define AI_RAD_TO_DEG(x) ((x)*(ai_real)57.2957795)
+/* Numerical limits */
+static const ai_real ai_epsilon = (ai_real) 0.00001;
+
/* Support for big-endian builds */
#if defined(__BYTE_ORDER__)
# if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
@@ -293,11 +300,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef _MSC_VER
# define AI_NO_EXCEPT noexcept
#else
-# if (_MSC_VER == 1915 )
+# if (_MSC_VER >= 1915 )
# define AI_NO_EXCEPT noexcept
# else
# define AI_NO_EXCEPT
# endif
-#endif
+#endif // _MSC_VER
#endif // !! AI_DEFINES_H_INC
diff --git a/thirdparty/assimp/include/assimp/mesh.h b/thirdparty/assimp/include/assimp/mesh.h
index 36f3ed2afd..f1628f1f54 100644
--- a/thirdparty/assimp/include/assimp/mesh.h
+++ b/thirdparty/assimp/include/assimp/mesh.h
@@ -48,7 +48,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_MESH_H_INC
#define AI_MESH_H_INC
-#include "types.h"
+#include <assimp/types.h>
+#include <assimp/aabb.h>
#ifdef __cplusplus
extern "C" {
@@ -714,6 +715,11 @@ struct aiMesh
* Method of morphing when animeshes are specified.
*/
unsigned int mMethod;
+
+ /**
+ *
+ */
+ C_STRUCT aiAABB mAABB;
#ifdef __cplusplus
@@ -735,7 +741,8 @@ struct aiMesh
, mMaterialIndex( 0 )
, mNumAnimMeshes( 0 )
, mAnimMeshes(nullptr)
- , mMethod( 0 ) {
+ , mMethod( 0 )
+ , mAABB() {
for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a ) {
mNumUVComponents[a] = 0;
mTextureCoords[a] = nullptr;
diff --git a/thirdparty/assimp/include/assimp/postprocess.h b/thirdparty/assimp/include/assimp/postprocess.h
index c23a5490a5..2a74414216 100644
--- a/thirdparty/assimp/include/assimp/postprocess.h
+++ b/thirdparty/assimp/include/assimp/postprocess.h
@@ -438,7 +438,7 @@ enum aiPostProcessSteps
aiProcess_FindInstances = 0x100000,
// -------------------------------------------------------------------------
- /** <hr>A postprocessing step to reduce the number of meshes.
+ /** <hr>A post-processing step to reduce the number of meshes.
*
* This will, in fact, reduce the number of draw calls.
*
@@ -450,7 +450,7 @@ enum aiPostProcessSteps
// -------------------------------------------------------------------------
- /** <hr>A postprocessing step to optimize the scene hierarchy.
+ /** <hr>A post-processing step to optimize the scene hierarchy.
*
* Nodes without animations, bones, lights or cameras assigned are
* collapsed and joined.
@@ -514,7 +514,7 @@ enum aiPostProcessSteps
// -------------------------------------------------------------------------
/** <hr>This step splits meshes with many bones into sub-meshes so that each
- * su-bmesh has fewer or as many bones as a given limit.
+ * sub-mesh has fewer or as many bones as a given limit.
*/
aiProcess_SplitByBoneCount = 0x2000000,
@@ -541,7 +541,7 @@ enum aiPostProcessSteps
* global scaling from your importer settings like in FBX. Use the flag
* AI_CONFIG_GLOBAL_SCALE_FACTOR_KEY from the global property table to configure this.
*
- * Use <tt>#AI_CONFIG_GLOBAL_SCALE_FACTOR_KEY</tt> to setup the global scaing factor.
+ * Use <tt>#AI_CONFIG_GLOBAL_SCALE_FACTOR_KEY</tt> to setup the global scaling factor.
*/
aiProcess_GlobalScale = 0x8000000,
@@ -574,6 +574,11 @@ enum aiPostProcessSteps
* This process gives sense back to aiProcess_JoinIdenticalVertices
*/
aiProcess_DropNormals = 0x40000000,
+
+ // -------------------------------------------------------------------------
+ /**
+ */
+ aiProcess_GenBoundingBoxes = 0x80000000
};
diff --git a/thirdparty/assimp/include/assimp/scene.h b/thirdparty/assimp/include/assimp/scene.h
index de0239702d..df5d6f3b5e 100644
--- a/thirdparty/assimp/include/assimp/scene.h
+++ b/thirdparty/assimp/include/assimp/scene.h
@@ -56,6 +56,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "material.h"
#include "anim.h"
#include "metadata.h"
+#include <cstdlib>
#ifdef __cplusplus
extern "C" {
@@ -389,6 +390,14 @@ struct aiScene
//! Returns an embedded texture
const aiTexture* GetEmbeddedTexture(const char* filename) const {
+ // lookup using texture ID (if referenced like: "*1", "*2", etc.)
+ if ('*' == *filename) {
+ int index = std::atoi(filename + 1);
+ if (0 > index || mNumTextures <= static_cast<unsigned>(index))
+ return nullptr;
+ return mTextures[index];
+ }
+ // lookup using filename
const char* shortFilename = GetShortFilename(filename);
for (unsigned int i = 0; i < mNumTextures; i++) {
const char* shortTextureFilename = GetShortFilename(mTextures[i]->mFilename.C_Str());
diff --git a/thirdparty/freetype/include/freetype/freetype.h b/thirdparty/freetype/include/freetype/freetype.h
index 4f2eaca691..a6bb667e3a 100644
--- a/thirdparty/freetype/include/freetype/freetype.h
+++ b/thirdparty/freetype/include/freetype/freetype.h
@@ -645,7 +645,7 @@ FT_BEGIN_HEADER
* FT_ENCODING_MS_SYMBOL ::
* Microsoft Symbol encoding, used to encode mathematical symbols and
* wingdings. For more information, see
- * 'https://www.microsoft.com/typography/otspec/recom.htm',
+ * 'https://www.microsoft.com/typography/otspec/recom.htm#non-standard-symbol-fonts',
* 'http://www.kostis.net/charsets/symbol.htm', and
* 'http://www.kostis.net/charsets/wingding.htm'.
*
@@ -1766,6 +1766,13 @@ FT_BEGIN_HEADER
* transformed, distorted, emboldened, etc. However, it must not be
* freed.
*
+ * [Since 2.10.1] If @FT_LOAD_NO_SCALE is set, outline coordinates of
+ * OpenType variation fonts for a selected instance are internally
+ * handled as 26.6 fractional font units but returned as (rounded)
+ * integers, as expected. To get unrounded font units, don't use
+ * @FT_LOAD_NO_SCALE but load the glyph with @FT_LOAD_NO_HINTING and
+ * scale it, using the font's `units_per_EM` value as the ppem.
+ *
* num_subglyphs ::
* The number of subglyphs in a composite glyph. This field is only
* valid for the composite glyph format that should normally only be
@@ -3932,8 +3939,8 @@ FT_BEGIN_HEADER
* The glyph index. 0~means 'undefined character code'.
*/
FT_EXPORT( FT_UInt )
- FT_Get_Name_Index( FT_Face face,
- FT_String* glyph_name );
+ FT_Get_Name_Index( FT_Face face,
+ const FT_String* glyph_name );
/**************************************************************************
@@ -4774,7 +4781,7 @@ FT_BEGIN_HEADER
*/
#define FREETYPE_MAJOR 2
#define FREETYPE_MINOR 10
-#define FREETYPE_PATCH 0
+#define FREETYPE_PATCH 1
/**************************************************************************
diff --git a/thirdparty/freetype/include/freetype/fterrors.h b/thirdparty/freetype/include/freetype/fterrors.h
index 58f5a3ead1..2b47eb2096 100644
--- a/thirdparty/freetype/include/freetype/fterrors.h
+++ b/thirdparty/freetype/include/freetype/fterrors.h
@@ -244,6 +244,8 @@
#define FT_ERR_PROTOS_DEFINED
+FT_BEGIN_HEADER
+
/**************************************************************************
*
* @function:
@@ -274,6 +276,8 @@
FT_EXPORT( const char* )
FT_Error_String( FT_Error error_code );
+FT_END_HEADER
+
#endif /* FT_ERR_PROTOS_DEFINED */
diff --git a/thirdparty/freetype/include/freetype/ftglyph.h b/thirdparty/freetype/include/freetype/ftglyph.h
index 4067c2e62f..fedab8491e 100644
--- a/thirdparty/freetype/include/freetype/ftglyph.h
+++ b/thirdparty/freetype/include/freetype/ftglyph.h
@@ -210,7 +210,7 @@ FT_BEGIN_HEADER
*
* As the outline is extracted from a glyph slot, its coordinates are
* expressed normally in 26.6 pixels, unless the flag @FT_LOAD_NO_SCALE
- * was used in @FT_Load_Glyph() or @FT_Load_Char().
+ * was used in @FT_Load_Glyph or @FT_Load_Char.
*
* The outline's tables are always owned by the object and are destroyed
* with it.
diff --git a/thirdparty/freetype/include/freetype/ftimage.h b/thirdparty/freetype/include/freetype/ftimage.h
index d640b0b0aa..face34fe49 100644
--- a/thirdparty/freetype/include/freetype/ftimage.h
+++ b/thirdparty/freetype/include/freetype/ftimage.h
@@ -869,7 +869,7 @@ FT_BEGIN_HEADER
*
* @input:
* y ::
- * The scanline's y~coordinate.
+ * The scanline's upward y~coordinate.
*
* count ::
* The number of spans to draw on this scanline.
@@ -945,19 +945,16 @@ FT_BEGIN_HEADER
* This flag is set to indicate direct rendering. In this mode, client
* applications must provide their own span callback. This lets them
* directly draw or compose over an existing bitmap. If this bit is
- * not set, the target pixmap's buffer _must_ be zeroed before
- * rendering.
+ * _not_ set, the target pixmap's buffer _must_ be zeroed before
+ * rendering and the output will be clipped to its size.
*
* Direct rendering is only possible with anti-aliased glyphs.
*
* FT_RASTER_FLAG_CLIP ::
* This flag is only used in direct rendering mode. If set, the output
* will be clipped to a box specified in the `clip_box` field of the
- * @FT_Raster_Params structure.
- *
- * Note that by default, the glyph bitmap is clipped to the target
- * pixmap, except in direct rendering mode where all spans are
- * generated if no clipping box is set.
+ * @FT_Raster_Params structure. Otherwise, the `clip_box` is
+ * effectively set to the bounding box and all spans are generated.
*/
#define FT_RASTER_FLAG_DEFAULT 0x0
#define FT_RASTER_FLAG_AA 0x1
@@ -978,7 +975,8 @@ FT_BEGIN_HEADER
* FT_Raster_Params
*
* @description:
- * A structure to hold the arguments used by a raster's render function.
+ * A structure to hold the parameters used by a raster's render function,
+ * passed as an argument to @FT_Outline_Render.
*
* @fields:
* target ::
diff --git a/thirdparty/freetype/include/freetype/ftmodapi.h b/thirdparty/freetype/include/freetype/ftmodapi.h
index 88488bfe89..8d039c4f3a 100644
--- a/thirdparty/freetype/include/freetype/ftmodapi.h
+++ b/thirdparty/freetype/include/freetype/ftmodapi.h
@@ -623,7 +623,7 @@ FT_BEGIN_HEADER
* it is bytecode interpreter's execution context, `TT_ExecContext`,
* which is declared in FreeType's internal header file `tttypes.h`.
*/
- typedef void
+ typedef FT_Error
(*FT_DebugHook_Func)( void* arg );
diff --git a/thirdparty/freetype/include/freetype/ftoutln.h b/thirdparty/freetype/include/freetype/ftoutln.h
index 75c3d01596..b72327b703 100644
--- a/thirdparty/freetype/include/freetype/ftoutln.h
+++ b/thirdparty/freetype/include/freetype/ftoutln.h
@@ -466,8 +466,6 @@ FT_BEGIN_HEADER
*
* @description:
* Render an outline within a bitmap using the current scan-convert.
- * This function uses an @FT_Raster_Params structure as an argument,
- * allowing advanced features like direct composition, translucency, etc.
*
* @input:
* library ::
@@ -485,8 +483,10 @@ FT_BEGIN_HEADER
* FreeType error code. 0~means success.
*
* @note:
- * You should know what you are doing and how @FT_Raster_Params works to
- * use this function.
+ * This advanced function uses @FT_Raster_Params as an argument,
+ * allowing FreeType rasterizer to be used for direct composition,
+ * translucency, etc. You should know how to set up @FT_Raster_Params
+ * for this function to work.
*
* The field `params.source` will be set to `outline` before the scan
* converter is called, which means that the value you give to it is
diff --git a/thirdparty/freetype/include/freetype/ftwinfnt.h b/thirdparty/freetype/include/freetype/ftwinfnt.h
index 3437913d53..a2fba903d2 100644
--- a/thirdparty/freetype/include/freetype/ftwinfnt.h
+++ b/thirdparty/freetype/include/freetype/ftwinfnt.h
@@ -58,7 +58,7 @@ FT_BEGIN_HEADER
* @description:
* A list of valid values for the `charset` byte in @FT_WinFNT_HeaderRec.
* Exact mapping tables for the various 'cpXXXX' encodings (except for
- * 'cp1361') can be found at 'ftp://ftp.unicode.org/Public' in the
+ * 'cp1361') can be found at 'ftp://ftp.unicode.org/Public/' in the
* `MAPPINGS/VENDORS/MICSFT/WINDOWS` subdirectory. 'cp1361' is roughly a
* superset of `MAPPINGS/OBSOLETE/EASTASIA/KSC/JOHAB.TXT`.
*
diff --git a/thirdparty/freetype/include/freetype/internal/ftcalc.h b/thirdparty/freetype/include/freetype/internal/ftcalc.h
index 2986ec359b..1811fcd1ea 100644
--- a/thirdparty/freetype/include/freetype/internal/ftcalc.h
+++ b/thirdparty/freetype/include/freetype/internal/ftcalc.h
@@ -378,6 +378,7 @@ FT_BEGIN_HEADER
#if FT_SIZEOF_INT == 4
#include <intrin.h>
+#pragma intrinsic( _BitScanReverse )
static __inline FT_Int32
FT_MSB_i386( FT_UInt32 x )
@@ -385,7 +386,6 @@ FT_BEGIN_HEADER
unsigned long where;
- /* not available in older VC versions */
_BitScanReverse( &where, x );
return (FT_Int32)where;
diff --git a/thirdparty/freetype/include/freetype/internal/ftobjs.h b/thirdparty/freetype/include/freetype/internal/ftobjs.h
index f3a41b35ab..0c1d3e5bf2 100644
--- a/thirdparty/freetype/include/freetype/internal/ftobjs.h
+++ b/thirdparty/freetype/include/freetype/internal/ftobjs.h
@@ -278,14 +278,12 @@ FT_BEGIN_HEADER
#ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
typedef void (*FT_Bitmap_LcdFilterFunc)( FT_Bitmap* bitmap,
- FT_Render_Mode render_mode,
FT_Byte* weights );
/* This is the default LCD filter, an in-place, 5-tap FIR filter. */
FT_BASE( void )
ft_lcd_filter_fir( FT_Bitmap* bitmap,
- FT_Render_Mode mode,
FT_LcdFiveTapFilter weights );
#endif /* FT_CONFIG_OPTION_SUBPIXEL_RENDERING */
@@ -941,8 +939,8 @@ FT_BEGIN_HEADER
FT_UInt buffer_max );
typedef FT_UInt
- (*FT_Face_GetGlyphNameIndexFunc)( FT_Face face,
- FT_String* glyph_name );
+ (*FT_Face_GetGlyphNameIndexFunc)( FT_Face face,
+ const FT_String* glyph_name );
#ifndef FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM
diff --git a/thirdparty/freetype/include/freetype/internal/ftstream.h b/thirdparty/freetype/include/freetype/internal/ftstream.h
index e4dca0b0a5..a579a039b9 100644
--- a/thirdparty/freetype/include/freetype/internal/ftstream.h
+++ b/thirdparty/freetype/include/freetype/internal/ftstream.h
@@ -166,6 +166,17 @@ FT_BEGIN_HEADER
/*
+ * function acts on increases does range for emits
+ * pointer checking frames error
+ * -------------------------------------------------------------------
+ * FT_PEEK_XXX buffer pointer no no no no
+ * FT_NEXT_XXX buffer pointer yes no no no
+ * FT_GET_XXX stream->cursor yes yes yes no
+ * FT_READ_XXX stream->pos yes yes no yes
+ */
+
+
+ /*
* `FT_PEEK_XXX' are generic macros to get data from a buffer position. No
* safety checks are performed.
*/
diff --git a/thirdparty/freetype/include/freetype/internal/fttrace.h b/thirdparty/freetype/include/freetype/internal/fttrace.h
index 8089babfb6..f5f9598046 100644
--- a/thirdparty/freetype/include/freetype/internal/fttrace.h
+++ b/thirdparty/freetype/include/freetype/internal/fttrace.h
@@ -48,6 +48,7 @@ FT_TRACE_DEF( cache ) /* cache sub-system (ftcache.c, etc.) */
/* SFNT driver components */
FT_TRACE_DEF( sfdriver ) /* SFNT font driver (sfdriver.c) */
FT_TRACE_DEF( sfobjs ) /* SFNT object handler (sfobjs.c) */
+FT_TRACE_DEF( sfwoff ) /* WOFF format handler (sfwoff.c) */
FT_TRACE_DEF( ttbdf ) /* TrueType embedded BDF (ttbdf.c) */
FT_TRACE_DEF( ttcmap ) /* charmap handler (ttcmap.c) */
FT_TRACE_DEF( ttcolr ) /* glyph layer table (ttcolr.c) */
diff --git a/thirdparty/freetype/include/freetype/internal/internal.h b/thirdparty/freetype/include/freetype/internal/internal.h
index 173d8ad906..3c8830f7e4 100644
--- a/thirdparty/freetype/include/freetype/internal/internal.h
+++ b/thirdparty/freetype/include/freetype/internal/internal.h
@@ -40,6 +40,7 @@
#define FT_INTERNAL_TRUETYPE_TYPES_H <freetype/internal/tttypes.h>
#define FT_INTERNAL_TYPE1_TYPES_H <freetype/internal/t1types.h>
+#define FT_INTERNAL_WOFF_TYPES_H <freetype/internal/wofftypes.h>
#define FT_INTERNAL_POSTSCRIPT_AUX_H <freetype/internal/psaux.h>
#define FT_INTERNAL_POSTSCRIPT_HINTS_H <freetype/internal/pshints.h>
diff --git a/thirdparty/freetype/include/freetype/internal/psaux.h b/thirdparty/freetype/include/freetype/internal/psaux.h
index 3ab01c3e68..f962a973de 100644
--- a/thirdparty/freetype/include/freetype/internal/psaux.h
+++ b/thirdparty/freetype/include/freetype/internal/psaux.h
@@ -96,10 +96,10 @@ FT_BEGIN_HEADER
(*done)( PS_Table table );
FT_Error
- (*add)( PS_Table table,
- FT_Int idx,
- void* object,
- FT_UInt length );
+ (*add)( PS_Table table,
+ FT_Int idx,
+ const void* object,
+ FT_UInt length );
void
(*release)( PS_Table table );
diff --git a/thirdparty/freetype/include/freetype/internal/services/svgldict.h b/thirdparty/freetype/include/freetype/internal/services/svgldict.h
index ca8edf0eb5..0949621835 100644
--- a/thirdparty/freetype/include/freetype/internal/services/svgldict.h
+++ b/thirdparty/freetype/include/freetype/internal/services/svgldict.h
@@ -41,8 +41,8 @@ FT_BEGIN_HEADER
FT_UInt buffer_max );
typedef FT_UInt
- (*FT_GlyphDict_NameIndexFunc)( FT_Face face,
- FT_String* glyph_name );
+ (*FT_GlyphDict_NameIndexFunc)( FT_Face face,
+ const FT_String* glyph_name );
FT_DEFINE_SERVICE( GlyphDict )
diff --git a/thirdparty/freetype/include/freetype/internal/sfnt.h b/thirdparty/freetype/include/freetype/internal/sfnt.h
index 225f40df6e..b19241c306 100644
--- a/thirdparty/freetype/include/freetype/internal/sfnt.h
+++ b/thirdparty/freetype/include/freetype/internal/sfnt.h
@@ -23,6 +23,7 @@
#include <ft2build.h>
#include FT_INTERNAL_DRIVER_H
#include FT_INTERNAL_TRUETYPE_TYPES_H
+#include FT_INTERNAL_WOFF_TYPES_H
FT_BEGIN_HEADER
diff --git a/thirdparty/freetype/include/freetype/internal/t1types.h b/thirdparty/freetype/include/freetype/internal/t1types.h
index e197a1afca..d94c8c1284 100644
--- a/thirdparty/freetype/include/freetype/internal/t1types.h
+++ b/thirdparty/freetype/include/freetype/internal/t1types.h
@@ -76,8 +76,8 @@ FT_BEGIN_HEADER
FT_Int code_first;
FT_Int code_last;
- FT_UShort* char_index;
- FT_String** char_name;
+ FT_UShort* char_index;
+ const FT_String** char_name;
} T1_EncodingRec, *T1_Encoding;
diff --git a/thirdparty/freetype/include/freetype/internal/tttypes.h b/thirdparty/freetype/include/freetype/internal/tttypes.h
index 5e9f40ec3f..23db240e7c 100644
--- a/thirdparty/freetype/include/freetype/internal/tttypes.h
+++ b/thirdparty/freetype/include/freetype/internal/tttypes.h
@@ -153,81 +153,6 @@ FT_BEGIN_HEADER
/**************************************************************************
*
* @struct:
- * WOFF_HeaderRec
- *
- * @description:
- * WOFF file format header.
- *
- * @fields:
- * See
- *
- * https://www.w3.org/TR/WOFF/#WOFFHeader
- */
- typedef struct WOFF_HeaderRec_
- {
- FT_ULong signature;
- FT_ULong flavor;
- FT_ULong length;
- FT_UShort num_tables;
- FT_UShort reserved;
- FT_ULong totalSfntSize;
- FT_UShort majorVersion;
- FT_UShort minorVersion;
- FT_ULong metaOffset;
- FT_ULong metaLength;
- FT_ULong metaOrigLength;
- FT_ULong privOffset;
- FT_ULong privLength;
-
- } WOFF_HeaderRec, *WOFF_Header;
-
-
- /**************************************************************************
- *
- * @struct:
- * WOFF_TableRec
- *
- * @description:
- * This structure describes a given table of a WOFF font.
- *
- * @fields:
- * Tag ::
- * A four-bytes tag describing the table.
- *
- * Offset ::
- * The offset of the table from the start of the WOFF font in its
- * resource.
- *
- * CompLength ::
- * Compressed table length (in bytes).
- *
- * OrigLength ::
- * Uncompressed table length (in bytes).
- *
- * CheckSum ::
- * The table checksum. This value can be ignored.
- *
- * OrigOffset ::
- * The uncompressed table file offset. This value gets computed while
- * constructing the (uncompressed) SFNT header. It is not contained in
- * the WOFF file.
- */
- typedef struct WOFF_TableRec_
- {
- FT_ULong Tag; /* table ID */
- FT_ULong Offset; /* table file offset */
- FT_ULong CompLength; /* compressed table length */
- FT_ULong OrigLength; /* uncompressed table length */
- FT_ULong CheckSum; /* uncompressed checksum */
-
- FT_ULong OrigOffset; /* uncompressed table file offset */
- /* (not in the WOFF file) */
- } WOFF_TableRec, *WOFF_Table;
-
-
- /**************************************************************************
- *
- * @struct:
* TT_LongMetricsRec
*
* @description:
@@ -1395,8 +1320,10 @@ FT_BEGIN_HEADER
*
* cvt ::
* The face's original control value table. Coordinates are expressed
- * in unscaled font units. Comes from the 'cvt~' table. Ignored for
- * Type 2 fonts.
+ * in unscaled font units (in 26.6 format). Comes from the 'cvt~'
+ * table. Ignored for Type 2 fonts.
+ *
+ * If varied by the `CVAR' table, non-integer values are possible.
*
* interpreter ::
* A pointer to the TrueType bytecode interpreters field is also used
@@ -1633,7 +1560,7 @@ FT_BEGIN_HEADER
/* the original, unscaled, control value table */
FT_ULong cvt_size;
- FT_Short* cvt;
+ FT_Int32* cvt;
/* A pointer to the bytecode interpreter to use. This is also */
/* used to hook the debugger for the `ttdebug' utility. */
diff --git a/thirdparty/freetype/include/freetype/internal/wofftypes.h b/thirdparty/freetype/include/freetype/internal/wofftypes.h
new file mode 100644
index 0000000000..ba55bf883e
--- /dev/null
+++ b/thirdparty/freetype/include/freetype/internal/wofftypes.h
@@ -0,0 +1,112 @@
+/****************************************************************************
+ *
+ * wofftypes.h
+ *
+ * Basic WOFF/WOFF2 type definitions and interface (specification
+ * only).
+ *
+ * Copyright (C) 1996-2019 by
+ * David Turner, Robert Wilhelm, and Werner Lemberg.
+ *
+ * This file is part of the FreeType project, and may only be used,
+ * modified, and distributed under the terms of the FreeType project
+ * license, LICENSE.TXT. By continuing to use, modify, or distribute
+ * this file you indicate that you have read the license and
+ * understand and accept it fully.
+ *
+ */
+
+
+#ifndef WOFFTYPES_H_
+#define WOFFTYPES_H_
+
+
+#include <ft2build.h>
+#include FT_TRUETYPE_TABLES_H
+#include FT_INTERNAL_OBJECTS_H
+
+
+FT_BEGIN_HEADER
+
+
+ /**************************************************************************
+ *
+ * @struct:
+ * WOFF_HeaderRec
+ *
+ * @description:
+ * WOFF file format header.
+ *
+ * @fields:
+ * See
+ *
+ * https://www.w3.org/TR/WOFF/#WOFFHeader
+ */
+ typedef struct WOFF_HeaderRec_
+ {
+ FT_ULong signature;
+ FT_ULong flavor;
+ FT_ULong length;
+ FT_UShort num_tables;
+ FT_UShort reserved;
+ FT_ULong totalSfntSize;
+ FT_UShort majorVersion;
+ FT_UShort minorVersion;
+ FT_ULong metaOffset;
+ FT_ULong metaLength;
+ FT_ULong metaOrigLength;
+ FT_ULong privOffset;
+ FT_ULong privLength;
+
+ } WOFF_HeaderRec, *WOFF_Header;
+
+
+ /**************************************************************************
+ *
+ * @struct:
+ * WOFF_TableRec
+ *
+ * @description:
+ * This structure describes a given table of a WOFF font.
+ *
+ * @fields:
+ * Tag ::
+ * A four-bytes tag describing the table.
+ *
+ * Offset ::
+ * The offset of the table from the start of the WOFF font in its
+ * resource.
+ *
+ * CompLength ::
+ * Compressed table length (in bytes).
+ *
+ * OrigLength ::
+ * Uncompressed table length (in bytes).
+ *
+ * CheckSum ::
+ * The table checksum. This value can be ignored.
+ *
+ * OrigOffset ::
+ * The uncompressed table file offset. This value gets computed while
+ * constructing the (uncompressed) SFNT header. It is not contained in
+ * the WOFF file.
+ */
+ typedef struct WOFF_TableRec_
+ {
+ FT_ULong Tag; /* table ID */
+ FT_ULong Offset; /* table file offset */
+ FT_ULong CompLength; /* compressed table length */
+ FT_ULong OrigLength; /* uncompressed table length */
+ FT_ULong CheckSum; /* uncompressed checksum */
+
+ FT_ULong OrigOffset; /* uncompressed table file offset */
+ /* (not in the WOFF file) */
+ } WOFF_TableRec, *WOFF_Table;
+
+
+FT_END_HEADER
+
+#endif /* WOFFTYPES_H_ */
+
+
+/* END */
diff --git a/thirdparty/freetype/src/autofit/afblue.c b/thirdparty/freetype/src/autofit/afblue.c
index 28da159008..b99dbeb19c 100644
--- a/thirdparty/freetype/src/autofit/afblue.c
+++ b/thirdparty/freetype/src/autofit/afblue.c
@@ -296,6 +296,10 @@
'\0',
'\xE0', '\xB4', '\x9F', ' ', '\xE0', '\xB4', '\xA0', ' ', '\xE0', '\xB4', '\xA7', ' ', '\xE0', '\xB4', '\xB6', ' ', '\xE0', '\xB4', '\x98', ' ', '\xE0', '\xB4', '\x9A', ' ', '\xE0', '\xB4', '\xA5', ' ', '\xE0', '\xB4', '\xB2', /* ട ഠ ധ ശ ഘ ച ഥ ല */
'\0',
+ '\xE1', '\xA0', '\xB3', ' ', '\xE1', '\xA0', '\xB4', ' ', '\xE1', '\xA0', '\xB6', ' ', '\xE1', '\xA0', '\xBD', ' ', '\xE1', '\xA1', '\x82', ' ', '\xE1', '\xA1', '\x8A', ' ', '\xE2', '\x80', '\x8D', '\xE1', '\xA1', '\xA1', '\xE2', '\x80', '\x8D', ' ', '\xE2', '\x80', '\x8D', '\xE1', '\xA1', '\xB3', '\xE2', '\x80', '\x8D', /* ᠳ ᠴ ᠶ ᠽ ᡂ ᡊ ‍ᡡ‍ ‍ᡳ‍ */
+ '\0',
+ '\xE1', '\xA1', '\x83', /* ᡃ */
+ '\0',
'\xE1', '\x80', '\x81', ' ', '\xE1', '\x80', '\x82', ' ', '\xE1', '\x80', '\x84', ' ', '\xE1', '\x80', '\x92', ' ', '\xE1', '\x80', '\x9D', ' ', '\xE1', '\x81', '\xA5', ' ', '\xE1', '\x81', '\x8A', ' ', '\xE1', '\x81', '\x8B', /* ခ ဂ င ဒ ဝ ၥ ၊ ။ */
'\0',
'\xE1', '\x80', '\x84', ' ', '\xE1', '\x80', '\x8E', ' ', '\xE1', '\x80', '\x92', ' ', '\xE1', '\x80', '\x95', ' ', '\xE1', '\x80', '\x97', ' ', '\xE1', '\x80', '\x9D', ' ', '\xE1', '\x81', '\x8A', ' ', '\xE1', '\x81', '\x8B', /* င ဎ ဒ ပ ဗ ဝ ၊ ။ */
@@ -649,6 +653,9 @@
{ AF_BLUE_STRING_MALAYALAM_TOP, AF_BLUE_PROPERTY_LATIN_TOP },
{ AF_BLUE_STRING_MALAYALAM_BOTTOM, 0 },
{ AF_BLUE_STRING_MAX, 0 },
+ { AF_BLUE_STRING_MONGOLIAN_TOP_BASE, AF_BLUE_PROPERTY_LATIN_TOP },
+ { AF_BLUE_STRING_MONGOLIAN_BOTTOM_BASE, 0 },
+ { AF_BLUE_STRING_MAX, 0 },
{ AF_BLUE_STRING_MYANMAR_TOP, AF_BLUE_PROPERTY_LATIN_TOP |
AF_BLUE_PROPERTY_LATIN_X_HEIGHT },
{ AF_BLUE_STRING_MYANMAR_BOTTOM, 0 },
diff --git a/thirdparty/freetype/src/autofit/afblue.dat b/thirdparty/freetype/src/autofit/afblue.dat
index 14a0993b61..46db43fe22 100644
--- a/thirdparty/freetype/src/autofit/afblue.dat
+++ b/thirdparty/freetype/src/autofit/afblue.dat
@@ -392,6 +392,11 @@ AF_BLUE_STRING_ENUM AF_BLUE_STRINGS_ARRAY AF_BLUE_STRING_MAX_LEN:
AF_BLUE_STRING_MALAYALAM_BOTTOM
"ട ഠ ധ ശ ഘ ച ഥ ല"
+ AF_BLUE_STRING_MONGOLIAN_TOP_BASE
+ "ᠳ ᠴ ᠶ ᠽ ᡂ ᡊ ‍ᡡ‍ ‍ᡳ‍"
+ AF_BLUE_STRING_MONGOLIAN_BOTTOM_BASE
+ "ᡃ"
+
AF_BLUE_STRING_MYANMAR_TOP
"ခ ဂ င ဒ ဝ ၥ ၊ ။"
AF_BLUE_STRING_MYANMAR_BOTTOM
@@ -947,6 +952,11 @@ AF_BLUE_STRINGSET_ENUM AF_BLUE_STRINGSETS_ARRAY AF_BLUE_STRINGSET_MAX_LEN:
{ AF_BLUE_STRING_MALAYALAM_BOTTOM, 0 }
{ AF_BLUE_STRING_MAX, 0 }
+ AF_BLUE_STRINGSET_MONG
+ { AF_BLUE_STRING_MONGOLIAN_TOP_BASE, AF_BLUE_PROPERTY_LATIN_TOP }
+ { AF_BLUE_STRING_MONGOLIAN_BOTTOM_BASE, 0 }
+ { AF_BLUE_STRING_MAX, 0 }
+
AF_BLUE_STRINGSET_MYMR
{ AF_BLUE_STRING_MYANMAR_TOP, AF_BLUE_PROPERTY_LATIN_TOP |
AF_BLUE_PROPERTY_LATIN_X_HEIGHT }
diff --git a/thirdparty/freetype/src/autofit/afblue.h b/thirdparty/freetype/src/autofit/afblue.h
index a2ff597b8e..b69b1df521 100644
--- a/thirdparty/freetype/src/autofit/afblue.h
+++ b/thirdparty/freetype/src/autofit/afblue.h
@@ -212,56 +212,58 @@ FT_BEGIN_HEADER
AF_BLUE_STRING_LISU_BOTTOM = 3506,
AF_BLUE_STRING_MALAYALAM_TOP = 3538,
AF_BLUE_STRING_MALAYALAM_BOTTOM = 3582,
- AF_BLUE_STRING_MYANMAR_TOP = 3614,
- AF_BLUE_STRING_MYANMAR_BOTTOM = 3646,
- AF_BLUE_STRING_MYANMAR_ASCENDER = 3678,
- AF_BLUE_STRING_MYANMAR_DESCENDER = 3706,
- AF_BLUE_STRING_NKO_TOP = 3738,
- AF_BLUE_STRING_NKO_BOTTOM = 3762,
- AF_BLUE_STRING_NKO_SMALL_TOP = 3777,
- AF_BLUE_STRING_NKO_SMALL_BOTTOM = 3786,
- AF_BLUE_STRING_OL_CHIKI = 3798,
- AF_BLUE_STRING_OLD_TURKIC_TOP = 3822,
- AF_BLUE_STRING_OLD_TURKIC_BOTTOM = 3837,
- AF_BLUE_STRING_OSAGE_CAPITAL_TOP = 3857,
- AF_BLUE_STRING_OSAGE_CAPITAL_BOTTOM = 3897,
- AF_BLUE_STRING_OSAGE_CAPITAL_DESCENDER = 3927,
- AF_BLUE_STRING_OSAGE_SMALL_TOP = 3942,
- AF_BLUE_STRING_OSAGE_SMALL_BOTTOM = 3982,
- AF_BLUE_STRING_OSAGE_SMALL_ASCENDER = 4022,
- AF_BLUE_STRING_OSAGE_SMALL_DESCENDER = 4047,
- AF_BLUE_STRING_OSMANYA_TOP = 4062,
- AF_BLUE_STRING_OSMANYA_BOTTOM = 4102,
- AF_BLUE_STRING_SAURASHTRA_TOP = 4142,
- AF_BLUE_STRING_SAURASHTRA_BOTTOM = 4174,
- AF_BLUE_STRING_SHAVIAN_TOP = 4194,
- AF_BLUE_STRING_SHAVIAN_BOTTOM = 4204,
- AF_BLUE_STRING_SHAVIAN_DESCENDER = 4229,
- AF_BLUE_STRING_SHAVIAN_SMALL_TOP = 4239,
- AF_BLUE_STRING_SHAVIAN_SMALL_BOTTOM = 4274,
- AF_BLUE_STRING_SINHALA_TOP = 4289,
- AF_BLUE_STRING_SINHALA_BOTTOM = 4321,
- AF_BLUE_STRING_SINHALA_DESCENDER = 4353,
- AF_BLUE_STRING_SUNDANESE_TOP = 4397,
- AF_BLUE_STRING_SUNDANESE_BOTTOM = 4421,
- AF_BLUE_STRING_SUNDANESE_DESCENDER = 4453,
- AF_BLUE_STRING_TAI_VIET_TOP = 4461,
- AF_BLUE_STRING_TAI_VIET_BOTTOM = 4481,
- AF_BLUE_STRING_TAMIL_TOP = 4493,
- AF_BLUE_STRING_TAMIL_BOTTOM = 4525,
- AF_BLUE_STRING_TELUGU_TOP = 4557,
- AF_BLUE_STRING_TELUGU_BOTTOM = 4585,
- AF_BLUE_STRING_THAI_TOP = 4613,
- AF_BLUE_STRING_THAI_BOTTOM = 4637,
- AF_BLUE_STRING_THAI_ASCENDER = 4665,
- AF_BLUE_STRING_THAI_LARGE_ASCENDER = 4677,
- AF_BLUE_STRING_THAI_DESCENDER = 4689,
- AF_BLUE_STRING_THAI_LARGE_DESCENDER = 4705,
- AF_BLUE_STRING_THAI_DIGIT_TOP = 4713,
- AF_BLUE_STRING_TIFINAGH = 4725,
- AF_BLUE_STRING_VAI_TOP = 4757,
- AF_BLUE_STRING_VAI_BOTTOM = 4789,
- af_blue_1_1 = 4820,
+ AF_BLUE_STRING_MONGOLIAN_TOP_BASE = 3614,
+ AF_BLUE_STRING_MONGOLIAN_BOTTOM_BASE = 3658,
+ AF_BLUE_STRING_MYANMAR_TOP = 3662,
+ AF_BLUE_STRING_MYANMAR_BOTTOM = 3694,
+ AF_BLUE_STRING_MYANMAR_ASCENDER = 3726,
+ AF_BLUE_STRING_MYANMAR_DESCENDER = 3754,
+ AF_BLUE_STRING_NKO_TOP = 3786,
+ AF_BLUE_STRING_NKO_BOTTOM = 3810,
+ AF_BLUE_STRING_NKO_SMALL_TOP = 3825,
+ AF_BLUE_STRING_NKO_SMALL_BOTTOM = 3834,
+ AF_BLUE_STRING_OL_CHIKI = 3846,
+ AF_BLUE_STRING_OLD_TURKIC_TOP = 3870,
+ AF_BLUE_STRING_OLD_TURKIC_BOTTOM = 3885,
+ AF_BLUE_STRING_OSAGE_CAPITAL_TOP = 3905,
+ AF_BLUE_STRING_OSAGE_CAPITAL_BOTTOM = 3945,
+ AF_BLUE_STRING_OSAGE_CAPITAL_DESCENDER = 3975,
+ AF_BLUE_STRING_OSAGE_SMALL_TOP = 3990,
+ AF_BLUE_STRING_OSAGE_SMALL_BOTTOM = 4030,
+ AF_BLUE_STRING_OSAGE_SMALL_ASCENDER = 4070,
+ AF_BLUE_STRING_OSAGE_SMALL_DESCENDER = 4095,
+ AF_BLUE_STRING_OSMANYA_TOP = 4110,
+ AF_BLUE_STRING_OSMANYA_BOTTOM = 4150,
+ AF_BLUE_STRING_SAURASHTRA_TOP = 4190,
+ AF_BLUE_STRING_SAURASHTRA_BOTTOM = 4222,
+ AF_BLUE_STRING_SHAVIAN_TOP = 4242,
+ AF_BLUE_STRING_SHAVIAN_BOTTOM = 4252,
+ AF_BLUE_STRING_SHAVIAN_DESCENDER = 4277,
+ AF_BLUE_STRING_SHAVIAN_SMALL_TOP = 4287,
+ AF_BLUE_STRING_SHAVIAN_SMALL_BOTTOM = 4322,
+ AF_BLUE_STRING_SINHALA_TOP = 4337,
+ AF_BLUE_STRING_SINHALA_BOTTOM = 4369,
+ AF_BLUE_STRING_SINHALA_DESCENDER = 4401,
+ AF_BLUE_STRING_SUNDANESE_TOP = 4445,
+ AF_BLUE_STRING_SUNDANESE_BOTTOM = 4469,
+ AF_BLUE_STRING_SUNDANESE_DESCENDER = 4501,
+ AF_BLUE_STRING_TAI_VIET_TOP = 4509,
+ AF_BLUE_STRING_TAI_VIET_BOTTOM = 4529,
+ AF_BLUE_STRING_TAMIL_TOP = 4541,
+ AF_BLUE_STRING_TAMIL_BOTTOM = 4573,
+ AF_BLUE_STRING_TELUGU_TOP = 4605,
+ AF_BLUE_STRING_TELUGU_BOTTOM = 4633,
+ AF_BLUE_STRING_THAI_TOP = 4661,
+ AF_BLUE_STRING_THAI_BOTTOM = 4685,
+ AF_BLUE_STRING_THAI_ASCENDER = 4713,
+ AF_BLUE_STRING_THAI_LARGE_ASCENDER = 4725,
+ AF_BLUE_STRING_THAI_DESCENDER = 4737,
+ AF_BLUE_STRING_THAI_LARGE_DESCENDER = 4753,
+ AF_BLUE_STRING_THAI_DIGIT_TOP = 4761,
+ AF_BLUE_STRING_TIFINAGH = 4773,
+ AF_BLUE_STRING_VAI_TOP = 4805,
+ AF_BLUE_STRING_VAI_BOTTOM = 4837,
+ af_blue_1_1 = 4868,
#ifdef AF_CONFIG_OPTION_CJK
AF_BLUE_STRING_CJK_TOP = af_blue_1_1 + 1,
AF_BLUE_STRING_CJK_BOTTOM = af_blue_1_1 + 203,
@@ -355,24 +357,25 @@ FT_BEGIN_HEADER
AF_BLUE_STRINGSET_LATP = 166,
AF_BLUE_STRINGSET_LISU = 173,
AF_BLUE_STRINGSET_MLYM = 176,
- AF_BLUE_STRINGSET_MYMR = 179,
- AF_BLUE_STRINGSET_NKOO = 184,
- AF_BLUE_STRINGSET_NONE = 189,
- AF_BLUE_STRINGSET_OLCK = 190,
- AF_BLUE_STRINGSET_ORKH = 193,
- AF_BLUE_STRINGSET_OSGE = 196,
- AF_BLUE_STRINGSET_OSMA = 204,
- AF_BLUE_STRINGSET_SAUR = 207,
- AF_BLUE_STRINGSET_SHAW = 210,
- AF_BLUE_STRINGSET_SINH = 216,
- AF_BLUE_STRINGSET_SUND = 220,
- AF_BLUE_STRINGSET_TAML = 224,
- AF_BLUE_STRINGSET_TAVT = 227,
- AF_BLUE_STRINGSET_TELU = 230,
- AF_BLUE_STRINGSET_TFNG = 233,
- AF_BLUE_STRINGSET_THAI = 236,
- AF_BLUE_STRINGSET_VAII = 244,
- af_blue_2_1 = 247,
+ AF_BLUE_STRINGSET_MONG = 179,
+ AF_BLUE_STRINGSET_MYMR = 182,
+ AF_BLUE_STRINGSET_NKOO = 187,
+ AF_BLUE_STRINGSET_NONE = 192,
+ AF_BLUE_STRINGSET_OLCK = 193,
+ AF_BLUE_STRINGSET_ORKH = 196,
+ AF_BLUE_STRINGSET_OSGE = 199,
+ AF_BLUE_STRINGSET_OSMA = 207,
+ AF_BLUE_STRINGSET_SAUR = 210,
+ AF_BLUE_STRINGSET_SHAW = 213,
+ AF_BLUE_STRINGSET_SINH = 219,
+ AF_BLUE_STRINGSET_SUND = 223,
+ AF_BLUE_STRINGSET_TAML = 227,
+ AF_BLUE_STRINGSET_TAVT = 230,
+ AF_BLUE_STRINGSET_TELU = 233,
+ AF_BLUE_STRINGSET_TFNG = 236,
+ AF_BLUE_STRINGSET_THAI = 239,
+ AF_BLUE_STRINGSET_VAII = 247,
+ af_blue_2_1 = 250,
#ifdef AF_CONFIG_OPTION_CJK
AF_BLUE_STRINGSET_HANI = af_blue_2_1 + 0,
af_blue_2_1_1 = af_blue_2_1 + 2,
diff --git a/thirdparty/freetype/src/autofit/afcjk.c b/thirdparty/freetype/src/autofit/afcjk.c
index 3b2b1cf24c..a61689bee3 100644
--- a/thirdparty/freetype/src/autofit/afcjk.c
+++ b/thirdparty/freetype/src/autofit/afcjk.c
@@ -1184,6 +1184,8 @@
seg = edge->first;
+ if ( !seg )
+ goto Skip_Loop;
do
{
@@ -1239,13 +1241,14 @@
edge2->flags |= AF_EDGE_SERIF;
}
else
- edge->link = edge2;
+ edge->link = edge2;
}
seg = seg->edge_next;
} while ( seg != edge->first );
+ Skip_Loop:
/* set the round/straight flags */
edge->flags = AF_EDGE_NORMAL;
diff --git a/thirdparty/freetype/src/autofit/afglobal.c b/thirdparty/freetype/src/autofit/afglobal.c
index 7183ce4a78..6a9a1e5aaa 100644
--- a/thirdparty/freetype/src/autofit/afglobal.c
+++ b/thirdparty/freetype/src/autofit/afglobal.c
@@ -443,6 +443,7 @@
style = (AF_Style)( globals->glyph_styles[gindex] &
AF_STYLE_UNASSIGNED );
+ Again:
style_class = af_style_classes[style];
writing_system_class = af_writing_system_classes
[style_class->writing_system];
@@ -470,6 +471,16 @@
writing_system_class->style_metrics_done( metrics );
FT_FREE( metrics );
+
+ /* internal error code -1 indicates */
+ /* that no blue zones have been found */
+ if ( error == -1 )
+ {
+ style = (AF_Style)( globals->glyph_styles[gindex] &
+ AF_STYLE_UNASSIGNED );
+ goto Again;
+ }
+
goto Exit;
}
}
diff --git a/thirdparty/freetype/src/autofit/aflatin.c b/thirdparty/freetype/src/autofit/aflatin.c
index dccdcaf345..27d4024882 100644
--- a/thirdparty/freetype/src/autofit/aflatin.c
+++ b/thirdparty/freetype/src/autofit/aflatin.c
@@ -149,7 +149,11 @@
af_shaper_buf_destroy( face, shaper_buf );
if ( !glyph_index )
+ {
+ FT_TRACE5(( "standard character missing;"
+ " using fallback stem widths\n" ));
goto Exit;
+ }
FT_TRACE5(( "standard character: U+%04lX (glyph index %d)\n",
ch, glyph_index ));
@@ -312,7 +316,7 @@
/* Find all blue zones. Flat segments give the reference points, */
/* round segments the overshoot positions. */
- static void
+ static int
af_latin_metrics_init_blues( AF_LatinMetrics metrics,
FT_Face face )
{
@@ -981,10 +985,11 @@
af_shaper_buf_destroy( face, shaper_buf );
- /* we finally check whether blue zones are ordered; */
- /* `ref' and `shoot' values of two blue zones must not overlap */
if ( axis->blue_count )
{
+ /* we finally check whether blue zones are ordered; */
+ /* `ref' and `shoot' values of two blue zones must not overlap */
+
FT_UInt i;
AF_LatinBlue blue_sorted[AF_BLUE_STRINGSET_MAX_LEN + 2];
@@ -1033,11 +1038,34 @@
*a ));
}
}
+
+ FT_TRACE5(( "\n" ));
+
+ return 0;
}
+ else
+ {
+ /* disable hinting for the current style if there are no blue zones */
- FT_TRACE5(( "\n" ));
+ AF_FaceGlobals globals = metrics->root.globals;
+ FT_UShort* gstyles = globals->glyph_styles;
+
+ FT_Long i;
+
+
+ FT_TRACE5(( "no blue zones found:"
+ " hinting disabled for this style\n" ));
- return;
+ for ( i = 0; i < globals->glyph_count; i++ )
+ {
+ if ( ( gstyles[i] & AF_STYLE_MASK ) == sc->style )
+ gstyles[i] = AF_STYLE_NONE_DFLT;
+ }
+
+ FT_TRACE5(( "\n" ));
+
+ return 1;
+ }
}
@@ -1116,6 +1144,8 @@
af_latin_metrics_init( AF_LatinMetrics metrics,
FT_Face face )
{
+ FT_Error error = FT_Err_Ok;
+
FT_CharMap oldmap = face->charmap;
@@ -1124,12 +1154,18 @@
if ( !FT_Select_Charmap( face, FT_ENCODING_UNICODE ) )
{
af_latin_metrics_init_widths( metrics, face );
- af_latin_metrics_init_blues( metrics, face );
+ if ( af_latin_metrics_init_blues( metrics, face ) )
+ {
+ /* use internal error code to indicate missing blue zones */
+ error = -1;
+ goto Exit;
+ }
af_latin_metrics_check_digits( metrics, face );
}
+ Exit:
FT_Set_Charmap( face, oldmap );
- return FT_Err_Ok;
+ return error;
}
@@ -1443,13 +1479,13 @@
nn,
blue->ref.org,
blue->ref.fit / 64.0,
- blue->flags & AF_LATIN_BLUE_ACTIVE ? ""
- : " (inactive)",
+ ( blue->flags & AF_LATIN_BLUE_ACTIVE ) ? ""
+ : " (inactive)",
nn,
blue->shoot.org,
blue->shoot.fit / 64.0,
- blue->flags & AF_LATIN_BLUE_ACTIVE ? ""
- : " (inactive)" ));
+ ( blue->flags & AF_LATIN_BLUE_ACTIVE ) ? ""
+ : " (inactive)" ));
}
#endif
}
diff --git a/thirdparty/freetype/src/autofit/afranges.c b/thirdparty/freetype/src/autofit/afranges.c
index c0dba818a1..45c8bbfc95 100644
--- a/thirdparty/freetype/src/autofit/afranges.c
+++ b/thirdparty/freetype/src/autofit/afranges.c
@@ -664,6 +664,21 @@
};
+ const AF_Script_UniRangeRec af_mong_uniranges[] =
+ {
+ AF_UNIRANGE_REC( 0x1800, 0x18AF ), /* Mongolian */
+ AF_UNIRANGE_REC( 0x11660, 0x1167F ), /* Mongolian Supplement */
+ AF_UNIRANGE_REC( 0, 0 )
+ };
+
+ const AF_Script_UniRangeRec af_mong_nonbase_uniranges[] =
+ {
+ AF_UNIRANGE_REC( 0x1885, 0x1886 ),
+ AF_UNIRANGE_REC( 0x18A9, 0x18A9 ),
+ AF_UNIRANGE_REC( 0, 0 )
+ };
+
+
const AF_Script_UniRangeRec af_mymr_uniranges[] =
{
AF_UNIRANGE_REC( 0x1000, 0x109F ), /* Myanmar */
diff --git a/thirdparty/freetype/src/autofit/afscript.h b/thirdparty/freetype/src/autofit/afscript.h
index c2f0c7ac60..2da8c70183 100644
--- a/thirdparty/freetype/src/autofit/afscript.h
+++ b/thirdparty/freetype/src/autofit/afscript.h
@@ -243,6 +243,12 @@
HINTING_BOTTOM_TO_TOP,
"\xE0\xB4\xA0 \xE0\xB4\xB1" ) /* ഠ റ */
+ SCRIPT( mong, MONG,
+ "Mongolian",
+ HB_SCRIPT_MONGOLIAN,
+ HINTING_TOP_TO_BOTTOM,
+ "\xE1\xA1\x82 \xE1\xA0\xAA" ) /* ᡂ ᠪ */
+
SCRIPT( mymr, MYMR,
"Myanmar",
HB_SCRIPT_MYANMAR,
diff --git a/thirdparty/freetype/src/autofit/afstyles.h b/thirdparty/freetype/src/autofit/afstyles.h
index edf4f54edd..8d1d70812f 100644
--- a/thirdparty/freetype/src/autofit/afstyles.h
+++ b/thirdparty/freetype/src/autofit/afstyles.h
@@ -322,6 +322,13 @@
AF_BLUE_STRINGSET_MLYM,
AF_COVERAGE_DEFAULT )
+ STYLE( mong_dflt, MONG_DFLT,
+ "Mongolian default style",
+ AF_WRITING_SYSTEM_LATIN,
+ AF_SCRIPT_MONG,
+ AF_BLUE_STRINGSET_MONG,
+ AF_COVERAGE_DEFAULT )
+
STYLE( mymr_dflt, MYMR_DFLT,
"Myanmar default style",
AF_WRITING_SYSTEM_LATIN,
diff --git a/thirdparty/freetype/src/base/ftbbox.c b/thirdparty/freetype/src/base/ftbbox.c
index 0b04fde635..a0b2c46f7b 100644
--- a/thirdparty/freetype/src/base/ftbbox.c
+++ b/thirdparty/freetype/src/base/ftbbox.c
@@ -319,9 +319,9 @@
q2 = q2 + q1;
q4 = q4 + q3;
q3 = q3 + q2;
- q4 = ( q4 + q3 ) / 8;
- q3 = q3 / 4;
- q2 = q2 / 2;
+ q4 = ( q4 + q3 ) >> 3;
+ q3 = q3 >> 2;
+ q2 = q2 >> 1;
}
else /* second half */
{
@@ -330,9 +330,9 @@
q3 = q3 + q4;
q1 = q1 + q2;
q2 = q2 + q3;
- q1 = ( q1 + q2 ) / 8;
- q2 = q2 / 4;
- q3 = q3 / 2;
+ q1 = ( q1 + q2 ) >> 3;
+ q2 = q2 >> 2;
+ q3 = q3 >> 1;
}
/* check whether either end reached the maximum */
diff --git a/thirdparty/freetype/src/base/ftbitmap.c b/thirdparty/freetype/src/base/ftbitmap.c
index 1bdcd9eff3..0e0a76fe40 100644
--- a/thirdparty/freetype/src/base/ftbitmap.c
+++ b/thirdparty/freetype/src/base/ftbitmap.c
@@ -922,12 +922,18 @@
else
FT_TRACE5(( " target bitmap: empty\n" ));
- FT_TRACE5(( " final bitmap: (%d, %d) -- (%d, %d); %d x %d\n",
- final_llx / 64, final_lly / 64,
- final_urx / 64, final_ury / 64,
- final_width, final_rows ));
+ if ( final_width && final_rows )
+ FT_TRACE5(( " final bitmap: (%d, %d) -- (%d, %d); %d x %d\n",
+ final_llx / 64, final_lly / 64,
+ final_urx / 64, final_ury / 64,
+ final_width, final_rows ));
+ else
+ FT_TRACE5(( " final bitmap: empty\n" ));
#endif /* FT_DEBUG_LEVEL_TRACE */
+ if ( !( final_width && final_rows ) )
+ return FT_Err_Ok; /* nothing to do */
+
/* for blending, set offset vector of final bitmap */
/* temporarily to (0,0) */
source_llx -= final_llx;
@@ -971,6 +977,7 @@
pitch = target->pitch;
+
if ( pitch < 0 )
pitch = -pitch;
diff --git a/thirdparty/freetype/src/base/fterrors.c b/thirdparty/freetype/src/base/fterrors.c
index 4ef326d8e2..84fe590289 100644
--- a/thirdparty/freetype/src/base/fterrors.c
+++ b/thirdparty/freetype/src/base/fterrors.c
@@ -17,6 +17,7 @@
#include <ft2build.h>
+#include FT_INTERNAL_DEBUG_H
#include FT_ERRORS_H
diff --git a/thirdparty/freetype/src/base/ftinit.c b/thirdparty/freetype/src/base/ftinit.c
index 9d524effa9..c73cd78b83 100644
--- a/thirdparty/freetype/src/base/ftinit.c
+++ b/thirdparty/freetype/src/base/ftinit.c
@@ -176,6 +176,9 @@
module_name,
property_name,
property_value );
+
+ if ( !*p )
+ break;
}
}
diff --git a/thirdparty/freetype/src/base/ftlcdfil.c b/thirdparty/freetype/src/base/ftlcdfil.c
index 9fb49ba116..d9f4af4293 100644
--- a/thirdparty/freetype/src/base/ftlcdfil.c
+++ b/thirdparty/freetype/src/base/ftlcdfil.c
@@ -77,13 +77,13 @@
/* FIR filter used by the default and light filters */
FT_BASE_DEF( void )
ft_lcd_filter_fir( FT_Bitmap* bitmap,
- FT_Render_Mode mode,
FT_LcdFiveTapFilter weights )
{
FT_UInt width = (FT_UInt)bitmap->width;
FT_UInt height = (FT_UInt)bitmap->rows;
FT_Int pitch = bitmap->pitch;
FT_Byte* origin = bitmap->buffer;
+ FT_Byte mode = bitmap->pixel_mode;
/* take care of bitmap flow */
@@ -91,7 +91,7 @@
origin += pitch * (FT_Int)( height - 1 );
/* horizontal in-place FIR filter */
- if ( mode == FT_RENDER_MODE_LCD && width >= 2 )
+ if ( mode == FT_PIXEL_MODE_LCD && width >= 2 )
{
FT_Byte* line = origin;
@@ -134,7 +134,7 @@
}
/* vertical in-place FIR filter */
- else if ( mode == FT_RENDER_MODE_LCD_V && height >= 2 )
+ else if ( mode == FT_PIXEL_MODE_LCD_V && height >= 2 )
{
FT_Byte* column = origin;
@@ -183,13 +183,13 @@
/* intra-pixel filter used by the legacy filter */
static void
_ft_lcd_filter_legacy( FT_Bitmap* bitmap,
- FT_Render_Mode mode,
FT_Byte* weights )
{
FT_UInt width = (FT_UInt)bitmap->width;
FT_UInt height = (FT_UInt)bitmap->rows;
FT_Int pitch = bitmap->pitch;
FT_Byte* origin = bitmap->buffer;
+ FT_Byte mode = bitmap->pixel_mode;
static const unsigned int filters[3][3] =
{
@@ -206,7 +206,7 @@
origin += pitch * (FT_Int)( height - 1 );
/* horizontal in-place intra-pixel filter */
- if ( mode == FT_RENDER_MODE_LCD && width >= 3 )
+ if ( mode == FT_PIXEL_MODE_LCD && width >= 3 )
{
FT_Byte* line = origin;
@@ -243,7 +243,7 @@
}
}
}
- else if ( mode == FT_RENDER_MODE_LCD_V && height >= 3 )
+ else if ( mode == FT_PIXEL_MODE_LCD_V && height >= 3 )
{
FT_Byte* column = origin;
diff --git a/thirdparty/freetype/src/base/ftobjs.c b/thirdparty/freetype/src/base/ftobjs.c
index 3f8619d3b3..e301f8f11a 100644
--- a/thirdparty/freetype/src/base/ftobjs.c
+++ b/thirdparty/freetype/src/base/ftobjs.c
@@ -4059,8 +4059,8 @@
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_UInt )
- FT_Get_Name_Index( FT_Face face,
- FT_String* glyph_name )
+ FT_Get_Name_Index( FT_Face face,
+ const FT_String* glyph_name )
{
FT_UInt result = 0;
diff --git a/thirdparty/freetype/src/base/ftoutln.c b/thirdparty/freetype/src/base/ftoutln.c
index 00329b46c6..0e2ba3475d 100644
--- a/thirdparty/freetype/src/base/ftoutln.c
+++ b/thirdparty/freetype/src/base/ftoutln.c
@@ -46,8 +46,7 @@
void* user )
{
#undef SCALED
-#define SCALED( x ) ( ( (x) < 0 ? -( -(x) << shift ) \
- : ( (x) << shift ) ) - delta )
+#define SCALED( x ) ( (x) * ( 1L << shift ) - delta )
FT_Vector v_last;
FT_Vector v_control;
@@ -621,6 +620,16 @@
params->source = (void*)outline;
+ /* preset clip_box for direct mode */
+ if ( params->flags & FT_RASTER_FLAG_DIRECT &&
+ !( params->flags & FT_RASTER_FLAG_CLIP ) )
+ {
+ params->clip_box.xMin = cbox.xMin >> 6;
+ params->clip_box.yMin = cbox.yMin >> 6;
+ params->clip_box.xMax = ( cbox.xMax + 63 ) >> 6;
+ params->clip_box.yMax = ( cbox.yMax + 63 ) >> 6;
+ }
+
error = FT_ERR( Cannot_Render_Glyph );
while ( renderer )
{
diff --git a/thirdparty/freetype/src/base/ftstroke.c b/thirdparty/freetype/src/base/ftstroke.c
index 826062c94e..1b2c0f657c 100644
--- a/thirdparty/freetype/src/base/ftstroke.c
+++ b/thirdparty/freetype/src/base/ftstroke.c
@@ -86,16 +86,18 @@
base[4].x = base[2].x;
- b = base[1].x;
- a = base[3].x = ( base[2].x + b ) / 2;
- b = base[1].x = ( base[0].x + b ) / 2;
- base[2].x = ( a + b ) / 2;
+ a = base[0].x + base[1].x;
+ b = base[1].x + base[2].x;
+ base[3].x = b >> 1;
+ base[2].x = ( a + b ) >> 2;
+ base[1].x = a >> 1;
base[4].y = base[2].y;
- b = base[1].y;
- a = base[3].y = ( base[2].y + b ) / 2;
- b = base[1].y = ( base[0].y + b ) / 2;
- base[2].y = ( a + b ) / 2;
+ a = base[0].y + base[1].y;
+ b = base[1].y + base[2].y;
+ base[3].y = b >> 1;
+ base[2].y = ( a + b ) >> 2;
+ base[1].y = a >> 1;
}
@@ -153,28 +155,32 @@
static void
ft_cubic_split( FT_Vector* base )
{
- FT_Pos a, b, c, d;
+ FT_Pos a, b, c;
base[6].x = base[3].x;
- c = base[1].x;
- d = base[2].x;
- base[1].x = a = ( base[0].x + c ) / 2;
- base[5].x = b = ( base[3].x + d ) / 2;
- c = ( c + d ) / 2;
- base[2].x = a = ( a + c ) / 2;
- base[4].x = b = ( b + c ) / 2;
- base[3].x = ( a + b ) / 2;
+ a = base[0].x + base[1].x;
+ b = base[1].x + base[2].x;
+ c = base[2].x + base[3].x;
+ base[5].x = c >> 1;
+ c += b;
+ base[4].x = c >> 2;
+ base[1].x = a >> 1;
+ a += b;
+ base[2].x = a >> 2;
+ base[3].x = ( a + c ) >> 3;
base[6].y = base[3].y;
- c = base[1].y;
- d = base[2].y;
- base[1].y = a = ( base[0].y + c ) / 2;
- base[5].y = b = ( base[3].y + d ) / 2;
- c = ( c + d ) / 2;
- base[2].y = a = ( a + c ) / 2;
- base[4].y = b = ( b + c ) / 2;
- base[3].y = ( a + b ) / 2;
+ a = base[0].y + base[1].y;
+ b = base[1].y + base[2].y;
+ c = base[2].y + base[3].y;
+ base[5].y = c >> 1;
+ c += b;
+ base[4].y = c >> 2;
+ base[1].y = a >> 1;
+ a += b;
+ base[2].y = a >> 2;
+ base[3].y = ( a + c ) >> 3;
}
diff --git a/thirdparty/freetype/src/base/ftver.rc b/thirdparty/freetype/src/base/ftver.rc
index e02a88652c..1354497423 100644
--- a/thirdparty/freetype/src/base/ftver.rc
+++ b/thirdparty/freetype/src/base/ftver.rc
@@ -18,8 +18,8 @@
#include<windows.h>
-#define FT_VERSION 2,10,0,0
-#define FT_VERSION_STR "2.10.0"
+#define FT_VERSION 2,10,1,0
+#define FT_VERSION_STR "2.10.1"
VS_VERSION_INFO VERSIONINFO
FILEVERSION FT_VERSION
diff --git a/thirdparty/freetype/src/bdf/bdf.h b/thirdparty/freetype/src/bdf/bdf.h
index 4018756f72..d9abd2378f 100644
--- a/thirdparty/freetype/src/bdf/bdf.h
+++ b/thirdparty/freetype/src/bdf/bdf.h
@@ -109,9 +109,9 @@ FT_BEGIN_HEADER
/* There are a set of defaults and each font has their own. */
typedef struct bdf_property_t_
{
- char* name; /* Name of the property. */
- int format; /* Format of the property. */
- int builtin; /* A builtin property. */
+ const char* name; /* Name of the property. */
+ int format; /* Format of the property. */
+ int builtin; /* A builtin property. */
union
{
char* atom;
diff --git a/thirdparty/freetype/src/bdf/bdfdrivr.c b/thirdparty/freetype/src/bdf/bdfdrivr.c
index 4a11843a1c..60eb93305e 100644
--- a/thirdparty/freetype/src/bdf/bdfdrivr.c
+++ b/thirdparty/freetype/src/bdf/bdfdrivr.c
@@ -106,7 +106,7 @@ THE SOFTWARE.
FT_ULong code;
- if ( mid > max || mid < min )
+ if ( mid >= max || mid < min )
mid = ( min + max ) >> 1;
code = encodings[mid].enc;
@@ -152,7 +152,7 @@ THE SOFTWARE.
FT_ULong code; /* same as BDF_encoding_el.enc */
- if ( mid > max || mid < min )
+ if ( mid >= max || mid < min )
mid = ( min + max ) >> 1;
code = encodings[mid].enc;
@@ -216,13 +216,13 @@ THE SOFTWARE.
bdf_font_t* font = bdf->bdffont;
bdf_property_t* prop;
- char* strings[4] = { NULL, NULL, NULL, NULL };
- size_t nn, len, lengths[4];
+ const char* strings[4] = { NULL, NULL, NULL, NULL };
+ size_t lengths[4], nn, len;
face->style_flags = 0;
- prop = bdf_get_font_property( font, (char *)"SLANT" );
+ prop = bdf_get_font_property( font, "SLANT" );
if ( prop && prop->format == BDF_ATOM &&
prop->value.atom &&
( *(prop->value.atom) == 'O' || *(prop->value.atom) == 'o' ||
@@ -230,30 +230,30 @@ THE SOFTWARE.
{
face->style_flags |= FT_STYLE_FLAG_ITALIC;
strings[2] = ( *(prop->value.atom) == 'O' || *(prop->value.atom) == 'o' )
- ? (char *)"Oblique"
- : (char *)"Italic";
+ ? "Oblique"
+ : "Italic";
}
- prop = bdf_get_font_property( font, (char *)"WEIGHT_NAME" );
+ prop = bdf_get_font_property( font, "WEIGHT_NAME" );
if ( prop && prop->format == BDF_ATOM &&
prop->value.atom &&
( *(prop->value.atom) == 'B' || *(prop->value.atom) == 'b' ) )
{
face->style_flags |= FT_STYLE_FLAG_BOLD;
- strings[1] = (char *)"Bold";
+ strings[1] = "Bold";
}
- prop = bdf_get_font_property( font, (char *)"SETWIDTH_NAME" );
+ prop = bdf_get_font_property( font, "SETWIDTH_NAME" );
if ( prop && prop->format == BDF_ATOM &&
prop->value.atom && *(prop->value.atom) &&
!( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) )
- strings[3] = (char *)(prop->value.atom);
+ strings[3] = (const char *)(prop->value.atom);
- prop = bdf_get_font_property( font, (char *)"ADD_STYLE_NAME" );
+ prop = bdf_get_font_property( font, "ADD_STYLE_NAME" );
if ( prop && prop->format == BDF_ATOM &&
prop->value.atom && *(prop->value.atom) &&
!( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) )
- strings[0] = (char *)(prop->value.atom);
+ strings[0] = (const char *)(prop->value.atom);
for ( len = 0, nn = 0; nn < 4; nn++ )
{
@@ -267,7 +267,7 @@ THE SOFTWARE.
if ( len == 0 )
{
- strings[0] = (char *)"Regular";
+ strings[0] = "Regular";
lengths[0] = ft_strlen( strings[0] );
len = lengths[0] + 1;
}
@@ -283,7 +283,7 @@ THE SOFTWARE.
for ( nn = 0; nn < 4; nn++ )
{
- char* src = strings[nn];
+ const char* src = strings[nn];
len = lengths[nn];
diff --git a/thirdparty/freetype/src/bdf/bdflib.c b/thirdparty/freetype/src/bdf/bdflib.c
index 0898b0d470..63813f7edc 100644
--- a/thirdparty/freetype/src/bdf/bdflib.c
+++ b/thirdparty/freetype/src/bdf/bdflib.c
@@ -79,89 +79,89 @@
static const bdf_property_t _bdf_properties[] =
{
- { (char *)"ADD_STYLE_NAME", BDF_ATOM, 1, { 0 } },
- { (char *)"AVERAGE_WIDTH", BDF_INTEGER, 1, { 0 } },
- { (char *)"AVG_CAPITAL_WIDTH", BDF_INTEGER, 1, { 0 } },
- { (char *)"AVG_LOWERCASE_WIDTH", BDF_INTEGER, 1, { 0 } },
- { (char *)"CAP_HEIGHT", BDF_INTEGER, 1, { 0 } },
- { (char *)"CHARSET_COLLECTIONS", BDF_ATOM, 1, { 0 } },
- { (char *)"CHARSET_ENCODING", BDF_ATOM, 1, { 0 } },
- { (char *)"CHARSET_REGISTRY", BDF_ATOM, 1, { 0 } },
- { (char *)"COMMENT", BDF_ATOM, 1, { 0 } },
- { (char *)"COPYRIGHT", BDF_ATOM, 1, { 0 } },
- { (char *)"DEFAULT_CHAR", BDF_CARDINAL, 1, { 0 } },
- { (char *)"DESTINATION", BDF_CARDINAL, 1, { 0 } },
- { (char *)"DEVICE_FONT_NAME", BDF_ATOM, 1, { 0 } },
- { (char *)"END_SPACE", BDF_INTEGER, 1, { 0 } },
- { (char *)"FACE_NAME", BDF_ATOM, 1, { 0 } },
- { (char *)"FAMILY_NAME", BDF_ATOM, 1, { 0 } },
- { (char *)"FIGURE_WIDTH", BDF_INTEGER, 1, { 0 } },
- { (char *)"FONT", BDF_ATOM, 1, { 0 } },
- { (char *)"FONTNAME_REGISTRY", BDF_ATOM, 1, { 0 } },
- { (char *)"FONT_ASCENT", BDF_INTEGER, 1, { 0 } },
- { (char *)"FONT_DESCENT", BDF_INTEGER, 1, { 0 } },
- { (char *)"FOUNDRY", BDF_ATOM, 1, { 0 } },
- { (char *)"FULL_NAME", BDF_ATOM, 1, { 0 } },
- { (char *)"ITALIC_ANGLE", BDF_INTEGER, 1, { 0 } },
- { (char *)"MAX_SPACE", BDF_INTEGER, 1, { 0 } },
- { (char *)"MIN_SPACE", BDF_INTEGER, 1, { 0 } },
- { (char *)"NORM_SPACE", BDF_INTEGER, 1, { 0 } },
- { (char *)"NOTICE", BDF_ATOM, 1, { 0 } },
- { (char *)"PIXEL_SIZE", BDF_INTEGER, 1, { 0 } },
- { (char *)"POINT_SIZE", BDF_INTEGER, 1, { 0 } },
- { (char *)"QUAD_WIDTH", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_ASCENT", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_AVERAGE_WIDTH", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_AVG_CAPITAL_WIDTH", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_AVG_LOWERCASE_WIDTH", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_CAP_HEIGHT", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_DESCENT", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_END_SPACE", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_FIGURE_WIDTH", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_MAX_SPACE", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_MIN_SPACE", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_NORM_SPACE", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_PIXEL_SIZE", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_POINT_SIZE", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_PIXELSIZE", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_POINTSIZE", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_QUAD_WIDTH", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_SMALL_CAP_SIZE", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_STRIKEOUT_ASCENT", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_STRIKEOUT_DESCENT", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_SUBSCRIPT_SIZE", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_SUBSCRIPT_X", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_SUBSCRIPT_Y", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_SUPERSCRIPT_SIZE", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_SUPERSCRIPT_X", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_SUPERSCRIPT_Y", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_UNDERLINE_POSITION", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_UNDERLINE_THICKNESS", BDF_INTEGER, 1, { 0 } },
- { (char *)"RAW_X_HEIGHT", BDF_INTEGER, 1, { 0 } },
- { (char *)"RELATIVE_SETWIDTH", BDF_CARDINAL, 1, { 0 } },
- { (char *)"RELATIVE_WEIGHT", BDF_CARDINAL, 1, { 0 } },
- { (char *)"RESOLUTION", BDF_INTEGER, 1, { 0 } },
- { (char *)"RESOLUTION_X", BDF_CARDINAL, 1, { 0 } },
- { (char *)"RESOLUTION_Y", BDF_CARDINAL, 1, { 0 } },
- { (char *)"SETWIDTH_NAME", BDF_ATOM, 1, { 0 } },
- { (char *)"SLANT", BDF_ATOM, 1, { 0 } },
- { (char *)"SMALL_CAP_SIZE", BDF_INTEGER, 1, { 0 } },
- { (char *)"SPACING", BDF_ATOM, 1, { 0 } },
- { (char *)"STRIKEOUT_ASCENT", BDF_INTEGER, 1, { 0 } },
- { (char *)"STRIKEOUT_DESCENT", BDF_INTEGER, 1, { 0 } },
- { (char *)"SUBSCRIPT_SIZE", BDF_INTEGER, 1, { 0 } },
- { (char *)"SUBSCRIPT_X", BDF_INTEGER, 1, { 0 } },
- { (char *)"SUBSCRIPT_Y", BDF_INTEGER, 1, { 0 } },
- { (char *)"SUPERSCRIPT_SIZE", BDF_INTEGER, 1, { 0 } },
- { (char *)"SUPERSCRIPT_X", BDF_INTEGER, 1, { 0 } },
- { (char *)"SUPERSCRIPT_Y", BDF_INTEGER, 1, { 0 } },
- { (char *)"UNDERLINE_POSITION", BDF_INTEGER, 1, { 0 } },
- { (char *)"UNDERLINE_THICKNESS", BDF_INTEGER, 1, { 0 } },
- { (char *)"WEIGHT", BDF_CARDINAL, 1, { 0 } },
- { (char *)"WEIGHT_NAME", BDF_ATOM, 1, { 0 } },
- { (char *)"X_HEIGHT", BDF_INTEGER, 1, { 0 } },
- { (char *)"_MULE_BASELINE_OFFSET", BDF_INTEGER, 1, { 0 } },
- { (char *)"_MULE_RELATIVE_COMPOSE", BDF_INTEGER, 1, { 0 } },
+ { "ADD_STYLE_NAME", BDF_ATOM, 1, { 0 } },
+ { "AVERAGE_WIDTH", BDF_INTEGER, 1, { 0 } },
+ { "AVG_CAPITAL_WIDTH", BDF_INTEGER, 1, { 0 } },
+ { "AVG_LOWERCASE_WIDTH", BDF_INTEGER, 1, { 0 } },
+ { "CAP_HEIGHT", BDF_INTEGER, 1, { 0 } },
+ { "CHARSET_COLLECTIONS", BDF_ATOM, 1, { 0 } },
+ { "CHARSET_ENCODING", BDF_ATOM, 1, { 0 } },
+ { "CHARSET_REGISTRY", BDF_ATOM, 1, { 0 } },
+ { "COMMENT", BDF_ATOM, 1, { 0 } },
+ { "COPYRIGHT", BDF_ATOM, 1, { 0 } },
+ { "DEFAULT_CHAR", BDF_CARDINAL, 1, { 0 } },
+ { "DESTINATION", BDF_CARDINAL, 1, { 0 } },
+ { "DEVICE_FONT_NAME", BDF_ATOM, 1, { 0 } },
+ { "END_SPACE", BDF_INTEGER, 1, { 0 } },
+ { "FACE_NAME", BDF_ATOM, 1, { 0 } },
+ { "FAMILY_NAME", BDF_ATOM, 1, { 0 } },
+ { "FIGURE_WIDTH", BDF_INTEGER, 1, { 0 } },
+ { "FONT", BDF_ATOM, 1, { 0 } },
+ { "FONTNAME_REGISTRY", BDF_ATOM, 1, { 0 } },
+ { "FONT_ASCENT", BDF_INTEGER, 1, { 0 } },
+ { "FONT_DESCENT", BDF_INTEGER, 1, { 0 } },
+ { "FOUNDRY", BDF_ATOM, 1, { 0 } },
+ { "FULL_NAME", BDF_ATOM, 1, { 0 } },
+ { "ITALIC_ANGLE", BDF_INTEGER, 1, { 0 } },
+ { "MAX_SPACE", BDF_INTEGER, 1, { 0 } },
+ { "MIN_SPACE", BDF_INTEGER, 1, { 0 } },
+ { "NORM_SPACE", BDF_INTEGER, 1, { 0 } },
+ { "NOTICE", BDF_ATOM, 1, { 0 } },
+ { "PIXEL_SIZE", BDF_INTEGER, 1, { 0 } },
+ { "POINT_SIZE", BDF_INTEGER, 1, { 0 } },
+ { "QUAD_WIDTH", BDF_INTEGER, 1, { 0 } },
+ { "RAW_ASCENT", BDF_INTEGER, 1, { 0 } },
+ { "RAW_AVERAGE_WIDTH", BDF_INTEGER, 1, { 0 } },
+ { "RAW_AVG_CAPITAL_WIDTH", BDF_INTEGER, 1, { 0 } },
+ { "RAW_AVG_LOWERCASE_WIDTH", BDF_INTEGER, 1, { 0 } },
+ { "RAW_CAP_HEIGHT", BDF_INTEGER, 1, { 0 } },
+ { "RAW_DESCENT", BDF_INTEGER, 1, { 0 } },
+ { "RAW_END_SPACE", BDF_INTEGER, 1, { 0 } },
+ { "RAW_FIGURE_WIDTH", BDF_INTEGER, 1, { 0 } },
+ { "RAW_MAX_SPACE", BDF_INTEGER, 1, { 0 } },
+ { "RAW_MIN_SPACE", BDF_INTEGER, 1, { 0 } },
+ { "RAW_NORM_SPACE", BDF_INTEGER, 1, { 0 } },
+ { "RAW_PIXEL_SIZE", BDF_INTEGER, 1, { 0 } },
+ { "RAW_POINT_SIZE", BDF_INTEGER, 1, { 0 } },
+ { "RAW_PIXELSIZE", BDF_INTEGER, 1, { 0 } },
+ { "RAW_POINTSIZE", BDF_INTEGER, 1, { 0 } },
+ { "RAW_QUAD_WIDTH", BDF_INTEGER, 1, { 0 } },
+ { "RAW_SMALL_CAP_SIZE", BDF_INTEGER, 1, { 0 } },
+ { "RAW_STRIKEOUT_ASCENT", BDF_INTEGER, 1, { 0 } },
+ { "RAW_STRIKEOUT_DESCENT", BDF_INTEGER, 1, { 0 } },
+ { "RAW_SUBSCRIPT_SIZE", BDF_INTEGER, 1, { 0 } },
+ { "RAW_SUBSCRIPT_X", BDF_INTEGER, 1, { 0 } },
+ { "RAW_SUBSCRIPT_Y", BDF_INTEGER, 1, { 0 } },
+ { "RAW_SUPERSCRIPT_SIZE", BDF_INTEGER, 1, { 0 } },
+ { "RAW_SUPERSCRIPT_X", BDF_INTEGER, 1, { 0 } },
+ { "RAW_SUPERSCRIPT_Y", BDF_INTEGER, 1, { 0 } },
+ { "RAW_UNDERLINE_POSITION", BDF_INTEGER, 1, { 0 } },
+ { "RAW_UNDERLINE_THICKNESS", BDF_INTEGER, 1, { 0 } },
+ { "RAW_X_HEIGHT", BDF_INTEGER, 1, { 0 } },
+ { "RELATIVE_SETWIDTH", BDF_CARDINAL, 1, { 0 } },
+ { "RELATIVE_WEIGHT", BDF_CARDINAL, 1, { 0 } },
+ { "RESOLUTION", BDF_INTEGER, 1, { 0 } },
+ { "RESOLUTION_X", BDF_CARDINAL, 1, { 0 } },
+ { "RESOLUTION_Y", BDF_CARDINAL, 1, { 0 } },
+ { "SETWIDTH_NAME", BDF_ATOM, 1, { 0 } },
+ { "SLANT", BDF_ATOM, 1, { 0 } },
+ { "SMALL_CAP_SIZE", BDF_INTEGER, 1, { 0 } },
+ { "SPACING", BDF_ATOM, 1, { 0 } },
+ { "STRIKEOUT_ASCENT", BDF_INTEGER, 1, { 0 } },
+ { "STRIKEOUT_DESCENT", BDF_INTEGER, 1, { 0 } },
+ { "SUBSCRIPT_SIZE", BDF_INTEGER, 1, { 0 } },
+ { "SUBSCRIPT_X", BDF_INTEGER, 1, { 0 } },
+ { "SUBSCRIPT_Y", BDF_INTEGER, 1, { 0 } },
+ { "SUPERSCRIPT_SIZE", BDF_INTEGER, 1, { 0 } },
+ { "SUPERSCRIPT_X", BDF_INTEGER, 1, { 0 } },
+ { "SUPERSCRIPT_Y", BDF_INTEGER, 1, { 0 } },
+ { "UNDERLINE_POSITION", BDF_INTEGER, 1, { 0 } },
+ { "UNDERLINE_THICKNESS", BDF_INTEGER, 1, { 0 } },
+ { "WEIGHT", BDF_CARDINAL, 1, { 0 } },
+ { "WEIGHT_NAME", BDF_ATOM, 1, { 0 } },
+ { "X_HEIGHT", BDF_INTEGER, 1, { 0 } },
+ { "_MULE_BASELINE_OFFSET", BDF_INTEGER, 1, { 0 } },
+ { "_MULE_RELATIVE_COMPOSE", BDF_INTEGER, 1, { 0 } },
};
static const unsigned long
@@ -364,7 +364,7 @@
/* An empty string for empty fields. */
- static const char empty[1] = { 0 }; /* XXX eliminate this */
+ static const char empty[] = ""; /* XXX eliminate this */
static char *
@@ -407,13 +407,14 @@
static FT_Error
_bdf_list_split( _bdf_list_t* list,
- char* separators,
+ const char* separators,
char* line,
unsigned long linelen )
{
unsigned long final_empty;
int mult;
- char *sp, *ep, *end;
+ const char *sp, *end;
+ char *ep;
char seps[32];
FT_Error error = FT_Err_Ok;
@@ -473,7 +474,7 @@
}
/* Assign the field appropriately. */
- list->field[list->used++] = ( ep > sp ) ? sp : (char*)empty;
+ list->field[list->used++] = ( ep > sp ) ? (char*)sp : (char*)empty;
sp = ep;
@@ -692,7 +693,7 @@
/* Routine to convert a decimal ASCII string to an unsigned long integer. */
static unsigned long
- _bdf_atoul( char* s )
+ _bdf_atoul( const char* s )
{
unsigned long v;
@@ -717,7 +718,7 @@
/* Routine to convert a decimal ASCII string to a signed long integer. */
static long
- _bdf_atol( char* s )
+ _bdf_atol( const char* s )
{
long v, neg;
@@ -750,7 +751,7 @@
/* Routine to convert a decimal ASCII string to an unsigned short integer. */
static unsigned short
- _bdf_atous( char* s )
+ _bdf_atous( const char* s )
{
unsigned short v;
@@ -775,7 +776,7 @@
/* Routine to convert a decimal ASCII string to a signed short integer. */
static short
- _bdf_atos( char* s )
+ _bdf_atos( const char* s )
{
short v, neg;
@@ -828,7 +829,7 @@
static FT_Error
- bdf_create_property( char* name,
+ bdf_create_property( const char* name,
int format,
bdf_font_t* font )
{
@@ -998,7 +999,7 @@
FT_MEM_COPY( name, font->name, len );
- error = _bdf_list_split( &list, (char *)"-", name, (unsigned long)len );
+ error = _bdf_list_split( &list, "-", name, (unsigned long)len );
if ( error )
goto Fail;
@@ -1097,7 +1098,7 @@
static FT_Error
_bdf_add_property( bdf_font_t* font,
- char* name,
+ const char* name,
char* value,
unsigned long lineno )
{
@@ -1336,7 +1337,7 @@
goto Exit;
}
- error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
+ error = _bdf_list_split( &p->list, " +", line, linelen );
if ( error )
goto Exit;
p->cnt = font->glyphs_size = _bdf_atoul( p->list.field[1] );
@@ -1423,7 +1424,7 @@
/* encoding can be checked for an unencoded character. */
FT_FREE( p->glyph_name );
- error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
+ error = _bdf_list_split( &p->list, " +", line, linelen );
if ( error )
goto Exit;
@@ -1461,7 +1462,7 @@
goto Exit;
}
- error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
+ error = _bdf_list_split( &p->list, " +", line, linelen );
if ( error )
goto Exit;
@@ -1615,7 +1616,7 @@
/* Expect the SWIDTH (scalable width) field next. */
if ( _bdf_strncmp( line, "SWIDTH", 6 ) == 0 )
{
- error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
+ error = _bdf_list_split( &p->list, " +", line, linelen );
if ( error )
goto Exit;
@@ -1628,7 +1629,7 @@
/* Expect the DWIDTH (scalable width) field next. */
if ( _bdf_strncmp( line, "DWIDTH", 6 ) == 0 )
{
- error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
+ error = _bdf_list_split( &p->list, " +", line, linelen );
if ( error )
goto Exit;
@@ -1653,7 +1654,7 @@
/* Expect the BBX field next. */
if ( _bdf_strncmp( line, "BBX", 3 ) == 0 )
{
- error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
+ error = _bdf_list_split( &p->list, " +", line, linelen );
if ( error )
goto Exit;
@@ -1796,7 +1797,7 @@
{
p->font->font_ascent = p->font->bbx.ascent;
ft_sprintf( nbuf, "%hd", p->font->bbx.ascent );
- error = _bdf_add_property( p->font, (char *)"FONT_ASCENT",
+ error = _bdf_add_property( p->font, "FONT_ASCENT",
nbuf, lineno );
if ( error )
goto Exit;
@@ -1808,7 +1809,7 @@
{
p->font->font_descent = p->font->bbx.descent;
ft_sprintf( nbuf, "%hd", p->font->bbx.descent );
- error = _bdf_add_property( p->font, (char *)"FONT_DESCENT",
+ error = _bdf_add_property( p->font, "FONT_DESCENT",
nbuf, lineno );
if ( error )
goto Exit;
@@ -1846,7 +1847,7 @@
}
else
{
- error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
+ error = _bdf_list_split( &p->list, " +", line, linelen );
if ( error )
goto Exit;
name = p->list.field[0];
@@ -1976,7 +1977,7 @@
goto Exit;
}
- error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
+ error = _bdf_list_split( &p->list, " +", line, linelen );
if ( error )
goto Exit;
@@ -2015,7 +2016,7 @@
goto Exit;
}
- error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
+ error = _bdf_list_split( &p->list, " +", line, linelen );
if ( error )
goto Exit;
@@ -2038,7 +2039,7 @@
/* The next thing to check for is the FONT field. */
if ( _bdf_strncmp( line, "FONT", 4 ) == 0 )
{
- error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
+ error = _bdf_list_split( &p->list, " +", line, linelen );
if ( error )
goto Exit;
_bdf_list_shift( &p->list, 1 );
@@ -2081,7 +2082,7 @@
goto Exit;
}
- error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
+ error = _bdf_list_split( &p->list, " +", line, linelen );
if ( error )
goto Exit;
@@ -2136,7 +2137,7 @@
/* for compiling fonts. */
p->font->font_ascent = p->font->bbx.ascent;
ft_sprintf( nbuf, "%hd", p->font->bbx.ascent );
- error = _bdf_add_property( p->font, (char *)"FONT_ASCENT",
+ error = _bdf_add_property( p->font, "FONT_ASCENT",
nbuf, lineno );
if ( error )
goto Exit;
@@ -2144,7 +2145,7 @@
p->font->font_descent = p->font->bbx.descent;
ft_sprintf( nbuf, "%hd", p->font->bbx.descent );
- error = _bdf_add_property( p->font, (char *)"FONT_DESCENT",
+ error = _bdf_add_property( p->font, "FONT_DESCENT",
nbuf, lineno );
if ( error )
goto Exit;
diff --git a/thirdparty/freetype/src/cache/rules.mk b/thirdparty/freetype/src/cache/rules.mk
index abcb242239..1618d98303 100644
--- a/thirdparty/freetype/src/cache/rules.mk
+++ b/thirdparty/freetype/src/cache/rules.mk
@@ -15,7 +15,7 @@
# Cache driver directory
#
-CACHE_DIR := $(SRC_DIR)/cache
+CACHE_DIR := $(SRC_DIR)/cache
# compilation flags for the driver
diff --git a/thirdparty/freetype/src/cff/cffdrivr.c b/thirdparty/freetype/src/cff/cffdrivr.c
index bbd5c40329..2324989811 100644
--- a/thirdparty/freetype/src/cff/cffdrivr.c
+++ b/thirdparty/freetype/src/cff/cffdrivr.c
@@ -381,8 +381,8 @@
static FT_UInt
- cff_get_name_index( CFF_Face face,
- FT_String* glyph_name )
+ cff_get_name_index( CFF_Face face,
+ const FT_String* glyph_name )
{
CFF_Font cff;
CFF_Charset charset;
diff --git a/thirdparty/freetype/src/cff/cffobjs.c b/thirdparty/freetype/src/cff/cffobjs.c
index 1a1030c065..f76245f30b 100644
--- a/thirdparty/freetype/src/cff/cffobjs.c
+++ b/thirdparty/freetype/src/cff/cffobjs.c
@@ -962,7 +962,7 @@
cffface->style_name = style_name;
else
/* assume "Regular" style if we don't know better */
- cffface->style_name = cff_strcpy( memory, (char *)"Regular" );
+ cffface->style_name = cff_strcpy( memory, "Regular" );
/********************************************************************
*
diff --git a/thirdparty/freetype/src/cff/cffparse.c b/thirdparty/freetype/src/cff/cffparse.c
index fa806f1a90..008752c3ae 100644
--- a/thirdparty/freetype/src/cff/cffparse.c
+++ b/thirdparty/freetype/src/cff/cffparse.c
@@ -77,6 +77,23 @@
}
+#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
+ static void
+ finalize_t2_strings( FT_Memory memory,
+ void* data,
+ void* user )
+ {
+ CFF_T2_String t2 = (CFF_T2_String)data;
+
+
+ FT_UNUSED( user );
+
+ memory->free( memory, t2->start );
+ memory->free( memory, data );
+ }
+#endif /* CFF_CONFIG_OPTION_OLD_ENGINE */
+
+
FT_LOCAL_DEF( void )
cff_parser_done( CFF_Parser parser )
{
@@ -84,13 +101,65 @@
FT_FREE( parser->stack );
+
+#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
+ FT_List_Finalize( &parser->t2_strings,
+ finalize_t2_strings,
+ memory,
+ NULL );
+#endif
+ }
+
+
+ /* Assuming `first >= last'. */
+
+ static FT_Error
+ cff_parser_within_limits( CFF_Parser parser,
+ FT_Byte* first,
+ FT_Byte* last )
+ {
+#ifndef CFF_CONFIG_OPTION_OLD_ENGINE
+
+ /* Fast path for regular FreeType builds with the "new" engine; */
+ /* `first >= parser->start' can be assumed. */
+
+ FT_UNUSED( first );
+
+ return last < parser->limit ? FT_Err_Ok : FT_THROW( Invalid_Argument );
+
+#else /* CFF_CONFIG_OPTION_OLD_ENGINE */
+
+ FT_ListNode node;
+
+
+ if ( first >= parser->start &&
+ last < parser->limit )
+ return FT_Err_Ok;
+
+ node = parser->t2_strings.head;
+
+ while ( node )
+ {
+ CFF_T2_String t2 = (CFF_T2_String)node->data;
+
+
+ if ( first >= t2->start &&
+ last < t2->limit )
+ return FT_Err_Ok;
+
+ node = node->next;
+ }
+
+ return FT_THROW( Invalid_Argument );
+
+#endif /* CFF_CONFIG_OPTION_OLD_ENGINE */
}
/* read an integer */
static FT_Long
- cff_parse_integer( FT_Byte* start,
- FT_Byte* limit )
+ cff_parse_integer( CFF_Parser parser,
+ FT_Byte* start )
{
FT_Byte* p = start;
FT_Int v = *p++;
@@ -99,14 +168,14 @@
if ( v == 28 )
{
- if ( p + 2 > limit )
+ if ( cff_parser_within_limits( parser, p, p + 1 ) )
goto Bad;
val = (FT_Short)( ( (FT_UShort)p[0] << 8 ) | p[1] );
}
else if ( v == 29 )
{
- if ( p + 4 > limit )
+ if ( cff_parser_within_limits( parser, p, p + 3 ) )
goto Bad;
val = (FT_Long)( ( (FT_ULong)p[0] << 24 ) |
@@ -120,14 +189,14 @@
}
else if ( v < 251 )
{
- if ( p + 1 > limit )
+ if ( cff_parser_within_limits( parser, p, p ) )
goto Bad;
val = ( v - 247 ) * 256 + p[0] + 108;
}
else
{
- if ( p + 1 > limit )
+ if ( cff_parser_within_limits( parser, p, p ) )
goto Bad;
val = -( v - 251 ) * 256 - p[0] - 108;
@@ -176,10 +245,10 @@
/* read a real */
static FT_Fixed
- cff_parse_real( FT_Byte* start,
- FT_Byte* limit,
- FT_Long power_ten,
- FT_Long* scaling )
+ cff_parse_real( CFF_Parser parser,
+ FT_Byte* start,
+ FT_Long power_ten,
+ FT_Long* scaling )
{
FT_Byte* p = start;
FT_Int nib;
@@ -214,7 +283,7 @@
p++;
/* Make sure we don't read past the end. */
- if ( p >= limit )
+ if ( cff_parser_within_limits( parser, p, p ) )
goto Bad;
}
@@ -251,7 +320,7 @@
p++;
/* Make sure we don't read past the end. */
- if ( p >= limit )
+ if ( cff_parser_within_limits( parser, p, p ) )
goto Bad;
}
@@ -290,7 +359,7 @@
p++;
/* Make sure we don't read past the end. */
- if ( p >= limit )
+ if ( cff_parser_within_limits( parser, p, p ) )
goto Bad;
}
@@ -457,7 +526,7 @@
if ( **d == 30 )
{
/* binary-coded decimal is truncated to integer */
- return cff_parse_real( *d, parser->limit, 0, NULL ) >> 16;
+ return cff_parse_real( parser, *d, 0, NULL ) >> 16;
}
else if ( **d == 255 )
@@ -483,7 +552,7 @@
}
else
- return cff_parse_integer( *d, parser->limit );
+ return cff_parse_integer( parser, *d );
}
@@ -494,10 +563,10 @@
FT_Long scaling )
{
if ( **d == 30 )
- return cff_parse_real( *d, parser->limit, scaling, NULL );
+ return cff_parse_real( parser, *d, scaling, NULL );
else
{
- FT_Long val = cff_parse_integer( *d, parser->limit );
+ FT_Long val = cff_parse_integer( parser, *d );
if ( scaling )
@@ -562,14 +631,14 @@
FT_ASSERT( scaling );
if ( **d == 30 )
- return cff_parse_real( *d, parser->limit, 0, scaling );
+ return cff_parse_real( parser, *d, 0, scaling );
else
{
FT_Long number;
FT_Int integer_length;
- number = cff_parse_integer( d[0], d[1] );
+ number = cff_parse_integer( parser, d[0] );
if ( number > 0x7FFFL )
{
@@ -1122,18 +1191,6 @@
#endif /* FT_DEBUG_LEVEL_TRACE */
-#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
- static void
- destruct_t2s_item( FT_Memory memory,
- void* data,
- void* user )
- {
- FT_UNUSED( user );
- memory->free( memory, data );
- }
-#endif /* CFF_CONFIG_OPTION_OLD_ENGINE */
-
-
FT_LOCAL_DEF( FT_Error )
cff_parser_run( CFF_Parser parser,
FT_Byte* start,
@@ -1147,11 +1204,6 @@
FT_Library library = parser->library;
FT_Memory memory = library->memory;
-
- FT_ListRec t2s;
-
-
- FT_ZERO( &t2s );
#endif
parser->top = parser->stack;
@@ -1212,9 +1264,11 @@
FT_Byte* charstring_base;
FT_ULong charstring_len;
- FT_Fixed* stack;
- FT_ListNode node;
- FT_Byte* q;
+ FT_Fixed* stack;
+ FT_ListNode node;
+ CFF_T2_String t2;
+ size_t t2_size;
+ FT_Byte* q;
charstring_base = ++p;
@@ -1261,16 +1315,26 @@
if ( !node )
goto Out_Of_Memory_Error;
+ FT_List_Add( &parser->t2_strings, node );
+
+ t2 = (CFF_T2_String)memory->alloc( memory,
+ sizeof ( CFF_T2_StringRec ) );
+ if ( !t2 )
+ goto Out_Of_Memory_Error;
+
+ node->data = t2;
+
/* `5' is the conservative upper bound of required bytes per stack */
/* element. */
- q = (FT_Byte*)memory->alloc( memory,
- 5 * ( decoder.top - decoder.stack ) );
+
+ t2_size = 5 * ( decoder.top - decoder.stack );
+
+ q = (FT_Byte*)memory->alloc( memory, t2_size );
if ( !q )
goto Out_Of_Memory_Error;
- node->data = q;
-
- FT_List_Add( &t2s, node );
+ t2->start = q;
+ t2->limit = q + t2_size;
stack = decoder.stack;
@@ -1531,9 +1595,6 @@
} /* while ( p < limit ) */
Exit:
-#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
- FT_List_Finalize( &t2s, destruct_t2s_item, memory, NULL );
-#endif
return error;
#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
diff --git a/thirdparty/freetype/src/cff/cffparse.h b/thirdparty/freetype/src/cff/cffparse.h
index bac32f9449..4e74709a2d 100644
--- a/thirdparty/freetype/src/cff/cffparse.h
+++ b/thirdparty/freetype/src/cff/cffparse.h
@@ -60,6 +60,10 @@ FT_BEGIN_HEADER
FT_Byte** top;
FT_UInt stackSize; /* allocated size */
+#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
+ FT_ListRec t2_strings;
+#endif /* CFF_CONFIG_OPTION_OLD_ENGINE */
+
FT_UInt object_code;
void* object;
@@ -130,6 +134,15 @@ FT_BEGIN_HEADER
FT_END_HEADER
+#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
+ typedef struct CFF_T2_String_
+ {
+ FT_Byte* start;
+ FT_Byte* limit;
+
+ } CFF_T2_StringRec, *CFF_T2_String;
+#endif /* CFF_CONFIG_OPTION_OLD_ENGINE */
+
#endif /* CFFPARSE_H_ */
diff --git a/thirdparty/freetype/src/gzip/ftgzip.c b/thirdparty/freetype/src/gzip/ftgzip.c
index a5206307f4..5e78bc6f8d 100644
--- a/thirdparty/freetype/src/gzip/ftgzip.c
+++ b/thirdparty/freetype/src/gzip/ftgzip.c
@@ -746,7 +746,7 @@
stream.zfree = (free_func) ft_gzip_free;
stream.opaque = memory;
- err = inflateInit2( &stream, MAX_WBITS );
+ err = inflateInit2( &stream, MAX_WBITS|32 );
if ( err != Z_OK )
return FT_THROW( Invalid_Argument );
diff --git a/thirdparty/freetype/src/gzip/infblock.c b/thirdparty/freetype/src/gzip/infblock.c
index d6e2dc297d..2b4f0c2b53 100644
--- a/thirdparty/freetype/src/gzip/infblock.c
+++ b/thirdparty/freetype/src/gzip/infblock.c
@@ -235,6 +235,7 @@ int r )
s->sub.trees.index = 0;
Tracev((stderr, "inflate: table sizes ok\n"));
s->mode = BTREE;
+ /* fall through */
case BTREE:
while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10))
{
@@ -260,6 +261,7 @@ int r )
s->sub.trees.index = 0;
Tracev((stderr, "inflate: bits tree ok\n"));
s->mode = DTREE;
+ /* fall through */
case DTREE:
while (t = s->sub.trees.table,
s->sub.trees.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))
@@ -335,6 +337,7 @@ int r )
}
ZFREE(z, s->sub.trees.blens);
s->mode = CODES;
+ /* fall through */
case CODES:
UPDATE
if ((r = inflate_codes(s, z, r)) != Z_STREAM_END)
@@ -351,11 +354,13 @@ int r )
break;
}
s->mode = DRY;
+ /* fall through */
case DRY:
FLUSH
if (s->read != s->write)
LEAVE
s->mode = DONE;
+ /* fall through */
case DONE:
r = Z_STREAM_END;
LEAVE
diff --git a/thirdparty/freetype/src/gzip/infcodes.c b/thirdparty/freetype/src/gzip/infcodes.c
index f7bfd58c4f..ba30654990 100644
--- a/thirdparty/freetype/src/gzip/infcodes.c
+++ b/thirdparty/freetype/src/gzip/infcodes.c
@@ -117,6 +117,7 @@ int r )
c->sub.code.need = c->lbits;
c->sub.code.tree = c->ltree;
c->mode = LEN;
+ /* fall through */
case LEN: /* i: get length/literal/eob next */
j = c->sub.code.need;
NEEDBITS(j)
@@ -164,6 +165,7 @@ int r )
c->sub.code.tree = c->dtree;
Tracevv((stderr, "inflate: length %u\n", c->len));
c->mode = DIST;
+ /* fall through */
case DIST: /* i: get distance next */
j = c->sub.code.need;
NEEDBITS(j)
@@ -194,6 +196,7 @@ int r )
DUMPBITS(j)
Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist));
c->mode = COPY;
+ /* fall through */
case COPY: /* o: copying bytes in window, waiting for space */
f = q - c->sub.copy.dist;
while (f < s->window) /* modulo window size-"while" instead */
@@ -225,6 +228,7 @@ int r )
if (s->read != s->write)
LEAVE
c->mode = END;
+ /* fall through */
case END:
r = Z_STREAM_END;
LEAVE
diff --git a/thirdparty/freetype/src/gzip/inflate.c b/thirdparty/freetype/src/gzip/inflate.c
index 8877fa3eb2..95e2653662 100644
--- a/thirdparty/freetype/src/gzip/inflate.c
+++ b/thirdparty/freetype/src/gzip/inflate.c
@@ -174,6 +174,7 @@ int f )
break;
}
z->state->mode = FLAG;
+ /* fall through */
case FLAG:
NEEDBYTE
b = NEXTBYTE;
@@ -191,18 +192,22 @@ int f )
break;
}
z->state->mode = DICT4;
+ /* fall through */
case DICT4:
NEEDBYTE
z->state->sub.check.need = (uLong)NEXTBYTE << 24;
z->state->mode = DICT3;
+ /* fall through */
case DICT3:
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE << 16;
z->state->mode = DICT2;
+ /* fall through */
case DICT2:
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE << 8;
z->state->mode = DICT1;
+ /* fall through */
case DICT1:
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE;
@@ -234,18 +239,22 @@ int f )
break;
}
z->state->mode = CHECK4;
+ /* fall through */
case CHECK4:
NEEDBYTE
z->state->sub.check.need = (uLong)NEXTBYTE << 24;
z->state->mode = CHECK3;
+ /* fall through */
case CHECK3:
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE << 16;
z->state->mode = CHECK2;
+ /* fall through */
case CHECK2:
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE << 8;
z->state->mode = CHECK1;
+ /* fall through */
case CHECK1:
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE;
@@ -259,6 +268,7 @@ int f )
}
Tracev((stderr, "inflate: zlib check ok\n"));
z->state->mode = DONE;
+ /* fall through */
case DONE:
return Z_STREAM_END;
case BAD:
diff --git a/thirdparty/freetype/src/pcf/pcf.h b/thirdparty/freetype/src/pcf/pcf.h
index 529dd3adf8..33be4bcd85 100644
--- a/thirdparty/freetype/src/pcf/pcf.h
+++ b/thirdparty/freetype/src/pcf/pcf.h
@@ -99,7 +99,8 @@ FT_BEGIN_HEADER
FT_Short ascent;
FT_Short descent;
FT_Short attributes;
- FT_ULong bits;
+
+ FT_ULong bits; /* offset into the PCF_BITMAPS table */
} PCF_MetricRec, *PCF_Metric;
diff --git a/thirdparty/freetype/src/pcf/pcfdrivr.c b/thirdparty/freetype/src/pcf/pcfdrivr.c
index 54bbb9d119..b39592c794 100644
--- a/thirdparty/freetype/src/pcf/pcfdrivr.c
+++ b/thirdparty/freetype/src/pcf/pcfdrivr.c
@@ -122,9 +122,9 @@ THE SOFTWARE.
charcodeCol > enc->lastCol )
return 0;
- return (FT_UInt)enc->offset[ ( charcodeRow - enc->firstRow ) *
- ( enc->lastCol - enc->firstCol + 1 ) +
- charcodeCol - enc->firstCol ];
+ return (FT_UInt)enc->offset[( charcodeRow - enc->firstRow ) *
+ ( enc->lastCol - enc->firstCol + 1 ) +
+ charcodeCol - enc->firstCol];
}
@@ -160,9 +160,9 @@ THE SOFTWARE.
charcode = (FT_UInt32)( charcodeRow * 256 + charcodeCol );
- result = (FT_UInt)enc->offset[ ( charcodeRow - enc->firstRow ) *
- ( enc->lastCol - enc->firstCol + 1 ) +
- charcodeCol - enc->firstCol ];
+ result = (FT_UInt)enc->offset[( charcodeRow - enc->firstRow ) *
+ ( enc->lastCol - enc->firstCol + 1 ) +
+ charcodeCol - enc->firstCol];
if ( result != 0xFFFFU )
break;
}
diff --git a/thirdparty/freetype/src/pcf/pcfread.c b/thirdparty/freetype/src/pcf/pcfread.c
index 71143ecfb5..2ffe22d71c 100644
--- a/thirdparty/freetype/src/pcf/pcfread.c
+++ b/thirdparty/freetype/src/pcf/pcfread.c
@@ -743,33 +743,39 @@ THE SOFTWARE.
if ( !orig_nmetrics )
return FT_THROW( Invalid_Table );
- /* PCF is a format from ancient times; Unicode was in its */
- /* infancy, and widely used two-byte character sets for CJK */
- /* scripts (Big 5, GB 2312, JIS X 0208, etc.) did have at most */
- /* 15000 characters. Even the more exotic CNS 11643 and CCCII */
- /* standards, which were essentially three-byte character sets, */
- /* provided less then 65536 assigned characters. */
- /* */
- /* While technically possible to have a larger number of glyphs */
- /* in PCF files, we thus limit the number to 65536. */
- if ( orig_nmetrics > 65536 )
+ /*
+ * PCF is a format from ancient times; Unicode was in its infancy, and
+ * widely used two-byte character sets for CJK scripts (Big 5, GB 2312,
+ * JIS X 0208, etc.) did have at most 15000 characters. Even the more
+ * exotic CNS 11643 and CCCII standards, which were essentially
+ * three-byte character sets, provided less then 65536 assigned
+ * characters.
+ *
+ * While technically possible to have a larger number of glyphs in PCF
+ * files, we thus limit the number to 65535, taking into account that we
+ * synthesize the metrics of glyph 0 to be a copy of the `default
+ * character', and that 0xFFFF in the encodings array indicates a
+ * missing glyph.
+ */
+ if ( orig_nmetrics > 65534 )
{
FT_TRACE0(( "pcf_get_metrics:"
- " only loading first 65536 metrics\n" ));
- nmetrics = 65536;
+ " only loading first 65534 metrics\n" ));
+ nmetrics = 65534;
}
else
nmetrics = orig_nmetrics;
- face->nmetrics = nmetrics;
+ face->nmetrics = nmetrics + 1;
- if ( FT_NEW_ARRAY( face->metrics, nmetrics ) )
+ if ( FT_NEW_ARRAY( face->metrics, face->nmetrics ) )
return error;
- metrics = face->metrics;
+ /* we handle glyph index 0 later on */
+ metrics = face->metrics + 1;
FT_TRACE4(( "\n" ));
- for ( i = 0; i < nmetrics; i++, metrics++ )
+ for ( i = 1; i < face->nmetrics; i++, metrics++ )
{
FT_TRACE5(( " idx %ld:", i ));
error = pcf_get_metric( stream, format, metrics );
@@ -808,12 +814,10 @@ THE SOFTWARE.
pcf_get_bitmaps( FT_Stream stream,
PCF_Face face )
{
- FT_Error error;
- FT_Memory memory = FT_FACE( face )->memory;
- FT_ULong* offsets = NULL;
- FT_ULong bitmapSizes[GLYPHPADOPTIONS];
- FT_ULong format, size;
- FT_ULong nbitmaps, orig_nbitmaps, i, sizebitmaps = 0;
+ FT_Error error;
+ FT_ULong bitmapSizes[GLYPHPADOPTIONS];
+ FT_ULong format, size, pos;
+ FT_ULong nbitmaps, orig_nbitmaps, i, sizebitmaps = 0;
error = pcf_seek_to_table_type( stream,
@@ -859,31 +863,46 @@ THE SOFTWARE.
FT_TRACE4(( " number of bitmaps: %ld\n", orig_nbitmaps ));
/* see comment in `pcf_get_metrics' */
- if ( orig_nbitmaps > 65536 )
+ if ( orig_nbitmaps > 65534 )
{
FT_TRACE0(( "pcf_get_bitmaps:"
- " only loading first 65536 bitmaps\n" ));
- nbitmaps = 65536;
+ " only loading first 65534 bitmaps\n" ));
+ nbitmaps = 65534;
}
else
nbitmaps = orig_nbitmaps;
- if ( nbitmaps != face->nmetrics )
+ /* no extra bitmap for glyph 0 */
+ if ( nbitmaps != face->nmetrics - 1 )
return FT_THROW( Invalid_File_Format );
- if ( FT_NEW_ARRAY( offsets, nbitmaps ) )
- return error;
+ /* start position of bitmap data */
+ pos = stream->pos + nbitmaps * 4 + 4 * 4;
FT_TRACE5(( "\n" ));
- for ( i = 0; i < nbitmaps; i++ )
+ for ( i = 1; i <= nbitmaps; i++ )
{
+ FT_ULong offset;
+
+
if ( PCF_BYTE_ORDER( format ) == MSBFirst )
- (void)FT_READ_ULONG( offsets[i] );
+ (void)FT_READ_ULONG( offset );
else
- (void)FT_READ_ULONG_LE( offsets[i] );
+ (void)FT_READ_ULONG_LE( offset );
FT_TRACE5(( " bitmap %lu: offset %lu (0x%lX)\n",
- i, offsets[i], offsets[i] ));
+ i, offset, offset ));
+
+ /* right now, we only check the offset with a rough estimate; */
+ /* actual bitmaps are only loaded on demand */
+ if ( offset > size )
+ {
+ FT_TRACE0(( "pcf_get_bitmaps:"
+ " invalid offset to bitmap data of glyph %lu\n", i ));
+ face->metrics[i].bits = pos;
+ }
+ else
+ face->metrics[i].bits = pos + offset;
}
if ( error )
goto Bail;
@@ -910,24 +929,9 @@ THE SOFTWARE.
FT_UNUSED( sizebitmaps ); /* only used for debugging */
- /* right now, we only check the bitmap offsets; */
- /* actual bitmaps are only loaded on demand */
- for ( i = 0; i < nbitmaps; i++ )
- {
- /* rough estimate */
- if ( offsets[i] > size )
- {
- FT_TRACE0(( "pcf_get_bitmaps:"
- " invalid offset to bitmap data of glyph %lu\n", i ));
- }
- else
- face->metrics[i].bits = stream->pos + offsets[i];
- }
-
face->bitmapsFormat = format;
Bail:
- FT_FREE( offsets );
return error;
}
@@ -1062,41 +1066,52 @@ THE SOFTWARE.
defaultCharCol = enc->firstCol;
}
- /* FreeType mandates that glyph index 0 is the `undefined glyph', */
- /* which PCF calls the `default character'. For this reason, we */
- /* swap the positions of glyph index 0 and the index corresponding */
- /* to `defaultChar' in case they are different. */
-
- /* `stream->cursor' still points at the beginning of the frame; */
- /* we can thus easily get the offset to the default character */
+ /*
+ * FreeType mandates that glyph index 0 is the `undefined glyph', which
+ * PCF calls the `default character'. However, FreeType needs glyph
+ * index 0 to be used for the undefined glyph only, which is is not the
+ * case for PCF. For this reason, we add one slot for glyph index 0 and
+ * simply copy the default character to it.
+ *
+ * `stream->cursor' still points to the beginning of the frame; we can
+ * thus easily get the offset to the default character.
+ */
pos = stream->cursor +
2 * ( ( defaultCharRow - enc->firstRow ) *
- ( enc->lastCol - enc->firstCol + 1 ) +
- defaultCharCol - enc->firstCol );
+ ( enc->lastCol - enc->firstCol + 1 ) +
+ defaultCharCol - enc->firstCol );
if ( PCF_BYTE_ORDER( format ) == MSBFirst )
defaultCharEncodingOffset = FT_PEEK_USHORT( pos );
else
defaultCharEncodingOffset = FT_PEEK_USHORT_LE( pos );
- if ( defaultCharEncodingOffset >= face->nmetrics )
+ if ( defaultCharEncodingOffset == 0xFFFF )
{
FT_TRACE0(( "pcf_get_encodings:"
- " Invalid glyph index for default character,"
- " setting to zero\n" ));
- defaultCharEncodingOffset = 0;
+ " No glyph for default character,\n"
+ " "
+ " setting it to the first glyph of the font\n" ));
+ defaultCharEncodingOffset = 1;
}
-
- if ( defaultCharEncodingOffset )
+ else
{
- /* do the swapping */
- PCF_MetricRec tmp = face->metrics[defaultCharEncodingOffset];
-
+ defaultCharEncodingOffset++;
- face->metrics[defaultCharEncodingOffset] = face->metrics[0];
- face->metrics[0] = tmp;
+ if ( defaultCharEncodingOffset >= face->nmetrics )
+ {
+ FT_TRACE0(( "pcf_get_encodings:"
+ " Invalid glyph index for default character,\n"
+ " "
+ " setting it to the first glyph of the font\n" ));
+ defaultCharEncodingOffset = 1;
+ }
}
+ /* copy metrics of default character to index 0 */
+ face->metrics[0] = face->metrics[defaultCharEncodingOffset];
+
+ /* now loop over all values */
offset = enc->offset;
for ( i = enc->firstRow; i <= enc->lastRow; i++ )
{
@@ -1111,15 +1126,9 @@ THE SOFTWARE.
else
encodingOffset = FT_GET_USHORT_LE();
- if ( encodingOffset != 0xFFFFU )
- {
- if ( encodingOffset == defaultCharEncodingOffset )
- encodingOffset = 0;
- else if ( encodingOffset == 0 )
- encodingOffset = defaultCharEncodingOffset;
- }
-
- *offset++ = encodingOffset;
+ /* everything is off by 1 due to the artificial glyph 0 */
+ *offset++ = encodingOffset == 0xFFFF ? 0xFFFF
+ : encodingOffset + 1;
}
}
FT_Stream_ExitFrame( stream );
@@ -1303,9 +1312,8 @@ THE SOFTWARE.
PCF_Property prop;
- size_t nn, len;
- char* strings[4] = { NULL, NULL, NULL, NULL };
- size_t lengths[4];
+ const char* strings[4] = { NULL, NULL, NULL, NULL };
+ size_t lengths[4], nn, len;
face->style_flags = 0;
@@ -1317,8 +1325,8 @@ THE SOFTWARE.
{
face->style_flags |= FT_STYLE_FLAG_ITALIC;
strings[2] = ( *(prop->value.atom) == 'O' ||
- *(prop->value.atom) == 'o' ) ? (char *)"Oblique"
- : (char *)"Italic";
+ *(prop->value.atom) == 'o' ) ? "Oblique"
+ : "Italic";
}
prop = pcf_find_property( pcf, "WEIGHT_NAME" );
@@ -1326,20 +1334,20 @@ THE SOFTWARE.
( *(prop->value.atom) == 'B' || *(prop->value.atom) == 'b' ) )
{
face->style_flags |= FT_STYLE_FLAG_BOLD;
- strings[1] = (char*)"Bold";
+ strings[1] = "Bold";
}
prop = pcf_find_property( pcf, "SETWIDTH_NAME" );
if ( prop && prop->isString &&
*(prop->value.atom) &&
!( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) )
- strings[3] = (char*)( prop->value.atom );
+ strings[3] = (const char*)( prop->value.atom );
prop = pcf_find_property( pcf, "ADD_STYLE_NAME" );
if ( prop && prop->isString &&
*(prop->value.atom) &&
!( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) )
- strings[0] = (char*)( prop->value.atom );
+ strings[0] = (const char*)( prop->value.atom );
for ( len = 0, nn = 0; nn < 4; nn++ )
{
@@ -1353,7 +1361,7 @@ THE SOFTWARE.
if ( len == 0 )
{
- strings[0] = (char*)"Regular";
+ strings[0] = "Regular";
lengths[0] = ft_strlen( strings[0] );
len = lengths[0] + 1;
}
@@ -1369,7 +1377,7 @@ THE SOFTWARE.
for ( nn = 0; nn < 4; nn++ )
{
- char* src = strings[nn];
+ const char* src = strings[nn];
len = lengths[nn];
diff --git a/thirdparty/freetype/src/pfr/pfrobjs.c b/thirdparty/freetype/src/pfr/pfrobjs.c
index e103a3f6f2..9765f95c2f 100644
--- a/thirdparty/freetype/src/pfr/pfrobjs.c
+++ b/thirdparty/freetype/src/pfr/pfrobjs.c
@@ -378,7 +378,7 @@
outline->flags &= ~FT_OUTLINE_OWNER;
outline->flags |= FT_OUTLINE_REVERSE_FILL;
- if ( size && pfrsize->metrics.y_ppem < 24 )
+ if ( pfrsize->metrics.y_ppem < 24 )
outline->flags |= FT_OUTLINE_HIGH_PRECISION;
/* compute the advance vector */
diff --git a/thirdparty/freetype/src/psaux/afmparse.c b/thirdparty/freetype/src/psaux/afmparse.c
index 49225a9f78..f78adbba3d 100644
--- a/thirdparty/freetype/src/psaux/afmparse.c
+++ b/thirdparty/freetype/src/psaux/afmparse.c
@@ -953,7 +953,8 @@
error = afm_parse_kern_data( parser );
if ( error )
goto Fail;
- /* fall through since we only support kern data */
+ /* we only support kern data, so ... */
+ /* fall through */
case AFM_TOKEN_ENDFONTMETRICS:
return FT_Err_Ok;
diff --git a/thirdparty/freetype/src/psaux/psfixed.h b/thirdparty/freetype/src/psaux/psfixed.h
index fd3460f34a..7dff9ef1bd 100644
--- a/thirdparty/freetype/src/psaux/psfixed.h
+++ b/thirdparty/freetype/src/psaux/psfixed.h
@@ -72,8 +72,7 @@ FT_BEGIN_HEADER
#define cf2_fixedFraction( x ) \
( (x) - cf2_fixedFloor( x ) )
#define cf2_fracToFixed( x ) \
- ( (x) < 0 ? -( ( -(x) + 0x2000 ) >> 14 ) \
- : ( ( (x) + 0x2000 ) >> 14 ) )
+ ( ( (x) + 0x2000 - ( (x) < 0 ) ) >> 14 )
/* signed numeric types */
diff --git a/thirdparty/freetype/src/psaux/psfont.c b/thirdparty/freetype/src/psaux/psfont.c
index bb5faa38f5..00e4210819 100644
--- a/thirdparty/freetype/src/psaux/psfont.c
+++ b/thirdparty/freetype/src/psaux/psfont.c
@@ -274,9 +274,6 @@
if ( !font->isT1 )
{
- FT_Service_CFFLoad cffload = (FT_Service_CFFLoad)font->cffload;
-
-
/* check for variation vectors */
vstore = cf2_getVStore( decoder );
hasVariations = ( vstore->dataCount != 0 );
@@ -284,6 +281,9 @@
if ( hasVariations )
{
#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+ FT_Service_CFFLoad cffload = (FT_Service_CFFLoad)font->cffload;
+
+
/* check whether Private DICT in this subfont needs to be reparsed */
font->error = cf2_getNormalizedVector( decoder,
&lenNormalizedV,
diff --git a/thirdparty/freetype/src/psaux/psobjs.c b/thirdparty/freetype/src/psaux/psobjs.c
index e2168a3324..8bfdb92332 100644
--- a/thirdparty/freetype/src/psaux/psobjs.c
+++ b/thirdparty/freetype/src/psaux/psobjs.c
@@ -174,10 +174,10 @@
* reallocation fails.
*/
FT_LOCAL_DEF( FT_Error )
- ps_table_add( PS_Table table,
- FT_Int idx,
- void* object,
- FT_UInt length )
+ ps_table_add( PS_Table table,
+ FT_Int idx,
+ const void* object,
+ FT_UInt length )
{
if ( idx < 0 || idx >= table->max_elems )
{
diff --git a/thirdparty/freetype/src/psaux/psobjs.h b/thirdparty/freetype/src/psaux/psobjs.h
index 9466a1d075..c44dc450ec 100644
--- a/thirdparty/freetype/src/psaux/psobjs.h
+++ b/thirdparty/freetype/src/psaux/psobjs.h
@@ -53,10 +53,10 @@ FT_BEGIN_HEADER
FT_Memory memory );
FT_LOCAL( FT_Error )
- ps_table_add( PS_Table table,
- FT_Int idx,
- void* object,
- FT_UInt length );
+ ps_table_add( PS_Table table,
+ FT_Int idx,
+ const void* object,
+ FT_UInt length );
FT_LOCAL( void )
ps_table_done( PS_Table table );
diff --git a/thirdparty/freetype/src/raster/ftraster.c b/thirdparty/freetype/src/raster/ftraster.c
index 798a72d02a..023b6c1eff 100644
--- a/thirdparty/freetype/src/raster/ftraster.c
+++ b/thirdparty/freetype/src/raster/ftraster.c
@@ -399,7 +399,7 @@
#define RAS_ARGS /* void */
-#define RAS_ARG /* void */
+#define RAS_ARG void
#define RAS_VARS /* void */
#define RAS_VAR /* void */
@@ -546,8 +546,7 @@
#ifdef FT_STATIC_RASTER
- static black_TWorker cur_ras;
-#define ras cur_ras
+ static black_TWorker ras;
#else /* !FT_STATIC_RASTER */
@@ -661,7 +660,6 @@
return FAILURE;
}
- ras.cProfile->flags = 0;
ras.cProfile->start = 0;
ras.cProfile->height = 0;
ras.cProfile->offset = ras.top;
@@ -914,16 +912,18 @@
base[4].x = base[2].x;
- b = base[1].x;
- a = base[3].x = ( base[2].x + b ) / 2;
- b = base[1].x = ( base[0].x + b ) / 2;
- base[2].x = ( a + b ) / 2;
+ a = base[0].x + base[1].x;
+ b = base[1].x + base[2].x;
+ base[3].x = b >> 1;
+ base[2].x = ( a + b ) >> 2;
+ base[1].x = a >> 1;
base[4].y = base[2].y;
- b = base[1].y;
- a = base[3].y = ( base[2].y + b ) / 2;
- b = base[1].y = ( base[0].y + b ) / 2;
- base[2].y = ( a + b ) / 2;
+ a = base[0].y + base[1].y;
+ b = base[1].y + base[2].y;
+ base[3].y = b >> 1;
+ base[2].y = ( a + b ) >> 2;
+ base[1].y = a >> 1;
/* hand optimized. gcc doesn't seem to be too good at common */
/* expression substitution and instruction scheduling ;-) */
@@ -947,28 +947,32 @@
static void
Split_Cubic( TPoint* base )
{
- Long a, b, c, d;
+ Long a, b, c;
base[6].x = base[3].x;
- c = base[1].x;
- d = base[2].x;
- base[1].x = a = ( base[0].x + c + 1 ) >> 1;
- base[5].x = b = ( base[3].x + d + 1 ) >> 1;
- c = ( c + d + 1 ) >> 1;
- base[2].x = a = ( a + c + 1 ) >> 1;
- base[4].x = b = ( b + c + 1 ) >> 1;
- base[3].x = ( a + b + 1 ) >> 1;
+ a = base[0].x + base[1].x;
+ b = base[1].x + base[2].x;
+ c = base[2].x + base[3].x;
+ base[5].x = c >> 1;
+ c += b;
+ base[4].x = c >> 2;
+ base[1].x = a >> 1;
+ a += b;
+ base[2].x = a >> 2;
+ base[3].x = ( a + c ) >> 3;
base[6].y = base[3].y;
- c = base[1].y;
- d = base[2].y;
- base[1].y = a = ( base[0].y + c + 1 ) >> 1;
- base[5].y = b = ( base[3].y + d + 1 ) >> 1;
- c = ( c + d + 1 ) >> 1;
- base[2].y = a = ( a + c + 1 ) >> 1;
- base[4].y = b = ( b + c + 1 ) >> 1;
- base[3].y = ( a + b + 1 ) >> 1;
+ a = base[0].y + base[1].y;
+ b = base[1].y + base[2].y;
+ c = base[2].y + base[3].y;
+ base[5].y = c >> 1;
+ c += b;
+ base[4].y = c >> 2;
+ base[1].y = a >> 1;
+ a += b;
+ base[2].y = a >> 2;
+ base[3].y = ( a + c ) >> 3;
}
@@ -2784,7 +2788,7 @@
P_Left = draw_left;
P_Right = draw_right;
- while ( P_Left )
+ while ( P_Left && P_Right )
{
x1 = P_Left ->X;
x2 = P_Right->X;
@@ -2885,7 +2889,7 @@
P_Left = draw_left;
P_Right = draw_right;
- while ( P_Left )
+ while ( P_Left && P_Right )
{
if ( P_Left->countL )
{
@@ -3257,7 +3261,9 @@
const FT_Outline* outline = (const FT_Outline*)params->source;
const FT_Bitmap* target_map = params->target;
+#ifndef FT_STATIC_RASTER
black_TWorker worker[1];
+#endif
Long buffer[FT_MAX_BLACK_POOL];
@@ -3299,8 +3305,8 @@
ras.outline = *outline;
ras.target = *target_map;
- worker->buff = buffer;
- worker->sizeBuff = (&buffer)[1]; /* Points to right after buffer. */
+ ras.buff = buffer;
+ ras.sizeBuff = (&buffer)[1]; /* Points to right after buffer. */
return Render_Glyph( RAS_VAR );
}
diff --git a/thirdparty/freetype/src/sfnt/rules.mk b/thirdparty/freetype/src/sfnt/rules.mk
index ff9e7c6117..ee3314eac3 100644
--- a/thirdparty/freetype/src/sfnt/rules.mk
+++ b/thirdparty/freetype/src/sfnt/rules.mk
@@ -31,6 +31,7 @@ SFNT_COMPILE := $(CC) $(ANSIFLAGS) \
SFNT_DRV_SRC := $(SFNT_DIR)/pngshim.c \
$(SFNT_DIR)/sfdriver.c \
$(SFNT_DIR)/sfobjs.c \
+ $(SFNT_DIR)/sfwoff.c \
$(SFNT_DIR)/ttbdf.c \
$(SFNT_DIR)/ttcmap.c \
$(SFNT_DIR)/ttcolr.c \
diff --git a/thirdparty/freetype/src/sfnt/sfdriver.c b/thirdparty/freetype/src/sfnt/sfdriver.c
index c467ff4d37..2611685284 100644
--- a/thirdparty/freetype/src/sfnt/sfdriver.c
+++ b/thirdparty/freetype/src/sfnt/sfdriver.c
@@ -182,8 +182,8 @@
static FT_UInt
- sfnt_get_name_index( FT_Face face,
- FT_String* glyph_name )
+ sfnt_get_name_index( FT_Face face,
+ const FT_String* glyph_name )
{
TT_Face ttface = (TT_Face)face;
@@ -375,47 +375,61 @@
{
case 15:
k4 ^= (FT_UInt32)tail[14] << 16;
+ /* fall through */
case 14:
k4 ^= (FT_UInt32)tail[13] << 8;
+ /* fall through */
case 13:
k4 ^= (FT_UInt32)tail[12];
k4 *= c4;
k4 = ROTL32( k4, 18 );
k4 *= c1;
h4 ^= k4;
+ /* fall through */
case 12:
k3 ^= (FT_UInt32)tail[11] << 24;
+ /* fall through */
case 11:
k3 ^= (FT_UInt32)tail[10] << 16;
+ /* fall through */
case 10:
k3 ^= (FT_UInt32)tail[9] << 8;
+ /* fall through */
case 9:
k3 ^= (FT_UInt32)tail[8];
k3 *= c3;
k3 = ROTL32( k3, 17 );
k3 *= c4;
h3 ^= k3;
+ /* fall through */
case 8:
k2 ^= (FT_UInt32)tail[7] << 24;
+ /* fall through */
case 7:
k2 ^= (FT_UInt32)tail[6] << 16;
+ /* fall through */
case 6:
k2 ^= (FT_UInt32)tail[5] << 8;
+ /* fall through */
case 5:
k2 ^= (FT_UInt32)tail[4];
k2 *= c2;
k2 = ROTL32( k2, 16 );
k2 *= c3;
h2 ^= k2;
+ /* fall through */
case 4:
k1 ^= (FT_UInt32)tail[3] << 24;
+ /* fall through */
case 3:
k1 ^= (FT_UInt32)tail[2] << 16;
+ /* fall through */
case 2:
k1 ^= (FT_UInt32)tail[1] << 8;
+ /* fall through */
case 1:
k1 ^= (FT_UInt32)tail[0];
k1 *= c1;
diff --git a/thirdparty/freetype/src/sfnt/sfnt.c b/thirdparty/freetype/src/sfnt/sfnt.c
index 5a503f30c5..b4faf34a3a 100644
--- a/thirdparty/freetype/src/sfnt/sfnt.c
+++ b/thirdparty/freetype/src/sfnt/sfnt.c
@@ -22,6 +22,7 @@
#include "pngshim.c"
#include "sfdriver.c"
#include "sfobjs.c"
+#include "sfwoff.c"
#include "ttbdf.c"
#include "ttcmap.c"
#include "ttcolr.c"
diff --git a/thirdparty/freetype/src/sfnt/sfobjs.c b/thirdparty/freetype/src/sfnt/sfobjs.c
index 0b43d251b8..6edf3ae1de 100644
--- a/thirdparty/freetype/src/sfnt/sfobjs.c
+++ b/thirdparty/freetype/src/sfnt/sfobjs.c
@@ -21,13 +21,13 @@
#include "ttload.h"
#include "ttcmap.h"
#include "ttkern.h"
+#include "sfwoff.h"
#include FT_INTERNAL_SFNT_H
#include FT_INTERNAL_DEBUG_H
#include FT_TRUETYPE_IDS_H
#include FT_TRUETYPE_TAGS_H
#include FT_SERVICE_POSTSCRIPT_CMAPS_H
#include FT_SFNT_NAMES_H
-#include FT_GZIP_H
#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
#include FT_SERVICE_MULTIPLE_MASTERS_H
@@ -337,403 +337,6 @@
}
-#define WRITE_USHORT( p, v ) \
- do \
- { \
- *(p)++ = (FT_Byte)( (v) >> 8 ); \
- *(p)++ = (FT_Byte)( (v) >> 0 ); \
- \
- } while ( 0 )
-
-#define WRITE_ULONG( p, v ) \
- do \
- { \
- *(p)++ = (FT_Byte)( (v) >> 24 ); \
- *(p)++ = (FT_Byte)( (v) >> 16 ); \
- *(p)++ = (FT_Byte)( (v) >> 8 ); \
- *(p)++ = (FT_Byte)( (v) >> 0 ); \
- \
- } while ( 0 )
-
-
- static void
- sfnt_stream_close( FT_Stream stream )
- {
- FT_Memory memory = stream->memory;
-
-
- FT_FREE( stream->base );
-
- stream->size = 0;
- stream->base = NULL;
- stream->close = NULL;
- }
-
-
- FT_CALLBACK_DEF( int )
- compare_offsets( const void* a,
- const void* b )
- {
- WOFF_Table table1 = *(WOFF_Table*)a;
- WOFF_Table table2 = *(WOFF_Table*)b;
-
- FT_ULong offset1 = table1->Offset;
- FT_ULong offset2 = table2->Offset;
-
-
- if ( offset1 > offset2 )
- return 1;
- else if ( offset1 < offset2 )
- return -1;
- else
- return 0;
- }
-
-
- /* Replace `face->root.stream' with a stream containing the extracted */
- /* SFNT of a WOFF font. */
-
- static FT_Error
- woff_open_font( FT_Stream stream,
- TT_Face face )
- {
- FT_Memory memory = stream->memory;
- FT_Error error = FT_Err_Ok;
-
- WOFF_HeaderRec woff;
- WOFF_Table tables = NULL;
- WOFF_Table* indices = NULL;
-
- FT_ULong woff_offset;
-
- FT_Byte* sfnt = NULL;
- FT_Stream sfnt_stream = NULL;
-
- FT_Byte* sfnt_header;
- FT_ULong sfnt_offset;
-
- FT_Int nn;
- FT_ULong old_tag = 0;
-
- static const FT_Frame_Field woff_header_fields[] =
- {
-#undef FT_STRUCTURE
-#define FT_STRUCTURE WOFF_HeaderRec
-
- FT_FRAME_START( 44 ),
- FT_FRAME_ULONG ( signature ),
- FT_FRAME_ULONG ( flavor ),
- FT_FRAME_ULONG ( length ),
- FT_FRAME_USHORT( num_tables ),
- FT_FRAME_USHORT( reserved ),
- FT_FRAME_ULONG ( totalSfntSize ),
- FT_FRAME_USHORT( majorVersion ),
- FT_FRAME_USHORT( minorVersion ),
- FT_FRAME_ULONG ( metaOffset ),
- FT_FRAME_ULONG ( metaLength ),
- FT_FRAME_ULONG ( metaOrigLength ),
- FT_FRAME_ULONG ( privOffset ),
- FT_FRAME_ULONG ( privLength ),
- FT_FRAME_END
- };
-
-
- FT_ASSERT( stream == face->root.stream );
- FT_ASSERT( FT_STREAM_POS() == 0 );
-
- if ( FT_STREAM_READ_FIELDS( woff_header_fields, &woff ) )
- return error;
-
- /* Make sure we don't recurse back here or hit TTC code. */
- if ( woff.flavor == TTAG_wOFF || woff.flavor == TTAG_ttcf )
- return FT_THROW( Invalid_Table );
-
- /* Miscellaneous checks. */
- if ( woff.length != stream->size ||
- woff.num_tables == 0 ||
- 44 + woff.num_tables * 20UL >= woff.length ||
- 12 + woff.num_tables * 16UL >= woff.totalSfntSize ||
- ( woff.totalSfntSize & 3 ) != 0 ||
- ( woff.metaOffset == 0 && ( woff.metaLength != 0 ||
- woff.metaOrigLength != 0 ) ) ||
- ( woff.metaLength != 0 && woff.metaOrigLength == 0 ) ||
- ( woff.privOffset == 0 && woff.privLength != 0 ) )
- {
- FT_ERROR(( "woff_font_open: invalid WOFF header\n" ));
- return FT_THROW( Invalid_Table );
- }
-
- /* Don't trust `totalSfntSize' before thorough checks. */
- if ( FT_ALLOC( sfnt, 12 + woff.num_tables * 16UL ) ||
- FT_NEW( sfnt_stream ) )
- goto Exit;
-
- sfnt_header = sfnt;
-
- /* Write sfnt header. */
- {
- FT_UInt searchRange, entrySelector, rangeShift, x;
-
-
- x = woff.num_tables;
- entrySelector = 0;
- while ( x )
- {
- x >>= 1;
- entrySelector += 1;
- }
- entrySelector--;
-
- searchRange = ( 1 << entrySelector ) * 16;
- rangeShift = woff.num_tables * 16 - searchRange;
-
- WRITE_ULONG ( sfnt_header, woff.flavor );
- WRITE_USHORT( sfnt_header, woff.num_tables );
- WRITE_USHORT( sfnt_header, searchRange );
- WRITE_USHORT( sfnt_header, entrySelector );
- WRITE_USHORT( sfnt_header, rangeShift );
- }
-
- /* While the entries in the sfnt header must be sorted by the */
- /* tag value, the tables themselves are not. We thus have to */
- /* sort them by offset and check that they don't overlap. */
-
- if ( FT_NEW_ARRAY( tables, woff.num_tables ) ||
- FT_NEW_ARRAY( indices, woff.num_tables ) )
- goto Exit;
-
- FT_TRACE2(( "\n"
- " tag offset compLen origLen checksum\n"
- " -------------------------------------------\n" ));
-
- if ( FT_FRAME_ENTER( 20L * woff.num_tables ) )
- goto Exit;
-
- for ( nn = 0; nn < woff.num_tables; nn++ )
- {
- WOFF_Table table = tables + nn;
-
- table->Tag = FT_GET_TAG4();
- table->Offset = FT_GET_ULONG();
- table->CompLength = FT_GET_ULONG();
- table->OrigLength = FT_GET_ULONG();
- table->CheckSum = FT_GET_ULONG();
-
- FT_TRACE2(( " %c%c%c%c %08lx %08lx %08lx %08lx\n",
- (FT_Char)( table->Tag >> 24 ),
- (FT_Char)( table->Tag >> 16 ),
- (FT_Char)( table->Tag >> 8 ),
- (FT_Char)( table->Tag ),
- table->Offset,
- table->CompLength,
- table->OrigLength,
- table->CheckSum ));
-
- if ( table->Tag <= old_tag )
- {
- FT_FRAME_EXIT();
-
- FT_ERROR(( "woff_font_open: table tags are not sorted\n" ));
- error = FT_THROW( Invalid_Table );
- goto Exit;
- }
-
- old_tag = table->Tag;
- indices[nn] = table;
- }
-
- FT_FRAME_EXIT();
-
- /* Sort by offset. */
-
- ft_qsort( indices,
- woff.num_tables,
- sizeof ( WOFF_Table ),
- compare_offsets );
-
- /* Check offsets and lengths. */
-
- woff_offset = 44 + woff.num_tables * 20L;
- sfnt_offset = 12 + woff.num_tables * 16L;
-
- for ( nn = 0; nn < woff.num_tables; nn++ )
- {
- WOFF_Table table = indices[nn];
-
-
- if ( table->Offset != woff_offset ||
- table->CompLength > woff.length ||
- table->Offset > woff.length - table->CompLength ||
- table->OrigLength > woff.totalSfntSize ||
- sfnt_offset > woff.totalSfntSize - table->OrigLength ||
- table->CompLength > table->OrigLength )
- {
- FT_ERROR(( "woff_font_open: invalid table offsets\n" ));
- error = FT_THROW( Invalid_Table );
- goto Exit;
- }
-
- table->OrigOffset = sfnt_offset;
-
- /* The offsets must be multiples of 4. */
- woff_offset += ( table->CompLength + 3 ) & ~3U;
- sfnt_offset += ( table->OrigLength + 3 ) & ~3U;
- }
-
- /*
- * Final checks!
- *
- * We don't decode and check the metadata block.
- * We don't check table checksums either.
- * But other than those, I think we implement all
- * `MUST' checks from the spec.
- */
-
- if ( woff.metaOffset )
- {
- if ( woff.metaOffset != woff_offset ||
- woff.metaOffset + woff.metaLength > woff.length )
- {
- FT_ERROR(( "woff_font_open:"
- " invalid `metadata' offset or length\n" ));
- error = FT_THROW( Invalid_Table );
- goto Exit;
- }
-
- /* We have padding only ... */
- woff_offset += woff.metaLength;
- }
-
- if ( woff.privOffset )
- {
- /* ... if it isn't the last block. */
- woff_offset = ( woff_offset + 3 ) & ~3U;
-
- if ( woff.privOffset != woff_offset ||
- woff.privOffset + woff.privLength > woff.length )
- {
- FT_ERROR(( "woff_font_open: invalid `private' offset or length\n" ));
- error = FT_THROW( Invalid_Table );
- goto Exit;
- }
-
- /* No padding for the last block. */
- woff_offset += woff.privLength;
- }
-
- if ( sfnt_offset != woff.totalSfntSize ||
- woff_offset != woff.length )
- {
- FT_ERROR(( "woff_font_open: invalid `sfnt' table structure\n" ));
- error = FT_THROW( Invalid_Table );
- goto Exit;
- }
-
- /* Now use `totalSfntSize'. */
- if ( FT_REALLOC( sfnt,
- 12 + woff.num_tables * 16UL,
- woff.totalSfntSize ) )
- goto Exit;
-
- sfnt_header = sfnt + 12;
-
- /* Write the tables. */
-
- for ( nn = 0; nn < woff.num_tables; nn++ )
- {
- WOFF_Table table = tables + nn;
-
-
- /* Write SFNT table entry. */
- WRITE_ULONG( sfnt_header, table->Tag );
- WRITE_ULONG( sfnt_header, table->CheckSum );
- WRITE_ULONG( sfnt_header, table->OrigOffset );
- WRITE_ULONG( sfnt_header, table->OrigLength );
-
- /* Write table data. */
- if ( FT_STREAM_SEEK( table->Offset ) ||
- FT_FRAME_ENTER( table->CompLength ) )
- goto Exit;
-
- if ( table->CompLength == table->OrigLength )
- {
- /* Uncompressed data; just copy. */
- ft_memcpy( sfnt + table->OrigOffset,
- stream->cursor,
- table->OrigLength );
- }
- else
- {
-#ifdef FT_CONFIG_OPTION_USE_ZLIB
-
- /* Uncompress with zlib. */
- FT_ULong output_len = table->OrigLength;
-
-
- error = FT_Gzip_Uncompress( memory,
- sfnt + table->OrigOffset, &output_len,
- stream->cursor, table->CompLength );
- if ( error )
- goto Exit;
- if ( output_len != table->OrigLength )
- {
- FT_ERROR(( "woff_font_open: compressed table length mismatch\n" ));
- error = FT_THROW( Invalid_Table );
- goto Exit;
- }
-
-#else /* !FT_CONFIG_OPTION_USE_ZLIB */
-
- error = FT_THROW( Unimplemented_Feature );
- goto Exit;
-
-#endif /* !FT_CONFIG_OPTION_USE_ZLIB */
- }
-
- FT_FRAME_EXIT();
-
- /* We don't check whether the padding bytes in the WOFF file are */
- /* actually '\0'. For the output, however, we do set them properly. */
- sfnt_offset = table->OrigOffset + table->OrigLength;
- while ( sfnt_offset & 3 )
- {
- sfnt[sfnt_offset] = '\0';
- sfnt_offset++;
- }
- }
-
- /* Ok! Finally ready. Swap out stream and return. */
- FT_Stream_OpenMemory( sfnt_stream, sfnt, woff.totalSfntSize );
- sfnt_stream->memory = stream->memory;
- sfnt_stream->close = sfnt_stream_close;
-
- FT_Stream_Free(
- face->root.stream,
- ( face->root.face_flags & FT_FACE_FLAG_EXTERNAL_STREAM ) != 0 );
-
- face->root.stream = sfnt_stream;
-
- face->root.face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM;
-
- Exit:
- FT_FREE( tables );
- FT_FREE( indices );
-
- if ( error )
- {
- FT_FREE( sfnt );
- FT_Stream_Close( sfnt_stream );
- FT_FREE( sfnt_stream );
- }
-
- return error;
- }
-
-
-#undef WRITE_USHORT
-#undef WRITE_ULONG
-
-
/* Fill in face->ttc_header. If the font is not a TTC, it is */
/* synthesized into a TTC with one offset table. */
static FT_Error
diff --git a/thirdparty/freetype/src/sfnt/sfobjs.h b/thirdparty/freetype/src/sfnt/sfobjs.h
index 17b0d50105..3fbf2dd6bd 100644
--- a/thirdparty/freetype/src/sfnt/sfobjs.h
+++ b/thirdparty/freetype/src/sfnt/sfobjs.h
@@ -53,7 +53,7 @@ FT_BEGIN_HEADER
FT_END_HEADER
-#endif /* SFDRIVER_H_ */
+#endif /* SFOBJS_H_ */
/* END */
diff --git a/thirdparty/freetype/src/sfnt/sfwoff.c b/thirdparty/freetype/src/sfnt/sfwoff.c
new file mode 100644
index 0000000000..ca4821a20a
--- /dev/null
+++ b/thirdparty/freetype/src/sfnt/sfwoff.c
@@ -0,0 +1,434 @@
+/****************************************************************************
+ *
+ * sfwoff.c
+ *
+ * WOFF format management (base).
+ *
+ * Copyright (C) 1996-2019 by
+ * David Turner, Robert Wilhelm, and Werner Lemberg.
+ *
+ * This file is part of the FreeType project, and may only be used,
+ * modified, and distributed under the terms of the FreeType project
+ * license, LICENSE.TXT. By continuing to use, modify, or distribute
+ * this file you indicate that you have read the license and
+ * understand and accept it fully.
+ *
+ */
+
+
+#include <ft2build.h>
+#include "sfwoff.h"
+#include FT_TRUETYPE_TAGS_H
+#include FT_INTERNAL_DEBUG_H
+#include FT_INTERNAL_STREAM_H
+#include FT_GZIP_H
+
+
+ /**************************************************************************
+ *
+ * The macro FT_COMPONENT is used in trace mode. It is an implicit
+ * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
+ * messages during execution.
+ */
+#undef FT_COMPONENT
+#define FT_COMPONENT sfwoff
+
+
+#define WRITE_USHORT( p, v ) \
+ do \
+ { \
+ *(p)++ = (FT_Byte)( (v) >> 8 ); \
+ *(p)++ = (FT_Byte)( (v) >> 0 ); \
+ \
+ } while ( 0 )
+
+#define WRITE_ULONG( p, v ) \
+ do \
+ { \
+ *(p)++ = (FT_Byte)( (v) >> 24 ); \
+ *(p)++ = (FT_Byte)( (v) >> 16 ); \
+ *(p)++ = (FT_Byte)( (v) >> 8 ); \
+ *(p)++ = (FT_Byte)( (v) >> 0 ); \
+ \
+ } while ( 0 )
+
+
+ static void
+ sfnt_stream_close( FT_Stream stream )
+ {
+ FT_Memory memory = stream->memory;
+
+
+ FT_FREE( stream->base );
+
+ stream->size = 0;
+ stream->base = NULL;
+ stream->close = NULL;
+ }
+
+
+ FT_CALLBACK_DEF( int )
+ compare_offsets( const void* a,
+ const void* b )
+ {
+ WOFF_Table table1 = *(WOFF_Table*)a;
+ WOFF_Table table2 = *(WOFF_Table*)b;
+
+ FT_ULong offset1 = table1->Offset;
+ FT_ULong offset2 = table2->Offset;
+
+
+ if ( offset1 > offset2 )
+ return 1;
+ else if ( offset1 < offset2 )
+ return -1;
+ else
+ return 0;
+ }
+
+
+ /* Replace `face->root.stream' with a stream containing the extracted */
+ /* SFNT of a WOFF font. */
+
+ FT_LOCAL_DEF( FT_Error )
+ woff_open_font( FT_Stream stream,
+ TT_Face face )
+ {
+ FT_Memory memory = stream->memory;
+ FT_Error error = FT_Err_Ok;
+
+ WOFF_HeaderRec woff;
+ WOFF_Table tables = NULL;
+ WOFF_Table* indices = NULL;
+
+ FT_ULong woff_offset;
+
+ FT_Byte* sfnt = NULL;
+ FT_Stream sfnt_stream = NULL;
+
+ FT_Byte* sfnt_header;
+ FT_ULong sfnt_offset;
+
+ FT_Int nn;
+ FT_ULong old_tag = 0;
+
+ static const FT_Frame_Field woff_header_fields[] =
+ {
+#undef FT_STRUCTURE
+#define FT_STRUCTURE WOFF_HeaderRec
+
+ FT_FRAME_START( 44 ),
+ FT_FRAME_ULONG ( signature ),
+ FT_FRAME_ULONG ( flavor ),
+ FT_FRAME_ULONG ( length ),
+ FT_FRAME_USHORT( num_tables ),
+ FT_FRAME_USHORT( reserved ),
+ FT_FRAME_ULONG ( totalSfntSize ),
+ FT_FRAME_USHORT( majorVersion ),
+ FT_FRAME_USHORT( minorVersion ),
+ FT_FRAME_ULONG ( metaOffset ),
+ FT_FRAME_ULONG ( metaLength ),
+ FT_FRAME_ULONG ( metaOrigLength ),
+ FT_FRAME_ULONG ( privOffset ),
+ FT_FRAME_ULONG ( privLength ),
+ FT_FRAME_END
+ };
+
+
+ FT_ASSERT( stream == face->root.stream );
+ FT_ASSERT( FT_STREAM_POS() == 0 );
+
+ if ( FT_STREAM_READ_FIELDS( woff_header_fields, &woff ) )
+ return error;
+
+ /* Make sure we don't recurse back here or hit TTC code. */
+ if ( woff.flavor == TTAG_wOFF || woff.flavor == TTAG_ttcf )
+ return FT_THROW( Invalid_Table );
+
+ /* Miscellaneous checks. */
+ if ( woff.length != stream->size ||
+ woff.num_tables == 0 ||
+ 44 + woff.num_tables * 20UL >= woff.length ||
+ 12 + woff.num_tables * 16UL >= woff.totalSfntSize ||
+ ( woff.totalSfntSize & 3 ) != 0 ||
+ ( woff.metaOffset == 0 && ( woff.metaLength != 0 ||
+ woff.metaOrigLength != 0 ) ) ||
+ ( woff.metaLength != 0 && woff.metaOrigLength == 0 ) ||
+ ( woff.privOffset == 0 && woff.privLength != 0 ) )
+ {
+ FT_ERROR(( "woff_font_open: invalid WOFF header\n" ));
+ return FT_THROW( Invalid_Table );
+ }
+
+ /* Don't trust `totalSfntSize' before thorough checks. */
+ if ( FT_ALLOC( sfnt, 12 + woff.num_tables * 16UL ) ||
+ FT_NEW( sfnt_stream ) )
+ goto Exit;
+
+ sfnt_header = sfnt;
+
+ /* Write sfnt header. */
+ {
+ FT_UInt searchRange, entrySelector, rangeShift, x;
+
+
+ x = woff.num_tables;
+ entrySelector = 0;
+ while ( x )
+ {
+ x >>= 1;
+ entrySelector += 1;
+ }
+ entrySelector--;
+
+ searchRange = ( 1 << entrySelector ) * 16;
+ rangeShift = woff.num_tables * 16 - searchRange;
+
+ WRITE_ULONG ( sfnt_header, woff.flavor );
+ WRITE_USHORT( sfnt_header, woff.num_tables );
+ WRITE_USHORT( sfnt_header, searchRange );
+ WRITE_USHORT( sfnt_header, entrySelector );
+ WRITE_USHORT( sfnt_header, rangeShift );
+ }
+
+ /* While the entries in the sfnt header must be sorted by the */
+ /* tag value, the tables themselves are not. We thus have to */
+ /* sort them by offset and check that they don't overlap. */
+
+ if ( FT_NEW_ARRAY( tables, woff.num_tables ) ||
+ FT_NEW_ARRAY( indices, woff.num_tables ) )
+ goto Exit;
+
+ FT_TRACE2(( "\n"
+ " tag offset compLen origLen checksum\n"
+ " -------------------------------------------\n" ));
+
+ if ( FT_FRAME_ENTER( 20L * woff.num_tables ) )
+ goto Exit;
+
+ for ( nn = 0; nn < woff.num_tables; nn++ )
+ {
+ WOFF_Table table = tables + nn;
+
+ table->Tag = FT_GET_TAG4();
+ table->Offset = FT_GET_ULONG();
+ table->CompLength = FT_GET_ULONG();
+ table->OrigLength = FT_GET_ULONG();
+ table->CheckSum = FT_GET_ULONG();
+
+ FT_TRACE2(( " %c%c%c%c %08lx %08lx %08lx %08lx\n",
+ (FT_Char)( table->Tag >> 24 ),
+ (FT_Char)( table->Tag >> 16 ),
+ (FT_Char)( table->Tag >> 8 ),
+ (FT_Char)( table->Tag ),
+ table->Offset,
+ table->CompLength,
+ table->OrigLength,
+ table->CheckSum ));
+
+ if ( table->Tag <= old_tag )
+ {
+ FT_FRAME_EXIT();
+
+ FT_ERROR(( "woff_font_open: table tags are not sorted\n" ));
+ error = FT_THROW( Invalid_Table );
+ goto Exit;
+ }
+
+ old_tag = table->Tag;
+ indices[nn] = table;
+ }
+
+ FT_FRAME_EXIT();
+
+ /* Sort by offset. */
+
+ ft_qsort( indices,
+ woff.num_tables,
+ sizeof ( WOFF_Table ),
+ compare_offsets );
+
+ /* Check offsets and lengths. */
+
+ woff_offset = 44 + woff.num_tables * 20L;
+ sfnt_offset = 12 + woff.num_tables * 16L;
+
+ for ( nn = 0; nn < woff.num_tables; nn++ )
+ {
+ WOFF_Table table = indices[nn];
+
+
+ if ( table->Offset != woff_offset ||
+ table->CompLength > woff.length ||
+ table->Offset > woff.length - table->CompLength ||
+ table->OrigLength > woff.totalSfntSize ||
+ sfnt_offset > woff.totalSfntSize - table->OrigLength ||
+ table->CompLength > table->OrigLength )
+ {
+ FT_ERROR(( "woff_font_open: invalid table offsets\n" ));
+ error = FT_THROW( Invalid_Table );
+ goto Exit;
+ }
+
+ table->OrigOffset = sfnt_offset;
+
+ /* The offsets must be multiples of 4. */
+ woff_offset += ( table->CompLength + 3 ) & ~3U;
+ sfnt_offset += ( table->OrigLength + 3 ) & ~3U;
+ }
+
+ /*
+ * Final checks!
+ *
+ * We don't decode and check the metadata block.
+ * We don't check table checksums either.
+ * But other than those, I think we implement all
+ * `MUST' checks from the spec.
+ */
+
+ if ( woff.metaOffset )
+ {
+ if ( woff.metaOffset != woff_offset ||
+ woff.metaOffset + woff.metaLength > woff.length )
+ {
+ FT_ERROR(( "woff_font_open:"
+ " invalid `metadata' offset or length\n" ));
+ error = FT_THROW( Invalid_Table );
+ goto Exit;
+ }
+
+ /* We have padding only ... */
+ woff_offset += woff.metaLength;
+ }
+
+ if ( woff.privOffset )
+ {
+ /* ... if it isn't the last block. */
+ woff_offset = ( woff_offset + 3 ) & ~3U;
+
+ if ( woff.privOffset != woff_offset ||
+ woff.privOffset + woff.privLength > woff.length )
+ {
+ FT_ERROR(( "woff_font_open: invalid `private' offset or length\n" ));
+ error = FT_THROW( Invalid_Table );
+ goto Exit;
+ }
+
+ /* No padding for the last block. */
+ woff_offset += woff.privLength;
+ }
+
+ if ( sfnt_offset != woff.totalSfntSize ||
+ woff_offset != woff.length )
+ {
+ FT_ERROR(( "woff_font_open: invalid `sfnt' table structure\n" ));
+ error = FT_THROW( Invalid_Table );
+ goto Exit;
+ }
+
+ /* Now use `totalSfntSize'. */
+ if ( FT_REALLOC( sfnt,
+ 12 + woff.num_tables * 16UL,
+ woff.totalSfntSize ) )
+ goto Exit;
+
+ sfnt_header = sfnt + 12;
+
+ /* Write the tables. */
+
+ for ( nn = 0; nn < woff.num_tables; nn++ )
+ {
+ WOFF_Table table = tables + nn;
+
+
+ /* Write SFNT table entry. */
+ WRITE_ULONG( sfnt_header, table->Tag );
+ WRITE_ULONG( sfnt_header, table->CheckSum );
+ WRITE_ULONG( sfnt_header, table->OrigOffset );
+ WRITE_ULONG( sfnt_header, table->OrigLength );
+
+ /* Write table data. */
+ if ( FT_STREAM_SEEK( table->Offset ) ||
+ FT_FRAME_ENTER( table->CompLength ) )
+ goto Exit;
+
+ if ( table->CompLength == table->OrigLength )
+ {
+ /* Uncompressed data; just copy. */
+ ft_memcpy( sfnt + table->OrigOffset,
+ stream->cursor,
+ table->OrigLength );
+ }
+ else
+ {
+#ifdef FT_CONFIG_OPTION_USE_ZLIB
+
+ /* Uncompress with zlib. */
+ FT_ULong output_len = table->OrigLength;
+
+
+ error = FT_Gzip_Uncompress( memory,
+ sfnt + table->OrigOffset, &output_len,
+ stream->cursor, table->CompLength );
+ if ( error )
+ goto Exit;
+ if ( output_len != table->OrigLength )
+ {
+ FT_ERROR(( "woff_font_open: compressed table length mismatch\n" ));
+ error = FT_THROW( Invalid_Table );
+ goto Exit;
+ }
+
+#else /* !FT_CONFIG_OPTION_USE_ZLIB */
+
+ error = FT_THROW( Unimplemented_Feature );
+ goto Exit;
+
+#endif /* !FT_CONFIG_OPTION_USE_ZLIB */
+ }
+
+ FT_FRAME_EXIT();
+
+ /* We don't check whether the padding bytes in the WOFF file are */
+ /* actually '\0'. For the output, however, we do set them properly. */
+ sfnt_offset = table->OrigOffset + table->OrigLength;
+ while ( sfnt_offset & 3 )
+ {
+ sfnt[sfnt_offset] = '\0';
+ sfnt_offset++;
+ }
+ }
+
+ /* Ok! Finally ready. Swap out stream and return. */
+ FT_Stream_OpenMemory( sfnt_stream, sfnt, woff.totalSfntSize );
+ sfnt_stream->memory = stream->memory;
+ sfnt_stream->close = sfnt_stream_close;
+
+ FT_Stream_Free(
+ face->root.stream,
+ ( face->root.face_flags & FT_FACE_FLAG_EXTERNAL_STREAM ) != 0 );
+
+ face->root.stream = sfnt_stream;
+
+ face->root.face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM;
+
+ Exit:
+ FT_FREE( tables );
+ FT_FREE( indices );
+
+ if ( error )
+ {
+ FT_FREE( sfnt );
+ FT_Stream_Close( sfnt_stream );
+ FT_FREE( sfnt_stream );
+ }
+
+ return error;
+ }
+
+
+#undef WRITE_USHORT
+#undef WRITE_ULONG
+
+
+/* END */
diff --git a/thirdparty/freetype/src/sfnt/sfwoff.h b/thirdparty/freetype/src/sfnt/sfwoff.h
new file mode 100644
index 0000000000..15495c32a2
--- /dev/null
+++ b/thirdparty/freetype/src/sfnt/sfwoff.h
@@ -0,0 +1,41 @@
+/****************************************************************************
+ *
+ * sfwoff.h
+ *
+ * WOFFF format management (specification).
+ *
+ * Copyright (C) 1996-2019 by
+ * David Turner, Robert Wilhelm, and Werner Lemberg.
+ *
+ * This file is part of the FreeType project, and may only be used,
+ * modified, and distributed under the terms of the FreeType project
+ * license, LICENSE.TXT. By continuing to use, modify, or distribute
+ * this file you indicate that you have read the license and
+ * understand and accept it fully.
+ *
+ */
+
+
+#ifndef SFWOFF_H_
+#define SFWOFF_H_
+
+
+#include <ft2build.h>
+#include FT_INTERNAL_SFNT_H
+#include FT_INTERNAL_OBJECTS_H
+
+
+FT_BEGIN_HEADER
+
+
+ FT_LOCAL( FT_Error )
+ woff_open_font( FT_Stream stream,
+ TT_Face face );
+
+
+FT_END_HEADER
+
+#endif /* SFWOFF_H_ */
+
+
+/* END */
diff --git a/thirdparty/freetype/src/sfnt/ttcmap.c b/thirdparty/freetype/src/sfnt/ttcmap.c
index 8d9737310c..683f3b1818 100644
--- a/thirdparty/freetype/src/sfnt/ttcmap.c
+++ b/thirdparty/freetype/src/sfnt/ttcmap.c
@@ -2368,10 +2368,7 @@
/* if `gindex' is invalid, the remaining values */
/* in this group are invalid, too */
if ( gindex >= (FT_UInt)face->num_glyphs )
- {
- gindex = 0;
continue;
- }
cmap->cur_charcode = char_code;
cmap->cur_gindex = gindex;
@@ -3661,7 +3658,7 @@
tt_get_glyph_name( TT_Face face,
FT_UInt idx )
{
- FT_String* PSname;
+ FT_String* PSname = NULL;
tt_face_get_ps_name( face, idx, &PSname );
diff --git a/thirdparty/freetype/src/sfnt/ttmtx.c b/thirdparty/freetype/src/sfnt/ttmtx.c
index 7a4d2be2cb..b6725c962f 100644
--- a/thirdparty/freetype/src/sfnt/ttmtx.c
+++ b/thirdparty/freetype/src/sfnt/ttmtx.c
@@ -280,7 +280,7 @@
else
{
table_pos += 4 * ( k - 1 );
- if ( table_pos + 4 > table_end )
+ if ( table_pos + 2 > table_end )
goto NoData;
if ( FT_STREAM_SEEK( table_pos ) ||
@@ -292,7 +292,9 @@
*abearing = 0;
else
{
- if ( !FT_STREAM_SEEK( table_pos ) )
+ if ( FT_STREAM_SEEK( table_pos ) )
+ *abearing = 0;
+ else
(void)FT_READ_SHORT( *abearing );
}
}
diff --git a/thirdparty/freetype/src/smooth/ftgrays.c b/thirdparty/freetype/src/smooth/ftgrays.c
index 91293ac946..fd357a50fc 100644
--- a/thirdparty/freetype/src/smooth/ftgrays.c
+++ b/thirdparty/freetype/src/smooth/ftgrays.c
@@ -45,7 +45,7 @@
* This is a new anti-aliasing scan-converter for FreeType 2. The
* algorithm used here is _very_ different from the one in the standard
* `ftraster' module. Actually, `ftgrays' computes the _exact_
- * coverage of the outline on each pixel cell.
+ * coverage of the outline on each pixel cell by straight segments.
*
* It is based on ideas that I initially found in Raph Levien's
* excellent LibArt graphics library (see https://www.levien.com/libart
@@ -58,6 +58,14 @@
* different way, and I don't use sorted vector paths. Also, it doesn't
* use floating point values.
*
+ * Bézier segments are flattened by splitting them until their deviation
+ * from straight line becomes much smaller than a pixel. Therefore, the
+ * pixel coverage by a Bézier curve is calculated approximately. To
+ * estimate the deviation, we use the distance from the control point
+ * to the conic chord centre or the cubic chord trisection. These
+ * distances vanish fast after each split. In the conic case, they vanish
+ * predictably and the number of necessary splits can be calculated.
+ *
* This renderer has the following advantages:
*
* - It doesn't need an intermediate bitmap. Instead, one can supply a
@@ -67,7 +75,7 @@
* callback.
*
* - A perfect anti-aliaser, i.e., it computes the _exact_ coverage on
- * each pixel cell.
+ * each pixel cell by straight segments.
*
* - It performs a single pass on the outline (the `standard' FT2
* renderer makes two passes).
@@ -75,7 +83,7 @@
* - It can easily be modified to render to _any_ number of gray levels
* cheaply.
*
- * - For small (< 20) pixel sizes, it is faster than the standard
+ * - For small (< 80) pixel sizes, it is faster than the standard
* renderer.
*
*/
@@ -327,17 +335,9 @@ typedef ptrdiff_t FT_PtrDist;
/* must be at least 6 bits! */
#define PIXEL_BITS 8
-#undef FLOOR
-#undef CEILING
-#undef TRUNC
-#undef SCALED
-
#define ONE_PIXEL ( 1 << PIXEL_BITS )
-#define TRUNC( x ) ( (TCoord)( (x) >> PIXEL_BITS ) )
-#define SUBPIXELS( x ) ( (TPos)(x) * ONE_PIXEL )
-#define FLOOR( x ) ( (x) & -ONE_PIXEL )
-#define CEILING( x ) ( ( (x) + ONE_PIXEL - 1 ) & -ONE_PIXEL )
-#define ROUND( x ) ( ( (x) + ONE_PIXEL / 2 ) & -ONE_PIXEL )
+#define TRUNC( x ) (TCoord)( (x) >> PIXEL_BITS )
+#define FRACT( x ) (TCoord)( (x) & ( ONE_PIXEL - 1 ) )
#if PIXEL_BITS >= 6
#define UPSCALE( x ) ( (x) * ( ONE_PIXEL >> 6 ) )
@@ -388,9 +388,9 @@ typedef ptrdiff_t FT_PtrDist;
#define FT_UDIVPREP( c, b ) \
long b ## _r = c ? (long)( FT_ULONG_MAX >> PIXEL_BITS ) / ( b ) \
: 0
-#define FT_UDIV( a, b ) \
- ( ( (unsigned long)( a ) * (unsigned long)( b ## _r ) ) >> \
- ( sizeof( long ) * FT_CHAR_BIT - PIXEL_BITS ) )
+#define FT_UDIV( a, b ) \
+ (TCoord)( ( (unsigned long)( a ) * (unsigned long)( b ## _r ) ) >> \
+ ( sizeof( long ) * FT_CHAR_BIT - PIXEL_BITS ) )
/**************************************************************************
@@ -432,6 +432,9 @@ typedef ptrdiff_t FT_PtrDist;
#define FT_MAX_GRAY_POOL ( 2048 / sizeof ( TCell ) )
#endif
+ /* FT_Span buffer size for direct rendering only */
+#define FT_MAX_GRAY_SPANS 10
+
#if defined( _MSC_VER ) /* Visual C++ (and Intel C++) */
/* We disable the warning `structure was padded due to */
@@ -465,6 +468,8 @@ typedef ptrdiff_t FT_PtrDist;
FT_Raster_Span_Func render_span;
void* render_span_data;
+ FT_Span spans[FT_MAX_GRAY_SPANS];
+ int num_spans;
} gray_TWorker, *gray_PWorker;
@@ -516,7 +521,7 @@ typedef ptrdiff_t FT_PtrDist;
/**************************************************************************
*
- * Record the current cell in the table.
+ * Record the current cell in the linked list.
*/
static void
gray_record_cell( RAS_ARG )
@@ -526,10 +531,9 @@ typedef ptrdiff_t FT_PtrDist;
pcell = &ras.ycells[ras.ey - ras.min_ey];
- for (;;)
+ while ( ( cell = *pcell ) )
{
- cell = *pcell;
- if ( !cell || cell->x > x )
+ if ( cell->x > x )
break;
if ( cell->x == x )
@@ -577,16 +581,13 @@ typedef ptrdiff_t FT_PtrDist;
/* Note that if a cell is to the left of the clipping region, it is */
/* actually set to the (min_ex-1) horizontal position. */
- if ( ex < ras.min_ex )
- ex = ras.min_ex - 1;
-
/* record the current one if it is valid and substantial */
if ( !ras.invalid && ( ras.area || ras.cover ) )
gray_record_cell( RAS_VAR );
ras.area = 0;
ras.cover = 0;
- ras.ex = ex;
+ ras.ex = FT_MAX( ex, ras.min_ex - 1 );
ras.ey = ey;
ras.invalid = ( ey >= ras.max_ey || ey < ras.min_ey ||
@@ -622,8 +623,8 @@ typedef ptrdiff_t FT_PtrDist;
return;
}
- fx1 = (TCoord)( x1 - SUBPIXELS( ex1 ) );
- fx2 = (TCoord)( x2 - SUBPIXELS( ex2 ) );
+ fx1 = FRACT( x1 );
+ fx2 = FRACT( x2 );
/* everything is located in a single cell. That is easy! */
/* */
@@ -650,6 +651,9 @@ typedef ptrdiff_t FT_PtrDist;
dx = -dx;
}
+ /* the fractional part of y-delta is mod/dx. It is essential to */
+ /* keep track of its accumulation for accurate rendering. */
+ /* XXX: y-delta and x-delta below should be related. */
FT_DIV_MOD( TCoord, p, dx, delta, mod );
ras.area += (TArea)( ( fx1 + first ) * delta );
@@ -715,8 +719,8 @@ typedef ptrdiff_t FT_PtrDist;
( ey1 < ras.min_ey && ey2 < ras.min_ey ) )
goto End;
- fy1 = (TCoord)( ras.y - SUBPIXELS( ey1 ) );
- fy2 = (TCoord)( to_y - SUBPIXELS( ey2 ) );
+ fy1 = FRACT( ras.y );
+ fy2 = FRACT( to_y );
/* everything is on a single scanline */
if ( ey1 == ey2 )
@@ -732,7 +736,7 @@ typedef ptrdiff_t FT_PtrDist;
if ( dx == 0 )
{
TCoord ex = TRUNC( ras.x );
- TCoord two_fx = (TCoord)( ( ras.x - SUBPIXELS( ex ) ) << 1 );
+ TCoord two_fx = FRACT( ras.x ) << 1;
TArea area;
@@ -787,6 +791,8 @@ typedef ptrdiff_t FT_PtrDist;
dy = -dy;
}
+ /* the fractional part of x-delta is mod/dy. It is essential to */
+ /* keep track of its accumulation for accurate rendering. */
FT_DIV_MOD( TCoord, p, dy, delta, mod );
x = ras.x + delta;
@@ -843,8 +849,9 @@ typedef ptrdiff_t FT_PtrDist;
gray_render_line( RAS_ARG_ TPos to_x,
TPos to_y )
{
- TPos dx, dy, fx1, fy1, fx2, fy2;
- TCoord ex1, ex2, ey1, ey2;
+ TPos dx, dy;
+ TCoord fx1, fy1, fx2, fy2;
+ TCoord ex1, ey1, ex2, ey2;
ey1 = TRUNC( ras.y );
@@ -858,8 +865,8 @@ typedef ptrdiff_t FT_PtrDist;
ex1 = TRUNC( ras.x );
ex2 = TRUNC( to_x );
- fx1 = ras.x - SUBPIXELS( ex1 );
- fy1 = ras.y - SUBPIXELS( ey1 );
+ fx1 = FRACT( ras.x );
+ fy1 = FRACT( ras.y );
dx = to_x - ras.x;
dy = to_y - ras.y;
@@ -868,8 +875,8 @@ typedef ptrdiff_t FT_PtrDist;
;
else if ( dy == 0 ) /* ex1 != ex2 */ /* any horizontal line */
{
- ex1 = ex2;
- gray_set_cell( RAS_VAR_ ex1, ey1 );
+ gray_set_cell( RAS_VAR_ ex2, ey2 );
+ goto End;
}
else if ( dx == 0 )
{
@@ -896,7 +903,7 @@ typedef ptrdiff_t FT_PtrDist;
}
else /* any other line */
{
- TPos prod = dx * fy1 - dy * fx1;
+ TPos prod = dx * (TPos)fy1 - dy * (TPos)fx1;
FT_UDIVPREP( ex1 != ex2, dx );
FT_UDIVPREP( ey1 != ey2, dy );
@@ -910,7 +917,7 @@ typedef ptrdiff_t FT_PtrDist;
prod - dx * ONE_PIXEL > 0 ) /* left */
{
fx2 = 0;
- fy2 = (TPos)FT_UDIV( -prod, -dx );
+ fy2 = FT_UDIV( -prod, -dx );
prod -= dy * ONE_PIXEL;
ras.cover += ( fy2 - fy1 );
ras.area += ( fy2 - fy1 ) * ( fx1 + fx2 );
@@ -922,7 +929,7 @@ typedef ptrdiff_t FT_PtrDist;
prod - dx * ONE_PIXEL + dy * ONE_PIXEL > 0 ) /* up */
{
prod -= dx * ONE_PIXEL;
- fx2 = (TPos)FT_UDIV( -prod, dy );
+ fx2 = FT_UDIV( -prod, dy );
fy2 = ONE_PIXEL;
ras.cover += ( fy2 - fy1 );
ras.area += ( fy2 - fy1 ) * ( fx1 + fx2 );
@@ -935,7 +942,7 @@ typedef ptrdiff_t FT_PtrDist;
{
prod += dy * ONE_PIXEL;
fx2 = ONE_PIXEL;
- fy2 = (TPos)FT_UDIV( prod, dx );
+ fy2 = FT_UDIV( prod, dx );
ras.cover += ( fy2 - fy1 );
ras.area += ( fy2 - fy1 ) * ( fx1 + fx2 );
fx1 = 0;
@@ -945,7 +952,7 @@ typedef ptrdiff_t FT_PtrDist;
else /* ( prod + dy * ONE_PIXEL < 0 &&
prod > 0 ) down */
{
- fx2 = (TPos)FT_UDIV( prod, -dy );
+ fx2 = FT_UDIV( prod, -dy );
fy2 = 0;
prod += dx * ONE_PIXEL;
ras.cover += ( fy2 - fy1 );
@@ -959,8 +966,8 @@ typedef ptrdiff_t FT_PtrDist;
} while ( ex1 != ex2 || ey1 != ey2 );
}
- fx2 = to_x - SUBPIXELS( ex2 );
- fy2 = to_y - SUBPIXELS( ey2 );
+ fx2 = FRACT( to_x );
+ fy2 = FRACT( to_y );
ras.cover += ( fy2 - fy1 );
ras.area += ( fy2 - fy1 ) * ( fx1 + fx2 );
@@ -979,16 +986,18 @@ typedef ptrdiff_t FT_PtrDist;
base[4].x = base[2].x;
- b = base[1].x;
- a = base[3].x = ( base[2].x + b ) / 2;
- b = base[1].x = ( base[0].x + b ) / 2;
- base[2].x = ( a + b ) / 2;
+ a = base[0].x + base[1].x;
+ b = base[1].x + base[2].x;
+ base[3].x = b >> 1;
+ base[2].x = ( a + b ) >> 2;
+ base[1].x = a >> 1;
base[4].y = base[2].y;
- b = base[1].y;
- a = base[3].y = ( base[2].y + b ) / 2;
- b = base[1].y = ( base[0].y + b ) / 2;
- base[2].y = ( a + b ) / 2;
+ a = base[0].y + base[1].y;
+ b = base[1].y + base[2].y;
+ base[3].y = b >> 1;
+ base[2].y = ( a + b ) >> 2;
+ base[1].y = a >> 1;
}
@@ -1042,12 +1051,11 @@ typedef ptrdiff_t FT_PtrDist;
/* many times as there are trailing zeros in the counter. */
do
{
- split = 1;
- while ( ( draw & split ) == 0 )
+ split = draw & ( -draw ); /* isolate the rightmost 1-bit */
+ while ( ( split >>= 1 ) )
{
gray_split_conic( arc );
arc += 2;
- split <<= 1;
}
gray_render_line( RAS_VAR_ arc[0].x, arc[0].y );
@@ -1060,28 +1068,32 @@ typedef ptrdiff_t FT_PtrDist;
static void
gray_split_cubic( FT_Vector* base )
{
- TPos a, b, c, d;
+ TPos a, b, c;
base[6].x = base[3].x;
- c = base[1].x;
- d = base[2].x;
- base[1].x = a = ( base[0].x + c ) / 2;
- base[5].x = b = ( base[3].x + d ) / 2;
- c = ( c + d ) / 2;
- base[2].x = a = ( a + c ) / 2;
- base[4].x = b = ( b + c ) / 2;
- base[3].x = ( a + b ) / 2;
+ a = base[0].x + base[1].x;
+ b = base[1].x + base[2].x;
+ c = base[2].x + base[3].x;
+ base[5].x = c >> 1;
+ c += b;
+ base[4].x = c >> 2;
+ base[1].x = a >> 1;
+ a += b;
+ base[2].x = a >> 2;
+ base[3].x = ( a + c ) >> 3;
base[6].y = base[3].y;
- c = base[1].y;
- d = base[2].y;
- base[1].y = a = ( base[0].y + c ) / 2;
- base[5].y = b = ( base[3].y + d ) / 2;
- c = ( c + d ) / 2;
- base[2].y = a = ( a + c ) / 2;
- base[4].y = b = ( b + c ) / 2;
- base[3].y = ( a + b ) / 2;
+ a = base[0].y + base[1].y;
+ b = base[1].y + base[2].y;
+ c = base[2].y + base[3].y;
+ base[5].y = c >> 1;
+ c += b;
+ base[4].y = c >> 2;
+ base[1].y = a >> 1;
+ a += b;
+ base[2].y = a >> 2;
+ base[3].y = ( a + c ) >> 3;
}
@@ -1092,9 +1104,6 @@ typedef ptrdiff_t FT_PtrDist;
{
FT_Vector bez_stack[16 * 3 + 1]; /* enough to accommodate bisections */
FT_Vector* arc = bez_stack;
- TPos dx, dy, dx_, dy_;
- TPos dx1, dy1, dx2, dy2;
- TPos L, s, s_limit;
arc[0].x = UPSCALE( to->x );
@@ -1123,45 +1132,13 @@ typedef ptrdiff_t FT_PtrDist;
for (;;)
{
- /* Decide whether to split or draw. See `Rapid Termination */
- /* Evaluation for Recursive Subdivision of Bezier Curves' by Thomas */
- /* F. Hain, at */
- /* http://www.cis.southalabama.edu/~hain/general/Publications/Bezier/Camera-ready%20CISST02%202.pdf */
-
- /* dx and dy are x and y components of the P0-P3 chord vector. */
- dx = dx_ = arc[3].x - arc[0].x;
- dy = dy_ = arc[3].y - arc[0].y;
-
- L = FT_HYPOT( dx_, dy_ );
-
- /* Avoid possible arithmetic overflow below by splitting. */
- if ( L > 32767 )
- goto Split;
-
- /* Max deviation may be as much as (s/L) * 3/4 (if Hain's v = 1). */
- s_limit = L * (TPos)( ONE_PIXEL / 6 );
-
- /* s is L * the perpendicular distance from P1 to the line P0-P3. */
- dx1 = arc[1].x - arc[0].x;
- dy1 = arc[1].y - arc[0].y;
- s = FT_ABS( SUB_LONG( MUL_LONG( dy, dx1 ), MUL_LONG( dx, dy1 ) ) );
-
- if ( s > s_limit )
- goto Split;
-
- /* s is L * the perpendicular distance from P2 to the line P0-P3. */
- dx2 = arc[2].x - arc[0].x;
- dy2 = arc[2].y - arc[0].y;
- s = FT_ABS( SUB_LONG( MUL_LONG( dy, dx2 ), MUL_LONG( dx, dy2 ) ) );
-
- if ( s > s_limit )
- goto Split;
-
- /* Split super curvy segments where the off points are so far
- from the chord that the angles P0-P1-P3 or P0-P2-P3 become
- acute as detected by appropriate dot products. */
- if ( dx1 * ( dx1 - dx ) + dy1 * ( dy1 - dy ) > 0 ||
- dx2 * ( dx2 - dx ) + dy2 * ( dy2 - dy ) > 0 )
+ /* with each split, control points quickly converge towards */
+ /* chord trisection points and the vanishing distances below */
+ /* indicate when the segment is flat enough to draw */
+ if ( FT_ABS( 2 * arc[0].x - 3 * arc[1].x + arc[3].x ) > ONE_PIXEL / 2 ||
+ FT_ABS( 2 * arc[0].y - 3 * arc[1].y + arc[3].y ) > ONE_PIXEL / 2 ||
+ FT_ABS( arc[0].x - 3 * arc[2].x + 2 * arc[3].x ) > ONE_PIXEL / 2 ||
+ FT_ABS( arc[0].y - 3 * arc[2].y + 2 * arc[3].y ) > ONE_PIXEL / 2 )
goto Split;
gray_render_line( RAS_VAR_ arc[0].x, arc[0].y );
@@ -1236,8 +1213,6 @@ typedef ptrdiff_t FT_PtrDist;
{
/* scale the coverage from 0..(ONE_PIXEL*ONE_PIXEL*2) to 0..256 */
coverage >>= PIXEL_BITS * 2 + 1 - 8;
- if ( coverage < 0 )
- coverage = -coverage - 1;
/* compute the line's coverage depending on the outline fill rule */
if ( ras.outline.flags & FT_OUTLINE_EVEN_ODD_FILL )
@@ -1247,23 +1222,30 @@ typedef ptrdiff_t FT_PtrDist;
if ( coverage >= 256 )
coverage = 511 - coverage;
}
- else
+ else /* default non-zero winding rule */
{
- /* normal non-zero winding rule */
+ if ( coverage < 0 )
+ coverage = ~coverage; /* the same as -coverage - 1 */
+
if ( coverage >= 256 )
coverage = 255;
}
- if ( ras.render_span ) /* for FT_RASTER_FLAG_DIRECT only */
+ if ( ras.num_spans >= 0 ) /* for FT_RASTER_FLAG_DIRECT only */
{
- FT_Span span;
+ FT_Span* span = ras.spans + ras.num_spans++;
- span.x = (short)x;
- span.len = (unsigned short)acount;
- span.coverage = (unsigned char)coverage;
+ span->x = (short)x;
+ span->len = (unsigned short)acount;
+ span->coverage = (unsigned char)coverage;
- ras.render_span( y, 1, &span, ras.render_span_data );
+ if ( ras.num_spans == FT_MAX_GRAY_SPANS )
+ {
+ /* flush the span buffer and reset the count */
+ ras.render_span( y, ras.num_spans, ras.spans, ras.render_span_data );
+ ras.num_spans = 0;
+ }
}
else
{
@@ -1277,14 +1259,29 @@ typedef ptrdiff_t FT_PtrDist;
*/
switch ( acount )
{
- case 7: *q++ = c;
- case 6: *q++ = c;
- case 5: *q++ = c;
- case 4: *q++ = c;
- case 3: *q++ = c;
- case 2: *q++ = c;
- case 1: *q = c;
- case 0: break;
+ case 7:
+ *q++ = c;
+ /* fall through */
+ case 6:
+ *q++ = c;
+ /* fall through */
+ case 5:
+ *q++ = c;
+ /* fall through */
+ case 4:
+ *q++ = c;
+ /* fall through */
+ case 3:
+ *q++ = c;
+ /* fall through */
+ case 2:
+ *q++ = c;
+ /* fall through */
+ case 1:
+ *q = c;
+ /* fall through */
+ case 0:
+ break;
default:
FT_MEM_SET( q, c, acount );
}
@@ -1322,6 +1319,13 @@ typedef ptrdiff_t FT_PtrDist;
if ( cover != 0 )
gray_hline( RAS_VAR_ x, y, cover, ras.max_ex - x );
+
+ if ( ras.num_spans > 0 ) /* for FT_RASTER_FLAG_DIRECT only */
+ {
+ /* flush the span buffer and reset the count */
+ ras.render_span( y, ras.num_spans, ras.spans, ras.render_span_data );
+ ras.num_spans = 0;
+ }
}
}
@@ -1371,7 +1375,7 @@ typedef ptrdiff_t FT_PtrDist;
void* user )
{
#undef SCALED
-#define SCALED( x ) ( ( (x) << shift ) - delta )
+#define SCALED( x ) ( (x) * ( 1L << shift ) - delta )
FT_Vector v_last;
FT_Vector v_control;
@@ -1631,7 +1635,7 @@ typedef ptrdiff_t FT_PtrDist;
gray_convert_glyph_inner( RAS_ARG,
int continued )
{
- volatile int error = 0;
+ int error;
if ( ft_setjmp( ras.jump_buffer ) == 0 )
@@ -1755,7 +1759,6 @@ typedef ptrdiff_t FT_PtrDist;
{
const FT_Outline* outline = (const FT_Outline*)params->source;
const FT_Bitmap* target_map = params->target;
- FT_BBox clip;
#ifndef FT_STATIC_RASTER
gray_TWorker worker[1];
@@ -1792,6 +1795,12 @@ typedef ptrdiff_t FT_PtrDist;
ras.render_span = (FT_Raster_Span_Func)params->gray_spans;
ras.render_span_data = params->user;
+ ras.num_spans = 0;
+
+ ras.min_ex = params->clip_box.xMin;
+ ras.min_ey = params->clip_box.yMin;
+ ras.max_ex = params->clip_box.xMax;
+ ras.max_ey = params->clip_box.yMax;
}
else
{
@@ -1816,27 +1825,15 @@ typedef ptrdiff_t FT_PtrDist;
ras.render_span = (FT_Raster_Span_Func)NULL;
ras.render_span_data = NULL;
- }
+ ras.num_spans = -1; /* invalid */
- /* compute clipping box */
- if ( params->flags & FT_RASTER_FLAG_DIRECT &&
- params->flags & FT_RASTER_FLAG_CLIP )
- clip = params->clip_box;
- else
- {
- /* compute clip box from target pixmap */
- clip.xMin = 0;
- clip.yMin = 0;
- clip.xMax = (FT_Pos)target_map->width;
- clip.yMax = (FT_Pos)target_map->rows;
+ ras.min_ex = 0;
+ ras.min_ey = 0;
+ ras.max_ex = (FT_Pos)target_map->width;
+ ras.max_ey = (FT_Pos)target_map->rows;
}
- /* clip to target bitmap, exit if nothing to do */
- ras.min_ex = clip.xMin;
- ras.min_ey = clip.yMin;
- ras.max_ex = clip.xMax;
- ras.max_ey = clip.yMax;
-
+ /* exit if nothing to do */
if ( ras.max_ex <= ras.min_ex || ras.max_ey <= ras.min_ey )
return 0;
diff --git a/thirdparty/freetype/src/smooth/ftsmooth.c b/thirdparty/freetype/src/smooth/ftsmooth.c
index c8b6bb7518..cd034d2b40 100644
--- a/thirdparty/freetype/src/smooth/ftsmooth.c
+++ b/thirdparty/freetype/src/smooth/ftsmooth.c
@@ -243,7 +243,7 @@
}
if ( lcd_filter_func )
- lcd_filter_func( bitmap, mode, lcd_weights );
+ lcd_filter_func( bitmap, lcd_weights );
}
#else /* !FT_CONFIG_OPTION_SUBPIXEL_RENDERING */
diff --git a/thirdparty/freetype/src/truetype/ttgload.c b/thirdparty/freetype/src/truetype/ttgload.c
index cbee27aa69..a04684086b 100644
--- a/thirdparty/freetype/src/truetype/ttgload.c
+++ b/thirdparty/freetype/src/truetype/ttgload.c
@@ -82,6 +82,15 @@
#define UNSCALED_COMPONENT_OFFSET 0x1000
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+#define IS_DEFAULT_INSTANCE( _face ) \
+ ( !( FT_IS_NAMED_INSTANCE( _face ) || \
+ FT_IS_VARIATION( _face ) ) )
+#else
+#define IS_DEFAULT_INSTANCE( _face ) 1
+#endif
+
+
/**************************************************************************
*
* Return the horizontal metrics in font units for a given glyph.
@@ -927,6 +936,11 @@
FT_Outline* outline;
FT_Int n_points;
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+ FT_Memory memory = loader->face->root.memory;
+ FT_Vector* unrounded = NULL;
+#endif
+
outline = &gloader->current.outline;
n_points = outline->n_points;
@@ -947,26 +961,32 @@
#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
- if ( FT_IS_NAMED_INSTANCE( FT_FACE( loader->face ) ) ||
- FT_IS_VARIATION( FT_FACE( loader->face ) ) )
+ if ( !IS_DEFAULT_INSTANCE( FT_FACE( loader->face ) ) )
{
+ if ( FT_NEW_ARRAY( unrounded, n_points ) )
+ goto Exit;
+
/* Deltas apply to the unscaled data. */
error = TT_Vary_Apply_Glyph_Deltas( loader->face,
loader->glyph_index,
outline,
+ unrounded,
(FT_UInt)n_points );
/* recalculate linear horizontal and vertical advances */
/* if we don't have HVAR and VVAR, respectively */
+
+ /* XXX: change all FreeType modules to store `linear' and `vadvance' */
+ /* in 26.6 format before the `base' module scales them to 16.16 */
if ( !( loader->face->variation_support & TT_FACE_FLAG_VAR_HADVANCE ) )
- loader->linear = outline->points[n_points - 3].x -
- outline->points[n_points - 4].x;
+ loader->linear = FT_PIX_ROUND( unrounded[n_points - 3].x -
+ unrounded[n_points - 4].x ) / 64;
if ( !( loader->face->variation_support & TT_FACE_FLAG_VAR_VADVANCE ) )
- loader->vadvance = outline->points[n_points - 1].x -
- outline->points[n_points - 2].x;
+ loader->vadvance = FT_PIX_ROUND( unrounded[n_points - 1].x -
+ unrounded[n_points - 2].x ) / 64;
if ( error )
- return error;
+ goto Exit;
}
#endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */
@@ -1021,10 +1041,23 @@
/* compensate for any scaling by de/emboldening; */
/* the amount was determined via experimentation */
if ( x_scale_factor != 1000 && ppem > 11 )
+ {
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+ FT_Vector* orig_points = outline->points;
+
+
+ if ( !IS_DEFAULT_INSTANCE( FT_FACE( loader->face ) ) )
+ outline->points = unrounded;
+#endif
FT_Outline_EmboldenXY( outline,
FT_MulFix( 1280 * ppem,
1000 - x_scale_factor ),
0 );
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+ if ( !IS_DEFAULT_INSTANCE( FT_FACE( loader->face ) ) )
+ outline->points = orig_points;
+#endif
+ }
do_scale = TRUE;
}
}
@@ -1045,10 +1078,26 @@
if ( do_scale )
{
- for ( ; vec < limit; vec++ )
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+ if ( !IS_DEFAULT_INSTANCE( FT_FACE( loader->face ) ) )
{
- vec->x = FT_MulFix( vec->x, x_scale );
- vec->y = FT_MulFix( vec->y, y_scale );
+ FT_Vector* u = unrounded;
+
+
+ for ( ; vec < limit; vec++, u++ )
+ {
+ vec->x = ( FT_MulFix( u->x, x_scale ) + 32 ) >> 6;
+ vec->y = ( FT_MulFix( u->y, y_scale ) + 32 ) >> 6;
+ }
+ }
+ else
+#endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */
+ {
+ for ( ; vec < limit; vec++ )
+ {
+ vec->x = FT_MulFix( vec->x, x_scale );
+ vec->y = FT_MulFix( vec->y, y_scale );
+ }
}
}
@@ -1080,6 +1129,11 @@
error = TT_Hint_Glyph( loader, 0 );
}
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+ Exit:
+ FT_FREE( unrounded );
+#endif
+
return error;
}
@@ -1681,6 +1735,9 @@
short contours[4] = { 0, 1, 2, 3 };
FT_Outline outline;
+ /* unrounded values */
+ FT_Vector unrounded[4] = { {0, 0}, {0, 0}, {0, 0}, {0, 0} };
+
points[0].x = loader->pp1.x;
points[0].y = loader->pp1.y;
@@ -1702,6 +1759,7 @@
error = TT_Vary_Apply_Glyph_Deltas( loader->face,
glyph_index,
&outline,
+ unrounded,
(FT_UInt)outline.n_points );
if ( error )
goto Exit;
@@ -1719,9 +1777,11 @@
/* recalculate linear horizontal and vertical advances */
/* if we don't have HVAR and VVAR, respectively */
if ( !( loader->face->variation_support & TT_FACE_FLAG_VAR_HADVANCE ) )
- loader->linear = loader->pp2.x - loader->pp1.x;
+ loader->linear = FT_PIX_ROUND( unrounded[1].x -
+ unrounded[0].x ) / 64;
if ( !( loader->face->variation_support & TT_FACE_FLAG_VAR_VADVANCE ) )
- loader->vadvance = loader->pp4.x - loader->pp3.x;
+ loader->vadvance = FT_PIX_ROUND( unrounded[3].x -
+ unrounded[2].x ) / 64;
}
#endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */
@@ -1861,9 +1921,10 @@
FT_SubGlyph subglyph;
FT_Outline outline;
- FT_Vector* points = NULL;
- char* tags = NULL;
- short* contours = NULL;
+ FT_Vector* points = NULL;
+ char* tags = NULL;
+ short* contours = NULL;
+ FT_Vector* unrounded = NULL;
limit = (short)gloader->current.num_subglyphs;
@@ -1877,9 +1938,10 @@
outline.tags = NULL;
outline.contours = NULL;
- if ( FT_NEW_ARRAY( points, outline.n_points ) ||
- FT_NEW_ARRAY( tags, outline.n_points ) ||
- FT_NEW_ARRAY( contours, outline.n_points ) )
+ if ( FT_NEW_ARRAY( points, outline.n_points ) ||
+ FT_NEW_ARRAY( tags, outline.n_points ) ||
+ FT_NEW_ARRAY( contours, outline.n_points ) ||
+ FT_NEW_ARRAY( unrounded, outline.n_points ) )
goto Exit1;
subglyph = gloader->current.subglyphs;
@@ -1928,6 +1990,7 @@
face,
glyph_index,
&outline,
+ unrounded,
(FT_UInt)outline.n_points ) ) )
goto Exit1;
@@ -1955,14 +2018,19 @@
/* recalculate linear horizontal and vertical advances */
/* if we don't have HVAR and VVAR, respectively */
if ( !( face->variation_support & TT_FACE_FLAG_VAR_HADVANCE ) )
- loader->linear = loader->pp2.x - loader->pp1.x;
+ loader->linear =
+ FT_PIX_ROUND( unrounded[outline.n_points - 3].x -
+ unrounded[outline.n_points - 4].x ) / 64;
if ( !( face->variation_support & TT_FACE_FLAG_VAR_VADVANCE ) )
- loader->vadvance = loader->pp4.x - loader->pp3.x;
+ loader->vadvance =
+ FT_PIX_ROUND( unrounded[outline.n_points - 1].x -
+ unrounded[outline.n_points - 2].x ) / 64;
Exit1:
FT_FREE( outline.points );
FT_FREE( outline.tags );
FT_FREE( outline.contours );
+ FT_FREE( unrounded );
if ( error )
goto Exit;
@@ -2088,6 +2156,7 @@
loader->ins_pos = ins_pos;
if ( IS_HINTED( loader->load_flags ) &&
#ifdef TT_USE_BYTECODE_INTERPRETER
+ subglyph &&
subglyph->flags & WE_HAVE_INSTR &&
#endif
num_points > start_point )
@@ -2611,11 +2680,6 @@
if ( reexecute )
{
- FT_UInt i;
-
-
- for ( i = 0; i < size->cvt_size; i++ )
- size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale );
error = tt_size_run_prep( size, pedantic );
if ( error )
return error;
@@ -2718,13 +2782,6 @@
FT_Error error;
TT_LoaderRec loader;
-#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
-#define IS_DEFAULT_INSTANCE ( !( FT_IS_NAMED_INSTANCE( glyph->face ) || \
- FT_IS_VARIATION( glyph->face ) ) )
-#else
-#define IS_DEFAULT_INSTANCE 1
-#endif
-
FT_TRACE1(( "TT_Load_Glyph: glyph index %d\n", glyph_index ));
@@ -2733,7 +2790,7 @@
/* try to load embedded bitmap (if any) */
if ( size->strike_index != 0xFFFFFFFFUL &&
( load_flags & FT_LOAD_NO_BITMAP ) == 0 &&
- IS_DEFAULT_INSTANCE )
+ IS_DEFAULT_INSTANCE( glyph->face ) )
{
FT_Fixed x_scale = size->root.metrics.x_scale;
FT_Fixed y_scale = size->root.metrics.y_scale;
diff --git a/thirdparty/freetype/src/truetype/ttgxvar.c b/thirdparty/freetype/src/truetype/ttgxvar.c
index 020918f533..78d87dc097 100644
--- a/thirdparty/freetype/src/truetype/ttgxvar.c
+++ b/thirdparty/freetype/src/truetype/ttgxvar.c
@@ -68,12 +68,16 @@
/* some macros we need */
-#define FT_fdot14ToFixed( x ) \
- ( (FT_Fixed)( (FT_ULong)(x) << 2 ) )
-#define FT_intToFixed( i ) \
- ( (FT_Fixed)( (FT_ULong)(i) << 16 ) )
-#define FT_fixedToInt( x ) \
- ( (FT_Short)( ( (FT_UInt32)(x) + 0x8000U ) >> 16 ) )
+#define FT_fdot14ToFixed( x ) \
+ ( (FT_Fixed)( (FT_ULong)(x) << 2 ) )
+#define FT_intToFixed( i ) \
+ ( (FT_Fixed)( (FT_ULong)(i) << 16 ) )
+#define FT_fdot6ToFixed( i ) \
+ ( (FT_Fixed)( (FT_ULong)(i) << 10 ) )
+#define FT_fixedToInt( x ) \
+ ( (FT_Short)( ( (x) + 0x8000U ) >> 16 ) )
+#define FT_fixedToFdot6( x ) \
+ ( (FT_Pos)( ( (x) + 0x200 ) >> 10 ) )
/**************************************************************************
@@ -397,9 +401,10 @@
for ( j = 0; j < segment->pairCount; j++ )
{
- /* convert to Fixed */
- segment->correspondence[j].fromCoord = FT_GET_SHORT() * 4;
- segment->correspondence[j].toCoord = FT_GET_SHORT() * 4;
+ segment->correspondence[j].fromCoord =
+ FT_fdot14ToFixed( FT_GET_SHORT() );
+ segment->correspondence[j].toCoord =
+ FT_fdot14ToFixed( FT_GET_SHORT() );
FT_TRACE5(( " mapping %.5f to %.5f\n",
segment->correspondence[j].fromCoord / 65536.0,
@@ -1616,7 +1621,7 @@
for ( j = 0; j < (FT_UInt)gvar_head.axisCount; j++ )
{
blend->tuplecoords[i * gvar_head.axisCount + j] =
- FT_GET_SHORT() * 4; /* convert to FT_Fixed */
+ FT_fdot14ToFixed( FT_GET_SHORT() );
FT_TRACE5(( "%.5f ",
blend->tuplecoords[i * gvar_head.axisCount + j] / 65536.0 ));
}
@@ -3054,7 +3059,7 @@
if ( instance_index > num_instances )
goto Exit;
- if ( instance_index > 0 && mmvar->namedstyle )
+ if ( instance_index > 0 )
{
FT_Memory memory = face->root.memory;
SFNT_Service sfnt = (SFNT_Service)face->sfnt;
@@ -3080,7 +3085,12 @@
mmvar->num_axis,
named_style->coords );
if ( error )
+ {
+ /* internal error code -1 means `no change' */
+ if ( error == -1 )
+ error = FT_Err_Ok;
goto Exit;
+ }
}
else
error = TT_Set_Var_Design( face, 0, NULL );
@@ -3103,6 +3113,21 @@
/*************************************************************************/
+ static FT_Error
+ tt_cvt_ready_iterator( FT_ListNode node,
+ void* user )
+ {
+ TT_Size size = (TT_Size)node->data;
+
+ FT_UNUSED( user );
+
+
+ size->cvt_ready = -1;
+
+ return FT_Err_Ok;
+ }
+
+
/**************************************************************************
*
* @Function:
@@ -3133,6 +3158,8 @@
FT_Error error;
FT_Memory memory = stream->memory;
+ FT_Face root = &face->root;
+
FT_ULong table_start;
FT_ULong table_len;
@@ -3261,8 +3288,7 @@
if ( tupleIndex & GX_TI_EMBEDDED_TUPLE_COORD )
{
for ( j = 0; j < blend->num_axis; j++ )
- tuple_coords[j] = FT_GET_SHORT() * 4; /* convert from */
- /* short frac to fixed */
+ tuple_coords[j] = FT_fdot14ToFixed( FT_GET_SHORT() );
}
else if ( ( tupleIndex & GX_TI_TUPLE_INDEX_MASK ) >= blend->tuplecount )
{
@@ -3293,9 +3319,9 @@
if ( tupleIndex & GX_TI_INTERMEDIATE_TUPLE )
{
for ( j = 0; j < blend->num_axis; j++ )
- im_start_coords[j] = FT_GET_SHORT() * 4;
+ im_start_coords[j] = FT_fdot14ToFixed( FT_GET_SHORT() );
for ( j = 0; j < blend->num_axis; j++ )
- im_end_coords[j] = FT_GET_SHORT() * 4;
+ im_end_coords[j] = FT_fdot14ToFixed( FT_GET_SHORT() );
}
apply = ft_var_apply_tuple( blend,
@@ -3360,9 +3386,9 @@
{
FT_TRACE7(( " %d: %f -> %f\n",
j,
- ( FT_intToFixed( face->cvt[j] ) +
+ ( FT_fdot6ToFixed( face->cvt[j] ) +
old_cvt_delta ) / 65536.0,
- ( FT_intToFixed( face->cvt[j] ) +
+ ( FT_fdot6ToFixed( face->cvt[j] ) +
cvt_deltas[j] ) / 65536.0 ));
count++;
}
@@ -3402,9 +3428,9 @@
{
FT_TRACE7(( " %d: %f -> %f\n",
pindex,
- ( FT_intToFixed( face->cvt[pindex] ) +
+ ( FT_fdot6ToFixed( face->cvt[pindex] ) +
old_cvt_delta ) / 65536.0,
- ( FT_intToFixed( face->cvt[pindex] ) +
+ ( FT_fdot6ToFixed( face->cvt[pindex] ) +
cvt_deltas[pindex] ) / 65536.0 ));
count++;
}
@@ -3429,7 +3455,7 @@
FT_TRACE5(( "\n" ));
for ( i = 0; i < face->cvt_size; i++ )
- face->cvt[i] += FT_fixedToInt( cvt_deltas[i] );
+ face->cvt[i] += FT_fixedToFdot6( cvt_deltas[i] );
FExit:
FT_FRAME_EXIT();
@@ -3442,6 +3468,12 @@
FT_FREE( im_end_coords );
FT_FREE( cvt_deltas );
+ /* iterate over all FT_Size objects and set `cvt_ready' to -1 */
+ /* to trigger rescaling of all CVT values */
+ FT_List_Iterate( &root->sizes_list,
+ tt_cvt_ready_iterator,
+ NULL );
+
return error;
}
@@ -3669,6 +3701,11 @@
* outline ::
* The outline to change.
*
+ * @Output:
+ * unrounded ::
+ * An array with `n_points' elements that is filled with unrounded
+ * point coordinates (in 26.6 format).
+ *
* @Return:
* FreeType error code. 0 means success.
*/
@@ -3676,6 +3713,7 @@
TT_Vary_Apply_Glyph_Deltas( TT_Face face,
FT_UInt glyph_index,
FT_Outline* outline,
+ FT_Vector* unrounded,
FT_UInt n_points )
{
FT_Error error;
@@ -3717,6 +3755,12 @@
if ( !face->doblend || !blend )
return FT_THROW( Invalid_Argument );
+ for ( i = 0; i < n_points; i++ )
+ {
+ unrounded[i].x = INT_TO_F26DOT6( outline->points[i].x );
+ unrounded[i].y = INT_TO_F26DOT6( outline->points[i].y );
+ }
+
if ( glyph_index >= blend->gv_glyphcnt ||
blend->glyphoffsets[glyph_index] ==
blend->glyphoffsets[glyph_index + 1] )
@@ -3807,8 +3851,7 @@
if ( tupleIndex & GX_TI_EMBEDDED_TUPLE_COORD )
{
for ( j = 0; j < blend->num_axis; j++ )
- tuple_coords[j] = FT_GET_SHORT() * 4; /* convert from */
- /* short frac to fixed */
+ tuple_coords[j] = FT_fdot14ToFixed( FT_GET_SHORT() );
}
else if ( ( tupleIndex & GX_TI_TUPLE_INDEX_MASK ) >= blend->tuplecount )
{
@@ -3828,9 +3871,9 @@
if ( tupleIndex & GX_TI_INTERMEDIATE_TUPLE )
{
for ( j = 0; j < blend->num_axis; j++ )
- im_start_coords[j] = FT_GET_SHORT() * 4;
+ im_start_coords[j] = FT_fdot14ToFixed( FT_GET_SHORT() );
for ( j = 0; j < blend->num_axis; j++ )
- im_end_coords[j] = FT_GET_SHORT() * 4;
+ im_end_coords[j] = FT_fdot14ToFixed( FT_GET_SHORT() );
}
apply = ft_var_apply_tuple( blend,
@@ -4064,6 +4107,9 @@
for ( i = 0; i < n_points; i++ )
{
+ unrounded[i].x += FT_fixedToFdot6( point_deltas_x[i] );
+ unrounded[i].y += FT_fixedToFdot6( point_deltas_y[i] );
+
outline->points[i].x += FT_fixedToInt( point_deltas_x[i] );
outline->points[i].y += FT_fixedToInt( point_deltas_y[i] );
}
diff --git a/thirdparty/freetype/src/truetype/ttgxvar.h b/thirdparty/freetype/src/truetype/ttgxvar.h
index 7e8d9768a7..07c99b6403 100644
--- a/thirdparty/freetype/src/truetype/ttgxvar.h
+++ b/thirdparty/freetype/src/truetype/ttgxvar.h
@@ -416,6 +416,7 @@ FT_BEGIN_HEADER
TT_Vary_Apply_Glyph_Deltas( TT_Face face,
FT_UInt glyph_index,
FT_Outline* outline,
+ FT_Vector* unrounded,
FT_UInt n_points );
FT_LOCAL( FT_Error )
diff --git a/thirdparty/freetype/src/truetype/ttinterp.c b/thirdparty/freetype/src/truetype/ttinterp.c
index 403f3753c7..70434e1729 100644
--- a/thirdparty/freetype/src/truetype/ttinterp.c
+++ b/thirdparty/freetype/src/truetype/ttinterp.c
@@ -654,23 +654,25 @@
/* opcodes are gathered in groups of 16 */
/* please keep the spaces as they are */
- /* SVTCA y */ PACK( 0, 0 ),
- /* SVTCA x */ PACK( 0, 0 ),
- /* SPvTCA y */ PACK( 0, 0 ),
- /* SPvTCA x */ PACK( 0, 0 ),
- /* SFvTCA y */ PACK( 0, 0 ),
- /* SFvTCA x */ PACK( 0, 0 ),
- /* SPvTL // */ PACK( 2, 0 ),
- /* SPvTL + */ PACK( 2, 0 ),
- /* SFvTL // */ PACK( 2, 0 ),
- /* SFvTL + */ PACK( 2, 0 ),
- /* SPvFS */ PACK( 2, 0 ),
- /* SFvFS */ PACK( 2, 0 ),
- /* GPv */ PACK( 0, 2 ),
- /* GFv */ PACK( 0, 2 ),
- /* SFvTPv */ PACK( 0, 0 ),
+ /* 0x00 */
+ /* SVTCA[0] */ PACK( 0, 0 ),
+ /* SVTCA[1] */ PACK( 0, 0 ),
+ /* SPVTCA[0] */ PACK( 0, 0 ),
+ /* SPVTCA[1] */ PACK( 0, 0 ),
+ /* SFVTCA[0] */ PACK( 0, 0 ),
+ /* SFVTCA[1] */ PACK( 0, 0 ),
+ /* SPVTL[0] */ PACK( 2, 0 ),
+ /* SPVTL[1] */ PACK( 2, 0 ),
+ /* SFVTL[0] */ PACK( 2, 0 ),
+ /* SFVTL[1] */ PACK( 2, 0 ),
+ /* SPVFS */ PACK( 2, 0 ),
+ /* SFVFS */ PACK( 2, 0 ),
+ /* GPV */ PACK( 0, 2 ),
+ /* GFV */ PACK( 0, 2 ),
+ /* SFVTPV */ PACK( 0, 0 ),
/* ISECT */ PACK( 5, 0 ),
+ /* 0x10 */
/* SRP0 */ PACK( 1, 0 ),
/* SRP1 */ PACK( 1, 0 ),
/* SRP2 */ PACK( 1, 0 ),
@@ -684,10 +686,11 @@
/* SMD */ PACK( 1, 0 ),
/* ELSE */ PACK( 0, 0 ),
/* JMPR */ PACK( 1, 0 ),
- /* SCvTCi */ PACK( 1, 0 ),
- /* SSwCi */ PACK( 1, 0 ),
+ /* SCVTCI */ PACK( 1, 0 ),
+ /* SSWCI */ PACK( 1, 0 ),
/* SSW */ PACK( 1, 0 ),
+ /* 0x20 */
/* DUP */ PACK( 1, 2 ),
/* POP */ PACK( 1, 0 ),
/* CLEAR */ PACK( 0, 0 ),
@@ -695,7 +698,7 @@
/* DEPTH */ PACK( 0, 1 ),
/* CINDEX */ PACK( 1, 1 ),
/* MINDEX */ PACK( 1, 0 ),
- /* AlignPTS */ PACK( 2, 0 ),
+ /* ALIGNPTS */ PACK( 2, 0 ),
/* INS_$28 */ PACK( 0, 0 ),
/* UTP */ PACK( 1, 0 ),
/* LOOPCALL */ PACK( 2, 0 ),
@@ -705,6 +708,7 @@
/* MDAP[0] */ PACK( 1, 0 ),
/* MDAP[1] */ PACK( 1, 0 ),
+ /* 0x30 */
/* IUP[0] */ PACK( 0, 0 ),
/* IUP[1] */ PACK( 0, 0 ),
/* SHP[0] */ PACK( 0, 0 ), /* loops */
@@ -717,17 +721,18 @@
/* IP */ PACK( 0, 0 ), /* loops */
/* MSIRP[0] */ PACK( 2, 0 ),
/* MSIRP[1] */ PACK( 2, 0 ),
- /* AlignRP */ PACK( 0, 0 ), /* loops */
+ /* ALIGNRP */ PACK( 0, 0 ), /* loops */
/* RTDG */ PACK( 0, 0 ),
/* MIAP[0] */ PACK( 2, 0 ),
/* MIAP[1] */ PACK( 2, 0 ),
- /* NPushB */ PACK( 0, 0 ),
- /* NPushW */ PACK( 0, 0 ),
+ /* 0x40 */
+ /* NPUSHB */ PACK( 0, 0 ),
+ /* NPUSHW */ PACK( 0, 0 ),
/* WS */ PACK( 2, 0 ),
/* RS */ PACK( 1, 1 ),
- /* WCvtP */ PACK( 2, 0 ),
- /* RCvt */ PACK( 1, 1 ),
+ /* WCVTP */ PACK( 2, 0 ),
+ /* RCVT */ PACK( 1, 1 ),
/* GC[0] */ PACK( 1, 1 ),
/* GC[1] */ PACK( 1, 1 ),
/* SCFS */ PACK( 2, 0 ),
@@ -735,10 +740,11 @@
/* MD[1] */ PACK( 2, 1 ),
/* MPPEM */ PACK( 0, 1 ),
/* MPS */ PACK( 0, 1 ),
- /* FlipON */ PACK( 0, 0 ),
- /* FlipOFF */ PACK( 0, 0 ),
+ /* FLIPON */ PACK( 0, 0 ),
+ /* FLIPOFF */ PACK( 0, 0 ),
/* DEBUG */ PACK( 1, 0 ),
+ /* 0x50 */
/* LT */ PACK( 2, 1 ),
/* LTEQ */ PACK( 2, 1 ),
/* GT */ PACK( 2, 1 ),
@@ -752,10 +758,11 @@
/* AND */ PACK( 2, 1 ),
/* OR */ PACK( 2, 1 ),
/* NOT */ PACK( 1, 1 ),
- /* DeltaP1 */ PACK( 1, 0 ),
+ /* DELTAP1 */ PACK( 1, 0 ),
/* SDB */ PACK( 1, 0 ),
/* SDS */ PACK( 1, 0 ),
+ /* 0x60 */
/* ADD */ PACK( 2, 1 ),
/* SUB */ PACK( 2, 1 ),
/* DIV */ PACK( 2, 1 ),
@@ -773,14 +780,15 @@
/* NROUND[2] */ PACK( 1, 1 ),
/* NROUND[3] */ PACK( 1, 1 ),
- /* WCvtF */ PACK( 2, 0 ),
- /* DeltaP2 */ PACK( 1, 0 ),
- /* DeltaP3 */ PACK( 1, 0 ),
- /* DeltaCn[0] */ PACK( 1, 0 ),
- /* DeltaCn[1] */ PACK( 1, 0 ),
- /* DeltaCn[2] */ PACK( 1, 0 ),
+ /* 0x70 */
+ /* WCVTF */ PACK( 2, 0 ),
+ /* DELTAP2 */ PACK( 1, 0 ),
+ /* DELTAP3 */ PACK( 1, 0 ),
+ /* DELTAC1 */ PACK( 1, 0 ),
+ /* DELTAC2 */ PACK( 1, 0 ),
+ /* DELTAC3 */ PACK( 1, 0 ),
/* SROUND */ PACK( 1, 0 ),
- /* S45Round */ PACK( 1, 0 ),
+ /* S45ROUND */ PACK( 1, 0 ),
/* JROT */ PACK( 2, 0 ),
/* JROF */ PACK( 2, 0 ),
/* ROFF */ PACK( 0, 0 ),
@@ -790,23 +798,25 @@
/* SANGW */ PACK( 1, 0 ),
/* AA */ PACK( 1, 0 ),
- /* FlipPT */ PACK( 0, 0 ), /* loops */
- /* FlipRgON */ PACK( 2, 0 ),
- /* FlipRgOFF */ PACK( 2, 0 ),
+ /* 0x80 */
+ /* FLIPPT */ PACK( 0, 0 ), /* loops */
+ /* FLIPRGON */ PACK( 2, 0 ),
+ /* FLIPRGOFF */ PACK( 2, 0 ),
/* INS_$83 */ PACK( 0, 0 ),
/* INS_$84 */ PACK( 0, 0 ),
- /* ScanCTRL */ PACK( 1, 0 ),
- /* SDPvTL[0] */ PACK( 2, 0 ),
- /* SDPvTL[1] */ PACK( 2, 0 ),
- /* GetINFO */ PACK( 1, 1 ),
+ /* SCANCTRL */ PACK( 1, 0 ),
+ /* SDPVTL[0] */ PACK( 2, 0 ),
+ /* SDPVTL[1] */ PACK( 2, 0 ),
+ /* GETINFO */ PACK( 1, 1 ),
/* IDEF */ PACK( 1, 0 ),
/* ROLL */ PACK( 3, 3 ),
/* MAX */ PACK( 2, 1 ),
/* MIN */ PACK( 2, 1 ),
- /* ScanTYPE */ PACK( 1, 0 ),
- /* InstCTRL */ PACK( 2, 0 ),
+ /* SCANTYPE */ PACK( 1, 0 ),
+ /* INSTCTRL */ PACK( 2, 0 ),
/* INS_$8F */ PACK( 0, 0 ),
+ /* 0x90 */
/* INS_$90 */ PACK( 0, 0 ),
/* GETVAR */ PACK( 0, 0 ), /* will be handled specially */
/* GETDATA */ PACK( 0, 1 ),
@@ -824,6 +834,7 @@
/* INS_$9E */ PACK( 0, 0 ),
/* INS_$9F */ PACK( 0, 0 ),
+ /* 0xA0 */
/* INS_$A0 */ PACK( 0, 0 ),
/* INS_$A1 */ PACK( 0, 0 ),
/* INS_$A2 */ PACK( 0, 0 ),
@@ -841,23 +852,25 @@
/* INS_$AE */ PACK( 0, 0 ),
/* INS_$AF */ PACK( 0, 0 ),
- /* PushB[0] */ PACK( 0, 1 ),
- /* PushB[1] */ PACK( 0, 2 ),
- /* PushB[2] */ PACK( 0, 3 ),
- /* PushB[3] */ PACK( 0, 4 ),
- /* PushB[4] */ PACK( 0, 5 ),
- /* PushB[5] */ PACK( 0, 6 ),
- /* PushB[6] */ PACK( 0, 7 ),
- /* PushB[7] */ PACK( 0, 8 ),
- /* PushW[0] */ PACK( 0, 1 ),
- /* PushW[1] */ PACK( 0, 2 ),
- /* PushW[2] */ PACK( 0, 3 ),
- /* PushW[3] */ PACK( 0, 4 ),
- /* PushW[4] */ PACK( 0, 5 ),
- /* PushW[5] */ PACK( 0, 6 ),
- /* PushW[6] */ PACK( 0, 7 ),
- /* PushW[7] */ PACK( 0, 8 ),
-
+ /* 0xB0 */
+ /* PUSHB[0] */ PACK( 0, 1 ),
+ /* PUSHB[1] */ PACK( 0, 2 ),
+ /* PUSHB[2] */ PACK( 0, 3 ),
+ /* PUSHB[3] */ PACK( 0, 4 ),
+ /* PUSHB[4] */ PACK( 0, 5 ),
+ /* PUSHB[5] */ PACK( 0, 6 ),
+ /* PUSHB[6] */ PACK( 0, 7 ),
+ /* PUSHB[7] */ PACK( 0, 8 ),
+ /* PUSHW[0] */ PACK( 0, 1 ),
+ /* PUSHW[1] */ PACK( 0, 2 ),
+ /* PUSHW[2] */ PACK( 0, 3 ),
+ /* PUSHW[3] */ PACK( 0, 4 ),
+ /* PUSHW[4] */ PACK( 0, 5 ),
+ /* PUSHW[5] */ PACK( 0, 6 ),
+ /* PUSHW[6] */ PACK( 0, 7 ),
+ /* PUSHW[7] */ PACK( 0, 8 ),
+
+ /* 0xC0 */
/* MDRP[00] */ PACK( 1, 0 ),
/* MDRP[01] */ PACK( 1, 0 ),
/* MDRP[02] */ PACK( 1, 0 ),
@@ -875,6 +888,7 @@
/* MDRP[14] */ PACK( 1, 0 ),
/* MDRP[15] */ PACK( 1, 0 ),
+ /* 0xD0 */
/* MDRP[16] */ PACK( 1, 0 ),
/* MDRP[17] */ PACK( 1, 0 ),
/* MDRP[18] */ PACK( 1, 0 ),
@@ -892,6 +906,7 @@
/* MDRP[30] */ PACK( 1, 0 ),
/* MDRP[31] */ PACK( 1, 0 ),
+ /* 0xE0 */
/* MIRP[00] */ PACK( 2, 0 ),
/* MIRP[01] */ PACK( 2, 0 ),
/* MIRP[02] */ PACK( 2, 0 ),
@@ -909,6 +924,7 @@
/* MIRP[14] */ PACK( 2, 0 ),
/* MIRP[15] */ PACK( 2, 0 ),
+ /* 0xF0 */
/* MIRP[16] */ PACK( 2, 0 ),
/* MIRP[17] */ PACK( 2, 0 ),
/* MIRP[18] */ PACK( 2, 0 ),
@@ -937,23 +953,25 @@
static
const char* const opcode_name[256] =
{
- "7 SVTCA y",
- "7 SVTCA x",
- "8 SPvTCA y",
- "8 SPvTCA x",
- "8 SFvTCA y",
- "8 SFvTCA x",
- "8 SPvTL ||",
- "7 SPvTL +",
- "8 SFvTL ||",
- "7 SFvTL +",
- "5 SPvFS",
- "5 SFvFS",
- "3 GPv",
- "3 GFv",
- "6 SFvTPv",
+ /* 0x00 */
+ "8 SVTCA[y]",
+ "8 SVTCA[x]",
+ "9 SPVTCA[y]",
+ "9 SPVTCA[x]",
+ "9 SFVTCA[y]",
+ "9 SFVTCA[x]",
+ "9 SPVTL[||]",
+ "8 SPVTL[+]",
+ "9 SFVTL[||]",
+ "8 SFVTL[+]",
+ "5 SPVFS",
+ "5 SFVFS",
+ "3 GPV",
+ "3 GFV",
+ "6 SFVTPV",
"5 ISECT",
+ /* 0x10 */
"4 SRP0",
"4 SRP1",
"4 SRP2",
@@ -967,10 +985,11 @@
"3 SMD",
"4 ELSE",
"4 JMPR",
- "6 SCvTCi",
- "5 SSwCi",
+ "6 SCVTCI",
+ "5 SSWCI",
"3 SSW",
+ /* 0x20 */
"3 DUP",
"3 POP",
"5 CLEAR",
@@ -978,50 +997,53 @@
"5 DEPTH",
"6 CINDEX",
"6 MINDEX",
- "8 AlignPTS",
+ "8 ALIGNPTS",
"7 INS_$28",
"3 UTP",
"8 LOOPCALL",
"4 CALL",
"4 FDEF",
"4 ENDF",
- "7 MDAP[0]",
- "7 MDAP[1]",
-
- "6 IUP[0]",
- "6 IUP[1]",
- "6 SHP[0]",
- "6 SHP[1]",
- "6 SHC[0]",
- "6 SHC[1]",
- "6 SHZ[0]",
- "6 SHZ[1]",
+ "6 MDAP[]",
+ "9 MDAP[rnd]",
+
+ /* 0x30 */
+ "6 IUP[y]",
+ "6 IUP[x]",
+ "8 SHP[rp2]",
+ "8 SHP[rp1]",
+ "8 SHC[rp2]",
+ "8 SHC[rp1]",
+ "8 SHZ[rp2]",
+ "8 SHZ[rp1]",
"5 SHPIX",
"2 IP",
- "8 MSIRP[0]",
- "8 MSIRP[1]",
- "7 AlignRP",
+ "7 MSIRP[]",
+ "A MSIRP[rp0]",
+ "7 ALIGNRP",
"4 RTDG",
- "7 MIAP[0]",
- "7 MIAP[1]",
+ "6 MIAP[]",
+ "9 MIAP[rnd]",
- "6 NPushB",
- "6 NPushW",
+ /* 0x40 */
+ "6 NPUSHB",
+ "6 NPUSHW",
"2 WS",
"2 RS",
- "5 WCvtP",
- "4 RCvt",
- "5 GC[0]",
- "5 GC[1]",
+ "5 WCVTP",
+ "4 RCVT",
+ "8 GC[curr]",
+ "8 GC[orig]",
"4 SCFS",
- "5 MD[0]",
- "5 MD[1]",
+ "8 MD[curr]",
+ "8 MD[orig]",
"5 MPPEM",
"3 MPS",
- "6 FlipON",
- "7 FlipOFF",
+ "6 FLIPON",
+ "7 FLIPOFF",
"5 DEBUG",
+ /* 0x50 */
"2 LT",
"4 LTEQ",
"2 GT",
@@ -1035,10 +1057,11 @@
"3 AND",
"2 OR",
"3 NOT",
- "7 DeltaP1",
+ "7 DELTAP1",
"3 SDB",
"3 SDS",
+ /* 0x60 */
"3 ADD",
"3 SUB",
"3 DIV",
@@ -1047,23 +1070,24 @@
"3 NEG",
"5 FLOOR",
"7 CEILING",
- "8 ROUND[0]",
- "8 ROUND[1]",
- "8 ROUND[2]",
- "8 ROUND[3]",
- "9 NROUND[0]",
- "9 NROUND[1]",
- "9 NROUND[2]",
- "9 NROUND[3]",
-
- "5 WCvtF",
- "7 DeltaP2",
- "7 DeltaP3",
- "A DeltaCn[0]",
- "A DeltaCn[1]",
- "A DeltaCn[2]",
+ "8 ROUND[G]",
+ "8 ROUND[B]",
+ "8 ROUND[W]",
+ "7 ROUND[]",
+ "9 NROUND[G]",
+ "9 NROUND[B]",
+ "9 NROUND[W]",
+ "8 NROUND[]",
+
+ /* 0x70 */
+ "5 WCVTF",
+ "7 DELTAP2",
+ "7 DELTAP3",
+ "7 DELTAC1",
+ "7 DELTAC2",
+ "7 DELTAC3",
"6 SROUND",
- "8 S45Round",
+ "8 S45ROUND",
"4 JROT",
"4 JROF",
"4 ROFF",
@@ -1073,26 +1097,28 @@
"5 SANGW",
"2 AA",
- "6 FlipPT",
- "8 FlipRgON",
- "9 FlipRgOFF",
+ /* 0x80 */
+ "6 FLIPPT",
+ "8 FLIPRGON",
+ "9 FLIPRGOFF",
"7 INS_$83",
"7 INS_$84",
- "8 ScanCTRL",
- "9 SDPvTL[0]",
- "9 SDPvTL[1]",
- "7 GetINFO",
+ "8 SCANCTRL",
+ "A SDPVTL[||]",
+ "9 SDPVTL[+]",
+ "7 GETINFO",
"4 IDEF",
"4 ROLL",
"3 MAX",
"3 MIN",
- "8 ScanTYPE",
- "8 InstCTRL",
+ "8 SCANTYPE",
+ "8 INSTCTRL",
"7 INS_$8F",
+ /* 0x90 */
"7 INS_$90",
#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
- "6 GETVAR",
+ "C GETVARIATION",
"7 GETDATA",
#else
"7 INS_$91",
@@ -1112,6 +1138,7 @@
"7 INS_$9E",
"7 INS_$9F",
+ /* 0xA0 */
"7 INS_$A0",
"7 INS_$A1",
"7 INS_$A2",
@@ -1129,90 +1156,95 @@
"7 INS_$AE",
"7 INS_$AF",
- "8 PushB[0]",
- "8 PushB[1]",
- "8 PushB[2]",
- "8 PushB[3]",
- "8 PushB[4]",
- "8 PushB[5]",
- "8 PushB[6]",
- "8 PushB[7]",
- "8 PushW[0]",
- "8 PushW[1]",
- "8 PushW[2]",
- "8 PushW[3]",
- "8 PushW[4]",
- "8 PushW[5]",
- "8 PushW[6]",
- "8 PushW[7]",
-
+ /* 0xB0 */
+ "8 PUSHB[0]",
+ "8 PUSHB[1]",
+ "8 PUSHB[2]",
+ "8 PUSHB[3]",
+ "8 PUSHB[4]",
+ "8 PUSHB[5]",
+ "8 PUSHB[6]",
+ "8 PUSHB[7]",
+ "8 PUSHW[0]",
+ "8 PUSHW[1]",
+ "8 PUSHW[2]",
+ "8 PUSHW[3]",
+ "8 PUSHW[4]",
+ "8 PUSHW[5]",
+ "8 PUSHW[6]",
+ "8 PUSHW[7]",
+
+ /* 0xC0 */
"7 MDRP[G]",
"7 MDRP[B]",
"7 MDRP[W]",
- "7 MDRP[?]",
+ "6 MDRP[]",
"8 MDRP[rG]",
"8 MDRP[rB]",
"8 MDRP[rW]",
- "8 MDRP[r?]",
+ "7 MDRP[r]",
"8 MDRP[mG]",
"8 MDRP[mB]",
"8 MDRP[mW]",
- "8 MDRP[m?]",
+ "7 MDRP[m]",
"9 MDRP[mrG]",
"9 MDRP[mrB]",
"9 MDRP[mrW]",
- "9 MDRP[mr?]",
+ "8 MDRP[mr]",
+ /* 0xD0 */
"8 MDRP[pG]",
"8 MDRP[pB]",
"8 MDRP[pW]",
- "8 MDRP[p?]",
+ "7 MDRP[p]",
"9 MDRP[prG]",
"9 MDRP[prB]",
"9 MDRP[prW]",
- "9 MDRP[pr?]",
+ "8 MDRP[pr]",
"9 MDRP[pmG]",
"9 MDRP[pmB]",
"9 MDRP[pmW]",
- "9 MDRP[pm?]",
+ "8 MDRP[pm]",
"A MDRP[pmrG]",
"A MDRP[pmrB]",
"A MDRP[pmrW]",
- "A MDRP[pmr?]",
+ "9 MDRP[pmr]",
+ /* 0xE0 */
"7 MIRP[G]",
"7 MIRP[B]",
"7 MIRP[W]",
- "7 MIRP[?]",
+ "6 MIRP[]",
"8 MIRP[rG]",
"8 MIRP[rB]",
"8 MIRP[rW]",
- "8 MIRP[r?]",
+ "7 MIRP[r]",
"8 MIRP[mG]",
"8 MIRP[mB]",
"8 MIRP[mW]",
- "8 MIRP[m?]",
+ "7 MIRP[m]",
"9 MIRP[mrG]",
"9 MIRP[mrB]",
"9 MIRP[mrW]",
- "9 MIRP[mr?]",
+ "8 MIRP[mr]",
+ /* 0xF0 */
"8 MIRP[pG]",
"8 MIRP[pB]",
"8 MIRP[pW]",
- "8 MIRP[p?]",
+ "7 MIRP[p]",
"9 MIRP[prG]",
"9 MIRP[prB]",
"9 MIRP[prW]",
- "9 MIRP[pr?]",
+ "8 MIRP[pr]",
"9 MIRP[pmG]",
"9 MIRP[pmB]",
"9 MIRP[pmW]",
- "9 MIRP[pm?]",
+ "8 MIRP[pm]",
"A MIRP[pmrG]",
"A MIRP[pmrB]",
"A MIRP[pmrW]",
- "A MIRP[pmr?]"
+ "9 MIRP[pmr]"
};
#endif /* FT_DEBUG_LEVEL_TRACE */
@@ -1662,6 +1694,32 @@
}
+ /*
+ *
+ * Apple's TrueType specification at
+ *
+ * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM02/Chap2.html#order
+ *
+ * gives the following order of operations in instructions that move
+ * points.
+ *
+ * - check single width cut-in (MIRP, MDRP)
+ *
+ * - check control value cut-in (MIRP, MIAP)
+ *
+ * - apply engine compensation (MIRP, MDRP)
+ *
+ * - round distance (MIRP, MDRP) or value (MIAP, MDAP)
+ *
+ * - check minimum distance (MIRP,MDRP)
+ *
+ * - move point (MIRP, MDRP, MIAP, MSIRP, MDAP)
+ *
+ * For rounding instructions, engine compensation happens before rounding.
+ *
+ */
+
+
/**************************************************************************
*
* @Function:
@@ -1886,7 +1944,6 @@
zone->org[point].y = ADD_LONG( zone->org[point].y, distance );
}
-
/**************************************************************************
*
* @Function:
@@ -1904,12 +1961,6 @@
*
* @Return:
* The compensated distance.
- *
- * @Note:
- * The TrueType specification says very few about the relationship
- * between rounding and engine compensation. However, it seems from
- * the description of super round that we should add the compensation
- * before rounding.
*/
static FT_F26Dot6
Round_None( TT_ExecContext exc,
diff --git a/thirdparty/freetype/src/truetype/ttobjs.c b/thirdparty/freetype/src/truetype/ttobjs.c
index f3a432cedd..e4775a51ed 100644
--- a/thirdparty/freetype/src/truetype/ttobjs.c
+++ b/thirdparty/freetype/src/truetype/ttobjs.c
@@ -148,7 +148,7 @@
/* This list shall be expanded as we find more of them. */
static FT_Bool
- tt_check_trickyness_family( FT_String* name )
+ tt_check_trickyness_family( const FT_String* name )
{
#define TRICK_NAMES_MAX_CHARACTERS 19
@@ -937,7 +937,22 @@
TT_Face face = (TT_Face)size->root.face;
TT_ExecContext exec;
FT_Error error;
+ FT_UInt i;
+ /* unscaled CVT values are already stored in 26.6 format */
+ FT_Fixed scale = size->ttmetrics.scale >> 6;
+
+
+ /* Scale the cvt values to the new ppem. */
+ /* By default, we use the y ppem value for scaling. */
+ FT_TRACE6(( "CVT values:\n" ));
+ for ( i = 0; i < size->cvt_size; i++ )
+ {
+ size->cvt[i] = FT_MulFix( face->cvt[i], scale );
+ FT_TRACE6(( " %3d: %f (%f)\n",
+ i, face->cvt[i] / 64.0, size->cvt[i] / 64.0 ));
+ }
+ FT_TRACE6(( "\n" ));
exec = size->context;
@@ -1094,11 +1109,17 @@
tt_metrics->rotated = FALSE;
tt_metrics->stretched = FALSE;
- /* set default engine compensation */
- tt_metrics->compensations[0] = 0; /* gray */
- tt_metrics->compensations[1] = 0; /* black */
- tt_metrics->compensations[2] = 0; /* white */
- tt_metrics->compensations[3] = 0; /* reserved */
+ /* Set default engine compensation. Value 3 is not described */
+ /* in the OpenType specification (as of Mai 2019), but Greg */
+ /* says that MS handles it the same as `gray'. */
+ /* */
+ /* The Apple specification says that the compensation for */
+ /* `gray' is always zero. FreeType doesn't do any */
+ /* compensation at all. */
+ tt_metrics->compensations[0] = 0; /* gray */
+ tt_metrics->compensations[1] = 0; /* black */
+ tt_metrics->compensations[2] = 0; /* white */
+ tt_metrics->compensations[3] = 0; /* the same as gray */
}
/* allocate function defs, instruction defs, cvt, and storage area */
@@ -1171,20 +1192,8 @@
if ( size->cvt_ready < 0 )
{
FT_UInt i;
- TT_Face face = (TT_Face)size->root.face;
- /* Scale the cvt values to the new ppem. */
- /* By default, we use the y ppem value for scaling. */
- FT_TRACE6(( "CVT values:\n" ));
- for ( i = 0; i < size->cvt_size; i++ )
- {
- size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale );
- FT_TRACE6(( " %3d: %d (%f)\n",
- i, face->cvt[i], size->cvt[i] / 64.0 ));
- }
- FT_TRACE6(( "\n" ));
-
/* all twilight points are originally zero */
for ( i = 0; i < (FT_UInt)size->twilight.n_points; i++ )
{
diff --git a/thirdparty/freetype/src/truetype/ttpload.c b/thirdparty/freetype/src/truetype/ttpload.c
index e7718bf9b7..bc954c2dba 100644
--- a/thirdparty/freetype/src/truetype/ttpload.c
+++ b/thirdparty/freetype/src/truetype/ttpload.c
@@ -352,12 +352,12 @@
goto Exit;
{
- FT_Short* cur = face->cvt;
- FT_Short* limit = cur + face->cvt_size;
+ FT_Int32* cur = face->cvt;
+ FT_Int32* limit = cur + face->cvt_size;
for ( ; cur < limit; cur++ )
- *cur = FT_GET_SHORT();
+ *cur = FT_GET_SHORT() * 64;
}
FT_FRAME_EXIT();
diff --git a/thirdparty/freetype/src/type1/t1driver.c b/thirdparty/freetype/src/type1/t1driver.c
index 8625db5b01..557733da3b 100644
--- a/thirdparty/freetype/src/type1/t1driver.c
+++ b/thirdparty/freetype/src/type1/t1driver.c
@@ -70,8 +70,8 @@
static FT_UInt
- t1_get_name_index( T1_Face face,
- FT_String* glyph_name )
+ t1_get_name_index( T1_Face face,
+ const FT_String* glyph_name )
{
FT_Int i;
diff --git a/thirdparty/freetype/src/type1/t1load.c b/thirdparty/freetype/src/type1/t1load.c
index 3896af70ba..5cffdfaac4 100644
--- a/thirdparty/freetype/src/type1/t1load.c
+++ b/thirdparty/freetype/src/type1/t1load.c
@@ -1507,12 +1507,7 @@
/* We need to `zero' out encoding_table.elements */
for ( n = 0; n < array_size; n++ )
- {
- char* notdef = (char *)".notdef";
-
-
- (void)T1_Add_Table( char_table, n, notdef, 8 );
- }
+ (void)T1_Add_Table( char_table, n, ".notdef", 8 );
/* Now we need to read records of the form */
/* */
@@ -2147,7 +2142,6 @@
/* 0 333 hsbw endchar */
FT_Byte notdef_glyph[] = { 0x8B, 0xF7, 0xE1, 0x0D, 0x0E };
- char* notdef_name = (char *)".notdef";
error = T1_Add_Table( swap_table, 0,
@@ -2162,7 +2156,7 @@
if ( error )
goto Fail;
- error = T1_Add_Table( name_table, 0, notdef_name, 8 );
+ error = T1_Add_Table( name_table, 0, ".notdef", 8 );
if ( error )
goto Fail;
@@ -2633,8 +2627,7 @@
/* we must now build type1.encoding when we have a custom array */
if ( type1->encoding_type == T1_ENCODING_TYPE_ARRAY )
{
- FT_Int charcode, idx, min_char, max_char;
- FT_Byte* glyph_name;
+ FT_Int charcode, idx, min_char, max_char;
/* OK, we do the following: for each element in the encoding */
@@ -2648,27 +2641,27 @@
charcode = 0;
for ( ; charcode < loader.encoding_table.max_elems; charcode++ )
{
- FT_Byte* char_name;
+ const FT_String* char_name =
+ (const FT_String*)loader.encoding_table.elements[charcode];
type1->encoding.char_index[charcode] = 0;
- type1->encoding.char_name [charcode] = (char *)".notdef";
+ type1->encoding.char_name [charcode] = ".notdef";
- char_name = loader.encoding_table.elements[charcode];
if ( char_name )
for ( idx = 0; idx < type1->num_glyphs; idx++ )
{
- glyph_name = (FT_Byte*)type1->glyph_names[idx];
- if ( ft_strcmp( (const char*)char_name,
- (const char*)glyph_name ) == 0 )
+ const FT_String* glyph_name = type1->glyph_names[idx];
+
+
+ if ( ft_strcmp( char_name, glyph_name ) == 0 )
{
type1->encoding.char_index[charcode] = (FT_UShort)idx;
- type1->encoding.char_name [charcode] = (char*)glyph_name;
+ type1->encoding.char_name [charcode] = glyph_name;
/* Change min/max encoded char only if glyph name is */
/* not /.notdef */
- if ( ft_strcmp( (const char*)".notdef",
- (const char*)glyph_name ) != 0 )
+ if ( ft_strcmp( ".notdef", glyph_name ) != 0 )
{
if ( charcode < min_char )
min_char = charcode;
diff --git a/thirdparty/freetype/src/type42/t42drivr.c b/thirdparty/freetype/src/type42/t42drivr.c
index 6d4e7a0955..09ad632e97 100644
--- a/thirdparty/freetype/src/type42/t42drivr.c
+++ b/thirdparty/freetype/src/type42/t42drivr.c
@@ -69,8 +69,8 @@
static FT_UInt
- t42_get_name_index( T42_Face face,
- FT_String* glyph_name )
+ t42_get_name_index( T42_Face face,
+ const FT_String* glyph_name )
{
FT_Int i;
diff --git a/thirdparty/freetype/src/type42/t42objs.c b/thirdparty/freetype/src/type42/t42objs.c
index 234c0a3e97..d31bace451 100644
--- a/thirdparty/freetype/src/type42/t42objs.c
+++ b/thirdparty/freetype/src/type42/t42objs.c
@@ -98,8 +98,7 @@
/* we must now build type1.encoding when we have a custom array */
if ( type1->encoding_type == T1_ENCODING_TYPE_ARRAY )
{
- FT_Int charcode, idx, min_char, max_char;
- FT_Byte* glyph_name;
+ FT_Int charcode, idx, min_char, max_char;
/* OK, we do the following: for each element in the encoding */
@@ -114,27 +113,27 @@
charcode = 0;
for ( ; charcode < loader.encoding_table.max_elems; charcode++ )
{
- FT_Byte* char_name;
+ const FT_String* char_name =
+ (const FT_String*)loader.encoding_table.elements[charcode];
type1->encoding.char_index[charcode] = 0;
- type1->encoding.char_name [charcode] = (char *)".notdef";
+ type1->encoding.char_name [charcode] = ".notdef";
- char_name = loader.encoding_table.elements[charcode];
if ( char_name )
for ( idx = 0; idx < type1->num_glyphs; idx++ )
{
- glyph_name = (FT_Byte*)type1->glyph_names[idx];
- if ( ft_strcmp( (const char*)char_name,
- (const char*)glyph_name ) == 0 )
+ const FT_String* glyph_name = type1->glyph_names[idx];
+
+
+ if ( ft_strcmp( char_name, glyph_name ) == 0 )
{
type1->encoding.char_index[charcode] = (FT_UShort)idx;
- type1->encoding.char_name [charcode] = (char*)glyph_name;
+ type1->encoding.char_name [charcode] = glyph_name;
/* Change min/max encoded char only if glyph name is */
/* not /.notdef */
- if ( ft_strcmp( (const char*)".notdef",
- (const char*)glyph_name ) != 0 )
+ if ( ft_strcmp( ".notdef", glyph_name ) != 0 )
{
if ( charcode < min_char )
min_char = charcode;
diff --git a/thirdparty/freetype/src/type42/t42parse.c b/thirdparty/freetype/src/type42/t42parse.c
index b653a133a5..c47a77786d 100644
--- a/thirdparty/freetype/src/type42/t42parse.c
+++ b/thirdparty/freetype/src/type42/t42parse.c
@@ -226,7 +226,8 @@
if ( !parser->in_memory )
FT_FREE( parser->base_dict );
- parser->root.funcs.done( &parser->root );
+ if ( parser->root.funcs.done )
+ parser->root.funcs.done( &parser->root );
}
@@ -373,12 +374,7 @@
/* We need to `zero' out encoding_table.elements */
for ( n = 0; n < count; n++ )
- {
- char* notdef = (char *)".notdef";
-
-
- (void)T1_Add_Table( char_table, n, notdef, 8 );
- }
+ (void)T1_Add_Table( char_table, n, ".notdef", 8 );
/* Now we need to read records of the form */
/* */
@@ -1021,8 +1017,7 @@
}
/* if /.notdef does not occupy index 0, do our magic. */
- if ( ft_strcmp( (const char*)".notdef",
- (const char*)name_table->elements[0] ) )
+ if ( ft_strcmp( ".notdef", (const char*)name_table->elements[0] ) )
{
/* Swap glyph in index 0 with /.notdef glyph. First, add index 0 */
/* name and code entries to swap_table. Then place notdef_index */
diff --git a/thirdparty/glad/KHR/khrplatform.h b/thirdparty/glad/KHR/khrplatform.h
index 975bbffed6..5b55ea2b98 100644
--- a/thirdparty/glad/KHR/khrplatform.h
+++ b/thirdparty/glad/KHR/khrplatform.h
@@ -90,12 +90,20 @@
* int arg2) KHRONOS_APIATTRIBUTES;
*/
+#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
+# define KHRONOS_STATIC 1
+#endif
+
/*-------------------------------------------------------------------------
* Definition of KHRONOS_APICALL
*-------------------------------------------------------------------------
* This precedes the return type of the function in the function prototype.
*/
-#if defined(_WIN32) && !defined(__SCITECH_SNAP__)
+#if defined(KHRONOS_STATIC)
+ /* If the preprocessor constant KHRONOS_STATIC is defined, make the
+ * header compatible with static linking. */
+# define KHRONOS_APICALL
+#elif defined(_WIN32)
# define KHRONOS_APICALL __declspec(dllimport)
#elif defined (__SYMBIAN32__)
# define KHRONOS_APICALL IMPORT_C
@@ -111,7 +119,7 @@
* This follows the return type of the function and precedes the function
* name in the function prototype.
*/
-#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
+#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(KHRONOS_STATIC)
/* Win32 but not WinCE */
# define KHRONOS_APIENTRY __stdcall
#else
diff --git a/thirdparty/glad/glad.c b/thirdparty/glad/glad.c
index 9704c1079f..08c9c7e228 100644
--- a/thirdparty/glad/glad.c
+++ b/thirdparty/glad/glad.c
@@ -1,6 +1,6 @@
/*
- OpenGL loader generated by glad 0.1.29 on Wed May 1 23:16:34 2019.
+ OpenGL loader generated by glad 0.1.31 on Thu Jul 11 10:09:18 2019.
Language/Generator: C/C++
Specification: gl
diff --git a/thirdparty/glad/glad/glad.h b/thirdparty/glad/glad/glad.h
index b398faf627..acf96d8cd9 100644
--- a/thirdparty/glad/glad/glad.h
+++ b/thirdparty/glad/glad/glad.h
@@ -1,6 +1,6 @@
/*
- OpenGL loader generated by glad 0.1.29 on Wed May 1 23:16:34 2019.
+ OpenGL loader generated by glad 0.1.31 on Thu Jul 11 10:09:18 2019.
Language/Generator: C/C++
Specification: gl
@@ -33,13 +33,7 @@
#define __gl_h_
#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)
-#ifndef WIN32_LEAN_AND_MEAN
-#define WIN32_LEAN_AND_MEAN 1
-#endif
-#ifndef NOMINMAX
-#define NOMINMAX 1
-#endif
-#include <windows.h>
+#define APIENTRY __stdcall
#endif
#ifndef APIENTRY
diff --git a/thirdparty/jpeg-compressor/jpgd.cpp b/thirdparty/jpeg-compressor/jpgd.cpp
index fad9a37a9a..62fbd1b72d 100644
--- a/thirdparty/jpeg-compressor/jpgd.cpp
+++ b/thirdparty/jpeg-compressor/jpgd.cpp
@@ -29,6 +29,10 @@
#define JPGD_MAX(a,b) (((a)>(b)) ? (a) : (b))
#define JPGD_MIN(a,b) (((a)<(b)) ? (a) : (b))
+// TODO: Move to header and use these constants when declaring the arrays.
+#define JPGD_HUFF_TREE_MAX_LENGTH 512
+#define JPGD_HUFF_CODE_SIZE_MAX_LENGTH 256
+
namespace jpgd {
static inline void *jpgd_malloc(size_t nSize) { return malloc(nSize); }
@@ -491,8 +495,9 @@ inline uint jpeg_decoder::get_bits_no_markers(int num_bits)
// Decodes a Huffman encoded symbol.
inline int jpeg_decoder::huff_decode(huff_tables *pH)
{
- int symbol;
+ JPGD_ASSERT(pH);
+ int symbol;
// Check first 8-bits: do we have a complete symbol?
if ((symbol = pH->look_up[m_bit_buf >> 24]) < 0)
{
@@ -500,14 +505,19 @@ inline int jpeg_decoder::huff_decode(huff_tables *pH)
int ofs = 23;
do
{
- symbol = pH->tree[-(int)(symbol + ((m_bit_buf >> ofs) & 1))];
+ unsigned int idx = -(int)(symbol + ((m_bit_buf >> ofs) & 1));
+ JPGD_ASSERT(idx < JPGD_HUFF_TREE_MAX_LENGTH);
+ symbol = pH->tree[idx];
ofs--;
} while (symbol < 0);
get_bits_no_markers(8 + (23 - ofs));
}
else
+ {
+ JPGD_ASSERT(symbol < JPGD_HUFF_CODE_SIZE_MAX_LENGTH);
get_bits_no_markers(pH->code_size[symbol]);
+ }
return symbol;
}
@@ -517,6 +527,8 @@ inline int jpeg_decoder::huff_decode(huff_tables *pH, int& extra_bits)
{
int symbol;
+ JPGD_ASSERT(pH);
+
// Check first 8-bits: do we have a complete symbol?
if ((symbol = pH->look_up2[m_bit_buf >> 24]) < 0)
{
@@ -524,7 +536,9 @@ inline int jpeg_decoder::huff_decode(huff_tables *pH, int& extra_bits)
int ofs = 23;
do
{
- symbol = pH->tree[-(int)(symbol + ((m_bit_buf >> ofs) & 1))];
+ unsigned int idx = -(int)(symbol + ((m_bit_buf >> ofs) & 1));
+ JPGD_ASSERT(idx < JPGD_HUFF_TREE_MAX_LENGTH);
+ symbol = pH->tree[idx];
ofs--;
} while (symbol < 0);
@@ -1495,6 +1509,12 @@ void jpeg_decoder::fix_in_buffer()
void jpeg_decoder::transform_mcu(int mcu_row)
{
jpgd_block_t* pSrc_ptr = m_pMCU_coefficients;
+ if (m_freq_domain_chroma_upsample) {
+ JPGD_ASSERT(mcu_row * m_blocks_per_mcu < m_expanded_blocks_per_row);
+ }
+ else {
+ JPGD_ASSERT(mcu_row * m_blocks_per_mcu < m_max_blocks_per_row);
+ }
uint8* pDst_ptr = m_pSample_buf + mcu_row * m_blocks_per_mcu * 64;
for (int mcu_block = 0; mcu_block < m_blocks_per_mcu; mcu_block++)
@@ -1650,6 +1670,7 @@ void jpeg_decoder::load_next_row()
for (mcu_block = 0; mcu_block < m_blocks_per_mcu; mcu_block++)
{
component_id = m_mcu_org[mcu_block];
+ JPGD_ASSERT(m_comp_quant[component_id] < JPGD_MAX_QUANT_TABLES);
q = m_quant[m_comp_quant[component_id]];
p = m_pMCU_coefficients + 64 * mcu_block;
@@ -1770,6 +1791,7 @@ void jpeg_decoder::decode_next_row()
for (int mcu_block = 0; mcu_block < m_blocks_per_mcu; mcu_block++, p += 64)
{
int component_id = m_mcu_org[mcu_block];
+ JPGD_ASSERT(m_comp_quant[component_id] < JPGD_MAX_QUANT_TABLES);
jpgd_quant_t* q = m_quant[m_comp_quant[component_id]];
int r, s;
@@ -2229,7 +2251,10 @@ void jpeg_decoder::make_huff_table(int index, huff_tables *pH)
for (l = 1; l <= 16; l++)
{
for (i = 1; i <= m_huff_num[index][l]; i++)
+ {
+ JPGD_ASSERT(p < 257);
huffsize[p++] = static_cast<uint8>(l);
+ }
}
huffsize[p] = 0;
@@ -2244,6 +2269,7 @@ void jpeg_decoder::make_huff_table(int index, huff_tables *pH)
{
while (huffsize[p] == si)
{
+ JPGD_ASSERT(p < 257);
huffcode[p++] = code;
code++;
}
@@ -2275,7 +2301,8 @@ void jpeg_decoder::make_huff_table(int index, huff_tables *pH)
for (l = 1 << (8 - code_size); l > 0; l--)
{
- JPGD_ASSERT(i < 256);
+ JPGD_ASSERT(i < JPGD_HUFF_CODE_SIZE_MAX_LENGTH);
+ JPGD_ASSERT(code < JPGD_HUFF_CODE_SIZE_MAX_LENGTH);
pH->look_up[code] = i;
@@ -2325,16 +2352,19 @@ void jpeg_decoder::make_huff_table(int index, huff_tables *pH)
if ((code & 0x8000) == 0)
currententry--;
- if (pH->tree[-currententry - 1] == 0)
+ unsigned int idx = -currententry - 1;
+ JPGD_ASSERT(idx < JPGD_HUFF_TREE_MAX_LENGTH);
+ if (pH->tree[idx] == 0)
{
- pH->tree[-currententry - 1] = nextfreeentry;
+ pH->tree[idx] = nextfreeentry;
currententry = nextfreeentry;
nextfreeentry -= 2;
}
- else
- currententry = pH->tree[-currententry - 1];
+ else {
+ currententry = pH->tree[idx];
+ }
code <<= 1;
}
@@ -2636,7 +2666,9 @@ void jpeg_decoder::decode_block_ac_first(jpeg_decoder *pD, int component_id, int
for (k = pD->m_spectral_start; k <= pD->m_spectral_end; k++)
{
- s = pD->huff_decode(pD->m_pHuff_tabs[pD->m_comp_ac_tab[component_id]]);
+ unsigned int idx = pD->m_comp_ac_tab[component_id];
+ JPGD_ASSERT(idx < JPGD_MAX_HUFF_TABLES);
+ s = pD->huff_decode(pD->m_pHuff_tabs[idx]);
r = s >> 4;
s &= 15;
@@ -2679,7 +2711,6 @@ void jpeg_decoder::decode_block_ac_refine(jpeg_decoder *pD, int component_id, in
int p1 = 1 << pD->m_successive_low;
int m1 = (-1) << pD->m_successive_low;
jpgd_block_t *p = pD->coeff_buf_getp(pD->m_ac_coeffs[component_id], block_x, block_y);
-
JPGD_ASSERT(pD->m_spectral_end <= 63);
k = pD->m_spectral_start;
@@ -2688,7 +2719,9 @@ void jpeg_decoder::decode_block_ac_refine(jpeg_decoder *pD, int component_id, in
{
for ( ; k <= pD->m_spectral_end; k++)
{
- s = pD->huff_decode(pD->m_pHuff_tabs[pD->m_comp_ac_tab[component_id]]);
+ unsigned int idx = pD->m_comp_ac_tab[component_id];
+ JPGD_ASSERT(idx < JPGD_MAX_HUFF_TABLES);
+ s = pD->huff_decode(pD->m_pHuff_tabs[idx]);
r = s >> 4;
s &= 15;
diff --git a/thirdparty/mbedtls/include/mbedtls/aes.h b/thirdparty/mbedtls/include/mbedtls/aes.h
index b42e564efc..94e7282d36 100644
--- a/thirdparty/mbedtls/include/mbedtls/aes.h
+++ b/thirdparty/mbedtls/include/mbedtls/aes.h
@@ -655,6 +655,8 @@ MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
#undef MBEDTLS_DEPRECATED
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
+
+#if defined(MBEDTLS_SELF_TEST)
/**
* \brief Checkup routine.
*
@@ -663,6 +665,8 @@ MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
*/
int mbedtls_aes_self_test( int verbose );
+#endif /* MBEDTLS_SELF_TEST */
+
#ifdef __cplusplus
}
#endif
diff --git a/thirdparty/mbedtls/include/mbedtls/aesni.h b/thirdparty/mbedtls/include/mbedtls/aesni.h
index 0196f49b87..a4ca012f8a 100644
--- a/thirdparty/mbedtls/include/mbedtls/aesni.h
+++ b/thirdparty/mbedtls/include/mbedtls/aesni.h
@@ -27,6 +27,12 @@
#ifndef MBEDTLS_AESNI_H
#define MBEDTLS_AESNI_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include "aes.h"
#define MBEDTLS_AESNI_AES 0x02000000u
diff --git a/thirdparty/mbedtls/include/mbedtls/arc4.h b/thirdparty/mbedtls/include/mbedtls/arc4.h
index c43f4065f1..fb044d5b7f 100644
--- a/thirdparty/mbedtls/include/mbedtls/arc4.h
+++ b/thirdparty/mbedtls/include/mbedtls/arc4.h
@@ -123,6 +123,8 @@ void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key,
int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
unsigned char *output );
+#if defined(MBEDTLS_SELF_TEST)
+
/**
* \brief Checkup routine
*
@@ -135,6 +137,8 @@ int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned
*/
int mbedtls_arc4_self_test( int verbose );
+#endif /* MBEDTLS_SELF_TEST */
+
#ifdef __cplusplus
}
#endif
diff --git a/thirdparty/mbedtls/include/mbedtls/asn1write.h b/thirdparty/mbedtls/include/mbedtls/asn1write.h
index 76c1780b59..a194243696 100644
--- a/thirdparty/mbedtls/include/mbedtls/asn1write.h
+++ b/thirdparty/mbedtls/include/mbedtls/asn1write.h
@@ -24,14 +24,21 @@
#ifndef MBEDTLS_ASN1_WRITE_H
#define MBEDTLS_ASN1_WRITE_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include "asn1.h"
#define MBEDTLS_ASN1_CHK_ADD(g, f) \
- do { \
- if( ( ret = f ) < 0 ) \
+ do \
+ { \
+ if( ( ret = (f) ) < 0 ) \
return( ret ); \
else \
- g += ret; \
+ (g) += ret; \
} while( 0 )
#ifdef __cplusplus
diff --git a/thirdparty/mbedtls/include/mbedtls/base64.h b/thirdparty/mbedtls/include/mbedtls/base64.h
index 7a64f52163..0d024164c5 100644
--- a/thirdparty/mbedtls/include/mbedtls/base64.h
+++ b/thirdparty/mbedtls/include/mbedtls/base64.h
@@ -24,6 +24,12 @@
#ifndef MBEDTLS_BASE64_H
#define MBEDTLS_BASE64_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include <stddef.h>
#define MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL -0x002A /**< Output buffer too small. */
@@ -75,6 +81,7 @@ int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen,
int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
const unsigned char *src, size_t slen );
+#if defined(MBEDTLS_SELF_TEST)
/**
* \brief Checkup routine
*
@@ -82,6 +89,8 @@ int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
*/
int mbedtls_base64_self_test( int verbose );
+#endif /* MBEDTLS_SELF_TEST */
+
#ifdef __cplusplus
}
#endif
diff --git a/thirdparty/mbedtls/include/mbedtls/bignum.h b/thirdparty/mbedtls/include/mbedtls/bignum.h
index 141a8e9adf..1c8607264f 100644
--- a/thirdparty/mbedtls/include/mbedtls/bignum.h
+++ b/thirdparty/mbedtls/include/mbedtls/bignum.h
@@ -46,7 +46,12 @@
#define MBEDTLS_ERR_MPI_NOT_ACCEPTABLE -0x000E /**< The input arguments are not acceptable. */
#define MBEDTLS_ERR_MPI_ALLOC_FAILED -0x0010 /**< Memory allocation failed. */
-#define MBEDTLS_MPI_CHK(f) do { if( ( ret = f ) != 0 ) goto cleanup; } while( 0 )
+#define MBEDTLS_MPI_CHK(f) \
+ do \
+ { \
+ if( ( ret = (f) ) != 0 ) \
+ goto cleanup; \
+ } while( 0 )
/*
* Maximum size MPIs are allowed to grow to in number of limbs.
@@ -943,6 +948,8 @@ int mbedtls_mpi_gen_prime( mbedtls_mpi *X, size_t nbits, int flags,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng );
+#if defined(MBEDTLS_SELF_TEST)
+
/**
* \brief Checkup routine
*
@@ -950,6 +957,8 @@ int mbedtls_mpi_gen_prime( mbedtls_mpi *X, size_t nbits, int flags,
*/
int mbedtls_mpi_self_test( int verbose );
+#endif /* MBEDTLS_SELF_TEST */
+
#ifdef __cplusplus
}
#endif
diff --git a/thirdparty/mbedtls/include/mbedtls/bn_mul.h b/thirdparty/mbedtls/include/mbedtls/bn_mul.h
index 2f7b72fe4c..c33bd8d4ab 100644
--- a/thirdparty/mbedtls/include/mbedtls/bn_mul.h
+++ b/thirdparty/mbedtls/include/mbedtls/bn_mul.h
@@ -38,6 +38,12 @@
#ifndef MBEDTLS_BN_MUL_H
#define MBEDTLS_BN_MUL_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include "bignum.h"
#if defined(MBEDTLS_HAVE_ASM)
@@ -750,7 +756,7 @@
"sw $10, %2 \n\t" \
: "=m" (c), "=m" (d), "=m" (s) \
: "m" (s), "m" (d), "m" (c), "m" (b) \
- : "$9", "$10", "$11", "$12", "$13", "$14", "$15" \
+ : "$9", "$10", "$11", "$12", "$13", "$14", "$15", "lo", "hi" \
);
#endif /* MIPS */
diff --git a/thirdparty/mbedtls/include/mbedtls/camellia.h b/thirdparty/mbedtls/include/mbedtls/camellia.h
index 0f7c42c92d..3eeb66366d 100644
--- a/thirdparty/mbedtls/include/mbedtls/camellia.h
+++ b/thirdparty/mbedtls/include/mbedtls/camellia.h
@@ -308,6 +308,8 @@ int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx,
unsigned char *output );
#endif /* MBEDTLS_CIPHER_MODE_CTR */
+#if defined(MBEDTLS_SELF_TEST)
+
/**
* \brief Checkup routine
*
@@ -315,6 +317,8 @@ int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx,
*/
int mbedtls_camellia_self_test( int verbose );
+#endif /* MBEDTLS_SELF_TEST */
+
#ifdef __cplusplus
}
#endif
diff --git a/thirdparty/mbedtls/include/mbedtls/ccm.h b/thirdparty/mbedtls/include/mbedtls/ccm.h
index 3f6b8f6709..f03e3b580e 100644
--- a/thirdparty/mbedtls/include/mbedtls/ccm.h
+++ b/thirdparty/mbedtls/include/mbedtls/ccm.h
@@ -49,6 +49,12 @@
#ifndef MBEDTLS_CCM_H
#define MBEDTLS_CCM_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include "cipher.h"
#define MBEDTLS_ERR_CCM_BAD_INPUT -0x000D /**< Bad input parameters to the function. */
diff --git a/thirdparty/mbedtls/include/mbedtls/certs.h b/thirdparty/mbedtls/include/mbedtls/certs.h
index 8dab7b5ce8..179ebbbad2 100644
--- a/thirdparty/mbedtls/include/mbedtls/certs.h
+++ b/thirdparty/mbedtls/include/mbedtls/certs.h
@@ -24,74 +24,226 @@
#ifndef MBEDTLS_CERTS_H
#define MBEDTLS_CERTS_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
+/* List of all PEM-encoded CA certificates, terminated by NULL;
+ * PEM encoded if MBEDTLS_PEM_PARSE_C is enabled, DER encoded
+ * otherwise. */
+extern const char * mbedtls_test_cas[];
+extern const size_t mbedtls_test_cas_len[];
+
+/* List of all DER-encoded CA certificates, terminated by NULL */
+extern const unsigned char * mbedtls_test_cas_der[];
+extern const size_t mbedtls_test_cas_der_len[];
+
#if defined(MBEDTLS_PEM_PARSE_C)
/* Concatenation of all CA certificates in PEM format if available */
extern const char mbedtls_test_cas_pem[];
extern const size_t mbedtls_test_cas_pem_len;
-#endif
-
-/* List of all CA certificates, terminated by NULL */
-extern const char * mbedtls_test_cas[];
-extern const size_t mbedtls_test_cas_len[];
+#endif /* MBEDTLS_PEM_PARSE_C */
/*
- * Convenience for users who just want a certificate:
- * RSA by default, or ECDSA if RSA is not available
+ * CA test certificates
*/
+
+extern const char mbedtls_test_ca_crt_ec_pem[];
+extern const char mbedtls_test_ca_key_ec_pem[];
+extern const char mbedtls_test_ca_pwd_ec_pem[];
+extern const char mbedtls_test_ca_key_rsa_pem[];
+extern const char mbedtls_test_ca_pwd_rsa_pem[];
+extern const char mbedtls_test_ca_crt_rsa_sha1_pem[];
+extern const char mbedtls_test_ca_crt_rsa_sha256_pem[];
+
+extern const unsigned char mbedtls_test_ca_crt_ec_der[];
+extern const unsigned char mbedtls_test_ca_key_ec_der[];
+extern const unsigned char mbedtls_test_ca_key_rsa_der[];
+extern const unsigned char mbedtls_test_ca_crt_rsa_sha1_der[];
+extern const unsigned char mbedtls_test_ca_crt_rsa_sha256_der[];
+
+extern const size_t mbedtls_test_ca_crt_ec_pem_len;
+extern const size_t mbedtls_test_ca_key_ec_pem_len;
+extern const size_t mbedtls_test_ca_pwd_ec_pem_len;
+extern const size_t mbedtls_test_ca_key_rsa_pem_len;
+extern const size_t mbedtls_test_ca_pwd_rsa_pem_len;
+extern const size_t mbedtls_test_ca_crt_rsa_sha1_pem_len;
+extern const size_t mbedtls_test_ca_crt_rsa_sha256_pem_len;
+
+extern const size_t mbedtls_test_ca_crt_ec_der_len;
+extern const size_t mbedtls_test_ca_key_ec_der_len;
+extern const size_t mbedtls_test_ca_pwd_ec_der_len;
+extern const size_t mbedtls_test_ca_key_rsa_der_len;
+extern const size_t mbedtls_test_ca_pwd_rsa_der_len;
+extern const size_t mbedtls_test_ca_crt_rsa_sha1_der_len;
+extern const size_t mbedtls_test_ca_crt_rsa_sha256_der_len;
+
+/* Config-dependent dispatch between PEM and DER encoding
+ * (PEM if enabled, otherwise DER) */
+
+extern const char mbedtls_test_ca_crt_ec[];
+extern const char mbedtls_test_ca_key_ec[];
+extern const char mbedtls_test_ca_pwd_ec[];
+extern const char mbedtls_test_ca_key_rsa[];
+extern const char mbedtls_test_ca_pwd_rsa[];
+extern const char mbedtls_test_ca_crt_rsa_sha1[];
+extern const char mbedtls_test_ca_crt_rsa_sha256[];
+
+extern const size_t mbedtls_test_ca_crt_ec_len;
+extern const size_t mbedtls_test_ca_key_ec_len;
+extern const size_t mbedtls_test_ca_pwd_ec_len;
+extern const size_t mbedtls_test_ca_key_rsa_len;
+extern const size_t mbedtls_test_ca_pwd_rsa_len;
+extern const size_t mbedtls_test_ca_crt_rsa_sha1_len;
+extern const size_t mbedtls_test_ca_crt_rsa_sha256_len;
+
+/* Config-dependent dispatch between SHA-1 and SHA-256
+ * (SHA-256 if enabled, otherwise SHA-1) */
+
+extern const char mbedtls_test_ca_crt_rsa[];
+extern const size_t mbedtls_test_ca_crt_rsa_len;
+
+/* Config-dependent dispatch between EC and RSA
+ * (RSA if enabled, otherwise EC) */
+
extern const char * mbedtls_test_ca_crt;
-extern const size_t mbedtls_test_ca_crt_len;
extern const char * mbedtls_test_ca_key;
-extern const size_t mbedtls_test_ca_key_len;
extern const char * mbedtls_test_ca_pwd;
+extern const size_t mbedtls_test_ca_crt_len;
+extern const size_t mbedtls_test_ca_key_len;
extern const size_t mbedtls_test_ca_pwd_len;
+
+/*
+ * Server test certificates
+ */
+
+extern const char mbedtls_test_srv_crt_ec_pem[];
+extern const char mbedtls_test_srv_key_ec_pem[];
+extern const char mbedtls_test_srv_pwd_ec_pem[];
+extern const char mbedtls_test_srv_key_rsa_pem[];
+extern const char mbedtls_test_srv_pwd_rsa_pem[];
+extern const char mbedtls_test_srv_crt_rsa_sha1_pem[];
+extern const char mbedtls_test_srv_crt_rsa_sha256_pem[];
+
+extern const unsigned char mbedtls_test_srv_crt_ec_der[];
+extern const unsigned char mbedtls_test_srv_key_ec_der[];
+extern const unsigned char mbedtls_test_srv_key_rsa_der[];
+extern const unsigned char mbedtls_test_srv_crt_rsa_sha1_der[];
+extern const unsigned char mbedtls_test_srv_crt_rsa_sha256_der[];
+
+extern const size_t mbedtls_test_srv_crt_ec_pem_len;
+extern const size_t mbedtls_test_srv_key_ec_pem_len;
+extern const size_t mbedtls_test_srv_pwd_ec_pem_len;
+extern const size_t mbedtls_test_srv_key_rsa_pem_len;
+extern const size_t mbedtls_test_srv_pwd_rsa_pem_len;
+extern const size_t mbedtls_test_srv_crt_rsa_sha1_pem_len;
+extern const size_t mbedtls_test_srv_crt_rsa_sha256_pem_len;
+
+extern const size_t mbedtls_test_srv_crt_ec_der_len;
+extern const size_t mbedtls_test_srv_key_ec_der_len;
+extern const size_t mbedtls_test_srv_pwd_ec_der_len;
+extern const size_t mbedtls_test_srv_key_rsa_der_len;
+extern const size_t mbedtls_test_srv_pwd_rsa_der_len;
+extern const size_t mbedtls_test_srv_crt_rsa_sha1_der_len;
+extern const size_t mbedtls_test_srv_crt_rsa_sha256_der_len;
+
+/* Config-dependent dispatch between PEM and DER encoding
+ * (PEM if enabled, otherwise DER) */
+
+extern const char mbedtls_test_srv_crt_ec[];
+extern const char mbedtls_test_srv_key_ec[];
+extern const char mbedtls_test_srv_pwd_ec[];
+extern const char mbedtls_test_srv_key_rsa[];
+extern const char mbedtls_test_srv_pwd_rsa[];
+extern const char mbedtls_test_srv_crt_rsa_sha1[];
+extern const char mbedtls_test_srv_crt_rsa_sha256[];
+
+extern const size_t mbedtls_test_srv_crt_ec_len;
+extern const size_t mbedtls_test_srv_key_ec_len;
+extern const size_t mbedtls_test_srv_pwd_ec_len;
+extern const size_t mbedtls_test_srv_key_rsa_len;
+extern const size_t mbedtls_test_srv_pwd_rsa_len;
+extern const size_t mbedtls_test_srv_crt_rsa_sha1_len;
+extern const size_t mbedtls_test_srv_crt_rsa_sha256_len;
+
+/* Config-dependent dispatch between SHA-1 and SHA-256
+ * (SHA-256 if enabled, otherwise SHA-1) */
+
+extern const char mbedtls_test_srv_crt_rsa[];
+extern const size_t mbedtls_test_srv_crt_rsa_len;
+
+/* Config-dependent dispatch between EC and RSA
+ * (RSA if enabled, otherwise EC) */
+
extern const char * mbedtls_test_srv_crt;
-extern const size_t mbedtls_test_srv_crt_len;
extern const char * mbedtls_test_srv_key;
+extern const char * mbedtls_test_srv_pwd;
+extern const size_t mbedtls_test_srv_crt_len;
extern const size_t mbedtls_test_srv_key_len;
-extern const char * mbedtls_test_cli_crt;
-extern const size_t mbedtls_test_cli_crt_len;
-extern const char * mbedtls_test_cli_key;
-extern const size_t mbedtls_test_cli_key_len;
+extern const size_t mbedtls_test_srv_pwd_len;
+
+/*
+ * Client test certificates
+ */
+
+extern const char mbedtls_test_cli_crt_ec_pem[];
+extern const char mbedtls_test_cli_key_ec_pem[];
+extern const char mbedtls_test_cli_pwd_ec_pem[];
+extern const char mbedtls_test_cli_key_rsa_pem[];
+extern const char mbedtls_test_cli_pwd_rsa_pem[];
+extern const char mbedtls_test_cli_crt_rsa_pem[];
+
+extern const unsigned char mbedtls_test_cli_crt_ec_der[];
+extern const unsigned char mbedtls_test_cli_key_ec_der[];
+extern const unsigned char mbedtls_test_cli_key_rsa_der[];
+extern const unsigned char mbedtls_test_cli_crt_rsa_der[];
+
+extern const size_t mbedtls_test_cli_crt_ec_pem_len;
+extern const size_t mbedtls_test_cli_key_ec_pem_len;
+extern const size_t mbedtls_test_cli_pwd_ec_pem_len;
+extern const size_t mbedtls_test_cli_key_rsa_pem_len;
+extern const size_t mbedtls_test_cli_pwd_rsa_pem_len;
+extern const size_t mbedtls_test_cli_crt_rsa_pem_len;
+
+extern const size_t mbedtls_test_cli_crt_ec_der_len;
+extern const size_t mbedtls_test_cli_key_ec_der_len;
+extern const size_t mbedtls_test_cli_key_rsa_der_len;
+extern const size_t mbedtls_test_cli_crt_rsa_der_len;
+
+/* Config-dependent dispatch between PEM and DER encoding
+ * (PEM if enabled, otherwise DER) */
+
+extern const char mbedtls_test_cli_crt_ec[];
+extern const char mbedtls_test_cli_key_ec[];
+extern const char mbedtls_test_cli_pwd_ec[];
+extern const char mbedtls_test_cli_key_rsa[];
+extern const char mbedtls_test_cli_pwd_rsa[];
+extern const char mbedtls_test_cli_crt_rsa[];
-#if defined(MBEDTLS_ECDSA_C)
-extern const char mbedtls_test_ca_crt_ec[];
-extern const size_t mbedtls_test_ca_crt_ec_len;
-extern const char mbedtls_test_ca_key_ec[];
-extern const size_t mbedtls_test_ca_key_ec_len;
-extern const char mbedtls_test_ca_pwd_ec[];
-extern const size_t mbedtls_test_ca_pwd_ec_len;
-extern const char mbedtls_test_srv_crt_ec[];
-extern const size_t mbedtls_test_srv_crt_ec_len;
-extern const char mbedtls_test_srv_key_ec[];
-extern const size_t mbedtls_test_srv_key_ec_len;
-extern const char mbedtls_test_cli_crt_ec[];
extern const size_t mbedtls_test_cli_crt_ec_len;
-extern const char mbedtls_test_cli_key_ec[];
extern const size_t mbedtls_test_cli_key_ec_len;
-#endif
-
-#if defined(MBEDTLS_RSA_C)
-extern const char mbedtls_test_ca_crt_rsa[];
-extern const size_t mbedtls_test_ca_crt_rsa_len;
-extern const char mbedtls_test_ca_key_rsa[];
-extern const size_t mbedtls_test_ca_key_rsa_len;
-extern const char mbedtls_test_ca_pwd_rsa[];
-extern const size_t mbedtls_test_ca_pwd_rsa_len;
-extern const char mbedtls_test_srv_crt_rsa[];
-extern const size_t mbedtls_test_srv_crt_rsa_len;
-extern const char mbedtls_test_srv_key_rsa[];
-extern const size_t mbedtls_test_srv_key_rsa_len;
-extern const char mbedtls_test_cli_crt_rsa[];
-extern const size_t mbedtls_test_cli_crt_rsa_len;
-extern const char mbedtls_test_cli_key_rsa[];
+extern const size_t mbedtls_test_cli_pwd_ec_len;
extern const size_t mbedtls_test_cli_key_rsa_len;
-#endif
+extern const size_t mbedtls_test_cli_pwd_rsa_len;
+extern const size_t mbedtls_test_cli_crt_rsa_len;
+
+/* Config-dependent dispatch between EC and RSA
+ * (RSA if enabled, otherwise EC) */
+
+extern const char * mbedtls_test_cli_crt;
+extern const char * mbedtls_test_cli_key;
+extern const char * mbedtls_test_cli_pwd;
+extern const size_t mbedtls_test_cli_crt_len;
+extern const size_t mbedtls_test_cli_key_len;
+extern const size_t mbedtls_test_cli_pwd_len;
#ifdef __cplusplus
}
diff --git a/thirdparty/mbedtls/include/mbedtls/cipher.h b/thirdparty/mbedtls/include/mbedtls/cipher.h
index 922b6c32c6..082a691741 100644
--- a/thirdparty/mbedtls/include/mbedtls/cipher.h
+++ b/thirdparty/mbedtls/include/mbedtls/cipher.h
@@ -36,7 +36,7 @@
#endif
#include <stddef.h>
-#include "mbedtls/platform_util.h"
+#include "platform_util.h"
#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
#define MBEDTLS_CIPHER_MODE_AEAD
diff --git a/thirdparty/mbedtls/include/mbedtls/cmac.h b/thirdparty/mbedtls/include/mbedtls/cmac.h
index c196793531..9d42b3f209 100644
--- a/thirdparty/mbedtls/include/mbedtls/cmac.h
+++ b/thirdparty/mbedtls/include/mbedtls/cmac.h
@@ -28,6 +28,12 @@
#ifndef MBEDTLS_CMAC_H
#define MBEDTLS_CMAC_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include "cipher.h"
#ifdef __cplusplus
diff --git a/thirdparty/mbedtls/include/mbedtls/compat-1.3.h b/thirdparty/mbedtls/include/mbedtls/compat-1.3.h
index 213b691403..a58b47243d 100644
--- a/thirdparty/mbedtls/include/mbedtls/compat-1.3.h
+++ b/thirdparty/mbedtls/include/mbedtls/compat-1.3.h
@@ -25,6 +25,12 @@
* This file is part of mbed TLS (https://tls.mbed.org)
*/
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
#if defined(MBEDTLS_DEPRECATED_WARNING)
diff --git a/thirdparty/mbedtls/include/mbedtls/config.h b/thirdparty/mbedtls/include/mbedtls/config.h
index 51d66291a5..e16e1e53d3 100644
--- a/thirdparty/mbedtls/include/mbedtls/config.h
+++ b/thirdparty/mbedtls/include/mbedtls/config.h
@@ -687,6 +687,26 @@
#define MBEDTLS_REMOVE_ARC4_CIPHERSUITES
/**
+ * \def MBEDTLS_REMOVE_3DES_CIPHERSUITES
+ *
+ * Remove 3DES ciphersuites by default in SSL / TLS.
+ * This flag removes the ciphersuites based on 3DES from the default list as
+ * returned by mbedtls_ssl_list_ciphersuites(). However, it is still possible
+ * to enable (some of) them with mbedtls_ssl_conf_ciphersuites() by including
+ * them explicitly.
+ *
+ * A man-in-the-browser attacker can recover authentication tokens sent through
+ * a TLS connection using a 3DES based cipher suite (see "On the Practical
+ * (In-)Security of 64-bit Block Ciphers" by Karthikeyan Bhargavan and Gaëtan
+ * Leurent, see https://sweet32.info/SWEET32_CCS16.pdf). If this attack falls
+ * in your threat model or you are unsure, then you should keep this option
+ * enabled to remove 3DES based cipher suites.
+ *
+ * Comment this macro to keep 3DES in the default ciphersuite list.
+ */
+#define MBEDTLS_REMOVE_3DES_CIPHERSUITES
+
+/**
* \def MBEDTLS_ECP_DP_SECP192R1_ENABLED
*
* MBEDTLS_ECP_XXXX_ENABLED: Enables specific curves within the Elliptic Curve
@@ -1622,7 +1642,9 @@
*
* Uncomment this to enable pthread mutexes.
*/
+// -- GODOT start --
//#define MBEDTLS_THREADING_PTHREAD
+// -- GODOT end --
/**
* \def MBEDTLS_VERSION_FEATURES
@@ -2816,7 +2838,9 @@
*
* Enable this layer to allow use of mutexes within mbed TLS
*/
+// -- GODOT start --
//#define MBEDTLS_THREADING_C
+// -- GODOT end --
/**
* \def MBEDTLS_TIMING_C
diff --git a/thirdparty/mbedtls/include/mbedtls/ctr_drbg.h b/thirdparty/mbedtls/include/mbedtls/ctr_drbg.h
index 10f9389d9f..cc3df7b113 100644
--- a/thirdparty/mbedtls/include/mbedtls/ctr_drbg.h
+++ b/thirdparty/mbedtls/include/mbedtls/ctr_drbg.h
@@ -36,6 +36,12 @@
#ifndef MBEDTLS_CTR_DRBG_H
#define MBEDTLS_CTR_DRBG_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include "aes.h"
#if defined(MBEDTLS_THREADING_C)
@@ -350,6 +356,8 @@ int mbedtls_ctr_drbg_write_seed_file( mbedtls_ctr_drbg_context *ctx, const char
int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
#endif /* MBEDTLS_FS_IO */
+#if defined(MBEDTLS_SELF_TEST)
+
/**
* \brief The CTR_DRBG checkup routine.
*
@@ -358,6 +366,8 @@ int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char
*/
int mbedtls_ctr_drbg_self_test( int verbose );
+#endif /* MBEDTLS_SELF_TEST */
+
/* Internal functions (do not call directly) */
int mbedtls_ctr_drbg_seed_entropy_len( mbedtls_ctr_drbg_context *,
int (*)(void *, unsigned char *, size_t), void *,
diff --git a/thirdparty/mbedtls/include/mbedtls/des.h b/thirdparty/mbedtls/include/mbedtls/des.h
index d62042d14e..54e6b7894b 100644
--- a/thirdparty/mbedtls/include/mbedtls/des.h
+++ b/thirdparty/mbedtls/include/mbedtls/des.h
@@ -338,6 +338,8 @@ int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx,
void mbedtls_des_setkey( uint32_t SK[32],
const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
+#if defined(MBEDTLS_SELF_TEST)
+
/**
* \brief Checkup routine
*
@@ -345,6 +347,8 @@ void mbedtls_des_setkey( uint32_t SK[32],
*/
int mbedtls_des_self_test( int verbose );
+#endif /* MBEDTLS_SELF_TEST */
+
#ifdef __cplusplus
}
#endif
diff --git a/thirdparty/mbedtls/include/mbedtls/dhm.h b/thirdparty/mbedtls/include/mbedtls/dhm.h
index a5452c199a..2909f5fbc8 100644
--- a/thirdparty/mbedtls/include/mbedtls/dhm.h
+++ b/thirdparty/mbedtls/include/mbedtls/dhm.h
@@ -334,6 +334,8 @@ int mbedtls_dhm_parse_dhmfile( mbedtls_dhm_context *dhm, const char *path );
#endif /* MBEDTLS_FS_IO */
#endif /* MBEDTLS_ASN1_PARSE_C */
+#if defined(MBEDTLS_SELF_TEST)
+
/**
* \brief The DMH checkup routine.
*
@@ -342,6 +344,7 @@ int mbedtls_dhm_parse_dhmfile( mbedtls_dhm_context *dhm, const char *path );
*/
int mbedtls_dhm_self_test( int verbose );
+#endif /* MBEDTLS_SELF_TEST */
#ifdef __cplusplus
}
#endif
diff --git a/thirdparty/mbedtls/include/mbedtls/ecdh.h b/thirdparty/mbedtls/include/mbedtls/ecdh.h
index 05b2b03970..4479a1d46f 100644
--- a/thirdparty/mbedtls/include/mbedtls/ecdh.h
+++ b/thirdparty/mbedtls/include/mbedtls/ecdh.h
@@ -34,6 +34,12 @@
#ifndef MBEDTLS_ECDH_H
#define MBEDTLS_ECDH_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include "ecp.h"
/*
diff --git a/thirdparty/mbedtls/include/mbedtls/ecdsa.h b/thirdparty/mbedtls/include/mbedtls/ecdsa.h
index 40fdab3729..f8b28507c2 100644
--- a/thirdparty/mbedtls/include/mbedtls/ecdsa.h
+++ b/thirdparty/mbedtls/include/mbedtls/ecdsa.h
@@ -32,6 +32,12 @@
#ifndef MBEDTLS_ECDSA_H
#define MBEDTLS_ECDSA_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include "ecp.h"
#include "md.h"
diff --git a/thirdparty/mbedtls/include/mbedtls/ecjpake.h b/thirdparty/mbedtls/include/mbedtls/ecjpake.h
index b967af8385..3d8d02ae64 100644
--- a/thirdparty/mbedtls/include/mbedtls/ecjpake.h
+++ b/thirdparty/mbedtls/include/mbedtls/ecjpake.h
@@ -40,6 +40,11 @@
* The payloads are serialized in a way suitable for use in TLS, but could
* also be use outside TLS.
*/
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
#include "ecp.h"
#include "md.h"
diff --git a/thirdparty/mbedtls/include/mbedtls/ecp.h b/thirdparty/mbedtls/include/mbedtls/ecp.h
index de3a343cb6..065a4cc0b9 100644
--- a/thirdparty/mbedtls/include/mbedtls/ecp.h
+++ b/thirdparty/mbedtls/include/mbedtls/ecp.h
@@ -36,6 +36,12 @@
#ifndef MBEDTLS_ECP_H
#define MBEDTLS_ECP_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include "bignum.h"
/*
@@ -189,6 +195,68 @@ typedef struct mbedtls_ecp_group
}
mbedtls_ecp_group;
+/**
+ * \name SECTION: Module settings
+ *
+ * The configuration options you can set for this module are in this section.
+ * Either change them in config.h, or define them using the compiler command line.
+ * \{
+ */
+
+#if !defined(MBEDTLS_ECP_MAX_BITS)
+/**
+ * The maximum size of the groups, that is, of \c N and \c P.
+ */
+#define MBEDTLS_ECP_MAX_BITS 521 /**< The maximum size of groups, in bits. */
+#endif
+
+#define MBEDTLS_ECP_MAX_BYTES ( ( MBEDTLS_ECP_MAX_BITS + 7 ) / 8 )
+#define MBEDTLS_ECP_MAX_PT_LEN ( 2 * MBEDTLS_ECP_MAX_BYTES + 1 )
+
+#if !defined(MBEDTLS_ECP_WINDOW_SIZE)
+/*
+ * Maximum "window" size used for point multiplication.
+ * Default: 6.
+ * Minimum value: 2. Maximum value: 7.
+ *
+ * Result is an array of at most ( 1 << ( MBEDTLS_ECP_WINDOW_SIZE - 1 ) )
+ * points used for point multiplication. This value is directly tied to EC
+ * peak memory usage, so decreasing it by one should roughly cut memory usage
+ * by two (if large curves are in use).
+ *
+ * Reduction in size may reduce speed, but larger curves are impacted first.
+ * Sample performances (in ECDHE handshakes/s, with FIXED_POINT_OPTIM = 1):
+ * w-size: 6 5 4 3 2
+ * 521 145 141 135 120 97
+ * 384 214 209 198 177 146
+ * 256 320 320 303 262 226
+ * 224 475 475 453 398 342
+ * 192 640 640 633 587 476
+ */
+#define MBEDTLS_ECP_WINDOW_SIZE 6 /**< The maximum window size used. */
+#endif /* MBEDTLS_ECP_WINDOW_SIZE */
+
+#if !defined(MBEDTLS_ECP_FIXED_POINT_OPTIM)
+/*
+ * Trade memory for speed on fixed-point multiplication.
+ *
+ * This speeds up repeated multiplication of the generator (that is, the
+ * multiplication in ECDSA signatures, and half of the multiplications in
+ * ECDSA verification and ECDHE) by a factor roughly 3 to 4.
+ *
+ * The cost is increasing EC peak memory usage by a factor roughly 2.
+ *
+ * Change this value to 0 to reduce peak memory usage.
+ */
+#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 /**< Enable fixed-point speed-up. */
+#endif /* MBEDTLS_ECP_FIXED_POINT_OPTIM */
+
+/* \} name SECTION: Module settings */
+
+#else /* MBEDTLS_ECP_ALT */
+#include "ecp_alt.h"
+#endif /* MBEDTLS_ECP_ALT */
+
#if defined(MBEDTLS_ECP_RESTARTABLE)
/**
@@ -254,68 +322,6 @@ typedef void mbedtls_ecp_restart_ctx;
#endif /* MBEDTLS_ECP_RESTARTABLE */
/**
- * \name SECTION: Module settings
- *
- * The configuration options you can set for this module are in this section.
- * Either change them in config.h, or define them using the compiler command line.
- * \{
- */
-
-#if !defined(MBEDTLS_ECP_MAX_BITS)
-/**
- * The maximum size of the groups, that is, of \c N and \c P.
- */
-#define MBEDTLS_ECP_MAX_BITS 521 /**< The maximum size of groups, in bits. */
-#endif
-
-#define MBEDTLS_ECP_MAX_BYTES ( ( MBEDTLS_ECP_MAX_BITS + 7 ) / 8 )
-#define MBEDTLS_ECP_MAX_PT_LEN ( 2 * MBEDTLS_ECP_MAX_BYTES + 1 )
-
-#if !defined(MBEDTLS_ECP_WINDOW_SIZE)
-/*
- * Maximum "window" size used for point multiplication.
- * Default: 6.
- * Minimum value: 2. Maximum value: 7.
- *
- * Result is an array of at most ( 1 << ( MBEDTLS_ECP_WINDOW_SIZE - 1 ) )
- * points used for point multiplication. This value is directly tied to EC
- * peak memory usage, so decreasing it by one should roughly cut memory usage
- * by two (if large curves are in use).
- *
- * Reduction in size may reduce speed, but larger curves are impacted first.
- * Sample performances (in ECDHE handshakes/s, with FIXED_POINT_OPTIM = 1):
- * w-size: 6 5 4 3 2
- * 521 145 141 135 120 97
- * 384 214 209 198 177 146
- * 256 320 320 303 262 226
- * 224 475 475 453 398 342
- * 192 640 640 633 587 476
- */
-#define MBEDTLS_ECP_WINDOW_SIZE 6 /**< The maximum window size used. */
-#endif /* MBEDTLS_ECP_WINDOW_SIZE */
-
-#if !defined(MBEDTLS_ECP_FIXED_POINT_OPTIM)
-/*
- * Trade memory for speed on fixed-point multiplication.
- *
- * This speeds up repeated multiplication of the generator (that is, the
- * multiplication in ECDSA signatures, and half of the multiplications in
- * ECDSA verification and ECDHE) by a factor roughly 3 to 4.
- *
- * The cost is increasing EC peak memory usage by a factor roughly 2.
- *
- * Change this value to 0 to reduce peak memory usage.
- */
-#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 /**< Enable fixed-point speed-up. */
-#endif /* MBEDTLS_ECP_FIXED_POINT_OPTIM */
-
-/* \} name SECTION: Module settings */
-
-#else /* MBEDTLS_ECP_ALT */
-#include "ecp_alt.h"
-#endif /* MBEDTLS_ECP_ALT */
-
-/**
* \brief The ECP key-pair structure.
*
* A generic key-pair that may be used for ECDSA and fixed ECDH, for example.
@@ -476,7 +482,7 @@ void mbedtls_ecp_point_init( mbedtls_ecp_point *pt );
*
* \note After this function is called, domain parameters
* for various ECP groups can be loaded through the
- * mbedtls_ecp_load() or mbedtls_ecp_tls_read_group()
+ * mbedtls_ecp_group_load() or mbedtls_ecp_tls_read_group()
* functions.
*/
void mbedtls_ecp_group_init( mbedtls_ecp_group *grp );
diff --git a/thirdparty/mbedtls/include/mbedtls/ecp_internal.h b/thirdparty/mbedtls/include/mbedtls/ecp_internal.h
index 18040697ad..7625ed48e1 100644
--- a/thirdparty/mbedtls/include/mbedtls/ecp_internal.h
+++ b/thirdparty/mbedtls/include/mbedtls/ecp_internal.h
@@ -61,6 +61,12 @@
#ifndef MBEDTLS_ECP_INTERNAL_H
#define MBEDTLS_ECP_INTERNAL_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#if defined(MBEDTLS_ECP_INTERNAL_ALT)
/**
diff --git a/thirdparty/mbedtls/include/mbedtls/error.h b/thirdparty/mbedtls/include/mbedtls/error.h
index 647a11a566..bee0fe485a 100644
--- a/thirdparty/mbedtls/include/mbedtls/error.h
+++ b/thirdparty/mbedtls/include/mbedtls/error.h
@@ -24,6 +24,12 @@
#ifndef MBEDTLS_ERROR_H
#define MBEDTLS_ERROR_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include <stddef.h>
/**
diff --git a/thirdparty/mbedtls/include/mbedtls/gcm.h b/thirdparty/mbedtls/include/mbedtls/gcm.h
index fccabb0d97..fd130abd7c 100644
--- a/thirdparty/mbedtls/include/mbedtls/gcm.h
+++ b/thirdparty/mbedtls/include/mbedtls/gcm.h
@@ -33,6 +33,12 @@
#ifndef MBEDTLS_GCM_H
#define MBEDTLS_GCM_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include "cipher.h"
#include <stdint.h>
@@ -300,6 +306,8 @@ int mbedtls_gcm_finish( mbedtls_gcm_context *ctx,
*/
void mbedtls_gcm_free( mbedtls_gcm_context *ctx );
+#if defined(MBEDTLS_SELF_TEST)
+
/**
* \brief The GCM checkup routine.
*
@@ -308,6 +316,8 @@ void mbedtls_gcm_free( mbedtls_gcm_context *ctx );
*/
int mbedtls_gcm_self_test( int verbose );
+#endif /* MBEDTLS_SELF_TEST */
+
#ifdef __cplusplus
}
#endif
diff --git a/thirdparty/mbedtls/include/mbedtls/havege.h b/thirdparty/mbedtls/include/mbedtls/havege.h
index 57e8c40943..4c1c86087a 100644
--- a/thirdparty/mbedtls/include/mbedtls/havege.h
+++ b/thirdparty/mbedtls/include/mbedtls/havege.h
@@ -24,6 +24,12 @@
#ifndef MBEDTLS_HAVEGE_H
#define MBEDTLS_HAVEGE_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include <stddef.h>
#define MBEDTLS_HAVEGE_COLLECT_SIZE 1024
diff --git a/thirdparty/mbedtls/include/mbedtls/hkdf.h b/thirdparty/mbedtls/include/mbedtls/hkdf.h
index e6ed7cde97..40ee64eb03 100644
--- a/thirdparty/mbedtls/include/mbedtls/hkdf.h
+++ b/thirdparty/mbedtls/include/mbedtls/hkdf.h
@@ -27,6 +27,12 @@
#ifndef MBEDTLS_HKDF_H
#define MBEDTLS_HKDF_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include "md.h"
/**
diff --git a/thirdparty/mbedtls/include/mbedtls/hmac_drbg.h b/thirdparty/mbedtls/include/mbedtls/hmac_drbg.h
index 146367b9de..7eae32bbd6 100644
--- a/thirdparty/mbedtls/include/mbedtls/hmac_drbg.h
+++ b/thirdparty/mbedtls/include/mbedtls/hmac_drbg.h
@@ -24,6 +24,12 @@
#ifndef MBEDTLS_HMAC_DRBG_H
#define MBEDTLS_HMAC_DRBG_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include "md.h"
#if defined(MBEDTLS_THREADING_C)
diff --git a/thirdparty/mbedtls/include/mbedtls/md2.h b/thirdparty/mbedtls/include/mbedtls/md2.h
index f9bd98f804..fe97cf08d4 100644
--- a/thirdparty/mbedtls/include/mbedtls/md2.h
+++ b/thirdparty/mbedtls/include/mbedtls/md2.h
@@ -283,6 +283,8 @@ MBEDTLS_DEPRECATED void mbedtls_md2( const unsigned char *input,
#undef MBEDTLS_DEPRECATED
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
+#if defined(MBEDTLS_SELF_TEST)
+
/**
* \brief Checkup routine
*
@@ -295,6 +297,8 @@ MBEDTLS_DEPRECATED void mbedtls_md2( const unsigned char *input,
*/
int mbedtls_md2_self_test( int verbose );
+#endif /* MBEDTLS_SELF_TEST */
+
#ifdef __cplusplus
}
#endif
diff --git a/thirdparty/mbedtls/include/mbedtls/md4.h b/thirdparty/mbedtls/include/mbedtls/md4.h
index dc3c048949..ce703c0ba4 100644
--- a/thirdparty/mbedtls/include/mbedtls/md4.h
+++ b/thirdparty/mbedtls/include/mbedtls/md4.h
@@ -288,6 +288,8 @@ MBEDTLS_DEPRECATED void mbedtls_md4( const unsigned char *input,
#undef MBEDTLS_DEPRECATED
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
+#if defined(MBEDTLS_SELF_TEST)
+
/**
* \brief Checkup routine
*
@@ -300,6 +302,8 @@ MBEDTLS_DEPRECATED void mbedtls_md4( const unsigned char *input,
*/
int mbedtls_md4_self_test( int verbose );
+#endif /* MBEDTLS_SELF_TEST */
+
#ifdef __cplusplus
}
#endif
diff --git a/thirdparty/mbedtls/include/mbedtls/md5.h b/thirdparty/mbedtls/include/mbedtls/md5.h
index 6c3354fd30..6eed6cc864 100644
--- a/thirdparty/mbedtls/include/mbedtls/md5.h
+++ b/thirdparty/mbedtls/include/mbedtls/md5.h
@@ -288,6 +288,8 @@ MBEDTLS_DEPRECATED void mbedtls_md5( const unsigned char *input,
#undef MBEDTLS_DEPRECATED
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
+#if defined(MBEDTLS_SELF_TEST)
+
/**
* \brief Checkup routine
*
@@ -300,6 +302,8 @@ MBEDTLS_DEPRECATED void mbedtls_md5( const unsigned char *input,
*/
int mbedtls_md5_self_test( int verbose );
+#endif /* MBEDTLS_SELF_TEST */
+
#ifdef __cplusplus
}
#endif
diff --git a/thirdparty/mbedtls/include/mbedtls/net.h b/thirdparty/mbedtls/include/mbedtls/net.h
index 6c13b53fb9..8cead58e5d 100644
--- a/thirdparty/mbedtls/include/mbedtls/net.h
+++ b/thirdparty/mbedtls/include/mbedtls/net.h
@@ -23,6 +23,11 @@
*
* This file is part of mbed TLS (https://tls.mbed.org)
*/
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
#include "net_sockets.h"
diff --git a/thirdparty/mbedtls/include/mbedtls/nist_kw.h b/thirdparty/mbedtls/include/mbedtls/nist_kw.h
index 5a0f656a8f..3b67b59cd2 100644
--- a/thirdparty/mbedtls/include/mbedtls/nist_kw.h
+++ b/thirdparty/mbedtls/include/mbedtls/nist_kw.h
@@ -37,6 +37,12 @@
#ifndef MBEDTLS_NIST_KW_H
#define MBEDTLS_NIST_KW_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include "cipher.h"
#ifdef __cplusplus
diff --git a/thirdparty/mbedtls/include/mbedtls/padlock.h b/thirdparty/mbedtls/include/mbedtls/padlock.h
index 7a5d083a95..721a5d4930 100644
--- a/thirdparty/mbedtls/include/mbedtls/padlock.h
+++ b/thirdparty/mbedtls/include/mbedtls/padlock.h
@@ -28,6 +28,12 @@
#ifndef MBEDTLS_PADLOCK_H
#define MBEDTLS_PADLOCK_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include "aes.h"
#define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */
@@ -53,7 +59,7 @@
#define MBEDTLS_PADLOCK_PHE 0x0C00
#define MBEDTLS_PADLOCK_PMM 0x3000
-#define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) x & ~15))
+#define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) (x) & ~15))
#ifdef __cplusplus
extern "C" {
diff --git a/thirdparty/mbedtls/include/mbedtls/pem.h b/thirdparty/mbedtls/include/mbedtls/pem.h
index fa82f7bdbd..a29e9ce300 100644
--- a/thirdparty/mbedtls/include/mbedtls/pem.h
+++ b/thirdparty/mbedtls/include/mbedtls/pem.h
@@ -24,6 +24,12 @@
#ifndef MBEDTLS_PEM_H
#define MBEDTLS_PEM_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include <stddef.h>
/**
diff --git a/thirdparty/mbedtls/include/mbedtls/pkcs12.h b/thirdparty/mbedtls/include/mbedtls/pkcs12.h
index 69f04177c8..d441357b7f 100644
--- a/thirdparty/mbedtls/include/mbedtls/pkcs12.h
+++ b/thirdparty/mbedtls/include/mbedtls/pkcs12.h
@@ -24,6 +24,12 @@
#ifndef MBEDTLS_PKCS12_H
#define MBEDTLS_PKCS12_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include "md.h"
#include "cipher.h"
#include "asn1.h"
diff --git a/thirdparty/mbedtls/include/mbedtls/pkcs5.h b/thirdparty/mbedtls/include/mbedtls/pkcs5.h
index d4bb36dfae..c92185f7a6 100644
--- a/thirdparty/mbedtls/include/mbedtls/pkcs5.h
+++ b/thirdparty/mbedtls/include/mbedtls/pkcs5.h
@@ -26,6 +26,12 @@
#ifndef MBEDTLS_PKCS5_H
#define MBEDTLS_PKCS5_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include "asn1.h"
#include "md.h"
@@ -85,6 +91,8 @@ int mbedtls_pkcs5_pbkdf2_hmac( mbedtls_md_context_t *ctx, const unsigned char *p
unsigned int iteration_count,
uint32_t key_length, unsigned char *output );
+#if defined(MBEDTLS_SELF_TEST)
+
/**
* \brief Checkup routine
*
@@ -92,6 +100,8 @@ int mbedtls_pkcs5_pbkdf2_hmac( mbedtls_md_context_t *ctx, const unsigned char *p
*/
int mbedtls_pkcs5_self_test( int verbose );
+#endif /* MBEDTLS_SELF_TEST */
+
#ifdef __cplusplus
}
#endif
diff --git a/thirdparty/mbedtls/include/mbedtls/platform_util.h b/thirdparty/mbedtls/include/mbedtls/platform_util.h
index b0e72ad149..dba6d45982 100644
--- a/thirdparty/mbedtls/include/mbedtls/platform_util.h
+++ b/thirdparty/mbedtls/include/mbedtls/platform_util.h
@@ -26,14 +26,14 @@
#define MBEDTLS_PLATFORM_UTIL_H
#if !defined(MBEDTLS_CONFIG_FILE)
-#include "mbedtls/config.h"
+#include "config.h"
#else
#include MBEDTLS_CONFIG_FILE
#endif
#include <stddef.h>
#if defined(MBEDTLS_HAVE_TIME_DATE)
-#include "mbedtls/platform_time.h"
+#include "platform_time.h"
#include <time.h>
#endif /* MBEDTLS_HAVE_TIME_DATE */
diff --git a/thirdparty/mbedtls/include/mbedtls/poly1305.h b/thirdparty/mbedtls/include/mbedtls/poly1305.h
index 05866a2da6..f0ec44c968 100644
--- a/thirdparty/mbedtls/include/mbedtls/poly1305.h
+++ b/thirdparty/mbedtls/include/mbedtls/poly1305.h
@@ -34,7 +34,7 @@
#define MBEDTLS_POLY1305_H
#if !defined(MBEDTLS_CONFIG_FILE)
-#include "mbedtls/config.h"
+#include "config.h"
#else
#include MBEDTLS_CONFIG_FILE
#endif
diff --git a/thirdparty/mbedtls/include/mbedtls/ripemd160.h b/thirdparty/mbedtls/include/mbedtls/ripemd160.h
index c74b7d2c6c..b42f6d2a95 100644
--- a/thirdparty/mbedtls/include/mbedtls/ripemd160.h
+++ b/thirdparty/mbedtls/include/mbedtls/ripemd160.h
@@ -219,6 +219,8 @@ MBEDTLS_DEPRECATED void mbedtls_ripemd160( const unsigned char *input,
#undef MBEDTLS_DEPRECATED
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
+#if defined(MBEDTLS_SELF_TEST)
+
/**
* \brief Checkup routine
*
@@ -226,6 +228,8 @@ MBEDTLS_DEPRECATED void mbedtls_ripemd160( const unsigned char *input,
*/
int mbedtls_ripemd160_self_test( int verbose );
+#endif /* MBEDTLS_SELF_TEST */
+
#ifdef __cplusplus
}
#endif
diff --git a/thirdparty/mbedtls/include/mbedtls/rsa.h b/thirdparty/mbedtls/include/mbedtls/rsa.h
index ed65a34452..906c427332 100644
--- a/thirdparty/mbedtls/include/mbedtls/rsa.h
+++ b/thirdparty/mbedtls/include/mbedtls/rsa.h
@@ -1252,6 +1252,8 @@ int mbedtls_rsa_copy( mbedtls_rsa_context *dst, const mbedtls_rsa_context *src )
*/
void mbedtls_rsa_free( mbedtls_rsa_context *ctx );
+#if defined(MBEDTLS_SELF_TEST)
+
/**
* \brief The RSA checkup routine.
*
@@ -1260,6 +1262,8 @@ void mbedtls_rsa_free( mbedtls_rsa_context *ctx );
*/
int mbedtls_rsa_self_test( int verbose );
+#endif /* MBEDTLS_SELF_TEST */
+
#ifdef __cplusplus
}
#endif
diff --git a/thirdparty/mbedtls/include/mbedtls/sha1.h b/thirdparty/mbedtls/include/mbedtls/sha1.h
index 38ea10b137..bb6ecf05a4 100644
--- a/thirdparty/mbedtls/include/mbedtls/sha1.h
+++ b/thirdparty/mbedtls/include/mbedtls/sha1.h
@@ -328,6 +328,8 @@ MBEDTLS_DEPRECATED void mbedtls_sha1( const unsigned char *input,
#undef MBEDTLS_DEPRECATED
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
+#if defined(MBEDTLS_SELF_TEST)
+
/**
* \brief The SHA-1 checkup routine.
*
@@ -341,6 +343,8 @@ MBEDTLS_DEPRECATED void mbedtls_sha1( const unsigned char *input,
*/
int mbedtls_sha1_self_test( int verbose );
+#endif /* MBEDTLS_SELF_TEST */
+
#ifdef __cplusplus
}
#endif
diff --git a/thirdparty/mbedtls/include/mbedtls/sha256.h b/thirdparty/mbedtls/include/mbedtls/sha256.h
index 0e42f0abba..d64739820c 100644
--- a/thirdparty/mbedtls/include/mbedtls/sha256.h
+++ b/thirdparty/mbedtls/include/mbedtls/sha256.h
@@ -278,6 +278,8 @@ MBEDTLS_DEPRECATED void mbedtls_sha256( const unsigned char *input,
#undef MBEDTLS_DEPRECATED
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
+#if defined(MBEDTLS_SELF_TEST)
+
/**
* \brief The SHA-224 and SHA-256 checkup routine.
*
@@ -286,6 +288,8 @@ MBEDTLS_DEPRECATED void mbedtls_sha256( const unsigned char *input,
*/
int mbedtls_sha256_self_test( int verbose );
+#endif /* MBEDTLS_SELF_TEST */
+
#ifdef __cplusplus
}
#endif
diff --git a/thirdparty/mbedtls/include/mbedtls/sha512.h b/thirdparty/mbedtls/include/mbedtls/sha512.h
index 7b26cf5cc3..c06ceed1d1 100644
--- a/thirdparty/mbedtls/include/mbedtls/sha512.h
+++ b/thirdparty/mbedtls/include/mbedtls/sha512.h
@@ -253,6 +253,7 @@ int mbedtls_sha512_ret( const unsigned char *input,
#else
#define MBEDTLS_DEPRECATED
#endif
+
/**
* \brief This function calculates the SHA-512 or SHA-384
* checksum of a buffer.
@@ -280,6 +281,9 @@ MBEDTLS_DEPRECATED void mbedtls_sha512( const unsigned char *input,
#undef MBEDTLS_DEPRECATED
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
+
+#if defined(MBEDTLS_SELF_TEST)
+
/**
* \brief The SHA-384 or SHA-512 checkup routine.
*
@@ -287,6 +291,7 @@ MBEDTLS_DEPRECATED void mbedtls_sha512( const unsigned char *input,
* \return \c 1 on failure.
*/
int mbedtls_sha512_self_test( int verbose );
+#endif /* MBEDTLS_SELF_TEST */
#ifdef __cplusplus
}
diff --git a/thirdparty/mbedtls/include/mbedtls/ssl.h b/thirdparty/mbedtls/include/mbedtls/ssl.h
index 8106bb4ab0..d31f6cdd56 100644
--- a/thirdparty/mbedtls/include/mbedtls/ssl.h
+++ b/thirdparty/mbedtls/include/mbedtls/ssl.h
@@ -2532,22 +2532,28 @@ void mbedtls_ssl_conf_cert_req_ca_list( mbedtls_ssl_config *conf,
#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
/**
- * \brief Set the maximum fragment length to emit and/or negotiate
- * (Default: the smaller of MBEDTLS_SSL_IN_CONTENT_LEN and
- * MBEDTLS_SSL_OUT_CONTENT_LEN, usually 2^14 bytes)
+ * \brief Set the maximum fragment length to emit and/or negotiate.
+ * (Typical: the smaller of #MBEDTLS_SSL_IN_CONTENT_LEN and
+ * #MBEDTLS_SSL_OUT_CONTENT_LEN, usually `2^14` bytes)
* (Server: set maximum fragment length to emit,
- * usually negotiated by the client during handshake
+ * usually negotiated by the client during handshake)
* (Client: set maximum fragment length to emit *and*
* negotiate with the server during handshake)
+ * (Default: #MBEDTLS_SSL_MAX_FRAG_LEN_NONE)
*
- * \note With TLS, this currently only affects ApplicationData (sent
- * with \c mbedtls_ssl_read()), not handshake messages.
- * With DTLS, this affects both ApplicationData and handshake.
+ * \note On the client side, the maximum fragment length extension
+ * *will not* be used, unless the maximum fragment length has
+ * been set via this function to a value different than
+ * #MBEDTLS_SSL_MAX_FRAG_LEN_NONE.
*
* \note This sets the maximum length for a record's payload,
* excluding record overhead that will be added to it, see
* \c mbedtls_ssl_get_record_expansion().
*
+ * \note With TLS, this currently only affects ApplicationData (sent
+ * with \c mbedtls_ssl_read()), not handshake messages.
+ * With DTLS, this affects both ApplicationData and handshake.
+ *
* \note For DTLS, it is also possible to set a limit for the total
* size of daragrams passed to the transport layer, including
* record overhead, see \c mbedtls_ssl_set_mtu().
diff --git a/thirdparty/mbedtls/include/mbedtls/ssl_cache.h b/thirdparty/mbedtls/include/mbedtls/ssl_cache.h
index ec081e6d24..52ba0948c5 100644
--- a/thirdparty/mbedtls/include/mbedtls/ssl_cache.h
+++ b/thirdparty/mbedtls/include/mbedtls/ssl_cache.h
@@ -24,6 +24,12 @@
#ifndef MBEDTLS_SSL_CACHE_H
#define MBEDTLS_SSL_CACHE_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include "ssl.h"
#if defined(MBEDTLS_THREADING_C)
diff --git a/thirdparty/mbedtls/include/mbedtls/ssl_ciphersuites.h b/thirdparty/mbedtls/include/mbedtls/ssl_ciphersuites.h
index cda8b4835b..71053e5ba7 100644
--- a/thirdparty/mbedtls/include/mbedtls/ssl_ciphersuites.h
+++ b/thirdparty/mbedtls/include/mbedtls/ssl_ciphersuites.h
@@ -24,6 +24,12 @@
#ifndef MBEDTLS_SSL_CIPHERSUITES_H
#define MBEDTLS_SSL_CIPHERSUITES_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include "pk.h"
#include "cipher.h"
#include "md.h"
diff --git a/thirdparty/mbedtls/include/mbedtls/ssl_cookie.h b/thirdparty/mbedtls/include/mbedtls/ssl_cookie.h
index 6a0ad4fa96..e34760ae85 100644
--- a/thirdparty/mbedtls/include/mbedtls/ssl_cookie.h
+++ b/thirdparty/mbedtls/include/mbedtls/ssl_cookie.h
@@ -24,6 +24,12 @@
#ifndef MBEDTLS_SSL_COOKIE_H
#define MBEDTLS_SSL_COOKIE_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include "ssl.h"
#if defined(MBEDTLS_THREADING_C)
diff --git a/thirdparty/mbedtls/include/mbedtls/ssl_internal.h b/thirdparty/mbedtls/include/mbedtls/ssl_internal.h
index 97abb9f90b..bd5ad94dbf 100644
--- a/thirdparty/mbedtls/include/mbedtls/ssl_internal.h
+++ b/thirdparty/mbedtls/include/mbedtls/ssl_internal.h
@@ -24,6 +24,12 @@
#ifndef MBEDTLS_SSL_INTERNAL_H
#define MBEDTLS_SSL_INTERNAL_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
#include "ssl.h"
#include "cipher.h"
diff --git a/thirdparty/mbedtls/include/mbedtls/ssl_ticket.h b/thirdparty/mbedtls/include/mbedtls/ssl_ticket.h
index b2686df09f..a84e7816e4 100644
--- a/thirdparty/mbedtls/include/mbedtls/ssl_ticket.h
+++ b/thirdparty/mbedtls/include/mbedtls/ssl_ticket.h
@@ -24,6 +24,12 @@
#ifndef MBEDTLS_SSL_TICKET_H
#define MBEDTLS_SSL_TICKET_H
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
/*
* This implementation of the session ticket callbacks includes key
* management, rotating the keys periodically in order to preserve forward
diff --git a/thirdparty/mbedtls/include/mbedtls/version.h b/thirdparty/mbedtls/include/mbedtls/version.h
index 56e7398a2a..ef8e4c1f4f 100644
--- a/thirdparty/mbedtls/include/mbedtls/version.h
+++ b/thirdparty/mbedtls/include/mbedtls/version.h
@@ -40,16 +40,16 @@
*/
#define MBEDTLS_VERSION_MAJOR 2
#define MBEDTLS_VERSION_MINOR 16
-#define MBEDTLS_VERSION_PATCH 0
+#define MBEDTLS_VERSION_PATCH 2
/**
* The single version number has the following structure:
* MMNNPP00
* Major version | Minor version | Patch version
*/
-#define MBEDTLS_VERSION_NUMBER 0x02100000
-#define MBEDTLS_VERSION_STRING "2.16.0"
-#define MBEDTLS_VERSION_STRING_FULL "mbed TLS 2.16.0"
+#define MBEDTLS_VERSION_NUMBER 0x02100200
+#define MBEDTLS_VERSION_STRING "2.16.2"
+#define MBEDTLS_VERSION_STRING_FULL "mbed TLS 2.16.2"
#if defined(MBEDTLS_VERSION_C)
diff --git a/thirdparty/mbedtls/include/mbedtls/x509.h b/thirdparty/mbedtls/include/mbedtls/x509.h
index d6db9c6e37..9ae825c183 100644
--- a/thirdparty/mbedtls/include/mbedtls/x509.h
+++ b/thirdparty/mbedtls/include/mbedtls/x509.h
@@ -269,6 +269,8 @@ int mbedtls_x509_time_is_past( const mbedtls_x509_time *to );
*/
int mbedtls_x509_time_is_future( const mbedtls_x509_time *from );
+#if defined(MBEDTLS_SELF_TEST)
+
/**
* \brief Checkup routine
*
@@ -276,6 +278,8 @@ int mbedtls_x509_time_is_future( const mbedtls_x509_time *from );
*/
int mbedtls_x509_self_test( int verbose );
+#endif /* MBEDTLS_SELF_TEST */
+
/*
* Internal module functions. You probably do not want to use these unless you
* know you do.
diff --git a/thirdparty/mbedtls/include/mbedtls/x509_crt.h b/thirdparty/mbedtls/include/mbedtls/x509_crt.h
index 3dd5922486..670bd10d89 100644
--- a/thirdparty/mbedtls/include/mbedtls/x509_crt.h
+++ b/thirdparty/mbedtls/include/mbedtls/x509_crt.h
@@ -98,7 +98,7 @@ mbedtls_x509_crt;
* Build flag from an algorithm/curve identifier (pk, md, ecp)
* Since 0 is always XXX_NONE, ignore it.
*/
-#define MBEDTLS_X509_ID_FLAG( id ) ( 1 << ( id - 1 ) )
+#define MBEDTLS_X509_ID_FLAG( id ) ( 1 << ( (id) - 1 ) )
/**
* Security profile for certificate verification.
diff --git a/thirdparty/mbedtls/include/mbedtls/x509_csr.h b/thirdparty/mbedtls/include/mbedtls/x509_csr.h
index 0c6ccad78d..a3c28048e0 100644
--- a/thirdparty/mbedtls/include/mbedtls/x509_csr.h
+++ b/thirdparty/mbedtls/include/mbedtls/x509_csr.h
@@ -205,6 +205,14 @@ void mbedtls_x509write_csr_set_md_alg( mbedtls_x509write_csr *ctx, mbedtls_md_ty
* \param key_usage key usage flags to set
*
* \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
+ *
+ * \note The <code>decipherOnly</code> flag from the Key Usage
+ * extension is represented by bit 8 (i.e.
+ * <code>0x8000</code>), which cannot typically be represented
+ * in an unsigned char. Therefore, the flag
+ * <code>decipherOnly</code> (i.e.
+ * #MBEDTLS_X509_KU_DECIPHER_ONLY) cannot be set using this
+ * function.
*/
int mbedtls_x509write_csr_set_key_usage( mbedtls_x509write_csr *ctx, unsigned char key_usage );
diff --git a/thirdparty/mbedtls/include/mbedtls/xtea.h b/thirdparty/mbedtls/include/mbedtls/xtea.h
index 6430c1318a..b47f553508 100644
--- a/thirdparty/mbedtls/include/mbedtls/xtea.h
+++ b/thirdparty/mbedtls/include/mbedtls/xtea.h
@@ -121,6 +121,8 @@ int mbedtls_xtea_crypt_cbc( mbedtls_xtea_context *ctx,
unsigned char *output);
#endif /* MBEDTLS_CIPHER_MODE_CBC */
+#if defined(MBEDTLS_SELF_TEST)
+
/**
* \brief Checkup routine
*
@@ -128,6 +130,8 @@ int mbedtls_xtea_crypt_cbc( mbedtls_xtea_context *ctx,
*/
int mbedtls_xtea_self_test( int verbose );
+#endif /* MBEDTLS_SELF_TEST */
+
#ifdef __cplusplus
}
#endif
diff --git a/thirdparty/mbedtls/library/aes.c b/thirdparty/mbedtls/library/aes.c
index 0543cd7817..aff0a9939a 100644
--- a/thirdparty/mbedtls/library/aes.c
+++ b/thirdparty/mbedtls/library/aes.c
@@ -395,9 +395,9 @@ static uint32_t RCON[10];
/*
* Tables generation code
*/
-#define ROTL8(x) ( ( x << 8 ) & 0xFFFFFFFF ) | ( x >> 24 )
-#define XTIME(x) ( ( x << 1 ) ^ ( ( x & 0x80 ) ? 0x1B : 0x00 ) )
-#define MUL(x,y) ( ( x && y ) ? pow[(log[x]+log[y]) % 255] : 0 )
+#define ROTL8(x) ( ( (x) << 8 ) & 0xFFFFFFFF ) | ( (x) >> 24 )
+#define XTIME(x) ( ( (x) << 1 ) ^ ( ( (x) & 0x80 ) ? 0x1B : 0x00 ) )
+#define MUL(x,y) ( ( (x) && (y) ) ? pow[(log[(x)]+log[(y)]) % 255] : 0 )
static int aes_init_done = 0;
@@ -815,51 +815,53 @@ int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx,
#endif /* !MBEDTLS_AES_SETKEY_DEC_ALT */
-#define AES_FROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \
-{ \
- X0 = *RK++ ^ AES_FT0( ( Y0 ) & 0xFF ) ^ \
- AES_FT1( ( Y1 >> 8 ) & 0xFF ) ^ \
- AES_FT2( ( Y2 >> 16 ) & 0xFF ) ^ \
- AES_FT3( ( Y3 >> 24 ) & 0xFF ); \
- \
- X1 = *RK++ ^ AES_FT0( ( Y1 ) & 0xFF ) ^ \
- AES_FT1( ( Y2 >> 8 ) & 0xFF ) ^ \
- AES_FT2( ( Y3 >> 16 ) & 0xFF ) ^ \
- AES_FT3( ( Y0 >> 24 ) & 0xFF ); \
- \
- X2 = *RK++ ^ AES_FT0( ( Y2 ) & 0xFF ) ^ \
- AES_FT1( ( Y3 >> 8 ) & 0xFF ) ^ \
- AES_FT2( ( Y0 >> 16 ) & 0xFF ) ^ \
- AES_FT3( ( Y1 >> 24 ) & 0xFF ); \
- \
- X3 = *RK++ ^ AES_FT0( ( Y3 ) & 0xFF ) ^ \
- AES_FT1( ( Y0 >> 8 ) & 0xFF ) ^ \
- AES_FT2( ( Y1 >> 16 ) & 0xFF ) ^ \
- AES_FT3( ( Y2 >> 24 ) & 0xFF ); \
-}
-
-#define AES_RROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \
-{ \
- X0 = *RK++ ^ AES_RT0( ( Y0 ) & 0xFF ) ^ \
- AES_RT1( ( Y3 >> 8 ) & 0xFF ) ^ \
- AES_RT2( ( Y2 >> 16 ) & 0xFF ) ^ \
- AES_RT3( ( Y1 >> 24 ) & 0xFF ); \
- \
- X1 = *RK++ ^ AES_RT0( ( Y1 ) & 0xFF ) ^ \
- AES_RT1( ( Y0 >> 8 ) & 0xFF ) ^ \
- AES_RT2( ( Y3 >> 16 ) & 0xFF ) ^ \
- AES_RT3( ( Y2 >> 24 ) & 0xFF ); \
- \
- X2 = *RK++ ^ AES_RT0( ( Y2 ) & 0xFF ) ^ \
- AES_RT1( ( Y1 >> 8 ) & 0xFF ) ^ \
- AES_RT2( ( Y0 >> 16 ) & 0xFF ) ^ \
- AES_RT3( ( Y3 >> 24 ) & 0xFF ); \
- \
- X3 = *RK++ ^ AES_RT0( ( Y3 ) & 0xFF ) ^ \
- AES_RT1( ( Y2 >> 8 ) & 0xFF ) ^ \
- AES_RT2( ( Y1 >> 16 ) & 0xFF ) ^ \
- AES_RT3( ( Y0 >> 24 ) & 0xFF ); \
-}
+#define AES_FROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \
+ do \
+ { \
+ (X0) = *RK++ ^ AES_FT0( ( (Y0) ) & 0xFF ) ^ \
+ AES_FT1( ( (Y1) >> 8 ) & 0xFF ) ^ \
+ AES_FT2( ( (Y2) >> 16 ) & 0xFF ) ^ \
+ AES_FT3( ( (Y3) >> 24 ) & 0xFF ); \
+ \
+ (X1) = *RK++ ^ AES_FT0( ( (Y1) ) & 0xFF ) ^ \
+ AES_FT1( ( (Y2) >> 8 ) & 0xFF ) ^ \
+ AES_FT2( ( (Y3) >> 16 ) & 0xFF ) ^ \
+ AES_FT3( ( (Y0) >> 24 ) & 0xFF ); \
+ \
+ (X2) = *RK++ ^ AES_FT0( ( (Y2) ) & 0xFF ) ^ \
+ AES_FT1( ( (Y3) >> 8 ) & 0xFF ) ^ \
+ AES_FT2( ( (Y0) >> 16 ) & 0xFF ) ^ \
+ AES_FT3( ( (Y1) >> 24 ) & 0xFF ); \
+ \
+ (X3) = *RK++ ^ AES_FT0( ( (Y3) ) & 0xFF ) ^ \
+ AES_FT1( ( (Y0) >> 8 ) & 0xFF ) ^ \
+ AES_FT2( ( (Y1) >> 16 ) & 0xFF ) ^ \
+ AES_FT3( ( (Y2) >> 24 ) & 0xFF ); \
+ } while( 0 )
+
+#define AES_RROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \
+ do \
+ { \
+ (X0) = *RK++ ^ AES_RT0( ( (Y0) ) & 0xFF ) ^ \
+ AES_RT1( ( (Y3) >> 8 ) & 0xFF ) ^ \
+ AES_RT2( ( (Y2) >> 16 ) & 0xFF ) ^ \
+ AES_RT3( ( (Y1) >> 24 ) & 0xFF ); \
+ \
+ (X1) = *RK++ ^ AES_RT0( ( (Y1) ) & 0xFF ) ^ \
+ AES_RT1( ( (Y0) >> 8 ) & 0xFF ) ^ \
+ AES_RT2( ( (Y3) >> 16 ) & 0xFF ) ^ \
+ AES_RT3( ( (Y2) >> 24 ) & 0xFF ); \
+ \
+ (X2) = *RK++ ^ AES_RT0( ( (Y2) ) & 0xFF ) ^ \
+ AES_RT1( ( (Y1) >> 8 ) & 0xFF ) ^ \
+ AES_RT2( ( (Y0) >> 16 ) & 0xFF ) ^ \
+ AES_RT3( ( (Y3) >> 24 ) & 0xFF ); \
+ \
+ (X3) = *RK++ ^ AES_RT0( ( (Y3) ) & 0xFF ) ^ \
+ AES_RT1( ( (Y2) >> 8 ) & 0xFF ) ^ \
+ AES_RT2( ( (Y1) >> 16 ) & 0xFF ) ^ \
+ AES_RT3( ( (Y0) >> 24 ) & 0xFF ); \
+ } while( 0 )
/*
* AES-ECB block encryption
diff --git a/thirdparty/mbedtls/library/asn1write.c b/thirdparty/mbedtls/library/asn1write.c
index a4d23f6196..c0b4622d58 100644
--- a/thirdparty/mbedtls/library/asn1write.c
+++ b/thirdparty/mbedtls/library/asn1write.c
@@ -294,22 +294,28 @@ int mbedtls_asn1_write_bitstring( unsigned char **p, unsigned char *start,
const unsigned char *buf, size_t bits )
{
int ret;
- size_t len = 0, size;
+ size_t len = 0;
+ size_t unused_bits, byte_len;
- size = ( bits / 8 ) + ( ( bits % 8 ) ? 1 : 0 );
+ byte_len = ( bits + 7 ) / 8;
+ unused_bits = ( byte_len * 8 ) - bits;
- // Calculate byte length
- //
- if( *p < start || (size_t)( *p - start ) < size + 1 )
+ if( *p < start || (size_t)( *p - start ) < byte_len + 1 )
return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
- len = size + 1;
- (*p) -= size;
- memcpy( *p, buf, size );
+ len = byte_len + 1;
- // Write unused bits
- //
- *--(*p) = (unsigned char) (size * 8 - bits);
+ /* Write the bitstring. Ensure the unused bits are zeroed */
+ if( byte_len > 0 )
+ {
+ byte_len--;
+ *--( *p ) = buf[byte_len] & ~( ( 0x1 << unused_bits ) - 1 );
+ ( *p ) -= byte_len;
+ memcpy( *p, buf, byte_len );
+ }
+
+ /* Write unused bits */
+ *--( *p ) = (unsigned char)unused_bits;
MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, len ) );
MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, MBEDTLS_ASN1_BIT_STRING ) );
diff --git a/thirdparty/mbedtls/library/bignum.c b/thirdparty/mbedtls/library/bignum.c
index f968a0ad7d..41946183c5 100644
--- a/thirdparty/mbedtls/library/bignum.c
+++ b/thirdparty/mbedtls/library/bignum.c
@@ -527,26 +527,38 @@ cleanup:
}
/*
- * Helper to write the digits high-order first
+ * Helper to write the digits high-order first.
*/
-static int mpi_write_hlp( mbedtls_mpi *X, int radix, char **p )
+static int mpi_write_hlp( mbedtls_mpi *X, int radix,
+ char **p, const size_t buflen )
{
int ret;
mbedtls_mpi_uint r;
+ size_t length = 0;
+ char *p_end = *p + buflen;
- if( radix < 2 || radix > 16 )
- return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
+ do
+ {
+ if( length >= buflen )
+ {
+ return( MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL );
+ }
- MBEDTLS_MPI_CHK( mbedtls_mpi_mod_int( &r, X, radix ) );
- MBEDTLS_MPI_CHK( mbedtls_mpi_div_int( X, NULL, X, radix ) );
+ MBEDTLS_MPI_CHK( mbedtls_mpi_mod_int( &r, X, radix ) );
+ MBEDTLS_MPI_CHK( mbedtls_mpi_div_int( X, NULL, X, radix ) );
+ /*
+ * Write the residue in the current position, as an ASCII character.
+ */
+ if( r < 0xA )
+ *(--p_end) = (char)( '0' + r );
+ else
+ *(--p_end) = (char)( 'A' + ( r - 0xA ) );
- if( mbedtls_mpi_cmp_int( X, 0 ) != 0 )
- MBEDTLS_MPI_CHK( mpi_write_hlp( X, radix, p ) );
+ length++;
+ } while( mbedtls_mpi_cmp_int( X, 0 ) != 0 );
- if( r < 10 )
- *(*p)++ = (char)( r + 0x30 );
- else
- *(*p)++ = (char)( r + 0x37 );
+ memmove( *p, p_end, length );
+ *p += length;
cleanup:
@@ -570,15 +582,20 @@ int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix,
if( radix < 2 || radix > 16 )
return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
- n = mbedtls_mpi_bitlen( X );
- if( radix >= 4 ) n >>= 1;
- if( radix >= 16 ) n >>= 1;
- /*
- * Round up the buffer length to an even value to ensure that there is
- * enough room for hexadecimal values that can be represented in an odd
- * number of digits.
- */
- n += 3 + ( ( n + 1 ) & 1 );
+ n = mbedtls_mpi_bitlen( X ); /* Number of bits necessary to present `n`. */
+ if( radix >= 4 ) n >>= 1; /* Number of 4-adic digits necessary to present
+ * `n`. If radix > 4, this might be a strict
+ * overapproximation of the number of
+ * radix-adic digits needed to present `n`. */
+ if( radix >= 16 ) n >>= 1; /* Number of hexadecimal digits necessary to
+ * present `n`. */
+
+ n += 1; /* Terminating null byte */
+ n += 1; /* Compensate for the divisions above, which round down `n`
+ * in case it's not even. */
+ n += 1; /* Potential '-'-sign. */
+ n += ( n & 1 ); /* Make n even to have enough space for hexadecimal writing,
+ * which always uses an even number of hex-digits. */
if( buflen < n )
{
@@ -590,7 +607,10 @@ int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix,
mbedtls_mpi_init( &T );
if( X->s == -1 )
+ {
*p++ = '-';
+ buflen--;
+ }
if( radix == 16 )
{
@@ -619,7 +639,7 @@ int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix,
if( T.s == -1 )
T.s = 1;
- MBEDTLS_MPI_CHK( mpi_write_hlp( &T, radix, &p ) );
+ MBEDTLS_MPI_CHK( mpi_write_hlp( &T, radix, &p, buflen ) );
}
*p++ = '\0';
@@ -715,14 +735,101 @@ cleanup:
}
#endif /* MBEDTLS_FS_IO */
+
+/* Convert a big-endian byte array aligned to the size of mbedtls_mpi_uint
+ * into the storage form used by mbedtls_mpi. */
+
+static mbedtls_mpi_uint mpi_uint_bigendian_to_host_c( mbedtls_mpi_uint x )
+{
+ uint8_t i;
+ mbedtls_mpi_uint tmp = 0;
+ /* This works regardless of the endianness. */
+ for( i = 0; i < ciL; i++, x >>= 8 )
+ tmp |= ( x & 0xFF ) << ( ( ciL - 1 - i ) << 3 );
+ return( tmp );
+}
+
+static mbedtls_mpi_uint mpi_uint_bigendian_to_host( mbedtls_mpi_uint x )
+{
+#if defined(__BYTE_ORDER__)
+
+/* Nothing to do on bigendian systems. */
+#if ( __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ )
+ return( x );
+#endif /* __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ */
+
+#if ( __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ )
+
+/* For GCC and Clang, have builtins for byte swapping. */
+#if defined(__GNUC__) && defined(__GNUC_PREREQ)
+#if __GNUC_PREREQ(4,3)
+#define have_bswap
+#endif
+#endif
+
+#if defined(__clang__) && defined(__has_builtin)
+#if __has_builtin(__builtin_bswap32) && \
+ __has_builtin(__builtin_bswap64)
+#define have_bswap
+#endif
+#endif
+
+#if defined(have_bswap)
+ /* The compiler is hopefully able to statically evaluate this! */
+ switch( sizeof(mbedtls_mpi_uint) )
+ {
+ case 4:
+ return( __builtin_bswap32(x) );
+ case 8:
+ return( __builtin_bswap64(x) );
+ }
+#endif
+#endif /* __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ */
+#endif /* __BYTE_ORDER__ */
+
+ /* Fall back to C-based reordering if we don't know the byte order
+ * or we couldn't use a compiler-specific builtin. */
+ return( mpi_uint_bigendian_to_host_c( x ) );
+}
+
+static void mpi_bigendian_to_host( mbedtls_mpi_uint * const p, size_t limbs )
+{
+ mbedtls_mpi_uint *cur_limb_left;
+ mbedtls_mpi_uint *cur_limb_right;
+ if( limbs == 0 )
+ return;
+
+ /*
+ * Traverse limbs and
+ * - adapt byte-order in each limb
+ * - swap the limbs themselves.
+ * For that, simultaneously traverse the limbs from left to right
+ * and from right to left, as long as the left index is not bigger
+ * than the right index (it's not a problem if limbs is odd and the
+ * indices coincide in the last iteration).
+ */
+ for( cur_limb_left = p, cur_limb_right = p + ( limbs - 1 );
+ cur_limb_left <= cur_limb_right;
+ cur_limb_left++, cur_limb_right-- )
+ {
+ mbedtls_mpi_uint tmp;
+ /* Note that if cur_limb_left == cur_limb_right,
+ * this code effectively swaps the bytes only once. */
+ tmp = mpi_uint_bigendian_to_host( *cur_limb_left );
+ *cur_limb_left = mpi_uint_bigendian_to_host( *cur_limb_right );
+ *cur_limb_right = tmp;
+ }
+}
+
/*
* Import X from unsigned binary data, big endian
*/
int mbedtls_mpi_read_binary( mbedtls_mpi *X, const unsigned char *buf, size_t buflen )
{
int ret;
- size_t i, j;
- size_t const limbs = CHARS_TO_LIMBS( buflen );
+ size_t const limbs = CHARS_TO_LIMBS( buflen );
+ size_t const overhead = ( limbs * ciL ) - buflen;
+ unsigned char *Xp;
MPI_VALIDATE_RET( X != NULL );
MPI_VALIDATE_RET( buflen == 0 || buf != NULL );
@@ -734,11 +841,17 @@ int mbedtls_mpi_read_binary( mbedtls_mpi *X, const unsigned char *buf, size_t bu
mbedtls_mpi_init( X );
MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, limbs ) );
}
-
MBEDTLS_MPI_CHK( mbedtls_mpi_lset( X, 0 ) );
- for( i = buflen, j = 0; i > 0; i--, j++ )
- X->p[j / ciL] |= ((mbedtls_mpi_uint) buf[i - 1]) << ((j % ciL) << 3);
+ /* Avoid calling `memcpy` with NULL source argument,
+ * even if buflen is 0. */
+ if( buf != NULL )
+ {
+ Xp = (unsigned char*) X->p;
+ memcpy( Xp + overhead, buf, buflen );
+
+ mpi_bigendian_to_host( X->p, limbs );
+ }
cleanup:
@@ -1764,8 +1877,10 @@ int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A,
wsize = ( i > 671 ) ? 6 : ( i > 239 ) ? 5 :
( i > 79 ) ? 4 : ( i > 23 ) ? 3 : 1;
+#if( MBEDTLS_MPI_WINDOW_SIZE < 6 )
if( wsize > MBEDTLS_MPI_WINDOW_SIZE )
wsize = MBEDTLS_MPI_WINDOW_SIZE;
+#endif
j = N->n + 1;
MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, j ) );
@@ -2008,18 +2123,28 @@ int mbedtls_mpi_fill_random( mbedtls_mpi *X, size_t size,
void *p_rng )
{
int ret;
- unsigned char buf[MBEDTLS_MPI_MAX_SIZE];
+ size_t const limbs = CHARS_TO_LIMBS( size );
+ size_t const overhead = ( limbs * ciL ) - size;
+ unsigned char *Xp;
+
MPI_VALIDATE_RET( X != NULL );
MPI_VALIDATE_RET( f_rng != NULL );
- if( size > MBEDTLS_MPI_MAX_SIZE )
- return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
+ /* Ensure that target MPI has exactly the necessary number of limbs */
+ if( X->n != limbs )
+ {
+ mbedtls_mpi_free( X );
+ mbedtls_mpi_init( X );
+ MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, limbs ) );
+ }
+ MBEDTLS_MPI_CHK( mbedtls_mpi_lset( X, 0 ) );
+
+ Xp = (unsigned char*) X->p;
+ f_rng( p_rng, Xp + overhead, size );
- MBEDTLS_MPI_CHK( f_rng( p_rng, buf, size ) );
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( X, buf, size ) );
+ mpi_bigendian_to_host( X->p, limbs );
cleanup:
- mbedtls_platform_zeroize( buf, sizeof( buf ) );
return( ret );
}
diff --git a/thirdparty/mbedtls/library/ccm.c b/thirdparty/mbedtls/library/ccm.c
index 01e58b0436..c6211ee773 100644
--- a/thirdparty/mbedtls/library/ccm.c
+++ b/thirdparty/mbedtls/library/ccm.c
@@ -134,11 +134,17 @@ void mbedtls_ccm_free( mbedtls_ccm_context *ctx )
* This avoids allocating one more 16 bytes buffer while allowing src == dst.
*/
#define CTR_CRYPT( dst, src, len ) \
- if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, ctr, 16, b, &olen ) ) != 0 ) \
- return( ret ); \
- \
- for( i = 0; i < len; i++ ) \
- dst[i] = src[i] ^ b[i];
+ do \
+ { \
+ if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, ctr, \
+ 16, b, &olen ) ) != 0 ) \
+ { \
+ return( ret ); \
+ } \
+ \
+ for( i = 0; i < (len); i++ ) \
+ (dst)[i] = (src)[i] ^ b[i]; \
+ } while( 0 )
/*
* Authenticated encryption or decryption
diff --git a/thirdparty/mbedtls/library/certs.c b/thirdparty/mbedtls/library/certs.c
index ff0f11e923..b07fd8a3a1 100644
--- a/thirdparty/mbedtls/library/certs.c
+++ b/thirdparty/mbedtls/library/certs.c
@@ -29,328 +29,1673 @@
#if defined(MBEDTLS_CERTS_C)
-#if defined(MBEDTLS_ECDSA_C)
-#define TEST_CA_CRT_EC \
-"-----BEGIN CERTIFICATE-----\r\n" \
-"MIICUjCCAdegAwIBAgIJAMFD4n5iQ8zoMAoGCCqGSM49BAMCMD4xCzAJBgNVBAYT\r\n" \
-"Ak5MMREwDwYDVQQKEwhQb2xhclNTTDEcMBoGA1UEAxMTUG9sYXJzc2wgVGVzdCBF\r\n" \
-"QyBDQTAeFw0xMzA5MjQxNTQ5NDhaFw0yMzA5MjIxNTQ5NDhaMD4xCzAJBgNVBAYT\r\n" \
-"Ak5MMREwDwYDVQQKEwhQb2xhclNTTDEcMBoGA1UEAxMTUG9sYXJzc2wgVGVzdCBF\r\n" \
-"QyBDQTB2MBAGByqGSM49AgEGBSuBBAAiA2IABMPaKzRBN1gvh1b+/Im6KUNLTuBu\r\n" \
-"ww5XUzM5WNRStJGVOQsj318XJGJI/BqVKc4sLYfCiFKAr9ZqqyHduNMcbli4yuiy\r\n" \
-"aY7zQa0pw7RfdadHb9UZKVVpmlM7ILRmFmAzHqOBoDCBnTAdBgNVHQ4EFgQUnW0g\r\n" \
-"JEkBPyvLeLUZvH4kydv7NnwwbgYDVR0jBGcwZYAUnW0gJEkBPyvLeLUZvH4kydv7\r\n" \
-"NnyhQqRAMD4xCzAJBgNVBAYTAk5MMREwDwYDVQQKEwhQb2xhclNTTDEcMBoGA1UE\r\n" \
-"AxMTUG9sYXJzc2wgVGVzdCBFQyBDQYIJAMFD4n5iQ8zoMAwGA1UdEwQFMAMBAf8w\r\n" \
-"CgYIKoZIzj0EAwIDaQAwZgIxAMO0YnNWKJUAfXgSJtJxexn4ipg+kv4znuR50v56\r\n" \
-"t4d0PCu412mUC6Nnd7izvtE2MgIxAP1nnJQjZ8BWukszFQDG48wxCCyci9qpdSMv\r\n" \
-"uCjn8pwUOkABXK8Mss90fzCfCEOtIA==\r\n" \
-"-----END CERTIFICATE-----\r\n"
-const char mbedtls_test_ca_crt_ec[] = TEST_CA_CRT_EC;
-const size_t mbedtls_test_ca_crt_ec_len = sizeof( mbedtls_test_ca_crt_ec );
-
-const char mbedtls_test_ca_key_ec[] =
-"-----BEGIN EC PRIVATE KEY-----\r\n"
-"Proc-Type: 4,ENCRYPTED\r\n"
-"DEK-Info: DES-EDE3-CBC,307EAB469933D64E\r\n"
-"\r\n"
-"IxbrRmKcAzctJqPdTQLA4SWyBYYGYJVkYEna+F7Pa5t5Yg/gKADrFKcm6B72e7DG\r\n"
-"ihExtZI648s0zdYw6qSJ74vrPSuWDe5qm93BqsfVH9svtCzWHW0pm1p0KTBCFfUq\r\n"
-"UsuWTITwJImcnlAs1gaRZ3sAWm7cOUidL0fo2G0fYUFNcYoCSLffCFTEHBuPnagb\r\n"
-"a77x/sY1Bvii8S9/XhDTb6pTMx06wzrm\r\n"
-"-----END EC PRIVATE KEY-----\r\n";
-const size_t mbedtls_test_ca_key_ec_len = sizeof( mbedtls_test_ca_key_ec );
-
-const char mbedtls_test_ca_pwd_ec[] = "PolarSSLTest";
-const size_t mbedtls_test_ca_pwd_ec_len = sizeof( mbedtls_test_ca_pwd_ec ) - 1;
-
-const char mbedtls_test_srv_crt_ec[] =
-"-----BEGIN CERTIFICATE-----\r\n"
-"MIICHzCCAaWgAwIBAgIBCTAKBggqhkjOPQQDAjA+MQswCQYDVQQGEwJOTDERMA8G\r\n"
-"A1UEChMIUG9sYXJTU0wxHDAaBgNVBAMTE1BvbGFyc3NsIFRlc3QgRUMgQ0EwHhcN\r\n"
-"MTMwOTI0MTU1MjA0WhcNMjMwOTIyMTU1MjA0WjA0MQswCQYDVQQGEwJOTDERMA8G\r\n"
-"A1UEChMIUG9sYXJTU0wxEjAQBgNVBAMTCWxvY2FsaG9zdDBZMBMGByqGSM49AgEG\r\n"
-"CCqGSM49AwEHA0IABDfMVtl2CR5acj7HWS3/IG7ufPkGkXTQrRS192giWWKSTuUA\r\n"
-"2CMR/+ov0jRdXRa9iojCa3cNVc2KKg76Aci07f+jgZ0wgZowCQYDVR0TBAIwADAd\r\n"
-"BgNVHQ4EFgQUUGGlj9QH2deCAQzlZX+MY0anE74wbgYDVR0jBGcwZYAUnW0gJEkB\r\n"
-"PyvLeLUZvH4kydv7NnyhQqRAMD4xCzAJBgNVBAYTAk5MMREwDwYDVQQKEwhQb2xh\r\n"
-"clNTTDEcMBoGA1UEAxMTUG9sYXJzc2wgVGVzdCBFQyBDQYIJAMFD4n5iQ8zoMAoG\r\n"
-"CCqGSM49BAMCA2gAMGUCMQCaLFzXptui5WQN8LlO3ddh1hMxx6tzgLvT03MTVK2S\r\n"
-"C12r0Lz3ri/moSEpNZWqPjkCMCE2f53GXcYLqyfyJR078c/xNSUU5+Xxl7VZ414V\r\n"
-"fGa5kHvHARBPc8YAIVIqDvHH1Q==\r\n"
-"-----END CERTIFICATE-----\r\n";
-const size_t mbedtls_test_srv_crt_ec_len = sizeof( mbedtls_test_srv_crt_ec );
-
-const char mbedtls_test_srv_key_ec[] =
-"-----BEGIN EC PRIVATE KEY-----\r\n"
-"MHcCAQEEIPEqEyB2AnCoPL/9U/YDHvdqXYbIogTywwyp6/UfDw6noAoGCCqGSM49\r\n"
-"AwEHoUQDQgAEN8xW2XYJHlpyPsdZLf8gbu58+QaRdNCtFLX3aCJZYpJO5QDYIxH/\r\n"
-"6i/SNF1dFr2KiMJrdw1VzYoqDvoByLTt/w==\r\n"
-"-----END EC PRIVATE KEY-----\r\n";
-const size_t mbedtls_test_srv_key_ec_len = sizeof( mbedtls_test_srv_key_ec );
-
-const char mbedtls_test_cli_crt_ec[] =
-"-----BEGIN CERTIFICATE-----\r\n"
-"MIICLDCCAbKgAwIBAgIBDTAKBggqhkjOPQQDAjA+MQswCQYDVQQGEwJOTDERMA8G\r\n"
-"A1UEChMIUG9sYXJTU0wxHDAaBgNVBAMTE1BvbGFyc3NsIFRlc3QgRUMgQ0EwHhcN\r\n"
-"MTMwOTI0MTU1MjA0WhcNMjMwOTIyMTU1MjA0WjBBMQswCQYDVQQGEwJOTDERMA8G\r\n"
-"A1UEChMIUG9sYXJTU0wxHzAdBgNVBAMTFlBvbGFyU1NMIFRlc3QgQ2xpZW50IDIw\r\n"
-"WTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARX5a6xc9/TrLuTuIH/Eq7u5lOszlVT\r\n"
-"9jQOzC7jYyUL35ji81xgNpbA1RgUcOV/n9VLRRjlsGzVXPiWj4dwo+THo4GdMIGa\r\n"
-"MAkGA1UdEwQCMAAwHQYDVR0OBBYEFHoAX4Zk/OBd5REQO7LmO8QmP8/iMG4GA1Ud\r\n"
-"IwRnMGWAFJ1tICRJAT8ry3i1Gbx+JMnb+zZ8oUKkQDA+MQswCQYDVQQGEwJOTDER\r\n"
-"MA8GA1UEChMIUG9sYXJTU0wxHDAaBgNVBAMTE1BvbGFyc3NsIFRlc3QgRUMgQ0GC\r\n"
-"CQDBQ+J+YkPM6DAKBggqhkjOPQQDAgNoADBlAjBKZQ17IIOimbmoD/yN7o89u3BM\r\n"
-"lgOsjnhw3fIOoLIWy2WOGsk/LGF++DzvrRzuNiACMQCd8iem1XS4JK7haj8xocpU\r\n"
-"LwjQje5PDGHfd3h9tP38Qknu5bJqws0md2KOKHyeV0U=\r\n"
-"-----END CERTIFICATE-----\r\n";
-const size_t mbedtls_test_cli_crt_ec_len = sizeof( mbedtls_test_cli_crt_ec );
-
-const char mbedtls_test_cli_key_ec[] =
-"-----BEGIN EC PRIVATE KEY-----\r\n"
-"MHcCAQEEIPb3hmTxZ3/mZI3vyk7p3U3wBf+WIop6hDhkFzJhmLcqoAoGCCqGSM49\r\n"
-"AwEHoUQDQgAEV+WusXPf06y7k7iB/xKu7uZTrM5VU/Y0Dswu42MlC9+Y4vNcYDaW\r\n"
-"wNUYFHDlf5/VS0UY5bBs1Vz4lo+HcKPkxw==\r\n"
-"-----END EC PRIVATE KEY-----\r\n";
-const size_t mbedtls_test_cli_key_ec_len = sizeof( mbedtls_test_cli_key_ec );
-#endif /* MBEDTLS_ECDSA_C */
+/*
+ * Test CA Certificates
+ *
+ * We define test CA certificates for each choice of the following parameters:
+ * - PEM or DER encoding
+ * - SHA-1 or SHA-256 hash
+ * - RSA or EC key
+ *
+ * Things to add:
+ * - multiple EC curve types
+ *
+ */
-#if defined(MBEDTLS_RSA_C)
+/* This is taken from tests/data_files/test-ca2.crt */
+/* BEGIN FILE string macro TEST_CA_CRT_EC_PEM tests/data_files/test-ca2.crt */
+#define TEST_CA_CRT_EC_PEM \
+ "-----BEGIN CERTIFICATE-----\r\n" \
+ "MIICUjCCAdegAwIBAgIJAMFD4n5iQ8zoMAoGCCqGSM49BAMCMD4xCzAJBgNVBAYT\r\n" \
+ "Ak5MMREwDwYDVQQKEwhQb2xhclNTTDEcMBoGA1UEAxMTUG9sYXJzc2wgVGVzdCBF\r\n" \
+ "QyBDQTAeFw0xMzA5MjQxNTQ5NDhaFw0yMzA5MjIxNTQ5NDhaMD4xCzAJBgNVBAYT\r\n" \
+ "Ak5MMREwDwYDVQQKEwhQb2xhclNTTDEcMBoGA1UEAxMTUG9sYXJzc2wgVGVzdCBF\r\n" \
+ "QyBDQTB2MBAGByqGSM49AgEGBSuBBAAiA2IABMPaKzRBN1gvh1b+/Im6KUNLTuBu\r\n" \
+ "ww5XUzM5WNRStJGVOQsj318XJGJI/BqVKc4sLYfCiFKAr9ZqqyHduNMcbli4yuiy\r\n" \
+ "aY7zQa0pw7RfdadHb9UZKVVpmlM7ILRmFmAzHqOBoDCBnTAdBgNVHQ4EFgQUnW0g\r\n" \
+ "JEkBPyvLeLUZvH4kydv7NnwwbgYDVR0jBGcwZYAUnW0gJEkBPyvLeLUZvH4kydv7\r\n" \
+ "NnyhQqRAMD4xCzAJBgNVBAYTAk5MMREwDwYDVQQKEwhQb2xhclNTTDEcMBoGA1UE\r\n" \
+ "AxMTUG9sYXJzc2wgVGVzdCBFQyBDQYIJAMFD4n5iQ8zoMAwGA1UdEwQFMAMBAf8w\r\n" \
+ "CgYIKoZIzj0EAwIDaQAwZgIxAMO0YnNWKJUAfXgSJtJxexn4ipg+kv4znuR50v56\r\n" \
+ "t4d0PCu412mUC6Nnd7izvtE2MgIxAP1nnJQjZ8BWukszFQDG48wxCCyci9qpdSMv\r\n" \
+ "uCjn8pwUOkABXK8Mss90fzCfCEOtIA==\r\n" \
+ "-----END CERTIFICATE-----\r\n"
+/* END FILE */
+
+/* This is generated from tests/data_files/test-ca2.crt.der using `xxd -i`. */
+/* BEGIN FILE binary macro TEST_CA_CRT_EC_DER tests/data_files/test-ca2.crt.der */
+#define TEST_CA_CRT_EC_DER { \
+ 0x30, 0x82, 0x02, 0x52, 0x30, 0x82, 0x01, 0xd7, 0xa0, 0x03, 0x02, 0x01, \
+ 0x02, 0x02, 0x09, 0x00, 0xc1, 0x43, 0xe2, 0x7e, 0x62, 0x43, 0xcc, 0xe8, \
+ 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, \
+ 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, \
+ 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, \
+ 0x13, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x1c, \
+ 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x13, 0x50, 0x6f, 0x6c, \
+ 0x61, 0x72, 0x73, 0x73, 0x6c, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x45, \
+ 0x43, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x33, 0x30, 0x39, \
+ 0x32, 0x34, 0x31, 0x35, 0x34, 0x39, 0x34, 0x38, 0x5a, 0x17, 0x0d, 0x32, \
+ 0x33, 0x30, 0x39, 0x32, 0x32, 0x31, 0x35, 0x34, 0x39, 0x34, 0x38, 0x5a, \
+ 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, \
+ 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, \
+ 0x13, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x1c, \
+ 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x13, 0x50, 0x6f, 0x6c, \
+ 0x61, 0x72, 0x73, 0x73, 0x6c, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x45, \
+ 0x43, 0x20, 0x43, 0x41, 0x30, 0x76, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, \
+ 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x22, \
+ 0x03, 0x62, 0x00, 0x04, 0xc3, 0xda, 0x2b, 0x34, 0x41, 0x37, 0x58, 0x2f, \
+ 0x87, 0x56, 0xfe, 0xfc, 0x89, 0xba, 0x29, 0x43, 0x4b, 0x4e, 0xe0, 0x6e, \
+ 0xc3, 0x0e, 0x57, 0x53, 0x33, 0x39, 0x58, 0xd4, 0x52, 0xb4, 0x91, 0x95, \
+ 0x39, 0x0b, 0x23, 0xdf, 0x5f, 0x17, 0x24, 0x62, 0x48, 0xfc, 0x1a, 0x95, \
+ 0x29, 0xce, 0x2c, 0x2d, 0x87, 0xc2, 0x88, 0x52, 0x80, 0xaf, 0xd6, 0x6a, \
+ 0xab, 0x21, 0xdd, 0xb8, 0xd3, 0x1c, 0x6e, 0x58, 0xb8, 0xca, 0xe8, 0xb2, \
+ 0x69, 0x8e, 0xf3, 0x41, 0xad, 0x29, 0xc3, 0xb4, 0x5f, 0x75, 0xa7, 0x47, \
+ 0x6f, 0xd5, 0x19, 0x29, 0x55, 0x69, 0x9a, 0x53, 0x3b, 0x20, 0xb4, 0x66, \
+ 0x16, 0x60, 0x33, 0x1e, 0xa3, 0x81, 0xa0, 0x30, 0x81, 0x9d, 0x30, 0x1d, \
+ 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x9d, 0x6d, 0x20, \
+ 0x24, 0x49, 0x01, 0x3f, 0x2b, 0xcb, 0x78, 0xb5, 0x19, 0xbc, 0x7e, 0x24, \
+ 0xc9, 0xdb, 0xfb, 0x36, 0x7c, 0x30, 0x6e, 0x06, 0x03, 0x55, 0x1d, 0x23, \
+ 0x04, 0x67, 0x30, 0x65, 0x80, 0x14, 0x9d, 0x6d, 0x20, 0x24, 0x49, 0x01, \
+ 0x3f, 0x2b, 0xcb, 0x78, 0xb5, 0x19, 0xbc, 0x7e, 0x24, 0xc9, 0xdb, 0xfb, \
+ 0x36, 0x7c, 0xa1, 0x42, 0xa4, 0x40, 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, \
+ 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, \
+ 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x50, 0x6f, 0x6c, 0x61, \
+ 0x72, 0x53, 0x53, 0x4c, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, \
+ 0x03, 0x13, 0x13, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x73, 0x73, 0x6c, 0x20, \
+ 0x54, 0x65, 0x73, 0x74, 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x82, 0x09, \
+ 0x00, 0xc1, 0x43, 0xe2, 0x7e, 0x62, 0x43, 0xcc, 0xe8, 0x30, 0x0c, 0x06, \
+ 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, \
+ 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, \
+ 0x69, 0x00, 0x30, 0x66, 0x02, 0x31, 0x00, 0xc3, 0xb4, 0x62, 0x73, 0x56, \
+ 0x28, 0x95, 0x00, 0x7d, 0x78, 0x12, 0x26, 0xd2, 0x71, 0x7b, 0x19, 0xf8, \
+ 0x8a, 0x98, 0x3e, 0x92, 0xfe, 0x33, 0x9e, 0xe4, 0x79, 0xd2, 0xfe, 0x7a, \
+ 0xb7, 0x87, 0x74, 0x3c, 0x2b, 0xb8, 0xd7, 0x69, 0x94, 0x0b, 0xa3, 0x67, \
+ 0x77, 0xb8, 0xb3, 0xbe, 0xd1, 0x36, 0x32, 0x02, 0x31, 0x00, 0xfd, 0x67, \
+ 0x9c, 0x94, 0x23, 0x67, 0xc0, 0x56, 0xba, 0x4b, 0x33, 0x15, 0x00, 0xc6, \
+ 0xe3, 0xcc, 0x31, 0x08, 0x2c, 0x9c, 0x8b, 0xda, 0xa9, 0x75, 0x23, 0x2f, \
+ 0xb8, 0x28, 0xe7, 0xf2, 0x9c, 0x14, 0x3a, 0x40, 0x01, 0x5c, 0xaf, 0x0c, \
+ 0xb2, 0xcf, 0x74, 0x7f, 0x30, 0x9f, 0x08, 0x43, 0xad, 0x20 \
+}
+/* END FILE */
+
+/* This is taken from tests/data_files/test-ca2.key.enc */
+/* BEGIN FILE string macro TEST_CA_KEY_EC_PEM tests/data_files/test-ca2.key.enc */
+#define TEST_CA_KEY_EC_PEM \
+ "-----BEGIN EC PRIVATE KEY-----\r\n" \
+ "Proc-Type: 4,ENCRYPTED\r\n" \
+ "DEK-Info: DES-EDE3-CBC,307EAB469933D64E\r\n" \
+ "\r\n" \
+ "IxbrRmKcAzctJqPdTQLA4SWyBYYGYJVkYEna+F7Pa5t5Yg/gKADrFKcm6B72e7DG\r\n" \
+ "ihExtZI648s0zdYw6qSJ74vrPSuWDe5qm93BqsfVH9svtCzWHW0pm1p0KTBCFfUq\r\n" \
+ "UsuWTITwJImcnlAs1gaRZ3sAWm7cOUidL0fo2G0fYUFNcYoCSLffCFTEHBuPnagb\r\n" \
+ "a77x/sY1Bvii8S9/XhDTb6pTMx06wzrm\r\n" \
+ "-----END EC PRIVATE KEY-----\r\n"
+/* END FILE */
+
+#define TEST_CA_PWD_EC_PEM "PolarSSLTest"
+
+/* This is generated from tests/data_files/test-ca2.key.der using `xxd -i`. */
+/* BEGIN FILE binary macro TEST_CA_KEY_EC_DER tests/data_files/test-ca2.key.der */
+#define TEST_CA_KEY_EC_DER { \
+ 0x30, 0x81, 0xa4, 0x02, 0x01, 0x01, 0x04, 0x30, 0x83, 0xd9, 0x15, 0x0e, \
+ 0xa0, 0x71, 0xf0, 0x57, 0x10, 0x33, 0xa3, 0x38, 0xb8, 0x86, 0xc1, 0xa6, \
+ 0x11, 0x5d, 0x6d, 0xb4, 0x03, 0xe1, 0x29, 0x76, 0x45, 0xd7, 0x87, 0x6f, \
+ 0x23, 0xab, 0x44, 0x20, 0xea, 0x64, 0x7b, 0x85, 0xb1, 0x76, 0xe7, 0x85, \
+ 0x95, 0xaa, 0x74, 0xd6, 0xd1, 0xa4, 0x5e, 0xea, 0xa0, 0x07, 0x06, 0x05, \
+ 0x2b, 0x81, 0x04, 0x00, 0x22, 0xa1, 0x64, 0x03, 0x62, 0x00, 0x04, 0xc3, \
+ 0xda, 0x2b, 0x34, 0x41, 0x37, 0x58, 0x2f, 0x87, 0x56, 0xfe, 0xfc, 0x89, \
+ 0xba, 0x29, 0x43, 0x4b, 0x4e, 0xe0, 0x6e, 0xc3, 0x0e, 0x57, 0x53, 0x33, \
+ 0x39, 0x58, 0xd4, 0x52, 0xb4, 0x91, 0x95, 0x39, 0x0b, 0x23, 0xdf, 0x5f, \
+ 0x17, 0x24, 0x62, 0x48, 0xfc, 0x1a, 0x95, 0x29, 0xce, 0x2c, 0x2d, 0x87, \
+ 0xc2, 0x88, 0x52, 0x80, 0xaf, 0xd6, 0x6a, 0xab, 0x21, 0xdd, 0xb8, 0xd3, \
+ 0x1c, 0x6e, 0x58, 0xb8, 0xca, 0xe8, 0xb2, 0x69, 0x8e, 0xf3, 0x41, 0xad, \
+ 0x29, 0xc3, 0xb4, 0x5f, 0x75, 0xa7, 0x47, 0x6f, 0xd5, 0x19, 0x29, 0x55, \
+ 0x69, 0x9a, 0x53, 0x3b, 0x20, 0xb4, 0x66, 0x16, 0x60, 0x33, 0x1e \
+}
+/* END FILE */
+
+/* This is taken from tests/data_files/test-ca-sha256.crt. */
+/* BEGIN FILE string macro TEST_CA_CRT_RSA_SHA256_PEM tests/data_files/test-ca-sha256.crt */
+#define TEST_CA_CRT_RSA_SHA256_PEM \
+ "-----BEGIN CERTIFICATE-----\r\n" \
+ "MIIDQTCCAimgAwIBAgIBAzANBgkqhkiG9w0BAQsFADA7MQswCQYDVQQGEwJOTDER\r\n" \
+ "MA8GA1UECgwIUG9sYXJTU0wxGTAXBgNVBAMMEFBvbGFyU1NMIFRlc3QgQ0EwHhcN\r\n" \
+ "MTEwMjEyMTQ0NDAwWhcNMjEwMjEyMTQ0NDAwWjA7MQswCQYDVQQGEwJOTDERMA8G\r\n" \
+ "A1UECgwIUG9sYXJTU0wxGTAXBgNVBAMMEFBvbGFyU1NMIFRlc3QgQ0EwggEiMA0G\r\n" \
+ "CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDA3zf8F7vglp0/ht6WMn1EpRagzSHx\r\n" \
+ "mdTs6st8GFgIlKXsm8WL3xoemTiZhx57wI053zhdcHgH057Zk+i5clHFzqMwUqny\r\n" \
+ "50BwFMtEonILwuVA+T7lpg6z+exKY8C4KQB0nFc7qKUEkHHxvYPZP9al4jwqj+8n\r\n" \
+ "YMPGn8u67GB9t+aEMr5P+1gmIgNb1LTV+/Xjli5wwOQuvfwu7uJBVcA0Ln0kcmnL\r\n" \
+ "R7EUQIN9Z/SG9jGr8XmksrUuEvmEF/Bibyc+E1ixVA0hmnM3oTDPb5Lc9un8rNsu\r\n" \
+ "KNF+AksjoBXyOGVkCeoMbo4bF6BxyLObyavpw/LPh5aPgAIynplYb6LVAgMBAAGj\r\n" \
+ "UDBOMAwGA1UdEwQFMAMBAf8wHQYDVR0OBBYEFLRa5KWz3tJS9rnVppUP6z68x/3/\r\n" \
+ "MB8GA1UdIwQYMBaAFLRa5KWz3tJS9rnVppUP6z68x/3/MA0GCSqGSIb3DQEBCwUA\r\n" \
+ "A4IBAQB2W2dIy4q4KysbrTL4HIaOqu62RceGuQ/KhyiI6O0ndCtQ/PgCBqHHTP8u\r\n" \
+ "8F1X2ivb60ynHV6baMLPI4Kf1k4MONtLSf/++1qh0Gdycd3A8IDAfy0YnC1F3OPK\r\n" \
+ "vWO/cZGitKoTbEpP4y4Rng3sFCDndRCWIRIDOEEW/H3lCcfL7sOQojdLl85ajFkh\r\n" \
+ "YvcDqjmnTcspUnuq9Y00C7porXJthZwz1S18qVjcFNk0zEhVMUbupSrdXVmKtOJW\r\n" \
+ "MWZjgcA+OXzcnb2hSKWbhjykH/u6/PqkuHPkD723rwXbmHdxRVS9CW57kDkn5ezJ\r\n" \
+ "5pE6Sam4qFsCNFJNBV9FRf3ZBMFi\r\n" \
+ "-----END CERTIFICATE-----\r\n"
+/* END FILE */
+
+/* This is generated from tests/data_files/test-ca-sha256.crt.der
+ * using `xxd -i`. */
+/* BEGIN FILE binary macro TEST_CA_CRT_RSA_SHA256_DER tests/data_files/test-ca-sha256.crt.der */
+#define TEST_CA_CRT_RSA_SHA256_DER { \
+ 0x30, 0x82, 0x03, 0x41, 0x30, 0x82, 0x02, 0x29, 0xa0, 0x03, 0x02, 0x01, \
+ 0x02, 0x02, 0x01, 0x03, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, \
+ 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, 0x30, \
+ 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, \
+ 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, \
+ 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, \
+ 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, \
+ 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, \
+ 0x31, 0x31, 0x30, 0x32, 0x31, 0x32, 0x31, 0x34, 0x34, 0x34, 0x30, 0x30, \
+ 0x5a, 0x17, 0x0d, 0x32, 0x31, 0x30, 0x32, 0x31, 0x32, 0x31, 0x34, 0x34, \
+ 0x34, 0x30, 0x30, 0x5a, 0x30, 0x3b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
+ 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
+ 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
+ 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, \
+ 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x54, 0x65, \
+ 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, \
+ 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, \
+ 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, \
+ 0x01, 0x00, 0xc0, 0xdf, 0x37, 0xfc, 0x17, 0xbb, 0xe0, 0x96, 0x9d, 0x3f, \
+ 0x86, 0xde, 0x96, 0x32, 0x7d, 0x44, 0xa5, 0x16, 0xa0, 0xcd, 0x21, 0xf1, \
+ 0x99, 0xd4, 0xec, 0xea, 0xcb, 0x7c, 0x18, 0x58, 0x08, 0x94, 0xa5, 0xec, \
+ 0x9b, 0xc5, 0x8b, 0xdf, 0x1a, 0x1e, 0x99, 0x38, 0x99, 0x87, 0x1e, 0x7b, \
+ 0xc0, 0x8d, 0x39, 0xdf, 0x38, 0x5d, 0x70, 0x78, 0x07, 0xd3, 0x9e, 0xd9, \
+ 0x93, 0xe8, 0xb9, 0x72, 0x51, 0xc5, 0xce, 0xa3, 0x30, 0x52, 0xa9, 0xf2, \
+ 0xe7, 0x40, 0x70, 0x14, 0xcb, 0x44, 0xa2, 0x72, 0x0b, 0xc2, 0xe5, 0x40, \
+ 0xf9, 0x3e, 0xe5, 0xa6, 0x0e, 0xb3, 0xf9, 0xec, 0x4a, 0x63, 0xc0, 0xb8, \
+ 0x29, 0x00, 0x74, 0x9c, 0x57, 0x3b, 0xa8, 0xa5, 0x04, 0x90, 0x71, 0xf1, \
+ 0xbd, 0x83, 0xd9, 0x3f, 0xd6, 0xa5, 0xe2, 0x3c, 0x2a, 0x8f, 0xef, 0x27, \
+ 0x60, 0xc3, 0xc6, 0x9f, 0xcb, 0xba, 0xec, 0x60, 0x7d, 0xb7, 0xe6, 0x84, \
+ 0x32, 0xbe, 0x4f, 0xfb, 0x58, 0x26, 0x22, 0x03, 0x5b, 0xd4, 0xb4, 0xd5, \
+ 0xfb, 0xf5, 0xe3, 0x96, 0x2e, 0x70, 0xc0, 0xe4, 0x2e, 0xbd, 0xfc, 0x2e, \
+ 0xee, 0xe2, 0x41, 0x55, 0xc0, 0x34, 0x2e, 0x7d, 0x24, 0x72, 0x69, 0xcb, \
+ 0x47, 0xb1, 0x14, 0x40, 0x83, 0x7d, 0x67, 0xf4, 0x86, 0xf6, 0x31, 0xab, \
+ 0xf1, 0x79, 0xa4, 0xb2, 0xb5, 0x2e, 0x12, 0xf9, 0x84, 0x17, 0xf0, 0x62, \
+ 0x6f, 0x27, 0x3e, 0x13, 0x58, 0xb1, 0x54, 0x0d, 0x21, 0x9a, 0x73, 0x37, \
+ 0xa1, 0x30, 0xcf, 0x6f, 0x92, 0xdc, 0xf6, 0xe9, 0xfc, 0xac, 0xdb, 0x2e, \
+ 0x28, 0xd1, 0x7e, 0x02, 0x4b, 0x23, 0xa0, 0x15, 0xf2, 0x38, 0x65, 0x64, \
+ 0x09, 0xea, 0x0c, 0x6e, 0x8e, 0x1b, 0x17, 0xa0, 0x71, 0xc8, 0xb3, 0x9b, \
+ 0xc9, 0xab, 0xe9, 0xc3, 0xf2, 0xcf, 0x87, 0x96, 0x8f, 0x80, 0x02, 0x32, \
+ 0x9e, 0x99, 0x58, 0x6f, 0xa2, 0xd5, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, \
+ 0x50, 0x30, 0x4e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, \
+ 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, \
+ 0x04, 0x16, 0x04, 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, \
+ 0xf6, 0xb9, 0xd5, 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, \
+ 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, \
+ 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, 0xb9, 0xd5, \
+ 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, 0x0d, 0x06, \
+ 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, \
+ 0x03, 0x82, 0x01, 0x01, 0x00, 0x76, 0x5b, 0x67, 0x48, 0xcb, 0x8a, 0xb8, \
+ 0x2b, 0x2b, 0x1b, 0xad, 0x32, 0xf8, 0x1c, 0x86, 0x8e, 0xaa, 0xee, 0xb6, \
+ 0x45, 0xc7, 0x86, 0xb9, 0x0f, 0xca, 0x87, 0x28, 0x88, 0xe8, 0xed, 0x27, \
+ 0x74, 0x2b, 0x50, 0xfc, 0xf8, 0x02, 0x06, 0xa1, 0xc7, 0x4c, 0xff, 0x2e, \
+ 0xf0, 0x5d, 0x57, 0xda, 0x2b, 0xdb, 0xeb, 0x4c, 0xa7, 0x1d, 0x5e, 0x9b, \
+ 0x68, 0xc2, 0xcf, 0x23, 0x82, 0x9f, 0xd6, 0x4e, 0x0c, 0x38, 0xdb, 0x4b, \
+ 0x49, 0xff, 0xfe, 0xfb, 0x5a, 0xa1, 0xd0, 0x67, 0x72, 0x71, 0xdd, 0xc0, \
+ 0xf0, 0x80, 0xc0, 0x7f, 0x2d, 0x18, 0x9c, 0x2d, 0x45, 0xdc, 0xe3, 0xca, \
+ 0xbd, 0x63, 0xbf, 0x71, 0x91, 0xa2, 0xb4, 0xaa, 0x13, 0x6c, 0x4a, 0x4f, \
+ 0xe3, 0x2e, 0x11, 0x9e, 0x0d, 0xec, 0x14, 0x20, 0xe7, 0x75, 0x10, 0x96, \
+ 0x21, 0x12, 0x03, 0x38, 0x41, 0x16, 0xfc, 0x7d, 0xe5, 0x09, 0xc7, 0xcb, \
+ 0xee, 0xc3, 0x90, 0xa2, 0x37, 0x4b, 0x97, 0xce, 0x5a, 0x8c, 0x59, 0x21, \
+ 0x62, 0xf7, 0x03, 0xaa, 0x39, 0xa7, 0x4d, 0xcb, 0x29, 0x52, 0x7b, 0xaa, \
+ 0xf5, 0x8d, 0x34, 0x0b, 0xba, 0x68, 0xad, 0x72, 0x6d, 0x85, 0x9c, 0x33, \
+ 0xd5, 0x2d, 0x7c, 0xa9, 0x58, 0xdc, 0x14, 0xd9, 0x34, 0xcc, 0x48, 0x55, \
+ 0x31, 0x46, 0xee, 0xa5, 0x2a, 0xdd, 0x5d, 0x59, 0x8a, 0xb4, 0xe2, 0x56, \
+ 0x31, 0x66, 0x63, 0x81, 0xc0, 0x3e, 0x39, 0x7c, 0xdc, 0x9d, 0xbd, 0xa1, \
+ 0x48, 0xa5, 0x9b, 0x86, 0x3c, 0xa4, 0x1f, 0xfb, 0xba, 0xfc, 0xfa, 0xa4, \
+ 0xb8, 0x73, 0xe4, 0x0f, 0xbd, 0xb7, 0xaf, 0x05, 0xdb, 0x98, 0x77, 0x71, \
+ 0x45, 0x54, 0xbd, 0x09, 0x6e, 0x7b, 0x90, 0x39, 0x27, 0xe5, 0xec, 0xc9, \
+ 0xe6, 0x91, 0x3a, 0x49, 0xa9, 0xb8, 0xa8, 0x5b, 0x02, 0x34, 0x52, 0x4d, \
+ 0x05, 0x5f, 0x45, 0x45, 0xfd, 0xd9, 0x04, 0xc1, 0x62 \
+}
+/* END FILE */
+
+/* This is taken from tests/data_files/test-ca-sha1.crt. */
+/* BEGIN FILE string macro TEST_CA_CRT_RSA_SHA1_PEM tests/data_files/test-ca-sha1.crt */
+#define TEST_CA_CRT_RSA_SHA1_PEM \
+ "-----BEGIN CERTIFICATE-----\r\n" \
+ "MIIDQTCCAimgAwIBAgIBAzANBgkqhkiG9w0BAQUFADA7MQswCQYDVQQGEwJOTDER\r\n" \
+ "MA8GA1UECgwIUG9sYXJTU0wxGTAXBgNVBAMMEFBvbGFyU1NMIFRlc3QgQ0EwHhcN\r\n" \
+ "MTEwMjEyMTQ0NDAwWhcNMjEwMjEyMTQ0NDAwWjA7MQswCQYDVQQGEwJOTDERMA8G\r\n" \
+ "A1UECgwIUG9sYXJTU0wxGTAXBgNVBAMMEFBvbGFyU1NMIFRlc3QgQ0EwggEiMA0G\r\n" \
+ "CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDA3zf8F7vglp0/ht6WMn1EpRagzSHx\r\n" \
+ "mdTs6st8GFgIlKXsm8WL3xoemTiZhx57wI053zhdcHgH057Zk+i5clHFzqMwUqny\r\n" \
+ "50BwFMtEonILwuVA+T7lpg6z+exKY8C4KQB0nFc7qKUEkHHxvYPZP9al4jwqj+8n\r\n" \
+ "YMPGn8u67GB9t+aEMr5P+1gmIgNb1LTV+/Xjli5wwOQuvfwu7uJBVcA0Ln0kcmnL\r\n" \
+ "R7EUQIN9Z/SG9jGr8XmksrUuEvmEF/Bibyc+E1ixVA0hmnM3oTDPb5Lc9un8rNsu\r\n" \
+ "KNF+AksjoBXyOGVkCeoMbo4bF6BxyLObyavpw/LPh5aPgAIynplYb6LVAgMBAAGj\r\n" \
+ "UDBOMAwGA1UdEwQFMAMBAf8wHQYDVR0OBBYEFLRa5KWz3tJS9rnVppUP6z68x/3/\r\n" \
+ "MB8GA1UdIwQYMBaAFLRa5KWz3tJS9rnVppUP6z68x/3/MA0GCSqGSIb3DQEBBQUA\r\n" \
+ "A4IBAQABE3OEPfEd/bcJW5ZdU3/VgPNS4tMzh8gnJP/V2FcvFtGylMpQq6YnEBYI\r\n" \
+ "yBHAL4DRvlMY5rnXGBp3ODR8MpqHC6AquRTCLzjS57iYff//4QFQqW9n92zctspv\r\n" \
+ "czkaPKgjqo1No3Uq0Xaz10rcxyTUPrf5wNVRZ2V0KvllvAAVSzbI4mpdUXztjhST\r\n" \
+ "S5A2BeWQAAOr0zq1F7TSRVJpJs7jmB2ai/igkh1IAjcuwV6VwlP+sbw0gjQ0NpGM\r\n" \
+ "iHpnlzRAi/tIbtOvMIGOBU2TIfax/5jq1agUx5aPmT5TWAiJPOOP6l5xXnDwxeYS\r\n" \
+ "NWqiX9GyusBZjezaCaHabjDLU0qQ\r\n" \
+ "-----END CERTIFICATE-----\r\n"
+/* END FILE */
+
+/* This is taken from tests/data_files/test-ca-sha1.crt.der. */
+/* BEGIN FILE binary macro TEST_CA_CRT_RSA_SHA1_DER tests/data_files/test-ca-sha1.crt.der */
+#define TEST_CA_CRT_RSA_SHA1_DER { \
+ 0x30, 0x82, 0x03, 0x41, 0x30, 0x82, 0x02, 0x29, 0xa0, 0x03, 0x02, 0x01, \
+ 0x02, 0x02, 0x01, 0x03, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, \
+ 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, 0x30, \
+ 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, \
+ 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, \
+ 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, \
+ 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, \
+ 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, \
+ 0x31, 0x31, 0x30, 0x32, 0x31, 0x32, 0x31, 0x34, 0x34, 0x34, 0x30, 0x30, \
+ 0x5a, 0x17, 0x0d, 0x32, 0x31, 0x30, 0x32, 0x31, 0x32, 0x31, 0x34, 0x34, \
+ 0x34, 0x30, 0x30, 0x5a, 0x30, 0x3b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
+ 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
+ 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
+ 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, \
+ 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x54, 0x65, \
+ 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, \
+ 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, \
+ 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, \
+ 0x01, 0x00, 0xc0, 0xdf, 0x37, 0xfc, 0x17, 0xbb, 0xe0, 0x96, 0x9d, 0x3f, \
+ 0x86, 0xde, 0x96, 0x32, 0x7d, 0x44, 0xa5, 0x16, 0xa0, 0xcd, 0x21, 0xf1, \
+ 0x99, 0xd4, 0xec, 0xea, 0xcb, 0x7c, 0x18, 0x58, 0x08, 0x94, 0xa5, 0xec, \
+ 0x9b, 0xc5, 0x8b, 0xdf, 0x1a, 0x1e, 0x99, 0x38, 0x99, 0x87, 0x1e, 0x7b, \
+ 0xc0, 0x8d, 0x39, 0xdf, 0x38, 0x5d, 0x70, 0x78, 0x07, 0xd3, 0x9e, 0xd9, \
+ 0x93, 0xe8, 0xb9, 0x72, 0x51, 0xc5, 0xce, 0xa3, 0x30, 0x52, 0xa9, 0xf2, \
+ 0xe7, 0x40, 0x70, 0x14, 0xcb, 0x44, 0xa2, 0x72, 0x0b, 0xc2, 0xe5, 0x40, \
+ 0xf9, 0x3e, 0xe5, 0xa6, 0x0e, 0xb3, 0xf9, 0xec, 0x4a, 0x63, 0xc0, 0xb8, \
+ 0x29, 0x00, 0x74, 0x9c, 0x57, 0x3b, 0xa8, 0xa5, 0x04, 0x90, 0x71, 0xf1, \
+ 0xbd, 0x83, 0xd9, 0x3f, 0xd6, 0xa5, 0xe2, 0x3c, 0x2a, 0x8f, 0xef, 0x27, \
+ 0x60, 0xc3, 0xc6, 0x9f, 0xcb, 0xba, 0xec, 0x60, 0x7d, 0xb7, 0xe6, 0x84, \
+ 0x32, 0xbe, 0x4f, 0xfb, 0x58, 0x26, 0x22, 0x03, 0x5b, 0xd4, 0xb4, 0xd5, \
+ 0xfb, 0xf5, 0xe3, 0x96, 0x2e, 0x70, 0xc0, 0xe4, 0x2e, 0xbd, 0xfc, 0x2e, \
+ 0xee, 0xe2, 0x41, 0x55, 0xc0, 0x34, 0x2e, 0x7d, 0x24, 0x72, 0x69, 0xcb, \
+ 0x47, 0xb1, 0x14, 0x40, 0x83, 0x7d, 0x67, 0xf4, 0x86, 0xf6, 0x31, 0xab, \
+ 0xf1, 0x79, 0xa4, 0xb2, 0xb5, 0x2e, 0x12, 0xf9, 0x84, 0x17, 0xf0, 0x62, \
+ 0x6f, 0x27, 0x3e, 0x13, 0x58, 0xb1, 0x54, 0x0d, 0x21, 0x9a, 0x73, 0x37, \
+ 0xa1, 0x30, 0xcf, 0x6f, 0x92, 0xdc, 0xf6, 0xe9, 0xfc, 0xac, 0xdb, 0x2e, \
+ 0x28, 0xd1, 0x7e, 0x02, 0x4b, 0x23, 0xa0, 0x15, 0xf2, 0x38, 0x65, 0x64, \
+ 0x09, 0xea, 0x0c, 0x6e, 0x8e, 0x1b, 0x17, 0xa0, 0x71, 0xc8, 0xb3, 0x9b, \
+ 0xc9, 0xab, 0xe9, 0xc3, 0xf2, 0xcf, 0x87, 0x96, 0x8f, 0x80, 0x02, 0x32, \
+ 0x9e, 0x99, 0x58, 0x6f, 0xa2, 0xd5, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, \
+ 0x50, 0x30, 0x4e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, \
+ 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, \
+ 0x04, 0x16, 0x04, 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, \
+ 0xf6, 0xb9, 0xd5, 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, \
+ 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, \
+ 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, 0xb9, 0xd5, \
+ 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, 0x0d, 0x06, \
+ 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, \
+ 0x03, 0x82, 0x01, 0x01, 0x00, 0x01, 0x13, 0x73, 0x84, 0x3d, 0xf1, 0x1d, \
+ 0xfd, 0xb7, 0x09, 0x5b, 0x96, 0x5d, 0x53, 0x7f, 0xd5, 0x80, 0xf3, 0x52, \
+ 0xe2, 0xd3, 0x33, 0x87, 0xc8, 0x27, 0x24, 0xff, 0xd5, 0xd8, 0x57, 0x2f, \
+ 0x16, 0xd1, 0xb2, 0x94, 0xca, 0x50, 0xab, 0xa6, 0x27, 0x10, 0x16, 0x08, \
+ 0xc8, 0x11, 0xc0, 0x2f, 0x80, 0xd1, 0xbe, 0x53, 0x18, 0xe6, 0xb9, 0xd7, \
+ 0x18, 0x1a, 0x77, 0x38, 0x34, 0x7c, 0x32, 0x9a, 0x87, 0x0b, 0xa0, 0x2a, \
+ 0xb9, 0x14, 0xc2, 0x2f, 0x38, 0xd2, 0xe7, 0xb8, 0x98, 0x7d, 0xff, 0xff, \
+ 0xe1, 0x01, 0x50, 0xa9, 0x6f, 0x67, 0xf7, 0x6c, 0xdc, 0xb6, 0xca, 0x6f, \
+ 0x73, 0x39, 0x1a, 0x3c, 0xa8, 0x23, 0xaa, 0x8d, 0x4d, 0xa3, 0x75, 0x2a, \
+ 0xd1, 0x76, 0xb3, 0xd7, 0x4a, 0xdc, 0xc7, 0x24, 0xd4, 0x3e, 0xb7, 0xf9, \
+ 0xc0, 0xd5, 0x51, 0x67, 0x65, 0x74, 0x2a, 0xf9, 0x65, 0xbc, 0x00, 0x15, \
+ 0x4b, 0x36, 0xc8, 0xe2, 0x6a, 0x5d, 0x51, 0x7c, 0xed, 0x8e, 0x14, 0x93, \
+ 0x4b, 0x90, 0x36, 0x05, 0xe5, 0x90, 0x00, 0x03, 0xab, 0xd3, 0x3a, 0xb5, \
+ 0x17, 0xb4, 0xd2, 0x45, 0x52, 0x69, 0x26, 0xce, 0xe3, 0x98, 0x1d, 0x9a, \
+ 0x8b, 0xf8, 0xa0, 0x92, 0x1d, 0x48, 0x02, 0x37, 0x2e, 0xc1, 0x5e, 0x95, \
+ 0xc2, 0x53, 0xfe, 0xb1, 0xbc, 0x34, 0x82, 0x34, 0x34, 0x36, 0x91, 0x8c, \
+ 0x88, 0x7a, 0x67, 0x97, 0x34, 0x40, 0x8b, 0xfb, 0x48, 0x6e, 0xd3, 0xaf, \
+ 0x30, 0x81, 0x8e, 0x05, 0x4d, 0x93, 0x21, 0xf6, 0xb1, 0xff, 0x98, 0xea, \
+ 0xd5, 0xa8, 0x14, 0xc7, 0x96, 0x8f, 0x99, 0x3e, 0x53, 0x58, 0x08, 0x89, \
+ 0x3c, 0xe3, 0x8f, 0xea, 0x5e, 0x71, 0x5e, 0x70, 0xf0, 0xc5, 0xe6, 0x12, \
+ 0x35, 0x6a, 0xa2, 0x5f, 0xd1, 0xb2, 0xba, 0xc0, 0x59, 0x8d, 0xec, 0xda, \
+ 0x09, 0xa1, 0xda, 0x6e, 0x30, 0xcb, 0x53, 0x4a, 0x90 \
+}
+/* END FILE */
+
+/* This is taken from tests/data_files/test-ca.key */
+/* BEGIN FILE string macro TEST_CA_KEY_RSA_PEM tests/data_files/test-ca.key */
+#define TEST_CA_KEY_RSA_PEM \
+ "-----BEGIN RSA PRIVATE KEY-----\r\n" \
+ "Proc-Type: 4,ENCRYPTED\r\n" \
+ "DEK-Info: DES-EDE3-CBC,A8A95B05D5B7206B\r\n" \
+ "\r\n" \
+ "9Qd9GeArejl1GDVh2lLV1bHt0cPtfbh5h/5zVpAVaFpqtSPMrElp50Rntn9et+JA\r\n" \
+ "7VOyboR+Iy2t/HU4WvA687k3Bppe9GwKHjHhtl//8xFKwZr3Xb5yO5JUP8AUctQq\r\n" \
+ "Nb8CLlZyuUC+52REAAthdWgsX+7dJO4yabzUcQ22Tp9JSD0hiL43BlkWYUNK3dAo\r\n" \
+ "PZlmiptjnzVTjg1MxsBSydZinWOLBV8/JQgxSPo2yD4uEfig28qbvQ2wNIn0pnAb\r\n" \
+ "GxnSAOazkongEGfvcjIIs+LZN9gXFhxcOh6kc4Q/c99B7QWETwLLkYgZ+z1a9VY9\r\n" \
+ "gEU7CwCxYCD+h9hY6FPmsK0/lC4O7aeRKpYq00rPPxs6i7phiexg6ax6yTMmArQq\r\n" \
+ "QmK3TAsJm8V/J5AWpLEV6jAFgRGymGGHnof0DXzVWZidrcZJWTNuGEX90nB3ee2w\r\n" \
+ "PXJEFWKoD3K3aFcSLdHYr3mLGxP7H9ThQai9VsycxZKS5kwvBKQ//YMrmFfwPk8x\r\n" \
+ "vTeY4KZMaUrveEel5tWZC94RSMKgxR6cyE1nBXyTQnDOGbfpNNgBKxyKbINWoOJU\r\n" \
+ "WJZAwlsQn+QzCDwpri7+sV1mS3gBE6UY7aQmnmiiaC2V3Hbphxct/en5QsfDOt1X\r\n" \
+ "JczSfpRWLlbPznZg8OQh/VgCMA58N5DjOzTIK7sJJ5r+94ZBTCpgAMbF588f0NTR\r\n" \
+ "KCe4yrxGJR7X02M4nvD4IwOlpsQ8xQxZtOSgXv4LkxvdU9XJJKWZ/XNKJeWztxSe\r\n" \
+ "Z1vdTc2YfsDBA2SEv33vxHx2g1vqtw8SjDRT2RaQSS0QuSaMJimdOX6mTOCBKk1J\r\n" \
+ "9Q5mXTrER+/LnK0jEmXsBXWA5bqqVZIyahXSx4VYZ7l7w/PHiUDtDgyRhMMKi4n2\r\n" \
+ "iQvQcWSQTjrpnlJbca1/DkpRt3YwrvJwdqb8asZU2VrNETh5x0QVefDRLFiVpif/\r\n" \
+ "tUaeAe/P1F8OkS7OIZDs1SUbv/sD2vMbhNkUoCms3/PvNtdnvgL4F0zhaDpKCmlT\r\n" \
+ "P8vx49E7v5CyRNmED9zZg4o3wmMqrQO93PtTug3Eu9oVx1zPQM1NVMyBa2+f29DL\r\n" \
+ "1nuTCeXdo9+ni45xx+jAI4DCwrRdhJ9uzZyC6962H37H6D+5naNvClFR1s6li1Gb\r\n" \
+ "nqPoiy/OBsEx9CaDGcqQBp5Wme/3XW+6z1ISOx+igwNTVCT14mHdBMbya0eIKft5\r\n" \
+ "X+GnwtgEMyCYyyWuUct8g4RzErcY9+yW9Om5Hzpx4zOuW4NPZgPDTgK+t2RSL/Yq\r\n" \
+ "rE1njrgeGYcVeG3f+OftH4s6fPbq7t1A5ZgUscbLMBqr9tK+OqygR4EgKBPsH6Cz\r\n" \
+ "L6zlv/2RV0qAHvVuDJcIDIgwY5rJtINEm32rhOeFNJwZS5MNIC1czXZx5//ugX7l\r\n" \
+ "I4sy5nbVhwSjtAk8Xg5dZbdTZ6mIrb7xqH+fdakZor1khG7bC2uIwibD3cSl2XkR\r\n" \
+ "wN48lslbHnqqagr6Xm1nNOSVl8C/6kbJEsMpLhAezfRtGwvOucoaE+WbeUNolGde\r\n" \
+ "P/eQiddSf0brnpiLJRh7qZrl9XuqYdpUqnoEdMAfotDOID8OtV7gt8a48ad8VPW2\r\n" \
+ "-----END RSA PRIVATE KEY-----\r\n"
+/* END FILE */
+
+#define TEST_CA_PWD_RSA_PEM "PolarSSLTest"
+
+/* This was generated from test-ca.key.der using `xxd -i`. */
+/* BEGIN FILE binary macro TEST_CA_KEY_RSA_DER tests/data_files/test-ca.key.der */
+#define TEST_CA_KEY_RSA_DER { \
+ 0x30, 0x82, 0x04, 0xa4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, \
+ 0xc0, 0xdf, 0x37, 0xfc, 0x17, 0xbb, 0xe0, 0x96, 0x9d, 0x3f, 0x86, 0xde, \
+ 0x96, 0x32, 0x7d, 0x44, 0xa5, 0x16, 0xa0, 0xcd, 0x21, 0xf1, 0x99, 0xd4, \
+ 0xec, 0xea, 0xcb, 0x7c, 0x18, 0x58, 0x08, 0x94, 0xa5, 0xec, 0x9b, 0xc5, \
+ 0x8b, 0xdf, 0x1a, 0x1e, 0x99, 0x38, 0x99, 0x87, 0x1e, 0x7b, 0xc0, 0x8d, \
+ 0x39, 0xdf, 0x38, 0x5d, 0x70, 0x78, 0x07, 0xd3, 0x9e, 0xd9, 0x93, 0xe8, \
+ 0xb9, 0x72, 0x51, 0xc5, 0xce, 0xa3, 0x30, 0x52, 0xa9, 0xf2, 0xe7, 0x40, \
+ 0x70, 0x14, 0xcb, 0x44, 0xa2, 0x72, 0x0b, 0xc2, 0xe5, 0x40, 0xf9, 0x3e, \
+ 0xe5, 0xa6, 0x0e, 0xb3, 0xf9, 0xec, 0x4a, 0x63, 0xc0, 0xb8, 0x29, 0x00, \
+ 0x74, 0x9c, 0x57, 0x3b, 0xa8, 0xa5, 0x04, 0x90, 0x71, 0xf1, 0xbd, 0x83, \
+ 0xd9, 0x3f, 0xd6, 0xa5, 0xe2, 0x3c, 0x2a, 0x8f, 0xef, 0x27, 0x60, 0xc3, \
+ 0xc6, 0x9f, 0xcb, 0xba, 0xec, 0x60, 0x7d, 0xb7, 0xe6, 0x84, 0x32, 0xbe, \
+ 0x4f, 0xfb, 0x58, 0x26, 0x22, 0x03, 0x5b, 0xd4, 0xb4, 0xd5, 0xfb, 0xf5, \
+ 0xe3, 0x96, 0x2e, 0x70, 0xc0, 0xe4, 0x2e, 0xbd, 0xfc, 0x2e, 0xee, 0xe2, \
+ 0x41, 0x55, 0xc0, 0x34, 0x2e, 0x7d, 0x24, 0x72, 0x69, 0xcb, 0x47, 0xb1, \
+ 0x14, 0x40, 0x83, 0x7d, 0x67, 0xf4, 0x86, 0xf6, 0x31, 0xab, 0xf1, 0x79, \
+ 0xa4, 0xb2, 0xb5, 0x2e, 0x12, 0xf9, 0x84, 0x17, 0xf0, 0x62, 0x6f, 0x27, \
+ 0x3e, 0x13, 0x58, 0xb1, 0x54, 0x0d, 0x21, 0x9a, 0x73, 0x37, 0xa1, 0x30, \
+ 0xcf, 0x6f, 0x92, 0xdc, 0xf6, 0xe9, 0xfc, 0xac, 0xdb, 0x2e, 0x28, 0xd1, \
+ 0x7e, 0x02, 0x4b, 0x23, 0xa0, 0x15, 0xf2, 0x38, 0x65, 0x64, 0x09, 0xea, \
+ 0x0c, 0x6e, 0x8e, 0x1b, 0x17, 0xa0, 0x71, 0xc8, 0xb3, 0x9b, 0xc9, 0xab, \
+ 0xe9, 0xc3, 0xf2, 0xcf, 0x87, 0x96, 0x8f, 0x80, 0x02, 0x32, 0x9e, 0x99, \
+ 0x58, 0x6f, 0xa2, 0xd5, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x82, 0x01, \
+ 0x00, 0x3f, 0xf7, 0x07, 0xd3, 0x34, 0x6f, 0xdb, 0xc9, 0x37, 0xb7, 0x84, \
+ 0xdc, 0x37, 0x45, 0xe1, 0x63, 0xad, 0xb8, 0xb6, 0x75, 0xb1, 0xc7, 0x35, \
+ 0xb4, 0x77, 0x2a, 0x5b, 0x77, 0xf9, 0x7e, 0xe0, 0xc1, 0xa3, 0xd1, 0xb7, \
+ 0xcb, 0xa9, 0x5a, 0xc1, 0x87, 0xda, 0x5a, 0xfa, 0x17, 0xe4, 0xd5, 0x38, \
+ 0x03, 0xde, 0x68, 0x98, 0x81, 0xec, 0xb5, 0xf2, 0x2a, 0x8d, 0xe9, 0x2c, \
+ 0xf3, 0xa6, 0xe5, 0x32, 0x17, 0x7f, 0x33, 0x81, 0xe8, 0x38, 0x72, 0xd5, \
+ 0x9c, 0xfa, 0x4e, 0xfb, 0x26, 0xf5, 0x15, 0x0b, 0xaf, 0x84, 0x66, 0xab, \
+ 0x02, 0xe0, 0x18, 0xd5, 0x91, 0x7c, 0xd6, 0x8f, 0xc9, 0x4b, 0x76, 0x08, \
+ 0x2b, 0x1d, 0x81, 0x68, 0x30, 0xe1, 0xfa, 0x70, 0x6c, 0x13, 0x4e, 0x10, \
+ 0x03, 0x35, 0x3e, 0xc5, 0xca, 0x58, 0x20, 0x8a, 0x21, 0x18, 0x38, 0xa0, \
+ 0x0f, 0xed, 0xc4, 0xbb, 0x45, 0x6f, 0xf5, 0x84, 0x5b, 0xb0, 0xcf, 0x4e, \
+ 0x9d, 0x58, 0x13, 0x6b, 0x35, 0x35, 0x69, 0xa1, 0xd2, 0xc4, 0xf2, 0xc1, \
+ 0x48, 0x04, 0x20, 0x51, 0xb9, 0x6b, 0xa4, 0x5d, 0xa5, 0x4b, 0x84, 0x88, \
+ 0x43, 0x48, 0x99, 0x2c, 0xbb, 0xa4, 0x97, 0xd6, 0xd6, 0x18, 0xf6, 0xec, \
+ 0x5c, 0xd1, 0x31, 0x49, 0xc9, 0xf2, 0x8f, 0x0b, 0x4d, 0xef, 0x09, 0x02, \
+ 0xfe, 0x7d, 0xfd, 0xbb, 0xaf, 0x2b, 0x83, 0x94, 0x22, 0xc4, 0xa7, 0x3e, \
+ 0x66, 0xf5, 0xe0, 0x57, 0xdc, 0xf2, 0xed, 0x2c, 0x3e, 0x81, 0x74, 0x76, \
+ 0x1e, 0x96, 0x6f, 0x74, 0x1e, 0x32, 0x0e, 0x14, 0x31, 0xd0, 0x74, 0xf0, \
+ 0xf4, 0x07, 0xbd, 0xc3, 0xd1, 0x22, 0xc2, 0xa8, 0x95, 0x92, 0x06, 0x7f, \
+ 0x43, 0x02, 0x91, 0xbc, 0xdd, 0x23, 0x01, 0x89, 0x94, 0x20, 0x44, 0x64, \
+ 0xf5, 0x1d, 0x67, 0xd2, 0x8f, 0xe8, 0x69, 0xa5, 0x29, 0x25, 0xe6, 0x50, \
+ 0x9c, 0xe3, 0xe9, 0xcb, 0x75, 0x02, 0x81, 0x81, 0x00, 0xe2, 0x29, 0x3e, \
+ 0xaa, 0x6b, 0xd5, 0x59, 0x1e, 0x9c, 0xe6, 0x47, 0xd5, 0xb6, 0xd7, 0xe3, \
+ 0xf1, 0x8e, 0x9e, 0xe9, 0x83, 0x5f, 0x10, 0x9f, 0x63, 0xec, 0x04, 0x44, \
+ 0xcc, 0x3f, 0xf8, 0xd9, 0x3a, 0x17, 0xe0, 0x4f, 0xfe, 0xd8, 0x4d, 0xcd, \
+ 0x46, 0x54, 0x74, 0xbf, 0x0a, 0xc4, 0x67, 0x9c, 0xa7, 0xd8, 0x89, 0x65, \
+ 0x4c, 0xfd, 0x58, 0x2a, 0x47, 0x0f, 0xf4, 0x37, 0xb6, 0x55, 0xb0, 0x1d, \
+ 0xed, 0xa7, 0x39, 0xfc, 0x4f, 0xa3, 0xc4, 0x75, 0x3a, 0xa3, 0x98, 0xa7, \
+ 0x45, 0xf5, 0x66, 0xcb, 0x7c, 0x65, 0xfb, 0x80, 0x23, 0xe6, 0xff, 0xfd, \
+ 0x99, 0x1f, 0x8e, 0x6b, 0xff, 0x5e, 0x93, 0x66, 0xdf, 0x6c, 0x6f, 0xc3, \
+ 0xf6, 0x38, 0x2e, 0xff, 0x69, 0xb5, 0xac, 0xae, 0xbb, 0xc6, 0x71, 0x16, \
+ 0x6b, 0xd0, 0xf8, 0x22, 0xd9, 0xf8, 0xa2, 0x72, 0x20, 0xd2, 0xe2, 0x3a, \
+ 0x70, 0x4b, 0xde, 0xab, 0x2f, 0x02, 0x81, 0x81, 0x00, 0xda, 0x51, 0x9b, \
+ 0xb8, 0xb2, 0x2a, 0x14, 0x75, 0x58, 0x40, 0x8d, 0x27, 0x70, 0xfa, 0x31, \
+ 0x48, 0xb0, 0x20, 0x21, 0x34, 0xfa, 0x4c, 0x57, 0xa8, 0x11, 0x88, 0xf3, \
+ 0xa7, 0xae, 0x21, 0xe9, 0xb6, 0x2b, 0xd1, 0xcd, 0xa7, 0xf8, 0xd8, 0x0c, \
+ 0x8a, 0x76, 0x22, 0x35, 0x44, 0xce, 0x3f, 0x25, 0x29, 0x83, 0x7d, 0x79, \
+ 0xa7, 0x31, 0xd6, 0xec, 0xb2, 0xbf, 0xda, 0x34, 0xb6, 0xf6, 0xb2, 0x3b, \
+ 0xf3, 0x78, 0x5a, 0x04, 0x83, 0x33, 0x3e, 0xa2, 0xe2, 0x81, 0x82, 0x13, \
+ 0xd4, 0x35, 0x17, 0x63, 0x9b, 0x9e, 0xc4, 0x8d, 0x91, 0x4c, 0x03, 0x77, \
+ 0xc7, 0x71, 0x5b, 0xee, 0x83, 0x6d, 0xd5, 0x78, 0x88, 0xf6, 0x2c, 0x79, \
+ 0xc2, 0x4a, 0xb4, 0x79, 0x90, 0x70, 0xbf, 0xdf, 0x34, 0x56, 0x96, 0x71, \
+ 0xe3, 0x0e, 0x68, 0x91, 0xbc, 0xea, 0xcb, 0x33, 0xc0, 0xbe, 0x45, 0xd7, \
+ 0xfc, 0x30, 0xfd, 0x01, 0x3b, 0x02, 0x81, 0x81, 0x00, 0xd2, 0x9f, 0x2a, \
+ 0xb7, 0x38, 0x19, 0xc7, 0x17, 0x95, 0x73, 0x78, 0xae, 0xf5, 0xcb, 0x75, \
+ 0x83, 0x7f, 0x19, 0x4b, 0xcb, 0x86, 0xfb, 0x4a, 0x15, 0x9a, 0xb6, 0x17, \
+ 0x04, 0x49, 0x07, 0x8d, 0xf6, 0x66, 0x4a, 0x06, 0xf6, 0x05, 0xa7, 0xdf, \
+ 0x66, 0x82, 0x3c, 0xff, 0xb6, 0x1d, 0x57, 0x89, 0x33, 0x5f, 0x9c, 0x05, \
+ 0x75, 0x7f, 0xf3, 0x5d, 0xdc, 0x34, 0x65, 0x72, 0x85, 0x22, 0xa4, 0x14, \
+ 0x1b, 0x41, 0xc3, 0xe4, 0xd0, 0x9e, 0x69, 0xd5, 0xeb, 0x38, 0x74, 0x70, \
+ 0x43, 0xdc, 0xd9, 0x50, 0xe4, 0x97, 0x6d, 0x73, 0xd6, 0xfb, 0xc8, 0xa7, \
+ 0xfa, 0xb4, 0xc2, 0xc4, 0x9d, 0x5d, 0x0c, 0xd5, 0x9f, 0x79, 0xb3, 0x54, \
+ 0xc2, 0xb7, 0x6c, 0x3d, 0x7d, 0xcb, 0x2d, 0xf8, 0xc4, 0xf3, 0x78, 0x5a, \
+ 0x33, 0x2a, 0xb8, 0x0c, 0x6d, 0x06, 0xfa, 0xf2, 0x62, 0xd3, 0x42, 0xd0, \
+ 0xbd, 0xc8, 0x4a, 0xa5, 0x0d, 0x02, 0x81, 0x81, 0x00, 0xd4, 0xa9, 0x90, \
+ 0x15, 0xde, 0xbf, 0x2c, 0xc4, 0x8d, 0x9d, 0xfb, 0xa1, 0xc2, 0xe4, 0x83, \
+ 0xe3, 0x79, 0x65, 0x22, 0xd3, 0xb7, 0x49, 0x6c, 0x4d, 0x94, 0x1f, 0x22, \
+ 0xb1, 0x60, 0xe7, 0x3a, 0x00, 0xb1, 0x38, 0xa2, 0xab, 0x0f, 0xb4, 0x6c, \
+ 0xaa, 0xe7, 0x9e, 0x34, 0xe3, 0x7c, 0x40, 0x78, 0x53, 0xb2, 0xf9, 0x23, \
+ 0xea, 0xa0, 0x9a, 0xea, 0x60, 0xc8, 0x8f, 0xa6, 0xaf, 0xdf, 0x29, 0x09, \
+ 0x4b, 0x06, 0x1e, 0x31, 0xad, 0x17, 0xda, 0xd8, 0xd1, 0xe9, 0x33, 0xab, \
+ 0x5b, 0x18, 0x08, 0x5b, 0x87, 0xf8, 0xa5, 0x1f, 0xfd, 0xbb, 0xdc, 0xd8, \
+ 0xed, 0x97, 0x57, 0xe4, 0xc3, 0x73, 0xd6, 0xf0, 0x9e, 0x01, 0xa6, 0x9b, \
+ 0x48, 0x8e, 0x7a, 0xb4, 0xbb, 0xe5, 0x88, 0x91, 0xc5, 0x2a, 0xdf, 0x4b, \
+ 0xba, 0xd0, 0x8b, 0x3e, 0x03, 0x97, 0x77, 0x2f, 0x47, 0x7e, 0x51, 0x0c, \
+ 0xae, 0x65, 0x8d, 0xde, 0x87, 0x02, 0x81, 0x80, 0x20, 0x24, 0x0f, 0xd2, \
+ 0xaf, 0xc2, 0x28, 0x3b, 0x97, 0x20, 0xb2, 0x92, 0x49, 0xeb, 0x09, 0x68, \
+ 0x40, 0xb2, 0xbe, 0xd1, 0xc3, 0x83, 0x94, 0x34, 0x38, 0xd6, 0xc9, 0xec, \
+ 0x34, 0x09, 0xf9, 0x41, 0x6d, 0x5c, 0x42, 0x94, 0xf7, 0x04, 0xfc, 0x32, \
+ 0x39, 0x69, 0xbc, 0x1c, 0xfb, 0x3e, 0x61, 0x98, 0xc0, 0x80, 0xd8, 0x36, \
+ 0x47, 0xc3, 0x6d, 0xc2, 0x2e, 0xe7, 0x81, 0x2a, 0x17, 0x34, 0x64, 0x30, \
+ 0x4e, 0x96, 0xbb, 0x26, 0x16, 0xb9, 0x41, 0x36, 0xfe, 0x8a, 0xd6, 0x53, \
+ 0x7c, 0xaa, 0xec, 0x39, 0x42, 0x50, 0xef, 0xe3, 0xb3, 0x01, 0x28, 0x32, \
+ 0xca, 0x6d, 0xf5, 0x9a, 0x1e, 0x9f, 0x37, 0xbe, 0xfe, 0x38, 0x20, 0x22, \
+ 0x91, 0x8c, 0xcd, 0x95, 0x02, 0xf2, 0x4d, 0x6f, 0x1a, 0xb4, 0x43, 0xf0, \
+ 0x19, 0xdf, 0x65, 0xc0, 0x92, 0xe7, 0x9d, 0x2f, 0x09, 0xe7, 0xec, 0x69, \
+ 0xa8, 0xc2, 0x8f, 0x0d \
+}
+/* END FILE */
+
+/*
+ * Test server Certificates
+ *
+ * Test server certificates are defined for each choice
+ * of the following parameters:
+ * - PEM or DER encoding
+ * - SHA-1 or SHA-256 hash
+ * - RSA or EC key
+ *
+ * Things to add:
+ * - multiple EC curve types
+ */
+
+/* This is taken from tests/data_files/server5.crt. */
+/* BEGIN FILE string macro TEST_SRV_CRT_EC_PEM tests/data_files/server5.crt */
+#define TEST_SRV_CRT_EC_PEM \
+ "-----BEGIN CERTIFICATE-----\r\n" \
+ "MIICHzCCAaWgAwIBAgIBCTAKBggqhkjOPQQDAjA+MQswCQYDVQQGEwJOTDERMA8G\r\n" \
+ "A1UEChMIUG9sYXJTU0wxHDAaBgNVBAMTE1BvbGFyc3NsIFRlc3QgRUMgQ0EwHhcN\r\n" \
+ "MTMwOTI0MTU1MjA0WhcNMjMwOTIyMTU1MjA0WjA0MQswCQYDVQQGEwJOTDERMA8G\r\n" \
+ "A1UEChMIUG9sYXJTU0wxEjAQBgNVBAMTCWxvY2FsaG9zdDBZMBMGByqGSM49AgEG\r\n" \
+ "CCqGSM49AwEHA0IABDfMVtl2CR5acj7HWS3/IG7ufPkGkXTQrRS192giWWKSTuUA\r\n" \
+ "2CMR/+ov0jRdXRa9iojCa3cNVc2KKg76Aci07f+jgZ0wgZowCQYDVR0TBAIwADAd\r\n" \
+ "BgNVHQ4EFgQUUGGlj9QH2deCAQzlZX+MY0anE74wbgYDVR0jBGcwZYAUnW0gJEkB\r\n" \
+ "PyvLeLUZvH4kydv7NnyhQqRAMD4xCzAJBgNVBAYTAk5MMREwDwYDVQQKEwhQb2xh\r\n" \
+ "clNTTDEcMBoGA1UEAxMTUG9sYXJzc2wgVGVzdCBFQyBDQYIJAMFD4n5iQ8zoMAoG\r\n" \
+ "CCqGSM49BAMCA2gAMGUCMQCaLFzXptui5WQN8LlO3ddh1hMxx6tzgLvT03MTVK2S\r\n" \
+ "C12r0Lz3ri/moSEpNZWqPjkCMCE2f53GXcYLqyfyJR078c/xNSUU5+Xxl7VZ414V\r\n" \
+ "fGa5kHvHARBPc8YAIVIqDvHH1Q==\r\n" \
+ "-----END CERTIFICATE-----\r\n"
+/* END FILE */
+
+/* This is generated from tests/data_files/server5.crt.der using `xxd -i`. */
+/* BEGIN FILE binary macro TEST_SRV_CRT_EC_DER tests/data_files/server5.crt.der */
+#define TEST_SRV_CRT_EC_DER { \
+ 0x30, 0x82, 0x02, 0x1f, 0x30, 0x82, 0x01, 0xa5, 0xa0, 0x03, 0x02, 0x01, \
+ 0x02, 0x02, 0x01, 0x09, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, \
+ 0x3d, 0x04, 0x03, 0x02, 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
+ 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
+ 0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
+ 0x53, 0x4c, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, \
+ 0x13, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x73, 0x73, 0x6c, 0x20, 0x54, 0x65, \
+ 0x73, 0x74, 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, \
+ 0x31, 0x33, 0x30, 0x39, 0x32, 0x34, 0x31, 0x35, 0x35, 0x32, 0x30, 0x34, \
+ 0x5a, 0x17, 0x0d, 0x32, 0x33, 0x30, 0x39, 0x32, 0x32, 0x31, 0x35, 0x35, \
+ 0x32, 0x30, 0x34, 0x5a, 0x30, 0x34, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
+ 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
+ 0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
+ 0x53, 0x4c, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, \
+ 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x30, 0x59, \
+ 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, \
+ 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, \
+ 0x04, 0x37, 0xcc, 0x56, 0xd9, 0x76, 0x09, 0x1e, 0x5a, 0x72, 0x3e, 0xc7, \
+ 0x59, 0x2d, 0xff, 0x20, 0x6e, 0xee, 0x7c, 0xf9, 0x06, 0x91, 0x74, 0xd0, \
+ 0xad, 0x14, 0xb5, 0xf7, 0x68, 0x22, 0x59, 0x62, 0x92, 0x4e, 0xe5, 0x00, \
+ 0xd8, 0x23, 0x11, 0xff, 0xea, 0x2f, 0xd2, 0x34, 0x5d, 0x5d, 0x16, 0xbd, \
+ 0x8a, 0x88, 0xc2, 0x6b, 0x77, 0x0d, 0x55, 0xcd, 0x8a, 0x2a, 0x0e, 0xfa, \
+ 0x01, 0xc8, 0xb4, 0xed, 0xff, 0xa3, 0x81, 0x9d, 0x30, 0x81, 0x9a, 0x30, \
+ 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, \
+ 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x50, 0x61, 0xa5, \
+ 0x8f, 0xd4, 0x07, 0xd9, 0xd7, 0x82, 0x01, 0x0c, 0xe5, 0x65, 0x7f, 0x8c, \
+ 0x63, 0x46, 0xa7, 0x13, 0xbe, 0x30, 0x6e, 0x06, 0x03, 0x55, 0x1d, 0x23, \
+ 0x04, 0x67, 0x30, 0x65, 0x80, 0x14, 0x9d, 0x6d, 0x20, 0x24, 0x49, 0x01, \
+ 0x3f, 0x2b, 0xcb, 0x78, 0xb5, 0x19, 0xbc, 0x7e, 0x24, 0xc9, 0xdb, 0xfb, \
+ 0x36, 0x7c, 0xa1, 0x42, 0xa4, 0x40, 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, \
+ 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, \
+ 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x50, 0x6f, 0x6c, 0x61, \
+ 0x72, 0x53, 0x53, 0x4c, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, \
+ 0x03, 0x13, 0x13, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x73, 0x73, 0x6c, 0x20, \
+ 0x54, 0x65, 0x73, 0x74, 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x82, 0x09, \
+ 0x00, 0xc1, 0x43, 0xe2, 0x7e, 0x62, 0x43, 0xcc, 0xe8, 0x30, 0x0a, 0x06, \
+ 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x68, 0x00, \
+ 0x30, 0x65, 0x02, 0x31, 0x00, 0x9a, 0x2c, 0x5c, 0xd7, 0xa6, 0xdb, 0xa2, \
+ 0xe5, 0x64, 0x0d, 0xf0, 0xb9, 0x4e, 0xdd, 0xd7, 0x61, 0xd6, 0x13, 0x31, \
+ 0xc7, 0xab, 0x73, 0x80, 0xbb, 0xd3, 0xd3, 0x73, 0x13, 0x54, 0xad, 0x92, \
+ 0x0b, 0x5d, 0xab, 0xd0, 0xbc, 0xf7, 0xae, 0x2f, 0xe6, 0xa1, 0x21, 0x29, \
+ 0x35, 0x95, 0xaa, 0x3e, 0x39, 0x02, 0x30, 0x21, 0x36, 0x7f, 0x9d, 0xc6, \
+ 0x5d, 0xc6, 0x0b, 0xab, 0x27, 0xf2, 0x25, 0x1d, 0x3b, 0xf1, 0xcf, 0xf1, \
+ 0x35, 0x25, 0x14, 0xe7, 0xe5, 0xf1, 0x97, 0xb5, 0x59, 0xe3, 0x5e, 0x15, \
+ 0x7c, 0x66, 0xb9, 0x90, 0x7b, 0xc7, 0x01, 0x10, 0x4f, 0x73, 0xc6, 0x00, \
+ 0x21, 0x52, 0x2a, 0x0e, 0xf1, 0xc7, 0xd5 \
+}
+/* END FILE */
+
+/* This is taken from tests/data_files/server5.key. */
+/* BEGIN FILE string macro TEST_SRV_KEY_EC_PEM tests/data_files/server5.key */
+#define TEST_SRV_KEY_EC_PEM \
+ "-----BEGIN EC PRIVATE KEY-----\r\n" \
+ "MHcCAQEEIPEqEyB2AnCoPL/9U/YDHvdqXYbIogTywwyp6/UfDw6noAoGCCqGSM49\r\n" \
+ "AwEHoUQDQgAEN8xW2XYJHlpyPsdZLf8gbu58+QaRdNCtFLX3aCJZYpJO5QDYIxH/\r\n" \
+ "6i/SNF1dFr2KiMJrdw1VzYoqDvoByLTt/w==\r\n" \
+ "-----END EC PRIVATE KEY-----\r\n"
+/* END FILE */
+
+/* This is generated from tests/data_files/server5.key.der using `xxd -i`. */
+/* BEGIN FILE binary macro TEST_SRV_KEY_EC_DER tests/data_files/server5.key.der */
+#define TEST_SRV_KEY_EC_DER { \
+ 0x30, 0x77, 0x02, 0x01, 0x01, 0x04, 0x20, 0xf1, 0x2a, 0x13, 0x20, 0x76, \
+ 0x02, 0x70, 0xa8, 0x3c, 0xbf, 0xfd, 0x53, 0xf6, 0x03, 0x1e, 0xf7, 0x6a, \
+ 0x5d, 0x86, 0xc8, 0xa2, 0x04, 0xf2, 0xc3, 0x0c, 0xa9, 0xeb, 0xf5, 0x1f, \
+ 0x0f, 0x0e, 0xa7, 0xa0, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, \
+ 0x03, 0x01, 0x07, 0xa1, 0x44, 0x03, 0x42, 0x00, 0x04, 0x37, 0xcc, 0x56, \
+ 0xd9, 0x76, 0x09, 0x1e, 0x5a, 0x72, 0x3e, 0xc7, 0x59, 0x2d, 0xff, 0x20, \
+ 0x6e, 0xee, 0x7c, 0xf9, 0x06, 0x91, 0x74, 0xd0, 0xad, 0x14, 0xb5, 0xf7, \
+ 0x68, 0x22, 0x59, 0x62, 0x92, 0x4e, 0xe5, 0x00, 0xd8, 0x23, 0x11, 0xff, \
+ 0xea, 0x2f, 0xd2, 0x34, 0x5d, 0x5d, 0x16, 0xbd, 0x8a, 0x88, 0xc2, 0x6b, \
+ 0x77, 0x0d, 0x55, 0xcd, 0x8a, 0x2a, 0x0e, 0xfa, 0x01, 0xc8, 0xb4, 0xed, \
+ 0xff \
+}
+/* END FILE */
+
+/* This is taken from tests/data_files/server2-sha256.crt. */
+/* BEGIN FILE string macro TEST_SRV_CRT_RSA_SHA256_PEM tests/data_files/server2-sha256.crt */
+#define TEST_SRV_CRT_RSA_SHA256_PEM \
+ "-----BEGIN CERTIFICATE-----\r\n" \
+ "MIIDNzCCAh+gAwIBAgIBAjANBgkqhkiG9w0BAQsFADA7MQswCQYDVQQGEwJOTDER\r\n" \
+ "MA8GA1UECgwIUG9sYXJTU0wxGTAXBgNVBAMMEFBvbGFyU1NMIFRlc3QgQ0EwHhcN\r\n" \
+ "MTEwMjEyMTQ0NDA2WhcNMjEwMjEyMTQ0NDA2WjA0MQswCQYDVQQGEwJOTDERMA8G\r\n" \
+ "A1UECgwIUG9sYXJTU0wxEjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcN\r\n" \
+ "AQEBBQADggEPADCCAQoCggEBAMFNo93nzR3RBNdJcriZrA545Do8Ss86ExbQWuTN\r\n" \
+ "owCIp+4ea5anUrSQ7y1yej4kmvy2NKwk9XfgJmSMnLAofaHa6ozmyRyWvP7BBFKz\r\n" \
+ "NtSj+uGxdtiQwWG0ZlI2oiZTqqt0Xgd9GYLbKtgfoNkNHC1JZvdbJXNG6AuKT2kM\r\n" \
+ "tQCQ4dqCEGZ9rlQri2V5kaHiYcPNQEkI7mgM8YuG0ka/0LiqEQMef1aoGh5EGA8P\r\n" \
+ "hYvai0Re4hjGYi/HZo36Xdh98yeJKQHFkA4/J/EwyEoO79bex8cna8cFPXrEAjya\r\n" \
+ "HT4P6DSYW8tzS1KW2BGiLICIaTla0w+w3lkvEcf36hIBMJcCAwEAAaNNMEswCQYD\r\n" \
+ "VR0TBAIwADAdBgNVHQ4EFgQUpQXoZLjc32APUBJNYKhkr02LQ5MwHwYDVR0jBBgw\r\n" \
+ "FoAUtFrkpbPe0lL2udWmlQ/rPrzH/f8wDQYJKoZIhvcNAQELBQADggEBAGGEshT5\r\n" \
+ "kvnRmLVScVeUEdwIrvW7ezbGbUvJ8VxeJ79/HSjlLiGbMc4uUathwtzEdi9R/4C5\r\n" \
+ "DXBNeEPTkbB+fhG1W06iHYj/Dp8+aaG7fuDxKVKHVZSqBnmQLn73ymyclZNHii5A\r\n" \
+ "3nTS8WUaHAzxN/rajOtoM7aH1P9tULpHrl+7HOeLMpxUnwI12ZqZaLIzxbcdJVcr\r\n" \
+ "ra2F00aXCGkYVLvyvbZIq7LC+yVysej5gCeQYD7VFOEks0jhFjrS06gP0/XnWv6v\r\n" \
+ "eBoPez9d+CCjkrhseiWzXOiriIMICX48EloO/DrsMRAtvlwq7EDz4QhILz6ffndm\r\n" \
+ "e4K1cVANRPN2o9Y=\r\n" \
+ "-----END CERTIFICATE-----\r\n"
+/* END FILE */
+
+/* This is taken from tests/data_files/server2-sha256.crt.der. */
+/* BEGIN FILE binary macro TEST_SRV_CRT_RSA_SHA256_DER tests/data_files/server2-sha256.crt.der */
+#define TEST_SRV_CRT_RSA_SHA256_DER { \
+ 0x30, 0x82, 0x03, 0x37, 0x30, 0x82, 0x02, 0x1f, 0xa0, 0x03, 0x02, 0x01, \
+ 0x02, 0x02, 0x01, 0x02, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, \
+ 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, 0x30, \
+ 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, \
+ 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, \
+ 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, \
+ 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, \
+ 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, \
+ 0x31, 0x31, 0x30, 0x32, 0x31, 0x32, 0x31, 0x34, 0x34, 0x34, 0x30, 0x36, \
+ 0x5a, 0x17, 0x0d, 0x32, 0x31, 0x30, 0x32, 0x31, 0x32, 0x31, 0x34, 0x34, \
+ 0x34, 0x30, 0x36, 0x5a, 0x30, 0x34, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
+ 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
+ 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
+ 0x53, 0x4c, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, \
+ 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x30, 0x82, \
+ 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, \
+ 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, \
+ 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc1, 0x4d, 0xa3, 0xdd, 0xe7, \
+ 0xcd, 0x1d, 0xd1, 0x04, 0xd7, 0x49, 0x72, 0xb8, 0x99, 0xac, 0x0e, 0x78, \
+ 0xe4, 0x3a, 0x3c, 0x4a, 0xcf, 0x3a, 0x13, 0x16, 0xd0, 0x5a, 0xe4, 0xcd, \
+ 0xa3, 0x00, 0x88, 0xa7, 0xee, 0x1e, 0x6b, 0x96, 0xa7, 0x52, 0xb4, 0x90, \
+ 0xef, 0x2d, 0x72, 0x7a, 0x3e, 0x24, 0x9a, 0xfc, 0xb6, 0x34, 0xac, 0x24, \
+ 0xf5, 0x77, 0xe0, 0x26, 0x64, 0x8c, 0x9c, 0xb0, 0x28, 0x7d, 0xa1, 0xda, \
+ 0xea, 0x8c, 0xe6, 0xc9, 0x1c, 0x96, 0xbc, 0xfe, 0xc1, 0x04, 0x52, 0xb3, \
+ 0x36, 0xd4, 0xa3, 0xfa, 0xe1, 0xb1, 0x76, 0xd8, 0x90, 0xc1, 0x61, 0xb4, \
+ 0x66, 0x52, 0x36, 0xa2, 0x26, 0x53, 0xaa, 0xab, 0x74, 0x5e, 0x07, 0x7d, \
+ 0x19, 0x82, 0xdb, 0x2a, 0xd8, 0x1f, 0xa0, 0xd9, 0x0d, 0x1c, 0x2d, 0x49, \
+ 0x66, 0xf7, 0x5b, 0x25, 0x73, 0x46, 0xe8, 0x0b, 0x8a, 0x4f, 0x69, 0x0c, \
+ 0xb5, 0x00, 0x90, 0xe1, 0xda, 0x82, 0x10, 0x66, 0x7d, 0xae, 0x54, 0x2b, \
+ 0x8b, 0x65, 0x79, 0x91, 0xa1, 0xe2, 0x61, 0xc3, 0xcd, 0x40, 0x49, 0x08, \
+ 0xee, 0x68, 0x0c, 0xf1, 0x8b, 0x86, 0xd2, 0x46, 0xbf, 0xd0, 0xb8, 0xaa, \
+ 0x11, 0x03, 0x1e, 0x7f, 0x56, 0xa8, 0x1a, 0x1e, 0x44, 0x18, 0x0f, 0x0f, \
+ 0x85, 0x8b, 0xda, 0x8b, 0x44, 0x5e, 0xe2, 0x18, 0xc6, 0x62, 0x2f, 0xc7, \
+ 0x66, 0x8d, 0xfa, 0x5d, 0xd8, 0x7d, 0xf3, 0x27, 0x89, 0x29, 0x01, 0xc5, \
+ 0x90, 0x0e, 0x3f, 0x27, 0xf1, 0x30, 0xc8, 0x4a, 0x0e, 0xef, 0xd6, 0xde, \
+ 0xc7, 0xc7, 0x27, 0x6b, 0xc7, 0x05, 0x3d, 0x7a, 0xc4, 0x02, 0x3c, 0x9a, \
+ 0x1d, 0x3e, 0x0f, 0xe8, 0x34, 0x98, 0x5b, 0xcb, 0x73, 0x4b, 0x52, 0x96, \
+ 0xd8, 0x11, 0xa2, 0x2c, 0x80, 0x88, 0x69, 0x39, 0x5a, 0xd3, 0x0f, 0xb0, \
+ 0xde, 0x59, 0x2f, 0x11, 0xc7, 0xf7, 0xea, 0x12, 0x01, 0x30, 0x97, 0x02, \
+ 0x03, 0x01, 0x00, 0x01, 0xa3, 0x4d, 0x30, 0x4b, 0x30, 0x09, 0x06, 0x03, \
+ 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03, 0x55, \
+ 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xa5, 0x05, 0xe8, 0x64, 0xb8, 0xdc, \
+ 0xdf, 0x60, 0x0f, 0x50, 0x12, 0x4d, 0x60, 0xa8, 0x64, 0xaf, 0x4d, 0x8b, \
+ 0x43, 0x93, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, \
+ 0x16, 0x80, 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, \
+ 0xb9, 0xd5, 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, \
+ 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, \
+ 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x61, 0x84, 0xb2, 0x14, 0xf9, \
+ 0x92, 0xf9, 0xd1, 0x98, 0xb5, 0x52, 0x71, 0x57, 0x94, 0x11, 0xdc, 0x08, \
+ 0xae, 0xf5, 0xbb, 0x7b, 0x36, 0xc6, 0x6d, 0x4b, 0xc9, 0xf1, 0x5c, 0x5e, \
+ 0x27, 0xbf, 0x7f, 0x1d, 0x28, 0xe5, 0x2e, 0x21, 0x9b, 0x31, 0xce, 0x2e, \
+ 0x51, 0xab, 0x61, 0xc2, 0xdc, 0xc4, 0x76, 0x2f, 0x51, 0xff, 0x80, 0xb9, \
+ 0x0d, 0x70, 0x4d, 0x78, 0x43, 0xd3, 0x91, 0xb0, 0x7e, 0x7e, 0x11, 0xb5, \
+ 0x5b, 0x4e, 0xa2, 0x1d, 0x88, 0xff, 0x0e, 0x9f, 0x3e, 0x69, 0xa1, 0xbb, \
+ 0x7e, 0xe0, 0xf1, 0x29, 0x52, 0x87, 0x55, 0x94, 0xaa, 0x06, 0x79, 0x90, \
+ 0x2e, 0x7e, 0xf7, 0xca, 0x6c, 0x9c, 0x95, 0x93, 0x47, 0x8a, 0x2e, 0x40, \
+ 0xde, 0x74, 0xd2, 0xf1, 0x65, 0x1a, 0x1c, 0x0c, 0xf1, 0x37, 0xfa, 0xda, \
+ 0x8c, 0xeb, 0x68, 0x33, 0xb6, 0x87, 0xd4, 0xff, 0x6d, 0x50, 0xba, 0x47, \
+ 0xae, 0x5f, 0xbb, 0x1c, 0xe7, 0x8b, 0x32, 0x9c, 0x54, 0x9f, 0x02, 0x35, \
+ 0xd9, 0x9a, 0x99, 0x68, 0xb2, 0x33, 0xc5, 0xb7, 0x1d, 0x25, 0x57, 0x2b, \
+ 0xad, 0xad, 0x85, 0xd3, 0x46, 0x97, 0x08, 0x69, 0x18, 0x54, 0xbb, 0xf2, \
+ 0xbd, 0xb6, 0x48, 0xab, 0xb2, 0xc2, 0xfb, 0x25, 0x72, 0xb1, 0xe8, 0xf9, \
+ 0x80, 0x27, 0x90, 0x60, 0x3e, 0xd5, 0x14, 0xe1, 0x24, 0xb3, 0x48, 0xe1, \
+ 0x16, 0x3a, 0xd2, 0xd3, 0xa8, 0x0f, 0xd3, 0xf5, 0xe7, 0x5a, 0xfe, 0xaf, \
+ 0x78, 0x1a, 0x0f, 0x7b, 0x3f, 0x5d, 0xf8, 0x20, 0xa3, 0x92, 0xb8, 0x6c, \
+ 0x7a, 0x25, 0xb3, 0x5c, 0xe8, 0xab, 0x88, 0x83, 0x08, 0x09, 0x7e, 0x3c, \
+ 0x12, 0x5a, 0x0e, 0xfc, 0x3a, 0xec, 0x31, 0x10, 0x2d, 0xbe, 0x5c, 0x2a, \
+ 0xec, 0x40, 0xf3, 0xe1, 0x08, 0x48, 0x2f, 0x3e, 0x9f, 0x7e, 0x77, 0x66, \
+ 0x7b, 0x82, 0xb5, 0x71, 0x50, 0x0d, 0x44, 0xf3, 0x76, 0xa3, 0xd6 \
+}
+/* END FILE */
+
+/* This is taken from tests/data_files/server2.crt. */
+/* BEGIN FILE string macro TEST_SRV_CRT_RSA_SHA1_PEM tests/data_files/server2.crt */
+#define TEST_SRV_CRT_RSA_SHA1_PEM \
+ "-----BEGIN CERTIFICATE-----\r\n" \
+ "MIIDNzCCAh+gAwIBAgIBAjANBgkqhkiG9w0BAQUFADA7MQswCQYDVQQGEwJOTDER\r\n" \
+ "MA8GA1UECgwIUG9sYXJTU0wxGTAXBgNVBAMMEFBvbGFyU1NMIFRlc3QgQ0EwHhcN\r\n" \
+ "MTEwMjEyMTQ0NDA2WhcNMjEwMjEyMTQ0NDA2WjA0MQswCQYDVQQGEwJOTDERMA8G\r\n" \
+ "A1UECgwIUG9sYXJTU0wxEjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcN\r\n" \
+ "AQEBBQADggEPADCCAQoCggEBAMFNo93nzR3RBNdJcriZrA545Do8Ss86ExbQWuTN\r\n" \
+ "owCIp+4ea5anUrSQ7y1yej4kmvy2NKwk9XfgJmSMnLAofaHa6ozmyRyWvP7BBFKz\r\n" \
+ "NtSj+uGxdtiQwWG0ZlI2oiZTqqt0Xgd9GYLbKtgfoNkNHC1JZvdbJXNG6AuKT2kM\r\n" \
+ "tQCQ4dqCEGZ9rlQri2V5kaHiYcPNQEkI7mgM8YuG0ka/0LiqEQMef1aoGh5EGA8P\r\n" \
+ "hYvai0Re4hjGYi/HZo36Xdh98yeJKQHFkA4/J/EwyEoO79bex8cna8cFPXrEAjya\r\n" \
+ "HT4P6DSYW8tzS1KW2BGiLICIaTla0w+w3lkvEcf36hIBMJcCAwEAAaNNMEswCQYD\r\n" \
+ "VR0TBAIwADAdBgNVHQ4EFgQUpQXoZLjc32APUBJNYKhkr02LQ5MwHwYDVR0jBBgw\r\n" \
+ "FoAUtFrkpbPe0lL2udWmlQ/rPrzH/f8wDQYJKoZIhvcNAQEFBQADggEBAAFzC0rF\r\n" \
+ "y6De8WMcdgQrEw3AhBHFjzqnxZw1ene4IBSC7lTw8rBSy3jOWQdPUWn+0y/pCeeF\r\n" \
+ "kti6sevFdl1hLemGtd4q+T9TKEKGg3ND4ARfB5AUZZ9uEHq8WBkiwus5clGS17Qd\r\n" \
+ "dS/TOisB59tQruLx1E1bPLtBKyqk4koC5WAULJwfpswGSyWJTpYwIpxcWE3D2tBu\r\n" \
+ "UB6MZfXZFzWmWEOyKbeoXjXe8GBCGgHLywvYDsGQ36HSGtEsAvR2QaTLSxWYcfk1\r\n" \
+ "fbDn4jSWkb4yZy1r01UEigFQtONieGwRFaUqEcFJHJvEEGVgh9keaVlOj2vrwf5r\r\n" \
+ "4mN4lW7gLdenN6g=\r\n" \
+ "-----END CERTIFICATE-----\r\n"
+/* END FILE */
+
+/* This is taken from tests/data_files/server2.crt.der. */
+/* BEGIN FILE binary macro TEST_SRV_CRT_RSA_SHA1_DER tests/data_files/server2.crt.der */
+#define TEST_SRV_CRT_RSA_SHA1_DER { \
+ 0x30, 0x82, 0x03, 0x37, 0x30, 0x82, 0x02, 0x1f, 0xa0, 0x03, 0x02, 0x01, \
+ 0x02, 0x02, 0x01, 0x02, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, \
+ 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, 0x30, \
+ 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, \
+ 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, \
+ 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, \
+ 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, \
+ 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, \
+ 0x31, 0x31, 0x30, 0x32, 0x31, 0x32, 0x31, 0x34, 0x34, 0x34, 0x30, 0x36, \
+ 0x5a, 0x17, 0x0d, 0x32, 0x31, 0x30, 0x32, 0x31, 0x32, 0x31, 0x34, 0x34, \
+ 0x34, 0x30, 0x36, 0x5a, 0x30, 0x34, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
+ 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
+ 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
+ 0x53, 0x4c, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, \
+ 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x30, 0x82, \
+ 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, \
+ 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, \
+ 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc1, 0x4d, 0xa3, 0xdd, 0xe7, \
+ 0xcd, 0x1d, 0xd1, 0x04, 0xd7, 0x49, 0x72, 0xb8, 0x99, 0xac, 0x0e, 0x78, \
+ 0xe4, 0x3a, 0x3c, 0x4a, 0xcf, 0x3a, 0x13, 0x16, 0xd0, 0x5a, 0xe4, 0xcd, \
+ 0xa3, 0x00, 0x88, 0xa7, 0xee, 0x1e, 0x6b, 0x96, 0xa7, 0x52, 0xb4, 0x90, \
+ 0xef, 0x2d, 0x72, 0x7a, 0x3e, 0x24, 0x9a, 0xfc, 0xb6, 0x34, 0xac, 0x24, \
+ 0xf5, 0x77, 0xe0, 0x26, 0x64, 0x8c, 0x9c, 0xb0, 0x28, 0x7d, 0xa1, 0xda, \
+ 0xea, 0x8c, 0xe6, 0xc9, 0x1c, 0x96, 0xbc, 0xfe, 0xc1, 0x04, 0x52, 0xb3, \
+ 0x36, 0xd4, 0xa3, 0xfa, 0xe1, 0xb1, 0x76, 0xd8, 0x90, 0xc1, 0x61, 0xb4, \
+ 0x66, 0x52, 0x36, 0xa2, 0x26, 0x53, 0xaa, 0xab, 0x74, 0x5e, 0x07, 0x7d, \
+ 0x19, 0x82, 0xdb, 0x2a, 0xd8, 0x1f, 0xa0, 0xd9, 0x0d, 0x1c, 0x2d, 0x49, \
+ 0x66, 0xf7, 0x5b, 0x25, 0x73, 0x46, 0xe8, 0x0b, 0x8a, 0x4f, 0x69, 0x0c, \
+ 0xb5, 0x00, 0x90, 0xe1, 0xda, 0x82, 0x10, 0x66, 0x7d, 0xae, 0x54, 0x2b, \
+ 0x8b, 0x65, 0x79, 0x91, 0xa1, 0xe2, 0x61, 0xc3, 0xcd, 0x40, 0x49, 0x08, \
+ 0xee, 0x68, 0x0c, 0xf1, 0x8b, 0x86, 0xd2, 0x46, 0xbf, 0xd0, 0xb8, 0xaa, \
+ 0x11, 0x03, 0x1e, 0x7f, 0x56, 0xa8, 0x1a, 0x1e, 0x44, 0x18, 0x0f, 0x0f, \
+ 0x85, 0x8b, 0xda, 0x8b, 0x44, 0x5e, 0xe2, 0x18, 0xc6, 0x62, 0x2f, 0xc7, \
+ 0x66, 0x8d, 0xfa, 0x5d, 0xd8, 0x7d, 0xf3, 0x27, 0x89, 0x29, 0x01, 0xc5, \
+ 0x90, 0x0e, 0x3f, 0x27, 0xf1, 0x30, 0xc8, 0x4a, 0x0e, 0xef, 0xd6, 0xde, \
+ 0xc7, 0xc7, 0x27, 0x6b, 0xc7, 0x05, 0x3d, 0x7a, 0xc4, 0x02, 0x3c, 0x9a, \
+ 0x1d, 0x3e, 0x0f, 0xe8, 0x34, 0x98, 0x5b, 0xcb, 0x73, 0x4b, 0x52, 0x96, \
+ 0xd8, 0x11, 0xa2, 0x2c, 0x80, 0x88, 0x69, 0x39, 0x5a, 0xd3, 0x0f, 0xb0, \
+ 0xde, 0x59, 0x2f, 0x11, 0xc7, 0xf7, 0xea, 0x12, 0x01, 0x30, 0x97, 0x02, \
+ 0x03, 0x01, 0x00, 0x01, 0xa3, 0x4d, 0x30, 0x4b, 0x30, 0x09, 0x06, 0x03, \
+ 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03, 0x55, \
+ 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xa5, 0x05, 0xe8, 0x64, 0xb8, 0xdc, \
+ 0xdf, 0x60, 0x0f, 0x50, 0x12, 0x4d, 0x60, 0xa8, 0x64, 0xaf, 0x4d, 0x8b, \
+ 0x43, 0x93, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, \
+ 0x16, 0x80, 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, \
+ 0xb9, 0xd5, 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, \
+ 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, \
+ 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x01, 0x73, 0x0b, 0x4a, 0xc5, \
+ 0xcb, 0xa0, 0xde, 0xf1, 0x63, 0x1c, 0x76, 0x04, 0x2b, 0x13, 0x0d, 0xc0, \
+ 0x84, 0x11, 0xc5, 0x8f, 0x3a, 0xa7, 0xc5, 0x9c, 0x35, 0x7a, 0x77, 0xb8, \
+ 0x20, 0x14, 0x82, 0xee, 0x54, 0xf0, 0xf2, 0xb0, 0x52, 0xcb, 0x78, 0xce, \
+ 0x59, 0x07, 0x4f, 0x51, 0x69, 0xfe, 0xd3, 0x2f, 0xe9, 0x09, 0xe7, 0x85, \
+ 0x92, 0xd8, 0xba, 0xb1, 0xeb, 0xc5, 0x76, 0x5d, 0x61, 0x2d, 0xe9, 0x86, \
+ 0xb5, 0xde, 0x2a, 0xf9, 0x3f, 0x53, 0x28, 0x42, 0x86, 0x83, 0x73, 0x43, \
+ 0xe0, 0x04, 0x5f, 0x07, 0x90, 0x14, 0x65, 0x9f, 0x6e, 0x10, 0x7a, 0xbc, \
+ 0x58, 0x19, 0x22, 0xc2, 0xeb, 0x39, 0x72, 0x51, 0x92, 0xd7, 0xb4, 0x1d, \
+ 0x75, 0x2f, 0xd3, 0x3a, 0x2b, 0x01, 0xe7, 0xdb, 0x50, 0xae, 0xe2, 0xf1, \
+ 0xd4, 0x4d, 0x5b, 0x3c, 0xbb, 0x41, 0x2b, 0x2a, 0xa4, 0xe2, 0x4a, 0x02, \
+ 0xe5, 0x60, 0x14, 0x2c, 0x9c, 0x1f, 0xa6, 0xcc, 0x06, 0x4b, 0x25, 0x89, \
+ 0x4e, 0x96, 0x30, 0x22, 0x9c, 0x5c, 0x58, 0x4d, 0xc3, 0xda, 0xd0, 0x6e, \
+ 0x50, 0x1e, 0x8c, 0x65, 0xf5, 0xd9, 0x17, 0x35, 0xa6, 0x58, 0x43, 0xb2, \
+ 0x29, 0xb7, 0xa8, 0x5e, 0x35, 0xde, 0xf0, 0x60, 0x42, 0x1a, 0x01, 0xcb, \
+ 0xcb, 0x0b, 0xd8, 0x0e, 0xc1, 0x90, 0xdf, 0xa1, 0xd2, 0x1a, 0xd1, 0x2c, \
+ 0x02, 0xf4, 0x76, 0x41, 0xa4, 0xcb, 0x4b, 0x15, 0x98, 0x71, 0xf9, 0x35, \
+ 0x7d, 0xb0, 0xe7, 0xe2, 0x34, 0x96, 0x91, 0xbe, 0x32, 0x67, 0x2d, 0x6b, \
+ 0xd3, 0x55, 0x04, 0x8a, 0x01, 0x50, 0xb4, 0xe3, 0x62, 0x78, 0x6c, 0x11, \
+ 0x15, 0xa5, 0x2a, 0x11, 0xc1, 0x49, 0x1c, 0x9b, 0xc4, 0x10, 0x65, 0x60, \
+ 0x87, 0xd9, 0x1e, 0x69, 0x59, 0x4e, 0x8f, 0x6b, 0xeb, 0xc1, 0xfe, 0x6b, \
+ 0xe2, 0x63, 0x78, 0x95, 0x6e, 0xe0, 0x2d, 0xd7, 0xa7, 0x37, 0xa8 \
+}
+/* END FILE */
+
+/* This is taken from tests/data_files/server2.key. */
+/* BEGIN FILE string macro TEST_SRV_KEY_RSA_PEM tests/data_files/server2.key */
+#define TEST_SRV_KEY_RSA_PEM \
+ "-----BEGIN RSA PRIVATE KEY-----\r\n" \
+ "MIIEpAIBAAKCAQEAwU2j3efNHdEE10lyuJmsDnjkOjxKzzoTFtBa5M2jAIin7h5r\r\n" \
+ "lqdStJDvLXJ6PiSa/LY0rCT1d+AmZIycsCh9odrqjObJHJa8/sEEUrM21KP64bF2\r\n" \
+ "2JDBYbRmUjaiJlOqq3ReB30Zgtsq2B+g2Q0cLUlm91slc0boC4pPaQy1AJDh2oIQ\r\n" \
+ "Zn2uVCuLZXmRoeJhw81ASQjuaAzxi4bSRr/QuKoRAx5/VqgaHkQYDw+Fi9qLRF7i\r\n" \
+ "GMZiL8dmjfpd2H3zJ4kpAcWQDj8n8TDISg7v1t7HxydrxwU9esQCPJodPg/oNJhb\r\n" \
+ "y3NLUpbYEaIsgIhpOVrTD7DeWS8Rx/fqEgEwlwIDAQABAoIBAQCXR0S8EIHFGORZ\r\n" \
+ "++AtOg6eENxD+xVs0f1IeGz57Tjo3QnXX7VBZNdj+p1ECvhCE/G7XnkgU5hLZX+G\r\n" \
+ "Z0jkz/tqJOI0vRSdLBbipHnWouyBQ4e/A1yIJdlBtqXxJ1KE/ituHRbNc4j4kL8Z\r\n" \
+ "/r6pvwnTI0PSx2Eqs048YdS92LT6qAv4flbNDxMn2uY7s4ycS4Q8w1JXnCeaAnYm\r\n" \
+ "WYI5wxO+bvRELR2Mcz5DmVnL8jRyml6l6582bSv5oufReFIbyPZbQWlXgYnpu6He\r\n" \
+ "GTc7E1zKYQGG/9+DQUl/1vQuCPqQwny0tQoX2w5tdYpdMdVm+zkLtbajzdTviJJa\r\n" \
+ "TWzL6lt5AoGBAN86+SVeJDcmQJcv4Eq6UhtRr4QGMiQMz0Sod6ettYxYzMgxtw28\r\n" \
+ "CIrgpozCc+UaZJLo7UxvC6an85r1b2nKPCLQFaggJ0H4Q0J/sZOhBIXaoBzWxveK\r\n" \
+ "nupceKdVxGsFi8CDy86DBfiyFivfBj+47BbaQzPBj7C4rK7UlLjab2rDAoGBAN2u\r\n" \
+ "AM2gchoFiu4v1HFL8D7lweEpi6ZnMJjnEu/dEgGQJFjwdpLnPbsj4c75odQ4Gz8g\r\n" \
+ "sw9lao9VVzbusoRE/JGI4aTdO0pATXyG7eG1Qu+5Yc1YGXcCrliA2xM9xx+d7f+s\r\n" \
+ "mPzN+WIEg5GJDYZDjAzHG5BNvi/FfM1C9dOtjv2dAoGAF0t5KmwbjWHBhcVqO4Ic\r\n" \
+ "BVvN3BIlc1ue2YRXEDlxY5b0r8N4XceMgKmW18OHApZxfl8uPDauWZLXOgl4uepv\r\n" \
+ "whZC3EuWrSyyICNhLY21Ah7hbIEBPF3L3ZsOwC+UErL+dXWLdB56Jgy3gZaBeW7b\r\n" \
+ "vDrEnocJbqCm7IukhXHOBK8CgYEAwqdHB0hqyNSzIOGY7v9abzB6pUdA3BZiQvEs\r\n" \
+ "3LjHVd4HPJ2x0N8CgrBIWOE0q8+0hSMmeE96WW/7jD3fPWwCR5zlXknxBQsfv0gP\r\n" \
+ "3BC5PR0Qdypz+d+9zfMf625kyit4T/hzwhDveZUzHnk1Cf+IG7Q+TOEnLnWAWBED\r\n" \
+ "ISOWmrUCgYAFEmRxgwAc/u+D6t0syCwAYh6POtscq9Y0i9GyWk89NzgC4NdwwbBH\r\n" \
+ "4AgahOxIxXx2gxJnq3yfkJfIjwf0s2DyP0kY2y6Ua1OeomPeY9mrIS4tCuDQ6LrE\r\n" \
+ "TB6l9VGoxJL4fyHnZb8L5gGvnB1bbD8cL6YPaDiOhcRseC9vBiEuVg==\r\n" \
+ "-----END RSA PRIVATE KEY-----\r\n"
+/* END FILE */
+
+/* This was generated from tests/data_files/server2.key.der using `xxd -i`. */
+/* BEGIN FILE binary macro TEST_SRV_KEY_RSA_DER tests/data_files/server2.key.der */
+#define TEST_SRV_KEY_RSA_DER { \
+ 0x30, 0x82, 0x04, 0xa4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, \
+ 0xc1, 0x4d, 0xa3, 0xdd, 0xe7, 0xcd, 0x1d, 0xd1, 0x04, 0xd7, 0x49, 0x72, \
+ 0xb8, 0x99, 0xac, 0x0e, 0x78, 0xe4, 0x3a, 0x3c, 0x4a, 0xcf, 0x3a, 0x13, \
+ 0x16, 0xd0, 0x5a, 0xe4, 0xcd, 0xa3, 0x00, 0x88, 0xa7, 0xee, 0x1e, 0x6b, \
+ 0x96, 0xa7, 0x52, 0xb4, 0x90, 0xef, 0x2d, 0x72, 0x7a, 0x3e, 0x24, 0x9a, \
+ 0xfc, 0xb6, 0x34, 0xac, 0x24, 0xf5, 0x77, 0xe0, 0x26, 0x64, 0x8c, 0x9c, \
+ 0xb0, 0x28, 0x7d, 0xa1, 0xda, 0xea, 0x8c, 0xe6, 0xc9, 0x1c, 0x96, 0xbc, \
+ 0xfe, 0xc1, 0x04, 0x52, 0xb3, 0x36, 0xd4, 0xa3, 0xfa, 0xe1, 0xb1, 0x76, \
+ 0xd8, 0x90, 0xc1, 0x61, 0xb4, 0x66, 0x52, 0x36, 0xa2, 0x26, 0x53, 0xaa, \
+ 0xab, 0x74, 0x5e, 0x07, 0x7d, 0x19, 0x82, 0xdb, 0x2a, 0xd8, 0x1f, 0xa0, \
+ 0xd9, 0x0d, 0x1c, 0x2d, 0x49, 0x66, 0xf7, 0x5b, 0x25, 0x73, 0x46, 0xe8, \
+ 0x0b, 0x8a, 0x4f, 0x69, 0x0c, 0xb5, 0x00, 0x90, 0xe1, 0xda, 0x82, 0x10, \
+ 0x66, 0x7d, 0xae, 0x54, 0x2b, 0x8b, 0x65, 0x79, 0x91, 0xa1, 0xe2, 0x61, \
+ 0xc3, 0xcd, 0x40, 0x49, 0x08, 0xee, 0x68, 0x0c, 0xf1, 0x8b, 0x86, 0xd2, \
+ 0x46, 0xbf, 0xd0, 0xb8, 0xaa, 0x11, 0x03, 0x1e, 0x7f, 0x56, 0xa8, 0x1a, \
+ 0x1e, 0x44, 0x18, 0x0f, 0x0f, 0x85, 0x8b, 0xda, 0x8b, 0x44, 0x5e, 0xe2, \
+ 0x18, 0xc6, 0x62, 0x2f, 0xc7, 0x66, 0x8d, 0xfa, 0x5d, 0xd8, 0x7d, 0xf3, \
+ 0x27, 0x89, 0x29, 0x01, 0xc5, 0x90, 0x0e, 0x3f, 0x27, 0xf1, 0x30, 0xc8, \
+ 0x4a, 0x0e, 0xef, 0xd6, 0xde, 0xc7, 0xc7, 0x27, 0x6b, 0xc7, 0x05, 0x3d, \
+ 0x7a, 0xc4, 0x02, 0x3c, 0x9a, 0x1d, 0x3e, 0x0f, 0xe8, 0x34, 0x98, 0x5b, \
+ 0xcb, 0x73, 0x4b, 0x52, 0x96, 0xd8, 0x11, 0xa2, 0x2c, 0x80, 0x88, 0x69, \
+ 0x39, 0x5a, 0xd3, 0x0f, 0xb0, 0xde, 0x59, 0x2f, 0x11, 0xc7, 0xf7, 0xea, \
+ 0x12, 0x01, 0x30, 0x97, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x82, 0x01, \
+ 0x01, 0x00, 0x97, 0x47, 0x44, 0xbc, 0x10, 0x81, 0xc5, 0x18, 0xe4, 0x59, \
+ 0xfb, 0xe0, 0x2d, 0x3a, 0x0e, 0x9e, 0x10, 0xdc, 0x43, 0xfb, 0x15, 0x6c, \
+ 0xd1, 0xfd, 0x48, 0x78, 0x6c, 0xf9, 0xed, 0x38, 0xe8, 0xdd, 0x09, 0xd7, \
+ 0x5f, 0xb5, 0x41, 0x64, 0xd7, 0x63, 0xfa, 0x9d, 0x44, 0x0a, 0xf8, 0x42, \
+ 0x13, 0xf1, 0xbb, 0x5e, 0x79, 0x20, 0x53, 0x98, 0x4b, 0x65, 0x7f, 0x86, \
+ 0x67, 0x48, 0xe4, 0xcf, 0xfb, 0x6a, 0x24, 0xe2, 0x34, 0xbd, 0x14, 0x9d, \
+ 0x2c, 0x16, 0xe2, 0xa4, 0x79, 0xd6, 0xa2, 0xec, 0x81, 0x43, 0x87, 0xbf, \
+ 0x03, 0x5c, 0x88, 0x25, 0xd9, 0x41, 0xb6, 0xa5, 0xf1, 0x27, 0x52, 0x84, \
+ 0xfe, 0x2b, 0x6e, 0x1d, 0x16, 0xcd, 0x73, 0x88, 0xf8, 0x90, 0xbf, 0x19, \
+ 0xfe, 0xbe, 0xa9, 0xbf, 0x09, 0xd3, 0x23, 0x43, 0xd2, 0xc7, 0x61, 0x2a, \
+ 0xb3, 0x4e, 0x3c, 0x61, 0xd4, 0xbd, 0xd8, 0xb4, 0xfa, 0xa8, 0x0b, 0xf8, \
+ 0x7e, 0x56, 0xcd, 0x0f, 0x13, 0x27, 0xda, 0xe6, 0x3b, 0xb3, 0x8c, 0x9c, \
+ 0x4b, 0x84, 0x3c, 0xc3, 0x52, 0x57, 0x9c, 0x27, 0x9a, 0x02, 0x76, 0x26, \
+ 0x59, 0x82, 0x39, 0xc3, 0x13, 0xbe, 0x6e, 0xf4, 0x44, 0x2d, 0x1d, 0x8c, \
+ 0x73, 0x3e, 0x43, 0x99, 0x59, 0xcb, 0xf2, 0x34, 0x72, 0x9a, 0x5e, 0xa5, \
+ 0xeb, 0x9f, 0x36, 0x6d, 0x2b, 0xf9, 0xa2, 0xe7, 0xd1, 0x78, 0x52, 0x1b, \
+ 0xc8, 0xf6, 0x5b, 0x41, 0x69, 0x57, 0x81, 0x89, 0xe9, 0xbb, 0xa1, 0xde, \
+ 0x19, 0x37, 0x3b, 0x13, 0x5c, 0xca, 0x61, 0x01, 0x86, 0xff, 0xdf, 0x83, \
+ 0x41, 0x49, 0x7f, 0xd6, 0xf4, 0x2e, 0x08, 0xfa, 0x90, 0xc2, 0x7c, 0xb4, \
+ 0xb5, 0x0a, 0x17, 0xdb, 0x0e, 0x6d, 0x75, 0x8a, 0x5d, 0x31, 0xd5, 0x66, \
+ 0xfb, 0x39, 0x0b, 0xb5, 0xb6, 0xa3, 0xcd, 0xd4, 0xef, 0x88, 0x92, 0x5a, \
+ 0x4d, 0x6c, 0xcb, 0xea, 0x5b, 0x79, 0x02, 0x81, 0x81, 0x00, 0xdf, 0x3a, \
+ 0xf9, 0x25, 0x5e, 0x24, 0x37, 0x26, 0x40, 0x97, 0x2f, 0xe0, 0x4a, 0xba, \
+ 0x52, 0x1b, 0x51, 0xaf, 0x84, 0x06, 0x32, 0x24, 0x0c, 0xcf, 0x44, 0xa8, \
+ 0x77, 0xa7, 0xad, 0xb5, 0x8c, 0x58, 0xcc, 0xc8, 0x31, 0xb7, 0x0d, 0xbc, \
+ 0x08, 0x8a, 0xe0, 0xa6, 0x8c, 0xc2, 0x73, 0xe5, 0x1a, 0x64, 0x92, 0xe8, \
+ 0xed, 0x4c, 0x6f, 0x0b, 0xa6, 0xa7, 0xf3, 0x9a, 0xf5, 0x6f, 0x69, 0xca, \
+ 0x3c, 0x22, 0xd0, 0x15, 0xa8, 0x20, 0x27, 0x41, 0xf8, 0x43, 0x42, 0x7f, \
+ 0xb1, 0x93, 0xa1, 0x04, 0x85, 0xda, 0xa0, 0x1c, 0xd6, 0xc6, 0xf7, 0x8a, \
+ 0x9e, 0xea, 0x5c, 0x78, 0xa7, 0x55, 0xc4, 0x6b, 0x05, 0x8b, 0xc0, 0x83, \
+ 0xcb, 0xce, 0x83, 0x05, 0xf8, 0xb2, 0x16, 0x2b, 0xdf, 0x06, 0x3f, 0xb8, \
+ 0xec, 0x16, 0xda, 0x43, 0x33, 0xc1, 0x8f, 0xb0, 0xb8, 0xac, 0xae, 0xd4, \
+ 0x94, 0xb8, 0xda, 0x6f, 0x6a, 0xc3, 0x02, 0x81, 0x81, 0x00, 0xdd, 0xae, \
+ 0x00, 0xcd, 0xa0, 0x72, 0x1a, 0x05, 0x8a, 0xee, 0x2f, 0xd4, 0x71, 0x4b, \
+ 0xf0, 0x3e, 0xe5, 0xc1, 0xe1, 0x29, 0x8b, 0xa6, 0x67, 0x30, 0x98, 0xe7, \
+ 0x12, 0xef, 0xdd, 0x12, 0x01, 0x90, 0x24, 0x58, 0xf0, 0x76, 0x92, 0xe7, \
+ 0x3d, 0xbb, 0x23, 0xe1, 0xce, 0xf9, 0xa1, 0xd4, 0x38, 0x1b, 0x3f, 0x20, \
+ 0xb3, 0x0f, 0x65, 0x6a, 0x8f, 0x55, 0x57, 0x36, 0xee, 0xb2, 0x84, 0x44, \
+ 0xfc, 0x91, 0x88, 0xe1, 0xa4, 0xdd, 0x3b, 0x4a, 0x40, 0x4d, 0x7c, 0x86, \
+ 0xed, 0xe1, 0xb5, 0x42, 0xef, 0xb9, 0x61, 0xcd, 0x58, 0x19, 0x77, 0x02, \
+ 0xae, 0x58, 0x80, 0xdb, 0x13, 0x3d, 0xc7, 0x1f, 0x9d, 0xed, 0xff, 0xac, \
+ 0x98, 0xfc, 0xcd, 0xf9, 0x62, 0x04, 0x83, 0x91, 0x89, 0x0d, 0x86, 0x43, \
+ 0x8c, 0x0c, 0xc7, 0x1b, 0x90, 0x4d, 0xbe, 0x2f, 0xc5, 0x7c, 0xcd, 0x42, \
+ 0xf5, 0xd3, 0xad, 0x8e, 0xfd, 0x9d, 0x02, 0x81, 0x80, 0x17, 0x4b, 0x79, \
+ 0x2a, 0x6c, 0x1b, 0x8d, 0x61, 0xc1, 0x85, 0xc5, 0x6a, 0x3b, 0x82, 0x1c, \
+ 0x05, 0x5b, 0xcd, 0xdc, 0x12, 0x25, 0x73, 0x5b, 0x9e, 0xd9, 0x84, 0x57, \
+ 0x10, 0x39, 0x71, 0x63, 0x96, 0xf4, 0xaf, 0xc3, 0x78, 0x5d, 0xc7, 0x8c, \
+ 0x80, 0xa9, 0x96, 0xd7, 0xc3, 0x87, 0x02, 0x96, 0x71, 0x7e, 0x5f, 0x2e, \
+ 0x3c, 0x36, 0xae, 0x59, 0x92, 0xd7, 0x3a, 0x09, 0x78, 0xb9, 0xea, 0x6f, \
+ 0xc2, 0x16, 0x42, 0xdc, 0x4b, 0x96, 0xad, 0x2c, 0xb2, 0x20, 0x23, 0x61, \
+ 0x2d, 0x8d, 0xb5, 0x02, 0x1e, 0xe1, 0x6c, 0x81, 0x01, 0x3c, 0x5d, 0xcb, \
+ 0xdd, 0x9b, 0x0e, 0xc0, 0x2f, 0x94, 0x12, 0xb2, 0xfe, 0x75, 0x75, 0x8b, \
+ 0x74, 0x1e, 0x7a, 0x26, 0x0c, 0xb7, 0x81, 0x96, 0x81, 0x79, 0x6e, 0xdb, \
+ 0xbc, 0x3a, 0xc4, 0x9e, 0x87, 0x09, 0x6e, 0xa0, 0xa6, 0xec, 0x8b, 0xa4, \
+ 0x85, 0x71, 0xce, 0x04, 0xaf, 0x02, 0x81, 0x81, 0x00, 0xc2, 0xa7, 0x47, \
+ 0x07, 0x48, 0x6a, 0xc8, 0xd4, 0xb3, 0x20, 0xe1, 0x98, 0xee, 0xff, 0x5a, \
+ 0x6f, 0x30, 0x7a, 0xa5, 0x47, 0x40, 0xdc, 0x16, 0x62, 0x42, 0xf1, 0x2c, \
+ 0xdc, 0xb8, 0xc7, 0x55, 0xde, 0x07, 0x3c, 0x9d, 0xb1, 0xd0, 0xdf, 0x02, \
+ 0x82, 0xb0, 0x48, 0x58, 0xe1, 0x34, 0xab, 0xcf, 0xb4, 0x85, 0x23, 0x26, \
+ 0x78, 0x4f, 0x7a, 0x59, 0x6f, 0xfb, 0x8c, 0x3d, 0xdf, 0x3d, 0x6c, 0x02, \
+ 0x47, 0x9c, 0xe5, 0x5e, 0x49, 0xf1, 0x05, 0x0b, 0x1f, 0xbf, 0x48, 0x0f, \
+ 0xdc, 0x10, 0xb9, 0x3d, 0x1d, 0x10, 0x77, 0x2a, 0x73, 0xf9, 0xdf, 0xbd, \
+ 0xcd, 0xf3, 0x1f, 0xeb, 0x6e, 0x64, 0xca, 0x2b, 0x78, 0x4f, 0xf8, 0x73, \
+ 0xc2, 0x10, 0xef, 0x79, 0x95, 0x33, 0x1e, 0x79, 0x35, 0x09, 0xff, 0x88, \
+ 0x1b, 0xb4, 0x3e, 0x4c, 0xe1, 0x27, 0x2e, 0x75, 0x80, 0x58, 0x11, 0x03, \
+ 0x21, 0x23, 0x96, 0x9a, 0xb5, 0x02, 0x81, 0x80, 0x05, 0x12, 0x64, 0x71, \
+ 0x83, 0x00, 0x1c, 0xfe, 0xef, 0x83, 0xea, 0xdd, 0x2c, 0xc8, 0x2c, 0x00, \
+ 0x62, 0x1e, 0x8f, 0x3a, 0xdb, 0x1c, 0xab, 0xd6, 0x34, 0x8b, 0xd1, 0xb2, \
+ 0x5a, 0x4f, 0x3d, 0x37, 0x38, 0x02, 0xe0, 0xd7, 0x70, 0xc1, 0xb0, 0x47, \
+ 0xe0, 0x08, 0x1a, 0x84, 0xec, 0x48, 0xc5, 0x7c, 0x76, 0x83, 0x12, 0x67, \
+ 0xab, 0x7c, 0x9f, 0x90, 0x97, 0xc8, 0x8f, 0x07, 0xf4, 0xb3, 0x60, 0xf2, \
+ 0x3f, 0x49, 0x18, 0xdb, 0x2e, 0x94, 0x6b, 0x53, 0x9e, 0xa2, 0x63, 0xde, \
+ 0x63, 0xd9, 0xab, 0x21, 0x2e, 0x2d, 0x0a, 0xe0, 0xd0, 0xe8, 0xba, 0xc4, \
+ 0x4c, 0x1e, 0xa5, 0xf5, 0x51, 0xa8, 0xc4, 0x92, 0xf8, 0x7f, 0x21, 0xe7, \
+ 0x65, 0xbf, 0x0b, 0xe6, 0x01, 0xaf, 0x9c, 0x1d, 0x5b, 0x6c, 0x3f, 0x1c, \
+ 0x2f, 0xa6, 0x0f, 0x68, 0x38, 0x8e, 0x85, 0xc4, 0x6c, 0x78, 0x2f, 0x6f, \
+ 0x06, 0x21, 0x2e, 0x56 \
+}
+/* END FILE */
+
+/*
+ * Test client Certificates
+ *
+ * Test client certificates are defined for each choice
+ * of the following parameters:
+ * - PEM or DER encoding
+ * - RSA or EC key
+ *
+ * Things to add:
+ * - hash type
+ * - multiple EC curve types
+ */
+
+/* This is taken from tests/data_files/cli2.crt. */
+/* BEGIN FILE string macro TEST_CLI_CRT_EC_PEM tests/data_files/cli2.crt */
+#define TEST_CLI_CRT_EC_PEM \
+ "-----BEGIN CERTIFICATE-----\r\n" \
+ "MIICLDCCAbKgAwIBAgIBDTAKBggqhkjOPQQDAjA+MQswCQYDVQQGEwJOTDERMA8G\r\n" \
+ "A1UEChMIUG9sYXJTU0wxHDAaBgNVBAMTE1BvbGFyc3NsIFRlc3QgRUMgQ0EwHhcN\r\n" \
+ "MTMwOTI0MTU1MjA0WhcNMjMwOTIyMTU1MjA0WjBBMQswCQYDVQQGEwJOTDERMA8G\r\n" \
+ "A1UEChMIUG9sYXJTU0wxHzAdBgNVBAMTFlBvbGFyU1NMIFRlc3QgQ2xpZW50IDIw\r\n" \
+ "WTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARX5a6xc9/TrLuTuIH/Eq7u5lOszlVT\r\n" \
+ "9jQOzC7jYyUL35ji81xgNpbA1RgUcOV/n9VLRRjlsGzVXPiWj4dwo+THo4GdMIGa\r\n" \
+ "MAkGA1UdEwQCMAAwHQYDVR0OBBYEFHoAX4Zk/OBd5REQO7LmO8QmP8/iMG4GA1Ud\r\n" \
+ "IwRnMGWAFJ1tICRJAT8ry3i1Gbx+JMnb+zZ8oUKkQDA+MQswCQYDVQQGEwJOTDER\r\n" \
+ "MA8GA1UEChMIUG9sYXJTU0wxHDAaBgNVBAMTE1BvbGFyc3NsIFRlc3QgRUMgQ0GC\r\n" \
+ "CQDBQ+J+YkPM6DAKBggqhkjOPQQDAgNoADBlAjBKZQ17IIOimbmoD/yN7o89u3BM\r\n" \
+ "lgOsjnhw3fIOoLIWy2WOGsk/LGF++DzvrRzuNiACMQCd8iem1XS4JK7haj8xocpU\r\n" \
+ "LwjQje5PDGHfd3h9tP38Qknu5bJqws0md2KOKHyeV0U=\r\n" \
+ "-----END CERTIFICATE-----\r\n"
+/* END FILE */
+
+/* This is generated from tests/data_files/cli2.crt.der using `xxd -i`. */
+/* BEGIN FILE binary macro TEST_CLI_CRT_EC_DER tests/data_files/cli2.crt.der */
+#define TEST_CLI_CRT_EC_DER { \
+ 0x30, 0x82, 0x02, 0x2c, 0x30, 0x82, 0x01, 0xb2, 0xa0, 0x03, 0x02, 0x01, \
+ 0x02, 0x02, 0x01, 0x0d, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, \
+ 0x3d, 0x04, 0x03, 0x02, 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
+ 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
+ 0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
+ 0x53, 0x4c, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, \
+ 0x13, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x73, 0x73, 0x6c, 0x20, 0x54, 0x65, \
+ 0x73, 0x74, 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, \
+ 0x31, 0x33, 0x30, 0x39, 0x32, 0x34, 0x31, 0x35, 0x35, 0x32, 0x30, 0x34, \
+ 0x5a, 0x17, 0x0d, 0x32, 0x33, 0x30, 0x39, 0x32, 0x32, 0x31, 0x35, 0x35, \
+ 0x32, 0x30, 0x34, 0x5a, 0x30, 0x41, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
+ 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
+ 0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
+ 0x53, 0x4c, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, \
+ 0x16, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x54, 0x65, \
+ 0x73, 0x74, 0x20, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x20, 0x32, 0x30, \
+ 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, \
+ 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, \
+ 0x00, 0x04, 0x57, 0xe5, 0xae, 0xb1, 0x73, 0xdf, 0xd3, 0xac, 0xbb, 0x93, \
+ 0xb8, 0x81, 0xff, 0x12, 0xae, 0xee, 0xe6, 0x53, 0xac, 0xce, 0x55, 0x53, \
+ 0xf6, 0x34, 0x0e, 0xcc, 0x2e, 0xe3, 0x63, 0x25, 0x0b, 0xdf, 0x98, 0xe2, \
+ 0xf3, 0x5c, 0x60, 0x36, 0x96, 0xc0, 0xd5, 0x18, 0x14, 0x70, 0xe5, 0x7f, \
+ 0x9f, 0xd5, 0x4b, 0x45, 0x18, 0xe5, 0xb0, 0x6c, 0xd5, 0x5c, 0xf8, 0x96, \
+ 0x8f, 0x87, 0x70, 0xa3, 0xe4, 0xc7, 0xa3, 0x81, 0x9d, 0x30, 0x81, 0x9a, \
+ 0x30, 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, \
+ 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x7a, 0x00, \
+ 0x5f, 0x86, 0x64, 0xfc, 0xe0, 0x5d, 0xe5, 0x11, 0x10, 0x3b, 0xb2, 0xe6, \
+ 0x3b, 0xc4, 0x26, 0x3f, 0xcf, 0xe2, 0x30, 0x6e, 0x06, 0x03, 0x55, 0x1d, \
+ 0x23, 0x04, 0x67, 0x30, 0x65, 0x80, 0x14, 0x9d, 0x6d, 0x20, 0x24, 0x49, \
+ 0x01, 0x3f, 0x2b, 0xcb, 0x78, 0xb5, 0x19, 0xbc, 0x7e, 0x24, 0xc9, 0xdb, \
+ 0xfb, 0x36, 0x7c, 0xa1, 0x42, 0xa4, 0x40, 0x30, 0x3e, 0x31, 0x0b, 0x30, \
+ 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, \
+ 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x50, 0x6f, 0x6c, \
+ 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, \
+ 0x04, 0x03, 0x13, 0x13, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x73, 0x73, 0x6c, \
+ 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x82, \
+ 0x09, 0x00, 0xc1, 0x43, 0xe2, 0x7e, 0x62, 0x43, 0xcc, 0xe8, 0x30, 0x0a, \
+ 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x68, \
+ 0x00, 0x30, 0x65, 0x02, 0x30, 0x4a, 0x65, 0x0d, 0x7b, 0x20, 0x83, 0xa2, \
+ 0x99, 0xb9, 0xa8, 0x0f, 0xfc, 0x8d, 0xee, 0x8f, 0x3d, 0xbb, 0x70, 0x4c, \
+ 0x96, 0x03, 0xac, 0x8e, 0x78, 0x70, 0xdd, 0xf2, 0x0e, 0xa0, 0xb2, 0x16, \
+ 0xcb, 0x65, 0x8e, 0x1a, 0xc9, 0x3f, 0x2c, 0x61, 0x7e, 0xf8, 0x3c, 0xef, \
+ 0xad, 0x1c, 0xee, 0x36, 0x20, 0x02, 0x31, 0x00, 0x9d, 0xf2, 0x27, 0xa6, \
+ 0xd5, 0x74, 0xb8, 0x24, 0xae, 0xe1, 0x6a, 0x3f, 0x31, 0xa1, 0xca, 0x54, \
+ 0x2f, 0x08, 0xd0, 0x8d, 0xee, 0x4f, 0x0c, 0x61, 0xdf, 0x77, 0x78, 0x7d, \
+ 0xb4, 0xfd, 0xfc, 0x42, 0x49, 0xee, 0xe5, 0xb2, 0x6a, 0xc2, 0xcd, 0x26, \
+ 0x77, 0x62, 0x8e, 0x28, 0x7c, 0x9e, 0x57, 0x45 \
+}
+/* END FILE */
+
+/* This is taken from tests/data_files/cli2.key. */
+/* BEGIN FILE string macro TEST_CLI_KEY_EC_PEM tests/data_files/cli2.key */
+#define TEST_CLI_KEY_EC_PEM \
+ "-----BEGIN EC PRIVATE KEY-----\r\n" \
+ "MHcCAQEEIPb3hmTxZ3/mZI3vyk7p3U3wBf+WIop6hDhkFzJhmLcqoAoGCCqGSM49\r\n" \
+ "AwEHoUQDQgAEV+WusXPf06y7k7iB/xKu7uZTrM5VU/Y0Dswu42MlC9+Y4vNcYDaW\r\n" \
+ "wNUYFHDlf5/VS0UY5bBs1Vz4lo+HcKPkxw==\r\n" \
+ "-----END EC PRIVATE KEY-----\r\n"
+/* END FILE */
+
+/* This is generated from tests/data_files/cli2.key.der using `xxd -i`. */
+/* BEGIN FILE binary macro TEST_CLI_KEY_EC_DER tests/data_files/cli2.key.der */
+#define TEST_CLI_KEY_EC_DER { \
+ 0x30, 0x77, 0x02, 0x01, 0x01, 0x04, 0x20, 0xf6, 0xf7, 0x86, 0x64, 0xf1, \
+ 0x67, 0x7f, 0xe6, 0x64, 0x8d, 0xef, 0xca, 0x4e, 0xe9, 0xdd, 0x4d, 0xf0, \
+ 0x05, 0xff, 0x96, 0x22, 0x8a, 0x7a, 0x84, 0x38, 0x64, 0x17, 0x32, 0x61, \
+ 0x98, 0xb7, 0x2a, 0xa0, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, \
+ 0x03, 0x01, 0x07, 0xa1, 0x44, 0x03, 0x42, 0x00, 0x04, 0x57, 0xe5, 0xae, \
+ 0xb1, 0x73, 0xdf, 0xd3, 0xac, 0xbb, 0x93, 0xb8, 0x81, 0xff, 0x12, 0xae, \
+ 0xee, 0xe6, 0x53, 0xac, 0xce, 0x55, 0x53, 0xf6, 0x34, 0x0e, 0xcc, 0x2e, \
+ 0xe3, 0x63, 0x25, 0x0b, 0xdf, 0x98, 0xe2, 0xf3, 0x5c, 0x60, 0x36, 0x96, \
+ 0xc0, 0xd5, 0x18, 0x14, 0x70, 0xe5, 0x7f, 0x9f, 0xd5, 0x4b, 0x45, 0x18, \
+ 0xe5, 0xb0, 0x6c, 0xd5, 0x5c, 0xf8, 0x96, 0x8f, 0x87, 0x70, 0xa3, 0xe4, \
+ 0xc7 \
+}
+/* END FILE */
+
+/* This is taken from tests/data_files/cli-rsa-sha256.crt. */
+/* BEGIN FILE string macro TEST_CLI_CRT_RSA_PEM tests/data_files/cli-rsa-sha256.crt */
+#define TEST_CLI_CRT_RSA_PEM \
+ "-----BEGIN CERTIFICATE-----\r\n" \
+ "MIIDPzCCAiegAwIBAgIBBDANBgkqhkiG9w0BAQsFADA7MQswCQYDVQQGEwJOTDER\r\n" \
+ "MA8GA1UECgwIUG9sYXJTU0wxGTAXBgNVBAMMEFBvbGFyU1NMIFRlc3QgQ0EwHhcN\r\n" \
+ "MTEwMjEyMTQ0NDA2WhcNMjEwMjEyMTQ0NDA2WjA8MQswCQYDVQQGEwJOTDERMA8G\r\n" \
+ "A1UECgwIUG9sYXJTU0wxGjAYBgNVBAMMEVBvbGFyU1NMIENsaWVudCAyMIIBIjAN\r\n" \
+ "BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyHTEzLn5tXnpRdkUYLB9u5Pyax6f\r\n" \
+ "M60Nj4o8VmXl3ETZzGaFB9X4J7BKNdBjngpuG7fa8H6r7gwQk4ZJGDTzqCrSV/Uu\r\n" \
+ "1C93KYRhTYJQj6eVSHD1bk2y1RPD0hrt5kPqQhTrdOrA7R/UV06p86jt0uDBMHEw\r\n" \
+ "MjDV0/YI0FZPRo7yX/k9Z5GIMC5Cst99++UMd//sMcB4j7/Cf8qtbCHWjdmLao5v\r\n" \
+ "4Jv4EFbMs44TFeY0BGbH7vk2DmqV9gmaBmf0ZXH4yqSxJeD+PIs1BGe64E92hfx/\r\n" \
+ "/DZrtenNLQNiTrM9AM+vdqBpVoNq0qjU51Bx5rU2BXcFbXvI5MT9TNUhXwIDAQAB\r\n" \
+ "o00wSzAJBgNVHRMEAjAAMB0GA1UdDgQWBBRxoQBzckAvVHZeM/xSj7zx3WtGITAf\r\n" \
+ "BgNVHSMEGDAWgBS0WuSls97SUva51aaVD+s+vMf9/zANBgkqhkiG9w0BAQsFAAOC\r\n" \
+ "AQEAlHabem2Tu69VUN7EipwnQn1dIHdgvT5i+iQHpSxY1crPnBbAeSdAXwsVEqLQ\r\n" \
+ "gOOIAQD5VIITNuoGgo4i+4OpNh9u7ZkpRHla+/swsfrFWRRbBNP5Bcu74AGLstwU\r\n" \
+ "zM8gIkBiyfM1Q1qDQISV9trlCG6O8vh8dp/rbI3rfzo99BOHXgFCrzXjCuW4vDsF\r\n" \
+ "r+Dao26bX3sJ6UnEWg1H3o2x6PpUcvQ36h71/bz4TEbbUUEpe02V4QWuL+wrhHJL\r\n" \
+ "U7o3SVE3Og7jPF8sat0a50YUWhwEFI256m02KAXLg89ueUyYKEr6rNwhcvXJpvU9\r\n" \
+ "giIVvd0Sbjjnn7NC4VDbcXV8vw==\r\n" \
+ "-----END CERTIFICATE-----\r\n"
+/* END FILE */
+
+/* This was generated from tests/data_files/cli-rsa-sha256.crt.der
+ using `xxd -i.` */
+/* BEGIN FILE binary macro TEST_CLI_CRT_RSA_DER tests/data_files/cli-rsa-sha256.crt.der */
+#define TEST_CLI_CRT_RSA_DER { \
+ 0x30, 0x82, 0x03, 0x3f, 0x30, 0x82, 0x02, 0x27, 0xa0, 0x03, 0x02, 0x01, \
+ 0x02, 0x02, 0x01, 0x04, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, \
+ 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, 0x30, \
+ 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, \
+ 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, \
+ 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, \
+ 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, \
+ 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, \
+ 0x31, 0x31, 0x30, 0x32, 0x31, 0x32, 0x31, 0x34, 0x34, 0x34, 0x30, 0x36, \
+ 0x5a, 0x17, 0x0d, 0x32, 0x31, 0x30, 0x32, 0x31, 0x32, 0x31, 0x34, 0x34, \
+ 0x34, 0x30, 0x36, 0x5a, 0x30, 0x3c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
+ 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
+ 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
+ 0x53, 0x4c, 0x31, 0x1a, 0x30, 0x18, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, \
+ 0x11, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x43, 0x6c, \
+ 0x69, 0x65, 0x6e, 0x74, 0x20, 0x32, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, \
+ 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, \
+ 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, \
+ 0x01, 0x01, 0x00, 0xc8, 0x74, 0xc4, 0xcc, 0xb9, 0xf9, 0xb5, 0x79, 0xe9, \
+ 0x45, 0xd9, 0x14, 0x60, 0xb0, 0x7d, 0xbb, 0x93, 0xf2, 0x6b, 0x1e, 0x9f, \
+ 0x33, 0xad, 0x0d, 0x8f, 0x8a, 0x3c, 0x56, 0x65, 0xe5, 0xdc, 0x44, 0xd9, \
+ 0xcc, 0x66, 0x85, 0x07, 0xd5, 0xf8, 0x27, 0xb0, 0x4a, 0x35, 0xd0, 0x63, \
+ 0x9e, 0x0a, 0x6e, 0x1b, 0xb7, 0xda, 0xf0, 0x7e, 0xab, 0xee, 0x0c, 0x10, \
+ 0x93, 0x86, 0x49, 0x18, 0x34, 0xf3, 0xa8, 0x2a, 0xd2, 0x57, 0xf5, 0x2e, \
+ 0xd4, 0x2f, 0x77, 0x29, 0x84, 0x61, 0x4d, 0x82, 0x50, 0x8f, 0xa7, 0x95, \
+ 0x48, 0x70, 0xf5, 0x6e, 0x4d, 0xb2, 0xd5, 0x13, 0xc3, 0xd2, 0x1a, 0xed, \
+ 0xe6, 0x43, 0xea, 0x42, 0x14, 0xeb, 0x74, 0xea, 0xc0, 0xed, 0x1f, 0xd4, \
+ 0x57, 0x4e, 0xa9, 0xf3, 0xa8, 0xed, 0xd2, 0xe0, 0xc1, 0x30, 0x71, 0x30, \
+ 0x32, 0x30, 0xd5, 0xd3, 0xf6, 0x08, 0xd0, 0x56, 0x4f, 0x46, 0x8e, 0xf2, \
+ 0x5f, 0xf9, 0x3d, 0x67, 0x91, 0x88, 0x30, 0x2e, 0x42, 0xb2, 0xdf, 0x7d, \
+ 0xfb, 0xe5, 0x0c, 0x77, 0xff, 0xec, 0x31, 0xc0, 0x78, 0x8f, 0xbf, 0xc2, \
+ 0x7f, 0xca, 0xad, 0x6c, 0x21, 0xd6, 0x8d, 0xd9, 0x8b, 0x6a, 0x8e, 0x6f, \
+ 0xe0, 0x9b, 0xf8, 0x10, 0x56, 0xcc, 0xb3, 0x8e, 0x13, 0x15, 0xe6, 0x34, \
+ 0x04, 0x66, 0xc7, 0xee, 0xf9, 0x36, 0x0e, 0x6a, 0x95, 0xf6, 0x09, 0x9a, \
+ 0x06, 0x67, 0xf4, 0x65, 0x71, 0xf8, 0xca, 0xa4, 0xb1, 0x25, 0xe0, 0xfe, \
+ 0x3c, 0x8b, 0x35, 0x04, 0x67, 0xba, 0xe0, 0x4f, 0x76, 0x85, 0xfc, 0x7f, \
+ 0xfc, 0x36, 0x6b, 0xb5, 0xe9, 0xcd, 0x2d, 0x03, 0x62, 0x4e, 0xb3, 0x3d, \
+ 0x00, 0xcf, 0xaf, 0x76, 0xa0, 0x69, 0x56, 0x83, 0x6a, 0xd2, 0xa8, 0xd4, \
+ 0xe7, 0x50, 0x71, 0xe6, 0xb5, 0x36, 0x05, 0x77, 0x05, 0x6d, 0x7b, 0xc8, \
+ 0xe4, 0xc4, 0xfd, 0x4c, 0xd5, 0x21, 0x5f, 0x02, 0x03, 0x01, 0x00, 0x01, \
+ 0xa3, 0x4d, 0x30, 0x4b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, \
+ 0x02, 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, \
+ 0x04, 0x14, 0x71, 0xa1, 0x00, 0x73, 0x72, 0x40, 0x2f, 0x54, 0x76, 0x5e, \
+ 0x33, 0xfc, 0x52, 0x8f, 0xbc, 0xf1, 0xdd, 0x6b, 0x46, 0x21, 0x30, 0x1f, \
+ 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xb4, \
+ 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, 0xb9, 0xd5, 0xa6, 0x95, \
+ 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, \
+ 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, \
+ 0x01, 0x01, 0x00, 0x94, 0x76, 0x9b, 0x7a, 0x6d, 0x93, 0xbb, 0xaf, 0x55, \
+ 0x50, 0xde, 0xc4, 0x8a, 0x9c, 0x27, 0x42, 0x7d, 0x5d, 0x20, 0x77, 0x60, \
+ 0xbd, 0x3e, 0x62, 0xfa, 0x24, 0x07, 0xa5, 0x2c, 0x58, 0xd5, 0xca, 0xcf, \
+ 0x9c, 0x16, 0xc0, 0x79, 0x27, 0x40, 0x5f, 0x0b, 0x15, 0x12, 0xa2, 0xd0, \
+ 0x80, 0xe3, 0x88, 0x01, 0x00, 0xf9, 0x54, 0x82, 0x13, 0x36, 0xea, 0x06, \
+ 0x82, 0x8e, 0x22, 0xfb, 0x83, 0xa9, 0x36, 0x1f, 0x6e, 0xed, 0x99, 0x29, \
+ 0x44, 0x79, 0x5a, 0xfb, 0xfb, 0x30, 0xb1, 0xfa, 0xc5, 0x59, 0x14, 0x5b, \
+ 0x04, 0xd3, 0xf9, 0x05, 0xcb, 0xbb, 0xe0, 0x01, 0x8b, 0xb2, 0xdc, 0x14, \
+ 0xcc, 0xcf, 0x20, 0x22, 0x40, 0x62, 0xc9, 0xf3, 0x35, 0x43, 0x5a, 0x83, \
+ 0x40, 0x84, 0x95, 0xf6, 0xda, 0xe5, 0x08, 0x6e, 0x8e, 0xf2, 0xf8, 0x7c, \
+ 0x76, 0x9f, 0xeb, 0x6c, 0x8d, 0xeb, 0x7f, 0x3a, 0x3d, 0xf4, 0x13, 0x87, \
+ 0x5e, 0x01, 0x42, 0xaf, 0x35, 0xe3, 0x0a, 0xe5, 0xb8, 0xbc, 0x3b, 0x05, \
+ 0xaf, 0xe0, 0xda, 0xa3, 0x6e, 0x9b, 0x5f, 0x7b, 0x09, 0xe9, 0x49, 0xc4, \
+ 0x5a, 0x0d, 0x47, 0xde, 0x8d, 0xb1, 0xe8, 0xfa, 0x54, 0x72, 0xf4, 0x37, \
+ 0xea, 0x1e, 0xf5, 0xfd, 0xbc, 0xf8, 0x4c, 0x46, 0xdb, 0x51, 0x41, 0x29, \
+ 0x7b, 0x4d, 0x95, 0xe1, 0x05, 0xae, 0x2f, 0xec, 0x2b, 0x84, 0x72, 0x4b, \
+ 0x53, 0xba, 0x37, 0x49, 0x51, 0x37, 0x3a, 0x0e, 0xe3, 0x3c, 0x5f, 0x2c, \
+ 0x6a, 0xdd, 0x1a, 0xe7, 0x46, 0x14, 0x5a, 0x1c, 0x04, 0x14, 0x8d, 0xb9, \
+ 0xea, 0x6d, 0x36, 0x28, 0x05, 0xcb, 0x83, 0xcf, 0x6e, 0x79, 0x4c, 0x98, \
+ 0x28, 0x4a, 0xfa, 0xac, 0xdc, 0x21, 0x72, 0xf5, 0xc9, 0xa6, 0xf5, 0x3d, \
+ 0x82, 0x22, 0x15, 0xbd, 0xdd, 0x12, 0x6e, 0x38, 0xe7, 0x9f, 0xb3, 0x42, \
+ 0xe1, 0x50, 0xdb, 0x71, 0x75, 0x7c, 0xbf \
+}
+/* END FILE */
+
+/* This is taken from tests/data_files/cli-rsa.key. */
+/* BEGIN FILE string macro TEST_CLI_KEY_RSA_PEM tests/data_files/cli-rsa.key */
+#define TEST_CLI_KEY_RSA_PEM \
+ "-----BEGIN RSA PRIVATE KEY-----\r\n" \
+ "MIIEpAIBAAKCAQEAyHTEzLn5tXnpRdkUYLB9u5Pyax6fM60Nj4o8VmXl3ETZzGaF\r\n" \
+ "B9X4J7BKNdBjngpuG7fa8H6r7gwQk4ZJGDTzqCrSV/Uu1C93KYRhTYJQj6eVSHD1\r\n" \
+ "bk2y1RPD0hrt5kPqQhTrdOrA7R/UV06p86jt0uDBMHEwMjDV0/YI0FZPRo7yX/k9\r\n" \
+ "Z5GIMC5Cst99++UMd//sMcB4j7/Cf8qtbCHWjdmLao5v4Jv4EFbMs44TFeY0BGbH\r\n" \
+ "7vk2DmqV9gmaBmf0ZXH4yqSxJeD+PIs1BGe64E92hfx//DZrtenNLQNiTrM9AM+v\r\n" \
+ "dqBpVoNq0qjU51Bx5rU2BXcFbXvI5MT9TNUhXwIDAQABAoIBAGdNtfYDiap6bzst\r\n" \
+ "yhCiI8m9TtrhZw4MisaEaN/ll3XSjaOG2dvV6xMZCMV+5TeXDHOAZnY18Yi18vzz\r\n" \
+ "4Ut2TnNFzizCECYNaA2fST3WgInnxUkV3YXAyP6CNxJaCmv2aA0yFr2kFVSeaKGt\r\n" \
+ "ymvljNp2NVkvm7Th8fBQBO7I7AXhz43k0mR7XmPgewe8ApZOG3hstkOaMvbWAvWA\r\n" \
+ "zCZupdDjZYjOJqlA4eEA4H8/w7F83r5CugeBE8LgEREjLPiyejrU5H1fubEY+h0d\r\n" \
+ "l5HZBJ68ybTXfQ5U9o/QKA3dd0toBEhhdRUDGzWtjvwkEQfqF1reGWj/tod/gCpf\r\n" \
+ "DFi6X0ECgYEA4wOv/pjSC3ty6TuOvKX2rOUiBrLXXv2JSxZnMoMiWI5ipLQt+RYT\r\n" \
+ "VPafL/m7Dn6MbwjayOkcZhBwk5CNz5A6Q4lJ64Mq/lqHznRCQQ2Mc1G8eyDF/fYL\r\n" \
+ "Ze2pLvwP9VD5jTc2miDfw+MnvJhywRRLcemDFP8k4hQVtm8PMp3ZmNECgYEA4gz7\r\n" \
+ "wzObR4gn8ibe617uQPZjWzUj9dUHYd+in1gwBCIrtNnaRn9I9U/Q6tegRYpii4ys\r\n" \
+ "c176NmU+umy6XmuSKV5qD9bSpZWG2nLFnslrN15Lm3fhZxoeMNhBaEDTnLT26yoi\r\n" \
+ "33gp0mSSWy94ZEqipms+ULF6sY1ZtFW6tpGFoy8CgYAQHhnnvJflIs2ky4q10B60\r\n" \
+ "ZcxFp3rtDpkp0JxhFLhiizFrujMtZSjYNm5U7KkgPVHhLELEUvCmOnKTt4ap/vZ0\r\n" \
+ "BxJNe1GZH3pW6SAvGDQpl9sG7uu/vTFP+lCxukmzxB0DrrDcvorEkKMom7ZCCRvW\r\n" \
+ "KZsZ6YeH2Z81BauRj218kQKBgQCUV/DgKP2985xDTT79N08jUo3hTP5MVYCCuj/+\r\n" \
+ "UeEw1TvZcx3LJby7P6Xad6a1/BqveaGyFKIfEFIaBUBItk801sDDpDaYc4gL00Xc\r\n" \
+ "7lFuBHOZkxJYlss5QrGpuOEl9ZwUt5IrFLBdYaKqNHzNVC1pCPfb/JyH6Dr2HUxq\r\n" \
+ "gxUwAQKBgQCcU6G2L8AG9d9c0UpOyL1tMvFe5Ttw0KjlQVdsh1MP6yigYo9DYuwu\r\n" \
+ "bHFVW2r0dBTqegP2/KTOxKzaHfC1qf0RGDsUoJCNJrd1cwoCLG8P2EF4w3OBrKqv\r\n" \
+ "8u4ytY0F+Vlanj5lm3TaoHSVF1+NWPyOTiwevIECGKwSxvlki4fDAA==\r\n" \
+ "-----END RSA PRIVATE KEY-----\r\n"/* END FILE */
+
+/* This was generated from tests/data_files/cli-rsa.key.der using `xxd -i`. */
+/* BEGIN FILE binary macro TEST_CLI_KEY_RSA_DER tests/data_files/cli-rsa.key.der */
+#define TEST_CLI_KEY_RSA_DER { \
+ 0x30, 0x82, 0x04, 0xa4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, \
+ 0xc8, 0x74, 0xc4, 0xcc, 0xb9, 0xf9, 0xb5, 0x79, 0xe9, 0x45, 0xd9, 0x14, \
+ 0x60, 0xb0, 0x7d, 0xbb, 0x93, 0xf2, 0x6b, 0x1e, 0x9f, 0x33, 0xad, 0x0d, \
+ 0x8f, 0x8a, 0x3c, 0x56, 0x65, 0xe5, 0xdc, 0x44, 0xd9, 0xcc, 0x66, 0x85, \
+ 0x07, 0xd5, 0xf8, 0x27, 0xb0, 0x4a, 0x35, 0xd0, 0x63, 0x9e, 0x0a, 0x6e, \
+ 0x1b, 0xb7, 0xda, 0xf0, 0x7e, 0xab, 0xee, 0x0c, 0x10, 0x93, 0x86, 0x49, \
+ 0x18, 0x34, 0xf3, 0xa8, 0x2a, 0xd2, 0x57, 0xf5, 0x2e, 0xd4, 0x2f, 0x77, \
+ 0x29, 0x84, 0x61, 0x4d, 0x82, 0x50, 0x8f, 0xa7, 0x95, 0x48, 0x70, 0xf5, \
+ 0x6e, 0x4d, 0xb2, 0xd5, 0x13, 0xc3, 0xd2, 0x1a, 0xed, 0xe6, 0x43, 0xea, \
+ 0x42, 0x14, 0xeb, 0x74, 0xea, 0xc0, 0xed, 0x1f, 0xd4, 0x57, 0x4e, 0xa9, \
+ 0xf3, 0xa8, 0xed, 0xd2, 0xe0, 0xc1, 0x30, 0x71, 0x30, 0x32, 0x30, 0xd5, \
+ 0xd3, 0xf6, 0x08, 0xd0, 0x56, 0x4f, 0x46, 0x8e, 0xf2, 0x5f, 0xf9, 0x3d, \
+ 0x67, 0x91, 0x88, 0x30, 0x2e, 0x42, 0xb2, 0xdf, 0x7d, 0xfb, 0xe5, 0x0c, \
+ 0x77, 0xff, 0xec, 0x31, 0xc0, 0x78, 0x8f, 0xbf, 0xc2, 0x7f, 0xca, 0xad, \
+ 0x6c, 0x21, 0xd6, 0x8d, 0xd9, 0x8b, 0x6a, 0x8e, 0x6f, 0xe0, 0x9b, 0xf8, \
+ 0x10, 0x56, 0xcc, 0xb3, 0x8e, 0x13, 0x15, 0xe6, 0x34, 0x04, 0x66, 0xc7, \
+ 0xee, 0xf9, 0x36, 0x0e, 0x6a, 0x95, 0xf6, 0x09, 0x9a, 0x06, 0x67, 0xf4, \
+ 0x65, 0x71, 0xf8, 0xca, 0xa4, 0xb1, 0x25, 0xe0, 0xfe, 0x3c, 0x8b, 0x35, \
+ 0x04, 0x67, 0xba, 0xe0, 0x4f, 0x76, 0x85, 0xfc, 0x7f, 0xfc, 0x36, 0x6b, \
+ 0xb5, 0xe9, 0xcd, 0x2d, 0x03, 0x62, 0x4e, 0xb3, 0x3d, 0x00, 0xcf, 0xaf, \
+ 0x76, 0xa0, 0x69, 0x56, 0x83, 0x6a, 0xd2, 0xa8, 0xd4, 0xe7, 0x50, 0x71, \
+ 0xe6, 0xb5, 0x36, 0x05, 0x77, 0x05, 0x6d, 0x7b, 0xc8, 0xe4, 0xc4, 0xfd, \
+ 0x4c, 0xd5, 0x21, 0x5f, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x82, 0x01, \
+ 0x00, 0x67, 0x4d, 0xb5, 0xf6, 0x03, 0x89, 0xaa, 0x7a, 0x6f, 0x3b, 0x2d, \
+ 0xca, 0x10, 0xa2, 0x23, 0xc9, 0xbd, 0x4e, 0xda, 0xe1, 0x67, 0x0e, 0x0c, \
+ 0x8a, 0xc6, 0x84, 0x68, 0xdf, 0xe5, 0x97, 0x75, 0xd2, 0x8d, 0xa3, 0x86, \
+ 0xd9, 0xdb, 0xd5, 0xeb, 0x13, 0x19, 0x08, 0xc5, 0x7e, 0xe5, 0x37, 0x97, \
+ 0x0c, 0x73, 0x80, 0x66, 0x76, 0x35, 0xf1, 0x88, 0xb5, 0xf2, 0xfc, 0xf3, \
+ 0xe1, 0x4b, 0x76, 0x4e, 0x73, 0x45, 0xce, 0x2c, 0xc2, 0x10, 0x26, 0x0d, \
+ 0x68, 0x0d, 0x9f, 0x49, 0x3d, 0xd6, 0x80, 0x89, 0xe7, 0xc5, 0x49, 0x15, \
+ 0xdd, 0x85, 0xc0, 0xc8, 0xfe, 0x82, 0x37, 0x12, 0x5a, 0x0a, 0x6b, 0xf6, \
+ 0x68, 0x0d, 0x32, 0x16, 0xbd, 0xa4, 0x15, 0x54, 0x9e, 0x68, 0xa1, 0xad, \
+ 0xca, 0x6b, 0xe5, 0x8c, 0xda, 0x76, 0x35, 0x59, 0x2f, 0x9b, 0xb4, 0xe1, \
+ 0xf1, 0xf0, 0x50, 0x04, 0xee, 0xc8, 0xec, 0x05, 0xe1, 0xcf, 0x8d, 0xe4, \
+ 0xd2, 0x64, 0x7b, 0x5e, 0x63, 0xe0, 0x7b, 0x07, 0xbc, 0x02, 0x96, 0x4e, \
+ 0x1b, 0x78, 0x6c, 0xb6, 0x43, 0x9a, 0x32, 0xf6, 0xd6, 0x02, 0xf5, 0x80, \
+ 0xcc, 0x26, 0x6e, 0xa5, 0xd0, 0xe3, 0x65, 0x88, 0xce, 0x26, 0xa9, 0x40, \
+ 0xe1, 0xe1, 0x00, 0xe0, 0x7f, 0x3f, 0xc3, 0xb1, 0x7c, 0xde, 0xbe, 0x42, \
+ 0xba, 0x07, 0x81, 0x13, 0xc2, 0xe0, 0x11, 0x11, 0x23, 0x2c, 0xf8, 0xb2, \
+ 0x7a, 0x3a, 0xd4, 0xe4, 0x7d, 0x5f, 0xb9, 0xb1, 0x18, 0xfa, 0x1d, 0x1d, \
+ 0x97, 0x91, 0xd9, 0x04, 0x9e, 0xbc, 0xc9, 0xb4, 0xd7, 0x7d, 0x0e, 0x54, \
+ 0xf6, 0x8f, 0xd0, 0x28, 0x0d, 0xdd, 0x77, 0x4b, 0x68, 0x04, 0x48, 0x61, \
+ 0x75, 0x15, 0x03, 0x1b, 0x35, 0xad, 0x8e, 0xfc, 0x24, 0x11, 0x07, 0xea, \
+ 0x17, 0x5a, 0xde, 0x19, 0x68, 0xff, 0xb6, 0x87, 0x7f, 0x80, 0x2a, 0x5f, \
+ 0x0c, 0x58, 0xba, 0x5f, 0x41, 0x02, 0x81, 0x81, 0x00, 0xe3, 0x03, 0xaf, \
+ 0xfe, 0x98, 0xd2, 0x0b, 0x7b, 0x72, 0xe9, 0x3b, 0x8e, 0xbc, 0xa5, 0xf6, \
+ 0xac, 0xe5, 0x22, 0x06, 0xb2, 0xd7, 0x5e, 0xfd, 0x89, 0x4b, 0x16, 0x67, \
+ 0x32, 0x83, 0x22, 0x58, 0x8e, 0x62, 0xa4, 0xb4, 0x2d, 0xf9, 0x16, 0x13, \
+ 0x54, 0xf6, 0x9f, 0x2f, 0xf9, 0xbb, 0x0e, 0x7e, 0x8c, 0x6f, 0x08, 0xda, \
+ 0xc8, 0xe9, 0x1c, 0x66, 0x10, 0x70, 0x93, 0x90, 0x8d, 0xcf, 0x90, 0x3a, \
+ 0x43, 0x89, 0x49, 0xeb, 0x83, 0x2a, 0xfe, 0x5a, 0x87, 0xce, 0x74, 0x42, \
+ 0x41, 0x0d, 0x8c, 0x73, 0x51, 0xbc, 0x7b, 0x20, 0xc5, 0xfd, 0xf6, 0x0b, \
+ 0x65, 0xed, 0xa9, 0x2e, 0xfc, 0x0f, 0xf5, 0x50, 0xf9, 0x8d, 0x37, 0x36, \
+ 0x9a, 0x20, 0xdf, 0xc3, 0xe3, 0x27, 0xbc, 0x98, 0x72, 0xc1, 0x14, 0x4b, \
+ 0x71, 0xe9, 0x83, 0x14, 0xff, 0x24, 0xe2, 0x14, 0x15, 0xb6, 0x6f, 0x0f, \
+ 0x32, 0x9d, 0xd9, 0x98, 0xd1, 0x02, 0x81, 0x81, 0x00, 0xe2, 0x0c, 0xfb, \
+ 0xc3, 0x33, 0x9b, 0x47, 0x88, 0x27, 0xf2, 0x26, 0xde, 0xeb, 0x5e, 0xee, \
+ 0x40, 0xf6, 0x63, 0x5b, 0x35, 0x23, 0xf5, 0xd5, 0x07, 0x61, 0xdf, 0xa2, \
+ 0x9f, 0x58, 0x30, 0x04, 0x22, 0x2b, 0xb4, 0xd9, 0xda, 0x46, 0x7f, 0x48, \
+ 0xf5, 0x4f, 0xd0, 0xea, 0xd7, 0xa0, 0x45, 0x8a, 0x62, 0x8b, 0x8c, 0xac, \
+ 0x73, 0x5e, 0xfa, 0x36, 0x65, 0x3e, 0xba, 0x6c, 0xba, 0x5e, 0x6b, 0x92, \
+ 0x29, 0x5e, 0x6a, 0x0f, 0xd6, 0xd2, 0xa5, 0x95, 0x86, 0xda, 0x72, 0xc5, \
+ 0x9e, 0xc9, 0x6b, 0x37, 0x5e, 0x4b, 0x9b, 0x77, 0xe1, 0x67, 0x1a, 0x1e, \
+ 0x30, 0xd8, 0x41, 0x68, 0x40, 0xd3, 0x9c, 0xb4, 0xf6, 0xeb, 0x2a, 0x22, \
+ 0xdf, 0x78, 0x29, 0xd2, 0x64, 0x92, 0x5b, 0x2f, 0x78, 0x64, 0x4a, 0xa2, \
+ 0xa6, 0x6b, 0x3e, 0x50, 0xb1, 0x7a, 0xb1, 0x8d, 0x59, 0xb4, 0x55, 0xba, \
+ 0xb6, 0x91, 0x85, 0xa3, 0x2f, 0x02, 0x81, 0x80, 0x10, 0x1e, 0x19, 0xe7, \
+ 0xbc, 0x97, 0xe5, 0x22, 0xcd, 0xa4, 0xcb, 0x8a, 0xb5, 0xd0, 0x1e, 0xb4, \
+ 0x65, 0xcc, 0x45, 0xa7, 0x7a, 0xed, 0x0e, 0x99, 0x29, 0xd0, 0x9c, 0x61, \
+ 0x14, 0xb8, 0x62, 0x8b, 0x31, 0x6b, 0xba, 0x33, 0x2d, 0x65, 0x28, 0xd8, \
+ 0x36, 0x6e, 0x54, 0xec, 0xa9, 0x20, 0x3d, 0x51, 0xe1, 0x2c, 0x42, 0xc4, \
+ 0x52, 0xf0, 0xa6, 0x3a, 0x72, 0x93, 0xb7, 0x86, 0xa9, 0xfe, 0xf6, 0x74, \
+ 0x07, 0x12, 0x4d, 0x7b, 0x51, 0x99, 0x1f, 0x7a, 0x56, 0xe9, 0x20, 0x2f, \
+ 0x18, 0x34, 0x29, 0x97, 0xdb, 0x06, 0xee, 0xeb, 0xbf, 0xbd, 0x31, 0x4f, \
+ 0xfa, 0x50, 0xb1, 0xba, 0x49, 0xb3, 0xc4, 0x1d, 0x03, 0xae, 0xb0, 0xdc, \
+ 0xbe, 0x8a, 0xc4, 0x90, 0xa3, 0x28, 0x9b, 0xb6, 0x42, 0x09, 0x1b, 0xd6, \
+ 0x29, 0x9b, 0x19, 0xe9, 0x87, 0x87, 0xd9, 0x9f, 0x35, 0x05, 0xab, 0x91, \
+ 0x8f, 0x6d, 0x7c, 0x91, 0x02, 0x81, 0x81, 0x00, 0x94, 0x57, 0xf0, 0xe0, \
+ 0x28, 0xfd, 0xbd, 0xf3, 0x9c, 0x43, 0x4d, 0x3e, 0xfd, 0x37, 0x4f, 0x23, \
+ 0x52, 0x8d, 0xe1, 0x4c, 0xfe, 0x4c, 0x55, 0x80, 0x82, 0xba, 0x3f, 0xfe, \
+ 0x51, 0xe1, 0x30, 0xd5, 0x3b, 0xd9, 0x73, 0x1d, 0xcb, 0x25, 0xbc, 0xbb, \
+ 0x3f, 0xa5, 0xda, 0x77, 0xa6, 0xb5, 0xfc, 0x1a, 0xaf, 0x79, 0xa1, 0xb2, \
+ 0x14, 0xa2, 0x1f, 0x10, 0x52, 0x1a, 0x05, 0x40, 0x48, 0xb6, 0x4f, 0x34, \
+ 0xd6, 0xc0, 0xc3, 0xa4, 0x36, 0x98, 0x73, 0x88, 0x0b, 0xd3, 0x45, 0xdc, \
+ 0xee, 0x51, 0x6e, 0x04, 0x73, 0x99, 0x93, 0x12, 0x58, 0x96, 0xcb, 0x39, \
+ 0x42, 0xb1, 0xa9, 0xb8, 0xe1, 0x25, 0xf5, 0x9c, 0x14, 0xb7, 0x92, 0x2b, \
+ 0x14, 0xb0, 0x5d, 0x61, 0xa2, 0xaa, 0x34, 0x7c, 0xcd, 0x54, 0x2d, 0x69, \
+ 0x08, 0xf7, 0xdb, 0xfc, 0x9c, 0x87, 0xe8, 0x3a, 0xf6, 0x1d, 0x4c, 0x6a, \
+ 0x83, 0x15, 0x30, 0x01, 0x02, 0x81, 0x81, 0x00, 0x9c, 0x53, 0xa1, 0xb6, \
+ 0x2f, 0xc0, 0x06, 0xf5, 0xdf, 0x5c, 0xd1, 0x4a, 0x4e, 0xc8, 0xbd, 0x6d, \
+ 0x32, 0xf1, 0x5e, 0xe5, 0x3b, 0x70, 0xd0, 0xa8, 0xe5, 0x41, 0x57, 0x6c, \
+ 0x87, 0x53, 0x0f, 0xeb, 0x28, 0xa0, 0x62, 0x8f, 0x43, 0x62, 0xec, 0x2e, \
+ 0x6c, 0x71, 0x55, 0x5b, 0x6a, 0xf4, 0x74, 0x14, 0xea, 0x7a, 0x03, 0xf6, \
+ 0xfc, 0xa4, 0xce, 0xc4, 0xac, 0xda, 0x1d, 0xf0, 0xb5, 0xa9, 0xfd, 0x11, \
+ 0x18, 0x3b, 0x14, 0xa0, 0x90, 0x8d, 0x26, 0xb7, 0x75, 0x73, 0x0a, 0x02, \
+ 0x2c, 0x6f, 0x0f, 0xd8, 0x41, 0x78, 0xc3, 0x73, 0x81, 0xac, 0xaa, 0xaf, \
+ 0xf2, 0xee, 0x32, 0xb5, 0x8d, 0x05, 0xf9, 0x59, 0x5a, 0x9e, 0x3e, 0x65, \
+ 0x9b, 0x74, 0xda, 0xa0, 0x74, 0x95, 0x17, 0x5f, 0x8d, 0x58, 0xfc, 0x8e, \
+ 0x4e, 0x2c, 0x1e, 0xbc, 0x81, 0x02, 0x18, 0xac, 0x12, 0xc6, 0xf9, 0x64, \
+ 0x8b, 0x87, 0xc3, 0x00 \
+}
+/* END FILE */
+
+/*
+ *
+ * Test certificates and keys as C variables
+ *
+ */
+
+/*
+ * CA
+ */
+
+const char mbedtls_test_ca_crt_ec_pem[] = TEST_CA_CRT_EC_PEM;
+const char mbedtls_test_ca_key_ec_pem[] = TEST_CA_KEY_EC_PEM;
+const char mbedtls_test_ca_pwd_ec_pem[] = TEST_CA_PWD_EC_PEM;
+const char mbedtls_test_ca_key_rsa_pem[] = TEST_CA_KEY_RSA_PEM;
+const char mbedtls_test_ca_pwd_rsa_pem[] = TEST_CA_PWD_RSA_PEM;
+const char mbedtls_test_ca_crt_rsa_sha1_pem[] = TEST_CA_CRT_RSA_SHA1_PEM;
+const char mbedtls_test_ca_crt_rsa_sha256_pem[] = TEST_CA_CRT_RSA_SHA256_PEM;
+
+const unsigned char mbedtls_test_ca_crt_ec_der[] = TEST_CA_CRT_EC_DER;
+const unsigned char mbedtls_test_ca_key_ec_der[] = TEST_CA_KEY_EC_DER;
+const unsigned char mbedtls_test_ca_key_rsa_der[] = TEST_CA_KEY_RSA_DER;
+const unsigned char mbedtls_test_ca_crt_rsa_sha1_der[] =
+ TEST_CA_CRT_RSA_SHA1_DER;
+const unsigned char mbedtls_test_ca_crt_rsa_sha256_der[] =
+ TEST_CA_CRT_RSA_SHA256_DER;
+
+const size_t mbedtls_test_ca_crt_ec_pem_len =
+ sizeof( mbedtls_test_ca_crt_ec_pem );
+const size_t mbedtls_test_ca_key_ec_pem_len =
+ sizeof( mbedtls_test_ca_key_ec_pem );
+const size_t mbedtls_test_ca_pwd_ec_pem_len =
+ sizeof( mbedtls_test_ca_pwd_ec_pem ) - 1;
+const size_t mbedtls_test_ca_key_rsa_pem_len =
+ sizeof( mbedtls_test_ca_key_rsa_pem );
+const size_t mbedtls_test_ca_pwd_rsa_pem_len =
+ sizeof( mbedtls_test_ca_pwd_rsa_pem ) - 1;
+const size_t mbedtls_test_ca_crt_rsa_sha1_pem_len =
+ sizeof( mbedtls_test_ca_crt_rsa_sha1_pem );
+const size_t mbedtls_test_ca_crt_rsa_sha256_pem_len =
+ sizeof( mbedtls_test_ca_crt_rsa_sha256_pem );
+
+const size_t mbedtls_test_ca_crt_ec_der_len =
+ sizeof( mbedtls_test_ca_crt_ec_der );
+const size_t mbedtls_test_ca_key_ec_der_len =
+ sizeof( mbedtls_test_ca_key_ec_der );
+const size_t mbedtls_test_ca_pwd_ec_der_len = 0;
+const size_t mbedtls_test_ca_key_rsa_der_len =
+ sizeof( mbedtls_test_ca_key_rsa_der );
+const size_t mbedtls_test_ca_pwd_rsa_der_len = 0;
+const size_t mbedtls_test_ca_crt_rsa_sha1_der_len =
+ sizeof( mbedtls_test_ca_crt_rsa_sha1_der );
+const size_t mbedtls_test_ca_crt_rsa_sha256_der_len =
+ sizeof( mbedtls_test_ca_crt_rsa_sha256_der );
+
+/*
+ * Server
+ */
+
+const char mbedtls_test_srv_crt_ec_pem[] = TEST_SRV_CRT_EC_PEM;
+const char mbedtls_test_srv_key_ec_pem[] = TEST_SRV_KEY_EC_PEM;
+const char mbedtls_test_srv_pwd_ec_pem[] = "";
+const char mbedtls_test_srv_key_rsa_pem[] = TEST_SRV_KEY_RSA_PEM;
+const char mbedtls_test_srv_pwd_rsa_pem[] = "";
+const char mbedtls_test_srv_crt_rsa_sha1_pem[] = TEST_SRV_CRT_RSA_SHA1_PEM;
+const char mbedtls_test_srv_crt_rsa_sha256_pem[] = TEST_SRV_CRT_RSA_SHA256_PEM;
+
+const unsigned char mbedtls_test_srv_crt_ec_der[] = TEST_SRV_CRT_EC_DER;
+const unsigned char mbedtls_test_srv_key_ec_der[] = TEST_SRV_KEY_EC_DER;
+const unsigned char mbedtls_test_srv_key_rsa_der[] = TEST_SRV_KEY_RSA_DER;
+const unsigned char mbedtls_test_srv_crt_rsa_sha1_der[] =
+ TEST_SRV_CRT_RSA_SHA1_DER;
+const unsigned char mbedtls_test_srv_crt_rsa_sha256_der[] =
+ TEST_SRV_CRT_RSA_SHA256_DER;
+
+const size_t mbedtls_test_srv_crt_ec_pem_len =
+ sizeof( mbedtls_test_srv_crt_ec_pem );
+const size_t mbedtls_test_srv_key_ec_pem_len =
+ sizeof( mbedtls_test_srv_key_ec_pem );
+const size_t mbedtls_test_srv_pwd_ec_pem_len =
+ sizeof( mbedtls_test_srv_pwd_ec_pem ) - 1;
+const size_t mbedtls_test_srv_key_rsa_pem_len =
+ sizeof( mbedtls_test_srv_key_rsa_pem );
+const size_t mbedtls_test_srv_pwd_rsa_pem_len =
+ sizeof( mbedtls_test_srv_pwd_rsa_pem ) - 1;
+const size_t mbedtls_test_srv_crt_rsa_sha1_pem_len =
+ sizeof( mbedtls_test_srv_crt_rsa_sha1_pem );
+const size_t mbedtls_test_srv_crt_rsa_sha256_pem_len =
+ sizeof( mbedtls_test_srv_crt_rsa_sha256_pem );
+
+const size_t mbedtls_test_srv_crt_ec_der_len =
+ sizeof( mbedtls_test_srv_crt_ec_der );
+const size_t mbedtls_test_srv_key_ec_der_len =
+ sizeof( mbedtls_test_srv_key_ec_der );
+const size_t mbedtls_test_srv_pwd_ec_der_len = 0;
+const size_t mbedtls_test_srv_key_rsa_der_len =
+ sizeof( mbedtls_test_srv_key_rsa_der );
+const size_t mbedtls_test_srv_pwd_rsa_der_len = 0;
+const size_t mbedtls_test_srv_crt_rsa_sha1_der_len =
+ sizeof( mbedtls_test_srv_crt_rsa_sha1_der );
+const size_t mbedtls_test_srv_crt_rsa_sha256_der_len =
+ sizeof( mbedtls_test_srv_crt_rsa_sha256_der );
+
+/*
+ * Client
+ */
+
+const char mbedtls_test_cli_crt_ec_pem[] = TEST_CLI_CRT_EC_PEM;
+const char mbedtls_test_cli_key_ec_pem[] = TEST_CLI_KEY_EC_PEM;
+const char mbedtls_test_cli_pwd_ec_pem[] = "";
+const char mbedtls_test_cli_key_rsa_pem[] = TEST_CLI_KEY_RSA_PEM;
+const char mbedtls_test_cli_pwd_rsa_pem[] = "";
+const char mbedtls_test_cli_crt_rsa_pem[] = TEST_CLI_CRT_RSA_PEM;
+
+const unsigned char mbedtls_test_cli_crt_ec_der[] = TEST_CLI_CRT_EC_DER;
+const unsigned char mbedtls_test_cli_key_ec_der[] = TEST_CLI_KEY_EC_DER;
+const unsigned char mbedtls_test_cli_key_rsa_der[] = TEST_CLI_KEY_RSA_DER;
+const unsigned char mbedtls_test_cli_crt_rsa_der[] = TEST_CLI_CRT_RSA_DER;
+
+const size_t mbedtls_test_cli_crt_ec_pem_len =
+ sizeof( mbedtls_test_cli_crt_ec_pem );
+const size_t mbedtls_test_cli_key_ec_pem_len =
+ sizeof( mbedtls_test_cli_key_ec_pem );
+const size_t mbedtls_test_cli_pwd_ec_pem_len =
+ sizeof( mbedtls_test_cli_pwd_ec_pem ) - 1;
+const size_t mbedtls_test_cli_key_rsa_pem_len =
+ sizeof( mbedtls_test_cli_key_rsa_pem );
+const size_t mbedtls_test_cli_pwd_rsa_pem_len =
+ sizeof( mbedtls_test_cli_pwd_rsa_pem ) - 1;
+const size_t mbedtls_test_cli_crt_rsa_pem_len =
+ sizeof( mbedtls_test_cli_crt_rsa_pem );
+
+const size_t mbedtls_test_cli_crt_ec_der_len =
+ sizeof( mbedtls_test_cli_crt_ec_der );
+const size_t mbedtls_test_cli_key_ec_der_len =
+ sizeof( mbedtls_test_cli_key_ec_der );
+const size_t mbedtls_test_cli_key_rsa_der_len =
+ sizeof( mbedtls_test_cli_key_rsa_der );
+const size_t mbedtls_test_cli_crt_rsa_der_len =
+ sizeof( mbedtls_test_cli_crt_rsa_der );
+
+/*
+ *
+ * Definitions of test CRTs without specification of all parameters, choosing
+ * them automatically according to the config. For example, mbedtls_test_ca_crt
+ * is one of mbedtls_test_ca_crt_{rsa|ec}_{sha1|sha256}_{pem|der}.
+ *
+ */
+
+/*
+ * Dispatch between PEM and DER according to config
+ */
+
+#if defined(MBEDTLS_PEM_PARSE_C)
+
+/* PEM encoded test CA certificates and keys */
+
+#define TEST_CA_KEY_RSA TEST_CA_KEY_RSA_PEM
+#define TEST_CA_PWD_RSA TEST_CA_PWD_RSA_PEM
+#define TEST_CA_CRT_RSA_SHA256 TEST_CA_CRT_RSA_SHA256_PEM
+#define TEST_CA_CRT_RSA_SHA1 TEST_CA_CRT_RSA_SHA1_PEM
+#define TEST_CA_KEY_EC TEST_CA_KEY_EC_PEM
+#define TEST_CA_PWD_EC TEST_CA_PWD_EC_PEM
+#define TEST_CA_CRT_EC TEST_CA_CRT_EC_PEM
+
+/* PEM encoded test server certificates and keys */
+
+#define TEST_SRV_KEY_RSA TEST_SRV_KEY_RSA_PEM
+#define TEST_SRV_PWD_RSA ""
+#define TEST_SRV_CRT_RSA_SHA256 TEST_SRV_CRT_RSA_SHA256_PEM
+#define TEST_SRV_CRT_RSA_SHA1 TEST_SRV_CRT_RSA_SHA1_PEM
+#define TEST_SRV_KEY_EC TEST_SRV_KEY_EC_PEM
+#define TEST_SRV_PWD_EC ""
+#define TEST_SRV_CRT_EC TEST_SRV_CRT_EC_PEM
+
+/* PEM encoded test client certificates and keys */
+
+#define TEST_CLI_KEY_RSA TEST_CLI_KEY_RSA_PEM
+#define TEST_CLI_PWD_RSA ""
+#define TEST_CLI_CRT_RSA TEST_CLI_CRT_RSA_PEM
+#define TEST_CLI_KEY_EC TEST_CLI_KEY_EC_PEM
+#define TEST_CLI_PWD_EC ""
+#define TEST_CLI_CRT_EC TEST_CLI_CRT_EC_PEM
+
+#else /* MBEDTLS_PEM_PARSE_C */
+
+/* DER encoded test CA certificates and keys */
+
+#define TEST_CA_KEY_RSA TEST_CA_KEY_RSA_DER
+#define TEST_CA_PWD_RSA ""
+#define TEST_CA_CRT_RSA_SHA256 TEST_CA_CRT_RSA_SHA256_DER
+#define TEST_CA_CRT_RSA_SHA1 TEST_CA_CRT_RSA_SHA1_DER
+#define TEST_CA_KEY_EC TEST_CA_KEY_EC_DER
+#define TEST_CA_PWD_EC ""
+#define TEST_CA_CRT_EC TEST_CA_CRT_EC_DER
+
+/* DER encoded test server certificates and keys */
+
+#define TEST_SRV_KEY_RSA TEST_SRV_KEY_RSA_DER
+#define TEST_SRV_PWD_RSA ""
+#define TEST_SRV_CRT_RSA_SHA256 TEST_SRV_CRT_RSA_SHA256_DER
+#define TEST_SRV_CRT_RSA_SHA1 TEST_SRV_CRT_RSA_SHA1_DER
+#define TEST_SRV_KEY_EC TEST_SRV_KEY_EC_DER
+#define TEST_SRV_PWD_EC ""
+#define TEST_SRV_CRT_EC TEST_SRV_CRT_EC_DER
+
+/* DER encoded test client certificates and keys */
+
+#define TEST_CLI_KEY_RSA TEST_CLI_KEY_RSA_DER
+#define TEST_CLI_PWD_RSA ""
+#define TEST_CLI_CRT_RSA TEST_CLI_CRT_RSA_DER
+#define TEST_CLI_KEY_EC TEST_CLI_KEY_EC_DER
+#define TEST_CLI_PWD_EC ""
+#define TEST_CLI_CRT_EC TEST_CLI_CRT_EC_DER
+
+#endif /* MBEDTLS_PEM_PARSE_C */
+
+const char mbedtls_test_ca_key_rsa[] = TEST_CA_KEY_RSA;
+const char mbedtls_test_ca_pwd_rsa[] = TEST_CA_PWD_RSA;
+const char mbedtls_test_ca_crt_rsa_sha256[] = TEST_CA_CRT_RSA_SHA256;
+const char mbedtls_test_ca_crt_rsa_sha1[] = TEST_CA_CRT_RSA_SHA1;
+const char mbedtls_test_ca_key_ec[] = TEST_CA_KEY_EC;
+const char mbedtls_test_ca_pwd_ec[] = TEST_CA_PWD_EC;
+const char mbedtls_test_ca_crt_ec[] = TEST_CA_CRT_EC;
+
+const char mbedtls_test_srv_key_rsa[] = TEST_SRV_KEY_RSA;
+const char mbedtls_test_srv_pwd_rsa[] = TEST_SRV_PWD_RSA;
+const char mbedtls_test_srv_crt_rsa_sha256[] = TEST_SRV_CRT_RSA_SHA256;
+const char mbedtls_test_srv_crt_rsa_sha1[] = TEST_SRV_CRT_RSA_SHA1;
+const char mbedtls_test_srv_key_ec[] = TEST_SRV_KEY_EC;
+const char mbedtls_test_srv_pwd_ec[] = TEST_SRV_PWD_EC;
+const char mbedtls_test_srv_crt_ec[] = TEST_SRV_CRT_EC;
+
+const char mbedtls_test_cli_key_rsa[] = TEST_CLI_KEY_RSA;
+const char mbedtls_test_cli_pwd_rsa[] = TEST_CLI_PWD_RSA;
+const char mbedtls_test_cli_crt_rsa[] = TEST_CLI_CRT_RSA;
+const char mbedtls_test_cli_key_ec[] = TEST_CLI_KEY_EC;
+const char mbedtls_test_cli_pwd_ec[] = TEST_CLI_PWD_EC;
+const char mbedtls_test_cli_crt_ec[] = TEST_CLI_CRT_EC;
+
+const size_t mbedtls_test_ca_key_rsa_len =
+ sizeof( mbedtls_test_ca_key_rsa );
+const size_t mbedtls_test_ca_pwd_rsa_len =
+ sizeof( mbedtls_test_ca_pwd_rsa ) - 1;
+const size_t mbedtls_test_ca_crt_rsa_sha256_len =
+ sizeof( mbedtls_test_ca_crt_rsa_sha256 );
+const size_t mbedtls_test_ca_crt_rsa_sha1_len =
+ sizeof( mbedtls_test_ca_crt_rsa_sha1 );
+const size_t mbedtls_test_ca_key_ec_len =
+ sizeof( mbedtls_test_ca_key_ec );
+const size_t mbedtls_test_ca_pwd_ec_len =
+ sizeof( mbedtls_test_ca_pwd_ec ) - 1;
+const size_t mbedtls_test_ca_crt_ec_len =
+ sizeof( mbedtls_test_ca_crt_ec );
+
+const size_t mbedtls_test_srv_key_rsa_len =
+ sizeof( mbedtls_test_srv_key_rsa );
+const size_t mbedtls_test_srv_pwd_rsa_len =
+ sizeof( mbedtls_test_srv_pwd_rsa ) -1;
+const size_t mbedtls_test_srv_crt_rsa_sha256_len =
+ sizeof( mbedtls_test_srv_crt_rsa_sha256 );
+const size_t mbedtls_test_srv_crt_rsa_sha1_len =
+ sizeof( mbedtls_test_srv_crt_rsa_sha1 );
+const size_t mbedtls_test_srv_key_ec_len =
+ sizeof( mbedtls_test_srv_key_ec );
+const size_t mbedtls_test_srv_pwd_ec_len =
+ sizeof( mbedtls_test_srv_pwd_ec ) - 1;
+const size_t mbedtls_test_srv_crt_ec_len =
+ sizeof( mbedtls_test_srv_crt_ec );
+
+const size_t mbedtls_test_cli_key_rsa_len =
+ sizeof( mbedtls_test_cli_key_rsa );
+const size_t mbedtls_test_cli_pwd_rsa_len =
+ sizeof( mbedtls_test_cli_pwd_rsa ) - 1;
+const size_t mbedtls_test_cli_crt_rsa_len =
+ sizeof( mbedtls_test_cli_crt_rsa );
+const size_t mbedtls_test_cli_key_ec_len =
+ sizeof( mbedtls_test_cli_key_ec );
+const size_t mbedtls_test_cli_pwd_ec_len =
+ sizeof( mbedtls_test_cli_pwd_ec ) - 1;
+const size_t mbedtls_test_cli_crt_ec_len =
+ sizeof( mbedtls_test_cli_crt_ec );
+
+/*
+ * Dispatch between SHA-1 and SHA-256
+ */
#if defined(MBEDTLS_SHA256_C)
-#define TEST_CA_CRT_RSA_SHA256 \
-"-----BEGIN CERTIFICATE-----\r\n" \
-"MIIDhzCCAm+gAwIBAgIBADANBgkqhkiG9w0BAQsFADA7MQswCQYDVQQGEwJOTDER\r\n" \
-"MA8GA1UECgwIUG9sYXJTU0wxGTAXBgNVBAMMEFBvbGFyU1NMIFRlc3QgQ0EwHhcN\r\n" \
-"MTcwNTA0MTY1NzAxWhcNMjcwNTA1MTY1NzAxWjA7MQswCQYDVQQGEwJOTDERMA8G\r\n" \
-"A1UECgwIUG9sYXJTU0wxGTAXBgNVBAMMEFBvbGFyU1NMIFRlc3QgQ0EwggEiMA0G\r\n" \
-"CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDA3zf8F7vglp0/ht6WMn1EpRagzSHx\r\n" \
-"mdTs6st8GFgIlKXsm8WL3xoemTiZhx57wI053zhdcHgH057Zk+i5clHFzqMwUqny\r\n" \
-"50BwFMtEonILwuVA+T7lpg6z+exKY8C4KQB0nFc7qKUEkHHxvYPZP9al4jwqj+8n\r\n" \
-"YMPGn8u67GB9t+aEMr5P+1gmIgNb1LTV+/Xjli5wwOQuvfwu7uJBVcA0Ln0kcmnL\r\n" \
-"R7EUQIN9Z/SG9jGr8XmksrUuEvmEF/Bibyc+E1ixVA0hmnM3oTDPb5Lc9un8rNsu\r\n" \
-"KNF+AksjoBXyOGVkCeoMbo4bF6BxyLObyavpw/LPh5aPgAIynplYb6LVAgMBAAGj\r\n" \
-"gZUwgZIwHQYDVR0OBBYEFLRa5KWz3tJS9rnVppUP6z68x/3/MGMGA1UdIwRcMFqA\r\n" \
-"FLRa5KWz3tJS9rnVppUP6z68x/3/oT+kPTA7MQswCQYDVQQGEwJOTDERMA8GA1UE\r\n" \
-"CgwIUG9sYXJTU0wxGTAXBgNVBAMMEFBvbGFyU1NMIFRlc3QgQ0GCAQAwDAYDVR0T\r\n" \
-"BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAHK/HHrTZMnnVMpde1io+voAtql7j\r\n" \
-"4sRhLrjD7o3THtwRbDa2diCvpq0Sq23Ng2LMYoXsOxoL/RQK3iN7UKxV3MKPEr0w\r\n" \
-"XQS+kKQqiT2bsfrjnWMVHZtUOMpm6FNqcdGm/Rss3vKda2lcKl8kUnq/ylc1+QbB\r\n" \
-"G6A6tUvQcr2ZyWfVg+mM5XkhTrOOXus2OLikb4WwEtJTJRNE0f+yPODSUz0/vT57\r\n" \
-"ApH0CnB80bYJshYHPHHymOtleAB8KSYtqm75g/YNobjnjB6cm4HkW3OZRVIl6fYY\r\n" \
-"n20NRVA1Vjs6GAROr4NqW4k/+LofY9y0LLDE+p0oIEKXIsIvhPr39swxSA==\r\n" \
-"-----END CERTIFICATE-----\r\n"
-
-const char mbedtls_test_ca_crt_rsa[] = TEST_CA_CRT_RSA_SHA256;
-const size_t mbedtls_test_ca_crt_rsa_len = sizeof( mbedtls_test_ca_crt_rsa );
-#define TEST_CA_CRT_RSA_SOME
-
-static const char mbedtls_test_ca_crt_rsa_sha256[] = TEST_CA_CRT_RSA_SHA256;
+#define TEST_CA_CRT_RSA TEST_CA_CRT_RSA_SHA256
+#define TEST_SRV_CRT_RSA TEST_SRV_CRT_RSA_SHA256
+#else
+#define TEST_CA_CRT_RSA TEST_CA_CRT_RSA_SHA1
+#define TEST_SRV_CRT_RSA TEST_SRV_CRT_RSA_SHA1
+#endif /* MBEDTLS_SHA256_C */
-#endif
+const char mbedtls_test_ca_crt_rsa[] = TEST_CA_CRT_RSA;
+const char mbedtls_test_srv_crt_rsa[] = TEST_SRV_CRT_RSA;
-#if !defined(TEST_CA_CRT_RSA_SOME) || defined(MBEDTLS_SHA1_C)
-#define TEST_CA_CRT_RSA_SHA1 \
-"-----BEGIN CERTIFICATE-----\r\n" \
-"MIIDhzCCAm+gAwIBAgIBADANBgkqhkiG9w0BAQUFADA7MQswCQYDVQQGEwJOTDER\r\n" \
-"MA8GA1UEChMIUG9sYXJTU0wxGTAXBgNVBAMTEFBvbGFyU1NMIFRlc3QgQ0EwHhcN\r\n" \
-"MTEwMjEyMTQ0NDAwWhcNMjEwMjEyMTQ0NDAwWjA7MQswCQYDVQQGEwJOTDERMA8G\r\n" \
-"A1UEChMIUG9sYXJTU0wxGTAXBgNVBAMTEFBvbGFyU1NMIFRlc3QgQ0EwggEiMA0G\r\n" \
-"CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDA3zf8F7vglp0/ht6WMn1EpRagzSHx\r\n" \
-"mdTs6st8GFgIlKXsm8WL3xoemTiZhx57wI053zhdcHgH057Zk+i5clHFzqMwUqny\r\n" \
-"50BwFMtEonILwuVA+T7lpg6z+exKY8C4KQB0nFc7qKUEkHHxvYPZP9al4jwqj+8n\r\n" \
-"YMPGn8u67GB9t+aEMr5P+1gmIgNb1LTV+/Xjli5wwOQuvfwu7uJBVcA0Ln0kcmnL\r\n" \
-"R7EUQIN9Z/SG9jGr8XmksrUuEvmEF/Bibyc+E1ixVA0hmnM3oTDPb5Lc9un8rNsu\r\n" \
-"KNF+AksjoBXyOGVkCeoMbo4bF6BxyLObyavpw/LPh5aPgAIynplYb6LVAgMBAAGj\r\n" \
-"gZUwgZIwDAYDVR0TBAUwAwEB/zAdBgNVHQ4EFgQUtFrkpbPe0lL2udWmlQ/rPrzH\r\n" \
-"/f8wYwYDVR0jBFwwWoAUtFrkpbPe0lL2udWmlQ/rPrzH/f+hP6Q9MDsxCzAJBgNV\r\n" \
-"BAYTAk5MMREwDwYDVQQKEwhQb2xhclNTTDEZMBcGA1UEAxMQUG9sYXJTU0wgVGVz\r\n" \
-"dCBDQYIBADANBgkqhkiG9w0BAQUFAAOCAQEAuP1U2ABUkIslsCfdlc2i94QHHYeJ\r\n" \
-"SsR4EdgHtdciUI5I62J6Mom+Y0dT/7a+8S6MVMCZP6C5NyNyXw1GWY/YR82XTJ8H\r\n" \
-"DBJiCTok5DbZ6SzaONBzdWHXwWwmi5vg1dxn7YxrM9d0IjxM27WNKs4sDQhZBQkF\r\n" \
-"pjmfs2cb4oPl4Y9T9meTx/lvdkRYEug61Jfn6cA+qHpyPYdTH+UshITnmp5/Ztkf\r\n" \
-"m/UTSLBNFNHesiTZeH31NcxYGdHSme9Nc/gfidRa0FLOCfWxRlFqAI47zG9jAQCZ\r\n" \
-"7Z2mCGDNMhjQc+BYcdnl0lPXjdDK6V0qCg1dVewhUBcW5gZKzV7e9+DpVA==\r\n" \
-"-----END CERTIFICATE-----\r\n"
-
-#if !defined (TEST_CA_CRT_RSA_SOME)
-const char mbedtls_test_ca_crt_rsa[] = TEST_CA_CRT_RSA_SHA1;
-const size_t mbedtls_test_ca_crt_rsa_len = sizeof( mbedtls_test_ca_crt_rsa );
-#endif
+const size_t mbedtls_test_ca_crt_rsa_len =
+ sizeof( mbedtls_test_ca_crt_rsa );
+const size_t mbedtls_test_srv_crt_rsa_len =
+ sizeof( mbedtls_test_srv_crt_rsa );
-static const char mbedtls_test_ca_crt_rsa_sha1[] = TEST_CA_CRT_RSA_SHA1;
+/*
+ * Dispatch between RSA and EC
+ */
-#endif
+#if defined(MBEDTLS_RSA_C)
+
+#define TEST_CA_KEY TEST_CA_KEY_RSA
+#define TEST_CA_PWD TEST_CA_PWD_RSA
+#define TEST_CA_CRT TEST_CA_CRT_RSA
+
+#define TEST_SRV_KEY TEST_SRV_KEY_RSA
+#define TEST_SRV_PWD TEST_SRV_PWD_RSA
+#define TEST_SRV_CRT TEST_SRV_CRT_RSA
+
+#define TEST_CLI_KEY TEST_CLI_KEY_RSA
+#define TEST_CLI_PWD TEST_CLI_PWD_RSA
+#define TEST_CLI_CRT TEST_CLI_CRT_RSA
+
+#else /* no RSA, so assume ECDSA */
+
+#define TEST_CA_KEY TEST_CA_KEY_EC
+#define TEST_CA_PWD TEST_CA_PWD_EC
+#define TEST_CA_CRT TEST_CA_CRT_EC
+
+#define TEST_SRV_KEY TEST_SRV_KEY_EC
+#define TEST_SRV_PWD TEST_SRV_PWD_EC
+#define TEST_SRV_CRT TEST_SRV_CRT_EC
+
+#define TEST_CLI_KEY TEST_CLI_KEY_EC
+#define TEST_CLI_PWD TEST_CLI_PWD_EC
+#define TEST_CLI_CRT TEST_CLI_CRT_EC
-const char mbedtls_test_ca_key_rsa[] =
-"-----BEGIN RSA PRIVATE KEY-----\r\n"
-"Proc-Type: 4,ENCRYPTED\r\n"
-"DEK-Info: DES-EDE3-CBC,A8A95B05D5B7206B\r\n"
-"\r\n"
-"9Qd9GeArejl1GDVh2lLV1bHt0cPtfbh5h/5zVpAVaFpqtSPMrElp50Rntn9et+JA\r\n"
-"7VOyboR+Iy2t/HU4WvA687k3Bppe9GwKHjHhtl//8xFKwZr3Xb5yO5JUP8AUctQq\r\n"
-"Nb8CLlZyuUC+52REAAthdWgsX+7dJO4yabzUcQ22Tp9JSD0hiL43BlkWYUNK3dAo\r\n"
-"PZlmiptjnzVTjg1MxsBSydZinWOLBV8/JQgxSPo2yD4uEfig28qbvQ2wNIn0pnAb\r\n"
-"GxnSAOazkongEGfvcjIIs+LZN9gXFhxcOh6kc4Q/c99B7QWETwLLkYgZ+z1a9VY9\r\n"
-"gEU7CwCxYCD+h9hY6FPmsK0/lC4O7aeRKpYq00rPPxs6i7phiexg6ax6yTMmArQq\r\n"
-"QmK3TAsJm8V/J5AWpLEV6jAFgRGymGGHnof0DXzVWZidrcZJWTNuGEX90nB3ee2w\r\n"
-"PXJEFWKoD3K3aFcSLdHYr3mLGxP7H9ThQai9VsycxZKS5kwvBKQ//YMrmFfwPk8x\r\n"
-"vTeY4KZMaUrveEel5tWZC94RSMKgxR6cyE1nBXyTQnDOGbfpNNgBKxyKbINWoOJU\r\n"
-"WJZAwlsQn+QzCDwpri7+sV1mS3gBE6UY7aQmnmiiaC2V3Hbphxct/en5QsfDOt1X\r\n"
-"JczSfpRWLlbPznZg8OQh/VgCMA58N5DjOzTIK7sJJ5r+94ZBTCpgAMbF588f0NTR\r\n"
-"KCe4yrxGJR7X02M4nvD4IwOlpsQ8xQxZtOSgXv4LkxvdU9XJJKWZ/XNKJeWztxSe\r\n"
-"Z1vdTc2YfsDBA2SEv33vxHx2g1vqtw8SjDRT2RaQSS0QuSaMJimdOX6mTOCBKk1J\r\n"
-"9Q5mXTrER+/LnK0jEmXsBXWA5bqqVZIyahXSx4VYZ7l7w/PHiUDtDgyRhMMKi4n2\r\n"
-"iQvQcWSQTjrpnlJbca1/DkpRt3YwrvJwdqb8asZU2VrNETh5x0QVefDRLFiVpif/\r\n"
-"tUaeAe/P1F8OkS7OIZDs1SUbv/sD2vMbhNkUoCms3/PvNtdnvgL4F0zhaDpKCmlT\r\n"
-"P8vx49E7v5CyRNmED9zZg4o3wmMqrQO93PtTug3Eu9oVx1zPQM1NVMyBa2+f29DL\r\n"
-"1nuTCeXdo9+ni45xx+jAI4DCwrRdhJ9uzZyC6962H37H6D+5naNvClFR1s6li1Gb\r\n"
-"nqPoiy/OBsEx9CaDGcqQBp5Wme/3XW+6z1ISOx+igwNTVCT14mHdBMbya0eIKft5\r\n"
-"X+GnwtgEMyCYyyWuUct8g4RzErcY9+yW9Om5Hzpx4zOuW4NPZgPDTgK+t2RSL/Yq\r\n"
-"rE1njrgeGYcVeG3f+OftH4s6fPbq7t1A5ZgUscbLMBqr9tK+OqygR4EgKBPsH6Cz\r\n"
-"L6zlv/2RV0qAHvVuDJcIDIgwY5rJtINEm32rhOeFNJwZS5MNIC1czXZx5//ugX7l\r\n"
-"I4sy5nbVhwSjtAk8Xg5dZbdTZ6mIrb7xqH+fdakZor1khG7bC2uIwibD3cSl2XkR\r\n"
-"wN48lslbHnqqagr6Xm1nNOSVl8C/6kbJEsMpLhAezfRtGwvOucoaE+WbeUNolGde\r\n"
-"P/eQiddSf0brnpiLJRh7qZrl9XuqYdpUqnoEdMAfotDOID8OtV7gt8a48ad8VPW2\r\n"
-"-----END RSA PRIVATE KEY-----\r\n";
-const size_t mbedtls_test_ca_key_rsa_len = sizeof( mbedtls_test_ca_key_rsa );
-
-const char mbedtls_test_ca_pwd_rsa[] = "PolarSSLTest";
-const size_t mbedtls_test_ca_pwd_rsa_len = sizeof( mbedtls_test_ca_pwd_rsa ) - 1;
-
-/* tests/data_files/server2.crt */
-const char mbedtls_test_srv_crt_rsa[] =
-"-----BEGIN CERTIFICATE-----\r\n"
-"MIIDNzCCAh+gAwIBAgIBAjANBgkqhkiG9w0BAQUFADA7MQswCQYDVQQGEwJOTDER\r\n"
-"MA8GA1UECgwIUG9sYXJTU0wxGTAXBgNVBAMMEFBvbGFyU1NMIFRlc3QgQ0EwHhcN\r\n"
-"MTEwMjEyMTQ0NDA2WhcNMjEwMjEyMTQ0NDA2WjA0MQswCQYDVQQGEwJOTDERMA8G\r\n"
-"A1UECgwIUG9sYXJTU0wxEjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcN\r\n"
-"AQEBBQADggEPADCCAQoCggEBAMFNo93nzR3RBNdJcriZrA545Do8Ss86ExbQWuTN\r\n"
-"owCIp+4ea5anUrSQ7y1yej4kmvy2NKwk9XfgJmSMnLAofaHa6ozmyRyWvP7BBFKz\r\n"
-"NtSj+uGxdtiQwWG0ZlI2oiZTqqt0Xgd9GYLbKtgfoNkNHC1JZvdbJXNG6AuKT2kM\r\n"
-"tQCQ4dqCEGZ9rlQri2V5kaHiYcPNQEkI7mgM8YuG0ka/0LiqEQMef1aoGh5EGA8P\r\n"
-"hYvai0Re4hjGYi/HZo36Xdh98yeJKQHFkA4/J/EwyEoO79bex8cna8cFPXrEAjya\r\n"
-"HT4P6DSYW8tzS1KW2BGiLICIaTla0w+w3lkvEcf36hIBMJcCAwEAAaNNMEswCQYD\r\n"
-"VR0TBAIwADAdBgNVHQ4EFgQUpQXoZLjc32APUBJNYKhkr02LQ5MwHwYDVR0jBBgw\r\n"
-"FoAUtFrkpbPe0lL2udWmlQ/rPrzH/f8wDQYJKoZIhvcNAQEFBQADggEBAAFzC0rF\r\n"
-"y6De8WMcdgQrEw3AhBHFjzqnxZw1ene4IBSC7lTw8rBSy3jOWQdPUWn+0y/pCeeF\r\n"
-"kti6sevFdl1hLemGtd4q+T9TKEKGg3ND4ARfB5AUZZ9uEHq8WBkiwus5clGS17Qd\r\n"
-"dS/TOisB59tQruLx1E1bPLtBKyqk4koC5WAULJwfpswGSyWJTpYwIpxcWE3D2tBu\r\n"
-"UB6MZfXZFzWmWEOyKbeoXjXe8GBCGgHLywvYDsGQ36HSGtEsAvR2QaTLSxWYcfk1\r\n"
-"fbDn4jSWkb4yZy1r01UEigFQtONieGwRFaUqEcFJHJvEEGVgh9keaVlOj2vrwf5r\r\n"
-"4mN4lW7gLdenN6g=\r\n"
-"-----END CERTIFICATE-----\r\n";
-const size_t mbedtls_test_srv_crt_rsa_len = sizeof( mbedtls_test_srv_crt_rsa );
-
-/* tests/data_files/server2.key */
-const char mbedtls_test_srv_key_rsa[] =
-"-----BEGIN RSA PRIVATE KEY-----\r\n"
-"MIIEpAIBAAKCAQEAwU2j3efNHdEE10lyuJmsDnjkOjxKzzoTFtBa5M2jAIin7h5r\r\n"
-"lqdStJDvLXJ6PiSa/LY0rCT1d+AmZIycsCh9odrqjObJHJa8/sEEUrM21KP64bF2\r\n"
-"2JDBYbRmUjaiJlOqq3ReB30Zgtsq2B+g2Q0cLUlm91slc0boC4pPaQy1AJDh2oIQ\r\n"
-"Zn2uVCuLZXmRoeJhw81ASQjuaAzxi4bSRr/QuKoRAx5/VqgaHkQYDw+Fi9qLRF7i\r\n"
-"GMZiL8dmjfpd2H3zJ4kpAcWQDj8n8TDISg7v1t7HxydrxwU9esQCPJodPg/oNJhb\r\n"
-"y3NLUpbYEaIsgIhpOVrTD7DeWS8Rx/fqEgEwlwIDAQABAoIBAQCXR0S8EIHFGORZ\r\n"
-"++AtOg6eENxD+xVs0f1IeGz57Tjo3QnXX7VBZNdj+p1ECvhCE/G7XnkgU5hLZX+G\r\n"
-"Z0jkz/tqJOI0vRSdLBbipHnWouyBQ4e/A1yIJdlBtqXxJ1KE/ituHRbNc4j4kL8Z\r\n"
-"/r6pvwnTI0PSx2Eqs048YdS92LT6qAv4flbNDxMn2uY7s4ycS4Q8w1JXnCeaAnYm\r\n"
-"WYI5wxO+bvRELR2Mcz5DmVnL8jRyml6l6582bSv5oufReFIbyPZbQWlXgYnpu6He\r\n"
-"GTc7E1zKYQGG/9+DQUl/1vQuCPqQwny0tQoX2w5tdYpdMdVm+zkLtbajzdTviJJa\r\n"
-"TWzL6lt5AoGBAN86+SVeJDcmQJcv4Eq6UhtRr4QGMiQMz0Sod6ettYxYzMgxtw28\r\n"
-"CIrgpozCc+UaZJLo7UxvC6an85r1b2nKPCLQFaggJ0H4Q0J/sZOhBIXaoBzWxveK\r\n"
-"nupceKdVxGsFi8CDy86DBfiyFivfBj+47BbaQzPBj7C4rK7UlLjab2rDAoGBAN2u\r\n"
-"AM2gchoFiu4v1HFL8D7lweEpi6ZnMJjnEu/dEgGQJFjwdpLnPbsj4c75odQ4Gz8g\r\n"
-"sw9lao9VVzbusoRE/JGI4aTdO0pATXyG7eG1Qu+5Yc1YGXcCrliA2xM9xx+d7f+s\r\n"
-"mPzN+WIEg5GJDYZDjAzHG5BNvi/FfM1C9dOtjv2dAoGAF0t5KmwbjWHBhcVqO4Ic\r\n"
-"BVvN3BIlc1ue2YRXEDlxY5b0r8N4XceMgKmW18OHApZxfl8uPDauWZLXOgl4uepv\r\n"
-"whZC3EuWrSyyICNhLY21Ah7hbIEBPF3L3ZsOwC+UErL+dXWLdB56Jgy3gZaBeW7b\r\n"
-"vDrEnocJbqCm7IukhXHOBK8CgYEAwqdHB0hqyNSzIOGY7v9abzB6pUdA3BZiQvEs\r\n"
-"3LjHVd4HPJ2x0N8CgrBIWOE0q8+0hSMmeE96WW/7jD3fPWwCR5zlXknxBQsfv0gP\r\n"
-"3BC5PR0Qdypz+d+9zfMf625kyit4T/hzwhDveZUzHnk1Cf+IG7Q+TOEnLnWAWBED\r\n"
-"ISOWmrUCgYAFEmRxgwAc/u+D6t0syCwAYh6POtscq9Y0i9GyWk89NzgC4NdwwbBH\r\n"
-"4AgahOxIxXx2gxJnq3yfkJfIjwf0s2DyP0kY2y6Ua1OeomPeY9mrIS4tCuDQ6LrE\r\n"
-"TB6l9VGoxJL4fyHnZb8L5gGvnB1bbD8cL6YPaDiOhcRseC9vBiEuVg==\r\n"
-"-----END RSA PRIVATE KEY-----\r\n";
-const size_t mbedtls_test_srv_key_rsa_len = sizeof( mbedtls_test_srv_key_rsa );
-
-/* tests/data_files/cli-rsa-sha256.crt */
-const char mbedtls_test_cli_crt_rsa[] =
-"-----BEGIN CERTIFICATE-----\r\n"
-"MIIDPzCCAiegAwIBAgIBBDANBgkqhkiG9w0BAQsFADA7MQswCQYDVQQGEwJOTDER\r\n"
-"MA8GA1UECgwIUG9sYXJTU0wxGTAXBgNVBAMMEFBvbGFyU1NMIFRlc3QgQ0EwHhcN\r\n"
-"MTEwMjEyMTQ0NDA2WhcNMjEwMjEyMTQ0NDA2WjA8MQswCQYDVQQGEwJOTDERMA8G\r\n"
-"A1UECgwIUG9sYXJTU0wxGjAYBgNVBAMMEVBvbGFyU1NMIENsaWVudCAyMIIBIjAN\r\n"
-"BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyHTEzLn5tXnpRdkUYLB9u5Pyax6f\r\n"
-"M60Nj4o8VmXl3ETZzGaFB9X4J7BKNdBjngpuG7fa8H6r7gwQk4ZJGDTzqCrSV/Uu\r\n"
-"1C93KYRhTYJQj6eVSHD1bk2y1RPD0hrt5kPqQhTrdOrA7R/UV06p86jt0uDBMHEw\r\n"
-"MjDV0/YI0FZPRo7yX/k9Z5GIMC5Cst99++UMd//sMcB4j7/Cf8qtbCHWjdmLao5v\r\n"
-"4Jv4EFbMs44TFeY0BGbH7vk2DmqV9gmaBmf0ZXH4yqSxJeD+PIs1BGe64E92hfx/\r\n"
-"/DZrtenNLQNiTrM9AM+vdqBpVoNq0qjU51Bx5rU2BXcFbXvI5MT9TNUhXwIDAQAB\r\n"
-"o00wSzAJBgNVHRMEAjAAMB0GA1UdDgQWBBRxoQBzckAvVHZeM/xSj7zx3WtGITAf\r\n"
-"BgNVHSMEGDAWgBS0WuSls97SUva51aaVD+s+vMf9/zANBgkqhkiG9w0BAQsFAAOC\r\n"
-"AQEAlHabem2Tu69VUN7EipwnQn1dIHdgvT5i+iQHpSxY1crPnBbAeSdAXwsVEqLQ\r\n"
-"gOOIAQD5VIITNuoGgo4i+4OpNh9u7ZkpRHla+/swsfrFWRRbBNP5Bcu74AGLstwU\r\n"
-"zM8gIkBiyfM1Q1qDQISV9trlCG6O8vh8dp/rbI3rfzo99BOHXgFCrzXjCuW4vDsF\r\n"
-"r+Dao26bX3sJ6UnEWg1H3o2x6PpUcvQ36h71/bz4TEbbUUEpe02V4QWuL+wrhHJL\r\n"
-"U7o3SVE3Og7jPF8sat0a50YUWhwEFI256m02KAXLg89ueUyYKEr6rNwhcvXJpvU9\r\n"
-"giIVvd0Sbjjnn7NC4VDbcXV8vw==\r\n"
-"-----END CERTIFICATE-----\r\n";
-const size_t mbedtls_test_cli_crt_rsa_len = sizeof( mbedtls_test_cli_crt_rsa );
-
-/* tests/data_files/cli-rsa.key */
-const char mbedtls_test_cli_key_rsa[] =
-"-----BEGIN RSA PRIVATE KEY-----\r\n"
-"MIIEpAIBAAKCAQEAyHTEzLn5tXnpRdkUYLB9u5Pyax6fM60Nj4o8VmXl3ETZzGaF\r\n"
-"B9X4J7BKNdBjngpuG7fa8H6r7gwQk4ZJGDTzqCrSV/Uu1C93KYRhTYJQj6eVSHD1\r\n"
-"bk2y1RPD0hrt5kPqQhTrdOrA7R/UV06p86jt0uDBMHEwMjDV0/YI0FZPRo7yX/k9\r\n"
-"Z5GIMC5Cst99++UMd//sMcB4j7/Cf8qtbCHWjdmLao5v4Jv4EFbMs44TFeY0BGbH\r\n"
-"7vk2DmqV9gmaBmf0ZXH4yqSxJeD+PIs1BGe64E92hfx//DZrtenNLQNiTrM9AM+v\r\n"
-"dqBpVoNq0qjU51Bx5rU2BXcFbXvI5MT9TNUhXwIDAQABAoIBAGdNtfYDiap6bzst\r\n"
-"yhCiI8m9TtrhZw4MisaEaN/ll3XSjaOG2dvV6xMZCMV+5TeXDHOAZnY18Yi18vzz\r\n"
-"4Ut2TnNFzizCECYNaA2fST3WgInnxUkV3YXAyP6CNxJaCmv2aA0yFr2kFVSeaKGt\r\n"
-"ymvljNp2NVkvm7Th8fBQBO7I7AXhz43k0mR7XmPgewe8ApZOG3hstkOaMvbWAvWA\r\n"
-"zCZupdDjZYjOJqlA4eEA4H8/w7F83r5CugeBE8LgEREjLPiyejrU5H1fubEY+h0d\r\n"
-"l5HZBJ68ybTXfQ5U9o/QKA3dd0toBEhhdRUDGzWtjvwkEQfqF1reGWj/tod/gCpf\r\n"
-"DFi6X0ECgYEA4wOv/pjSC3ty6TuOvKX2rOUiBrLXXv2JSxZnMoMiWI5ipLQt+RYT\r\n"
-"VPafL/m7Dn6MbwjayOkcZhBwk5CNz5A6Q4lJ64Mq/lqHznRCQQ2Mc1G8eyDF/fYL\r\n"
-"Ze2pLvwP9VD5jTc2miDfw+MnvJhywRRLcemDFP8k4hQVtm8PMp3ZmNECgYEA4gz7\r\n"
-"wzObR4gn8ibe617uQPZjWzUj9dUHYd+in1gwBCIrtNnaRn9I9U/Q6tegRYpii4ys\r\n"
-"c176NmU+umy6XmuSKV5qD9bSpZWG2nLFnslrN15Lm3fhZxoeMNhBaEDTnLT26yoi\r\n"
-"33gp0mSSWy94ZEqipms+ULF6sY1ZtFW6tpGFoy8CgYAQHhnnvJflIs2ky4q10B60\r\n"
-"ZcxFp3rtDpkp0JxhFLhiizFrujMtZSjYNm5U7KkgPVHhLELEUvCmOnKTt4ap/vZ0\r\n"
-"BxJNe1GZH3pW6SAvGDQpl9sG7uu/vTFP+lCxukmzxB0DrrDcvorEkKMom7ZCCRvW\r\n"
-"KZsZ6YeH2Z81BauRj218kQKBgQCUV/DgKP2985xDTT79N08jUo3hTP5MVYCCuj/+\r\n"
-"UeEw1TvZcx3LJby7P6Xad6a1/BqveaGyFKIfEFIaBUBItk801sDDpDaYc4gL00Xc\r\n"
-"7lFuBHOZkxJYlss5QrGpuOEl9ZwUt5IrFLBdYaKqNHzNVC1pCPfb/JyH6Dr2HUxq\r\n"
-"gxUwAQKBgQCcU6G2L8AG9d9c0UpOyL1tMvFe5Ttw0KjlQVdsh1MP6yigYo9DYuwu\r\n"
-"bHFVW2r0dBTqegP2/KTOxKzaHfC1qf0RGDsUoJCNJrd1cwoCLG8P2EF4w3OBrKqv\r\n"
-"8u4ytY0F+Vlanj5lm3TaoHSVF1+NWPyOTiwevIECGKwSxvlki4fDAA==\r\n"
-"-----END RSA PRIVATE KEY-----\r\n";
-const size_t mbedtls_test_cli_key_rsa_len = sizeof( mbedtls_test_cli_key_rsa );
#endif /* MBEDTLS_RSA_C */
-#if defined(MBEDTLS_PEM_PARSE_C)
-/* Concatenation of all available CA certificates */
-const char mbedtls_test_cas_pem[] =
-#ifdef TEST_CA_CRT_RSA_SHA1
- TEST_CA_CRT_RSA_SHA1
-#endif
-#ifdef TEST_CA_CRT_RSA_SHA256
- TEST_CA_CRT_RSA_SHA256
-#endif
-#ifdef TEST_CA_CRT_EC
- TEST_CA_CRT_EC
-#endif
- "";
-const size_t mbedtls_test_cas_pem_len = sizeof( mbedtls_test_cas_pem );
-#endif
+/* API stability forces us to declare
+ * mbedtls_test_{ca|srv|cli}_{key|pwd|crt}
+ * as pointers. */
+static const char test_ca_key[] = TEST_CA_KEY;
+static const char test_ca_pwd[] = TEST_CA_PWD;
+static const char test_ca_crt[] = TEST_CA_CRT;
+
+static const char test_srv_key[] = TEST_SRV_KEY;
+static const char test_srv_pwd[] = TEST_SRV_PWD;
+static const char test_srv_crt[] = TEST_SRV_CRT;
+
+static const char test_cli_key[] = TEST_CLI_KEY;
+static const char test_cli_pwd[] = TEST_CLI_PWD;
+static const char test_cli_crt[] = TEST_CLI_CRT;
+
+const char *mbedtls_test_ca_key = test_ca_key;
+const char *mbedtls_test_ca_pwd = test_ca_pwd;
+const char *mbedtls_test_ca_crt = test_ca_crt;
+
+const char *mbedtls_test_srv_key = test_srv_key;
+const char *mbedtls_test_srv_pwd = test_srv_pwd;
+const char *mbedtls_test_srv_crt = test_srv_crt;
+
+const char *mbedtls_test_cli_key = test_cli_key;
+const char *mbedtls_test_cli_pwd = test_cli_pwd;
+const char *mbedtls_test_cli_crt = test_cli_crt;
+
+const size_t mbedtls_test_ca_key_len =
+ sizeof( test_ca_key );
+const size_t mbedtls_test_ca_pwd_len =
+ sizeof( test_ca_pwd ) - 1;
+const size_t mbedtls_test_ca_crt_len =
+ sizeof( test_ca_crt );
-/* List of all available CA certificates */
+const size_t mbedtls_test_srv_key_len =
+ sizeof( test_srv_key );
+const size_t mbedtls_test_srv_pwd_len =
+ sizeof( test_srv_pwd ) - 1;
+const size_t mbedtls_test_srv_crt_len =
+ sizeof( test_srv_crt );
+
+const size_t mbedtls_test_cli_key_len =
+ sizeof( test_cli_key );
+const size_t mbedtls_test_cli_pwd_len =
+ sizeof( test_cli_pwd ) - 1;
+const size_t mbedtls_test_cli_crt_len =
+ sizeof( test_cli_crt );
+
+/*
+ *
+ * Lists of certificates
+ *
+ */
+
+/* List of CAs in PEM or DER, depending on config */
const char * mbedtls_test_cas[] = {
-#if defined(TEST_CA_CRT_RSA_SHA1)
+#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_SHA1_C)
mbedtls_test_ca_crt_rsa_sha1,
#endif
-#if defined(TEST_CA_CRT_RSA_SHA256)
+#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_SHA256_C)
mbedtls_test_ca_crt_rsa_sha256,
#endif
#if defined(MBEDTLS_ECDSA_C)
@@ -359,10 +1704,10 @@ const char * mbedtls_test_cas[] = {
NULL
};
const size_t mbedtls_test_cas_len[] = {
-#if defined(TEST_CA_CRT_RSA_SHA1)
+#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_SHA1_C)
sizeof( mbedtls_test_ca_crt_rsa_sha1 ),
#endif
-#if defined(TEST_CA_CRT_RSA_SHA256)
+#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_SHA256_C)
sizeof( mbedtls_test_ca_crt_rsa_sha256 ),
#endif
#if defined(MBEDTLS_ECDSA_C)
@@ -371,36 +1716,53 @@ const size_t mbedtls_test_cas_len[] = {
0
};
+/* List of all available CA certificates in DER format */
+const unsigned char * mbedtls_test_cas_der[] = {
#if defined(MBEDTLS_RSA_C)
-const char *mbedtls_test_ca_crt = mbedtls_test_ca_crt_rsa; /* SHA1 or SHA256 */
-const char *mbedtls_test_ca_key = mbedtls_test_ca_key_rsa;
-const char *mbedtls_test_ca_pwd = mbedtls_test_ca_pwd_rsa;
-const char *mbedtls_test_srv_crt = mbedtls_test_srv_crt_rsa;
-const char *mbedtls_test_srv_key = mbedtls_test_srv_key_rsa;
-const char *mbedtls_test_cli_crt = mbedtls_test_cli_crt_rsa;
-const char *mbedtls_test_cli_key = mbedtls_test_cli_key_rsa;
-const size_t mbedtls_test_ca_crt_len = sizeof( mbedtls_test_ca_crt_rsa );
-const size_t mbedtls_test_ca_key_len = sizeof( mbedtls_test_ca_key_rsa );
-const size_t mbedtls_test_ca_pwd_len = sizeof( mbedtls_test_ca_pwd_rsa ) - 1;
-const size_t mbedtls_test_srv_crt_len = sizeof( mbedtls_test_srv_crt_rsa );
-const size_t mbedtls_test_srv_key_len = sizeof( mbedtls_test_srv_key_rsa );
-const size_t mbedtls_test_cli_crt_len = sizeof( mbedtls_test_cli_crt_rsa );
-const size_t mbedtls_test_cli_key_len = sizeof( mbedtls_test_cli_key_rsa );
-#else /* ! MBEDTLS_RSA_C, so MBEDTLS_ECDSA_C */
-const char *mbedtls_test_ca_crt = mbedtls_test_ca_crt_ec;
-const char *mbedtls_test_ca_key = mbedtls_test_ca_key_ec;
-const char *mbedtls_test_ca_pwd = mbedtls_test_ca_pwd_ec;
-const char *mbedtls_test_srv_crt = mbedtls_test_srv_crt_ec;
-const char *mbedtls_test_srv_key = mbedtls_test_srv_key_ec;
-const char *mbedtls_test_cli_crt = mbedtls_test_cli_crt_ec;
-const char *mbedtls_test_cli_key = mbedtls_test_cli_key_ec;
-const size_t mbedtls_test_ca_crt_len = sizeof( mbedtls_test_ca_crt_ec );
-const size_t mbedtls_test_ca_key_len = sizeof( mbedtls_test_ca_key_ec );
-const size_t mbedtls_test_ca_pwd_len = sizeof( mbedtls_test_ca_pwd_ec ) - 1;
-const size_t mbedtls_test_srv_crt_len = sizeof( mbedtls_test_srv_crt_ec );
-const size_t mbedtls_test_srv_key_len = sizeof( mbedtls_test_srv_key_ec );
-const size_t mbedtls_test_cli_crt_len = sizeof( mbedtls_test_cli_crt_ec );
-const size_t mbedtls_test_cli_key_len = sizeof( mbedtls_test_cli_key_ec );
+#if defined(MBEDTLS_SHA256_C)
+ mbedtls_test_ca_crt_rsa_sha256_der,
+#endif /* MBEDTLS_SHA256_C */
+#if defined(MBEDTLS_SHA1_C)
+ mbedtls_test_ca_crt_rsa_sha1_der,
+#endif /* MBEDTLS_SHA1_C */
#endif /* MBEDTLS_RSA_C */
+#if defined(MBEDTLS_ECDSA_C)
+ mbedtls_test_ca_crt_ec_der,
+#endif /* MBEDTLS_ECDSA_C */
+ NULL
+};
+
+const size_t mbedtls_test_cas_der_len[] = {
+#if defined(MBEDTLS_RSA_C)
+#if defined(MBEDTLS_SHA256_C)
+ sizeof( mbedtls_test_ca_crt_rsa_sha256_der ),
+#endif /* MBEDTLS_SHA256_C */
+#if defined(MBEDTLS_SHA1_C)
+ sizeof( mbedtls_test_ca_crt_rsa_sha1_der ),
+#endif /* MBEDTLS_SHA1_C */
+#endif /* MBEDTLS_RSA_C */
+#if defined(MBEDTLS_ECDSA_C)
+ sizeof( mbedtls_test_ca_crt_ec_der ),
+#endif /* MBEDTLS_ECDSA_C */
+ 0
+};
+
+/* Concatenation of all available CA certificates in PEM format */
+#if defined(MBEDTLS_PEM_PARSE_C)
+const char mbedtls_test_cas_pem[] =
+#if defined(MBEDTLS_RSA_C)
+#if defined(MBEDTLS_SHA256_C)
+ TEST_CA_CRT_RSA_SHA256_PEM
+#endif /* MBEDTLS_SHA256_C */
+#if defined(MBEDTLS_SHA1_C)
+ TEST_CA_CRT_RSA_SHA1_PEM
+#endif /* MBEDTLS_SHA1_C */
+#endif /* MBEDTLS_RSA_C */
+#if defined(MBEDTLS_ECDSA_C)
+ TEST_CA_CRT_EC_PEM
+#endif /* MBEDTLS_ECDSA_C */
+ "";
+const size_t mbedtls_test_cas_pem_len = sizeof( mbedtls_test_cas_pem );
+#endif /* MBEDTLS_PEM_PARSE_C */
#endif /* MBEDTLS_CERTS_C */
diff --git a/thirdparty/mbedtls/library/chacha20.c b/thirdparty/mbedtls/library/chacha20.c
index 0757163e2f..8a3610f0e0 100644
--- a/thirdparty/mbedtls/library/chacha20.c
+++ b/thirdparty/mbedtls/library/chacha20.c
@@ -60,14 +60,14 @@
MBEDTLS_INTERNAL_VALIDATE( cond )
#define BYTES_TO_U32_LE( data, offset ) \
- ( (uint32_t) data[offset] \
- | (uint32_t) ( (uint32_t) data[( offset ) + 1] << 8 ) \
- | (uint32_t) ( (uint32_t) data[( offset ) + 2] << 16 ) \
- | (uint32_t) ( (uint32_t) data[( offset ) + 3] << 24 ) \
+ ( (uint32_t) (data)[offset] \
+ | (uint32_t) ( (uint32_t) (data)[( offset ) + 1] << 8 ) \
+ | (uint32_t) ( (uint32_t) (data)[( offset ) + 2] << 16 ) \
+ | (uint32_t) ( (uint32_t) (data)[( offset ) + 3] << 24 ) \
)
#define ROTL32( value, amount ) \
- ( (uint32_t) ( value << amount ) | ( value >> ( 32 - amount ) ) )
+ ( (uint32_t) ( (value) << (amount) ) | ( (value) >> ( 32 - (amount) ) ) )
#define CHACHA20_CTR_INDEX ( 12U )
diff --git a/thirdparty/mbedtls/library/debug.c b/thirdparty/mbedtls/library/debug.c
index 824cd0236e..36510cdd56 100644
--- a/thirdparty/mbedtls/library/debug.c
+++ b/thirdparty/mbedtls/library/debug.c
@@ -86,8 +86,13 @@ void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
char str[DEBUG_BUF_SIZE];
int ret;
- if( NULL == ssl || NULL == ssl->conf || NULL == ssl->conf->f_dbg || level > debug_threshold )
+ if( NULL == ssl ||
+ NULL == ssl->conf ||
+ NULL == ssl->conf->f_dbg ||
+ level > debug_threshold )
+ {
return;
+ }
va_start( argp, format );
#if defined(_WIN32)
@@ -121,8 +126,13 @@ void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level,
{
char str[DEBUG_BUF_SIZE];
- if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || level > debug_threshold )
+ if( NULL == ssl ||
+ NULL == ssl->conf ||
+ NULL == ssl->conf->f_dbg ||
+ level > debug_threshold )
+ {
return;
+ }
/*
* With non-blocking I/O and examples that just retry immediately,
@@ -146,8 +156,13 @@ void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
char txt[17];
size_t i, idx = 0;
- if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || level > debug_threshold )
+ if( NULL == ssl ||
+ NULL == ssl->conf ||
+ NULL == ssl->conf->f_dbg ||
+ level > debug_threshold )
+ {
return;
+ }
mbedtls_snprintf( str + idx, sizeof( str ) - idx, "dumping '%s' (%u bytes)\n",
text, (unsigned int) len );
@@ -199,8 +214,13 @@ void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level,
{
char str[DEBUG_BUF_SIZE];
- if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || level > debug_threshold )
+ if( NULL == ssl ||
+ NULL == ssl->conf ||
+ NULL == ssl->conf->f_dbg ||
+ level > debug_threshold )
+ {
return;
+ }
mbedtls_snprintf( str, sizeof( str ), "%s(X)", text );
mbedtls_debug_print_mpi( ssl, level, file, line, str, &X->X );
@@ -219,8 +239,14 @@ void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
int j, k, zeros = 1;
size_t i, n, idx = 0;
- if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || X == NULL || level > debug_threshold )
+ if( NULL == ssl ||
+ NULL == ssl->conf ||
+ NULL == ssl->conf->f_dbg ||
+ NULL == X ||
+ level > debug_threshold )
+ {
return;
+ }
for( n = X->n - 1; n > 0; n-- )
if( X->p[n] != 0 )
@@ -345,8 +371,14 @@ void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level,
char str[DEBUG_BUF_SIZE];
int i = 0;
- if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || crt == NULL || level > debug_threshold )
+ if( NULL == ssl ||
+ NULL == ssl->conf ||
+ NULL == ssl->conf->f_dbg ||
+ NULL == crt ||
+ level > debug_threshold )
+ {
return;
+ }
while( crt != NULL )
{
diff --git a/thirdparty/mbedtls/library/des.c b/thirdparty/mbedtls/library/des.c
index ca9e071f32..8a33d82e50 100644
--- a/thirdparty/mbedtls/library/des.c
+++ b/thirdparty/mbedtls/library/des.c
@@ -257,50 +257,57 @@ static const uint32_t RHs[16] =
/*
* Initial Permutation macro
*/
-#define DES_IP(X,Y) \
-{ \
- T = ((X >> 4) ^ Y) & 0x0F0F0F0F; Y ^= T; X ^= (T << 4); \
- T = ((X >> 16) ^ Y) & 0x0000FFFF; Y ^= T; X ^= (T << 16); \
- T = ((Y >> 2) ^ X) & 0x33333333; X ^= T; Y ^= (T << 2); \
- T = ((Y >> 8) ^ X) & 0x00FF00FF; X ^= T; Y ^= (T << 8); \
- Y = ((Y << 1) | (Y >> 31)) & 0xFFFFFFFF; \
- T = (X ^ Y) & 0xAAAAAAAA; Y ^= T; X ^= T; \
- X = ((X << 1) | (X >> 31)) & 0xFFFFFFFF; \
-}
+#define DES_IP(X,Y) \
+ do \
+ { \
+ T = (((X) >> 4) ^ (Y)) & 0x0F0F0F0F; (Y) ^= T; (X) ^= (T << 4); \
+ T = (((X) >> 16) ^ (Y)) & 0x0000FFFF; (Y) ^= T; (X) ^= (T << 16); \
+ T = (((Y) >> 2) ^ (X)) & 0x33333333; (X) ^= T; (Y) ^= (T << 2); \
+ T = (((Y) >> 8) ^ (X)) & 0x00FF00FF; (X) ^= T; (Y) ^= (T << 8); \
+ (Y) = (((Y) << 1) | ((Y) >> 31)) & 0xFFFFFFFF; \
+ T = ((X) ^ (Y)) & 0xAAAAAAAA; (Y) ^= T; (X) ^= T; \
+ (X) = (((X) << 1) | ((X) >> 31)) & 0xFFFFFFFF; \
+ } while( 0 )
/*
* Final Permutation macro
*/
-#define DES_FP(X,Y) \
-{ \
- X = ((X << 31) | (X >> 1)) & 0xFFFFFFFF; \
- T = (X ^ Y) & 0xAAAAAAAA; X ^= T; Y ^= T; \
- Y = ((Y << 31) | (Y >> 1)) & 0xFFFFFFFF; \
- T = ((Y >> 8) ^ X) & 0x00FF00FF; X ^= T; Y ^= (T << 8); \
- T = ((Y >> 2) ^ X) & 0x33333333; X ^= T; Y ^= (T << 2); \
- T = ((X >> 16) ^ Y) & 0x0000FFFF; Y ^= T; X ^= (T << 16); \
- T = ((X >> 4) ^ Y) & 0x0F0F0F0F; Y ^= T; X ^= (T << 4); \
-}
+#define DES_FP(X,Y) \
+ do \
+ { \
+ (X) = (((X) << 31) | ((X) >> 1)) & 0xFFFFFFFF; \
+ T = ((X) ^ (Y)) & 0xAAAAAAAA; (X) ^= T; (Y) ^= T; \
+ (Y) = (((Y) << 31) | ((Y) >> 1)) & 0xFFFFFFFF; \
+ T = (((Y) >> 8) ^ (X)) & 0x00FF00FF; (X) ^= T; (Y) ^= (T << 8); \
+ T = (((Y) >> 2) ^ (X)) & 0x33333333; (X) ^= T; (Y) ^= (T << 2); \
+ T = (((X) >> 16) ^ (Y)) & 0x0000FFFF; (Y) ^= T; (X) ^= (T << 16); \
+ T = (((X) >> 4) ^ (Y)) & 0x0F0F0F0F; (Y) ^= T; (X) ^= (T << 4); \
+ } while( 0 )
/*
* DES round macro
*/
-#define DES_ROUND(X,Y) \
-{ \
- T = *SK++ ^ X; \
- Y ^= SB8[ (T ) & 0x3F ] ^ \
- SB6[ (T >> 8) & 0x3F ] ^ \
- SB4[ (T >> 16) & 0x3F ] ^ \
- SB2[ (T >> 24) & 0x3F ]; \
- \
- T = *SK++ ^ ((X << 28) | (X >> 4)); \
- Y ^= SB7[ (T ) & 0x3F ] ^ \
- SB5[ (T >> 8) & 0x3F ] ^ \
- SB3[ (T >> 16) & 0x3F ] ^ \
- SB1[ (T >> 24) & 0x3F ]; \
-}
-
-#define SWAP(a,b) { uint32_t t = a; a = b; b = t; t = 0; }
+#define DES_ROUND(X,Y) \
+ do \
+ { \
+ T = *SK++ ^ (X); \
+ (Y) ^= SB8[ (T ) & 0x3F ] ^ \
+ SB6[ (T >> 8) & 0x3F ] ^ \
+ SB4[ (T >> 16) & 0x3F ] ^ \
+ SB2[ (T >> 24) & 0x3F ]; \
+ \
+ T = *SK++ ^ (((X) << 28) | ((X) >> 4)); \
+ (Y) ^= SB7[ (T ) & 0x3F ] ^ \
+ SB5[ (T >> 8) & 0x3F ] ^ \
+ SB3[ (T >> 16) & 0x3F ] ^ \
+ SB1[ (T >> 24) & 0x3F ]; \
+ } while( 0 )
+
+#define SWAP(a,b) \
+ do \
+ { \
+ uint32_t t = (a); (a) = (b); (b) = t; t = 0; \
+ } while( 0 )
void mbedtls_des_init( mbedtls_des_context *ctx )
{
diff --git a/thirdparty/mbedtls/library/dhm.c b/thirdparty/mbedtls/library/dhm.c
index fb6937e854..8255632a99 100644
--- a/thirdparty/mbedtls/library/dhm.c
+++ b/thirdparty/mbedtls/library/dhm.c
@@ -649,12 +649,28 @@ int mbedtls_dhm_parse_dhmfile( mbedtls_dhm_context *dhm, const char *path )
#if defined(MBEDTLS_SELF_TEST)
+#if defined(MBEDTLS_PEM_PARSE_C)
static const char mbedtls_test_dhm_params[] =
"-----BEGIN DH PARAMETERS-----\r\n"
"MIGHAoGBAJ419DBEOgmQTzo5qXl5fQcN9TN455wkOL7052HzxxRVMyhYmwQcgJvh\r\n"
"1sa18fyfR9OiVEMYglOpkqVoGLN7qd5aQNNi5W7/C+VBdHTBJcGZJyyP5B3qcz32\r\n"
"9mLJKudlVudV0Qxk5qUJaPZ/xupz0NyoVpviuiBOI1gNi8ovSXWzAgEC\r\n"
"-----END DH PARAMETERS-----\r\n";
+#else /* MBEDTLS_PEM_PARSE_C */
+static const char mbedtls_test_dhm_params[] = {
+ 0x30, 0x81, 0x87, 0x02, 0x81, 0x81, 0x00, 0x9e, 0x35, 0xf4, 0x30, 0x44,
+ 0x3a, 0x09, 0x90, 0x4f, 0x3a, 0x39, 0xa9, 0x79, 0x79, 0x7d, 0x07, 0x0d,
+ 0xf5, 0x33, 0x78, 0xe7, 0x9c, 0x24, 0x38, 0xbe, 0xf4, 0xe7, 0x61, 0xf3,
+ 0xc7, 0x14, 0x55, 0x33, 0x28, 0x58, 0x9b, 0x04, 0x1c, 0x80, 0x9b, 0xe1,
+ 0xd6, 0xc6, 0xb5, 0xf1, 0xfc, 0x9f, 0x47, 0xd3, 0xa2, 0x54, 0x43, 0x18,
+ 0x82, 0x53, 0xa9, 0x92, 0xa5, 0x68, 0x18, 0xb3, 0x7b, 0xa9, 0xde, 0x5a,
+ 0x40, 0xd3, 0x62, 0xe5, 0x6e, 0xff, 0x0b, 0xe5, 0x41, 0x74, 0x74, 0xc1,
+ 0x25, 0xc1, 0x99, 0x27, 0x2c, 0x8f, 0xe4, 0x1d, 0xea, 0x73, 0x3d, 0xf6,
+ 0xf6, 0x62, 0xc9, 0x2a, 0xe7, 0x65, 0x56, 0xe7, 0x55, 0xd1, 0x0c, 0x64,
+ 0xe6, 0xa5, 0x09, 0x68, 0xf6, 0x7f, 0xc6, 0xea, 0x73, 0xd0, 0xdc, 0xa8,
+ 0x56, 0x9b, 0xe2, 0xba, 0x20, 0x4e, 0x23, 0x58, 0x0d, 0x8b, 0xca, 0x2f,
+ 0x49, 0x75, 0xb3, 0x02, 0x01, 0x02 };
+#endif /* MBEDTLS_PEM_PARSE_C */
static const size_t mbedtls_test_dhm_params_len = sizeof( mbedtls_test_dhm_params );
diff --git a/thirdparty/mbedtls/library/ecdh.c b/thirdparty/mbedtls/library/ecdh.c
index da95c60dad..c5726877d5 100644
--- a/thirdparty/mbedtls/library/ecdh.c
+++ b/thirdparty/mbedtls/library/ecdh.c
@@ -49,6 +49,16 @@
typedef mbedtls_ecdh_context mbedtls_ecdh_context_mbed;
#endif
+static mbedtls_ecp_group_id mbedtls_ecdh_grp_id(
+ const mbedtls_ecdh_context *ctx )
+{
+#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
+ return( ctx->grp.id );
+#else
+ return( ctx->grp_id );
+#endif
+}
+
#if !defined(MBEDTLS_ECDH_GEN_PUBLIC_ALT)
/*
* Generate public key (restartable version)
@@ -442,8 +452,21 @@ int mbedtls_ecdh_get_params( mbedtls_ecdh_context *ctx,
ECDH_VALIDATE_RET( side == MBEDTLS_ECDH_OURS ||
side == MBEDTLS_ECDH_THEIRS );
- if( ( ret = mbedtls_ecdh_setup( ctx, key->grp.id ) ) != 0 )
- return( ret );
+ if( mbedtls_ecdh_grp_id( ctx ) == MBEDTLS_ECP_DP_NONE )
+ {
+ /* This is the first call to get_params(). Set up the context
+ * for use with the group. */
+ if( ( ret = mbedtls_ecdh_setup( ctx, key->grp.id ) ) != 0 )
+ return( ret );
+ }
+ else
+ {
+ /* This is not the first call to get_params(). Check that the
+ * current key's group is the same as the context's, which was set
+ * from the first key's group. */
+ if( mbedtls_ecdh_grp_id( ctx ) != key->grp.id )
+ return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA );
+ }
#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
return( ecdh_get_params_internal( ctx, key, side ) );
diff --git a/thirdparty/mbedtls/library/ecdsa.c b/thirdparty/mbedtls/library/ecdsa.c
index 1204ef9949..dc19384d61 100644
--- a/thirdparty/mbedtls/library/ecdsa.c
+++ b/thirdparty/mbedtls/library/ecdsa.c
@@ -800,11 +800,16 @@ cleanup:
int mbedtls_ecdsa_genkey( mbedtls_ecdsa_context *ctx, mbedtls_ecp_group_id gid,
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng )
{
+ int ret = 0;
ECDSA_VALIDATE_RET( ctx != NULL );
ECDSA_VALIDATE_RET( f_rng != NULL );
- return( mbedtls_ecp_group_load( &ctx->grp, gid ) ||
- mbedtls_ecp_gen_keypair( &ctx->grp, &ctx->d, &ctx->Q, f_rng, p_rng ) );
+ ret = mbedtls_ecp_group_load( &ctx->grp, gid );
+ if( ret != 0 )
+ return( ret );
+
+ return( mbedtls_ecp_gen_keypair( &ctx->grp, &ctx->d,
+ &ctx->Q, f_rng, p_rng ) );
}
#endif /* !MBEDTLS_ECDSA_GENKEY_ALT */
diff --git a/thirdparty/mbedtls/library/ecp.c b/thirdparty/mbedtls/library/ecp.c
index ecea5910e0..db36191b9b 100644
--- a/thirdparty/mbedtls/library/ecp.c
+++ b/thirdparty/mbedtls/library/ecp.c
@@ -1046,25 +1046,29 @@ cleanup:
#define INC_MUL_COUNT
#endif
-#define MOD_MUL( N ) do { MBEDTLS_MPI_CHK( ecp_modp( &N, grp ) ); INC_MUL_COUNT } \
- while( 0 )
+#define MOD_MUL( N ) \
+ do \
+ { \
+ MBEDTLS_MPI_CHK( ecp_modp( &(N), grp ) ); \
+ INC_MUL_COUNT \
+ } while( 0 )
/*
* Reduce a mbedtls_mpi mod p in-place, to use after mbedtls_mpi_sub_mpi
* N->s < 0 is a very fast test, which fails only if N is 0
*/
-#define MOD_SUB( N ) \
- while( N.s < 0 && mbedtls_mpi_cmp_int( &N, 0 ) != 0 ) \
- MBEDTLS_MPI_CHK( mbedtls_mpi_add_mpi( &N, &N, &grp->P ) )
+#define MOD_SUB( N ) \
+ while( (N).s < 0 && mbedtls_mpi_cmp_int( &(N), 0 ) != 0 ) \
+ MBEDTLS_MPI_CHK( mbedtls_mpi_add_mpi( &(N), &(N), &grp->P ) )
/*
* Reduce a mbedtls_mpi mod p in-place, to use after mbedtls_mpi_add_mpi and mbedtls_mpi_mul_int.
* We known P, N and the result are positive, so sub_abs is correct, and
* a bit faster.
*/
-#define MOD_ADD( N ) \
- while( mbedtls_mpi_cmp_mpi( &N, &grp->P ) >= 0 ) \
- MBEDTLS_MPI_CHK( mbedtls_mpi_sub_abs( &N, &N, &grp->P ) )
+#define MOD_ADD( N ) \
+ while( mbedtls_mpi_cmp_mpi( &(N), &grp->P ) >= 0 ) \
+ MBEDTLS_MPI_CHK( mbedtls_mpi_sub_abs( &(N), &(N), &grp->P ) )
#if defined(ECP_SHORTWEIERSTRASS)
/*
diff --git a/thirdparty/mbedtls/library/ecp_curves.c b/thirdparty/mbedtls/library/ecp_curves.c
index 731621dc3c..282481d053 100644
--- a/thirdparty/mbedtls/library/ecp_curves.c
+++ b/thirdparty/mbedtls/library/ecp_curves.c
@@ -51,11 +51,11 @@
*/
#if defined(MBEDTLS_HAVE_INT32)
-#define BYTES_TO_T_UINT_4( a, b, c, d ) \
- ( (mbedtls_mpi_uint) a << 0 ) | \
- ( (mbedtls_mpi_uint) b << 8 ) | \
- ( (mbedtls_mpi_uint) c << 16 ) | \
- ( (mbedtls_mpi_uint) d << 24 )
+#define BYTES_TO_T_UINT_4( a, b, c, d ) \
+ ( (mbedtls_mpi_uint) (a) << 0 ) | \
+ ( (mbedtls_mpi_uint) (b) << 8 ) | \
+ ( (mbedtls_mpi_uint) (c) << 16 ) | \
+ ( (mbedtls_mpi_uint) (d) << 24 )
#define BYTES_TO_T_UINT_2( a, b ) \
BYTES_TO_T_UINT_4( a, b, 0, 0 )
@@ -67,14 +67,14 @@
#else /* 64-bits */
#define BYTES_TO_T_UINT_8( a, b, c, d, e, f, g, h ) \
- ( (mbedtls_mpi_uint) a << 0 ) | \
- ( (mbedtls_mpi_uint) b << 8 ) | \
- ( (mbedtls_mpi_uint) c << 16 ) | \
- ( (mbedtls_mpi_uint) d << 24 ) | \
- ( (mbedtls_mpi_uint) e << 32 ) | \
- ( (mbedtls_mpi_uint) f << 40 ) | \
- ( (mbedtls_mpi_uint) g << 48 ) | \
- ( (mbedtls_mpi_uint) h << 56 )
+ ( (mbedtls_mpi_uint) (a) << 0 ) | \
+ ( (mbedtls_mpi_uint) (b) << 8 ) | \
+ ( (mbedtls_mpi_uint) (c) << 16 ) | \
+ ( (mbedtls_mpi_uint) (d) << 24 ) | \
+ ( (mbedtls_mpi_uint) (e) << 32 ) | \
+ ( (mbedtls_mpi_uint) (f) << 40 ) | \
+ ( (mbedtls_mpi_uint) (g) << 48 ) | \
+ ( (mbedtls_mpi_uint) (h) << 56 )
#define BYTES_TO_T_UINT_4( a, b, c, d ) \
BYTES_TO_T_UINT_8( a, b, c, d, 0, 0, 0, 0 )
@@ -890,7 +890,7 @@ static inline void carry64( mbedtls_mpi_uint *dst, mbedtls_mpi_uint *carry )
}
#define WIDTH 8 / sizeof( mbedtls_mpi_uint )
-#define A( i ) N->p + i * WIDTH
+#define A( i ) N->p + (i) * WIDTH
#define ADD( i ) add64( p, A( i ), &c )
#define NEXT p += WIDTH; carry64( p, &c )
#define LAST p += WIDTH; *p = c; while( ++p < end ) *p = 0
@@ -955,7 +955,8 @@ cleanup:
#else /* 64-bit */
#define MAX32 N->n * 2
-#define A( j ) j % 2 ? (uint32_t)( N->p[j/2] >> 32 ) : (uint32_t)( N->p[j/2] )
+#define A( j ) (j) % 2 ? (uint32_t)( N->p[(j)/2] >> 32 ) : \
+ (uint32_t)( N->p[(j)/2] )
#define STORE32 \
if( i % 2 ) { \
N->p[i/2] &= 0x00000000FFFFFFFF; \
@@ -989,20 +990,21 @@ static inline void sub32( uint32_t *dst, uint32_t src, signed char *carry )
* Helpers for the main 'loop'
* (see fix_negative for the motivation of C)
*/
-#define INIT( b ) \
- int ret; \
- signed char c = 0, cc; \
- uint32_t cur; \
- size_t i = 0, bits = b; \
- mbedtls_mpi C; \
- mbedtls_mpi_uint Cp[ b / 8 / sizeof( mbedtls_mpi_uint) + 1 ]; \
- \
- C.s = 1; \
- C.n = b / 8 / sizeof( mbedtls_mpi_uint) + 1; \
- C.p = Cp; \
- memset( Cp, 0, C.n * sizeof( mbedtls_mpi_uint ) ); \
- \
- MBEDTLS_MPI_CHK( mbedtls_mpi_grow( N, b * 2 / 8 / sizeof( mbedtls_mpi_uint ) ) ); \
+#define INIT( b ) \
+ int ret; \
+ signed char c = 0, cc; \
+ uint32_t cur; \
+ size_t i = 0, bits = (b); \
+ mbedtls_mpi C; \
+ mbedtls_mpi_uint Cp[ (b) / 8 / sizeof( mbedtls_mpi_uint) + 1 ]; \
+ \
+ C.s = 1; \
+ C.n = (b) / 8 / sizeof( mbedtls_mpi_uint) + 1; \
+ C.p = Cp; \
+ memset( Cp, 0, C.n * sizeof( mbedtls_mpi_uint ) ); \
+ \
+ MBEDTLS_MPI_CHK( mbedtls_mpi_grow( N, (b) * 2 / 8 / \
+ sizeof( mbedtls_mpi_uint ) ) ); \
LOAD32;
#define NEXT \
diff --git a/thirdparty/mbedtls/library/entropy_poll.c b/thirdparty/mbedtls/library/entropy_poll.c
index ba56b70f77..4556f88a55 100644
--- a/thirdparty/mbedtls/library/entropy_poll.c
+++ b/thirdparty/mbedtls/library/entropy_poll.c
@@ -61,43 +61,28 @@
#define _WIN32_WINNT 0x0400
#endif
#include <windows.h>
-#include <bcrypt.h>
-#if defined(_MSC_VER) && _MSC_VER <= 1600
-/* Visual Studio 2010 and earlier issue a warning when both <stdint.h> and
- * <intsafe.h> are included, as they redefine a number of <TYPE>_MAX constants.
- * These constants are guaranteed to be the same, though, so we suppress the
- * warning when including intsafe.h.
- */
-#pragma warning( push )
-#pragma warning( disable : 4005 )
-#endif
-#include <intsafe.h>
-#if defined(_MSC_VER) && _MSC_VER <= 1600
-#pragma warning( pop )
-#endif
+#include <wincrypt.h>
int mbedtls_platform_entropy_poll( void *data, unsigned char *output, size_t len,
size_t *olen )
{
- ULONG len_as_ulong = 0;
+ HCRYPTPROV provider;
((void) data);
*olen = 0;
- /*
- * BCryptGenRandom takes ULONG for size, which is smaller than size_t on
- * 64-bit Windows platforms. Ensure len's value can be safely converted into
- * a ULONG.
- */
- if ( FAILED( SizeTToULong( len, &len_as_ulong ) ) )
+ if( CryptAcquireContext( &provider, NULL, NULL,
+ PROV_RSA_FULL, CRYPT_VERIFYCONTEXT ) == FALSE )
{
return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
}
- if ( !BCRYPT_SUCCESS( BCryptGenRandom( NULL, output, len_as_ulong, BCRYPT_USE_SYSTEM_PREFERRED_RNG ) ) )
+ if( CryptGenRandom( provider, (DWORD) len, output ) == FALSE )
{
+ CryptReleaseContext( provider, 0 );
return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
}
+ CryptReleaseContext( provider, 0 );
*olen = len;
return( 0 );
diff --git a/thirdparty/mbedtls/library/havege.c b/thirdparty/mbedtls/library/havege.c
index 4dcac02875..54f897c6e7 100644
--- a/thirdparty/mbedtls/library/havege.c
+++ b/thirdparty/mbedtls/library/havege.c
@@ -54,7 +54,7 @@
* ------------------------------------------------------------------------
*/
-#define SWAP(X,Y) { int *T = X; X = Y; Y = T; }
+#define SWAP(X,Y) { int *T = (X); (X) = (Y); (Y) = T; }
#define TST1_ENTER if( PTEST & 1 ) { PTEST ^= 3; PTEST >>= 1;
#define TST2_ENTER if( PTEST & 1 ) { PTEST ^= 3; PTEST >>= 1;
diff --git a/thirdparty/mbedtls/library/md4.c b/thirdparty/mbedtls/library/md4.c
index 3f8ddff31d..828fd42999 100644
--- a/thirdparty/mbedtls/library/md4.c
+++ b/thirdparty/mbedtls/library/md4.c
@@ -137,15 +137,21 @@ int mbedtls_internal_md4_process( mbedtls_md4_context *ctx,
GET_UINT32_LE( X[14], data, 56 );
GET_UINT32_LE( X[15], data, 60 );
-#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
+#define S(x,n) (((x) << (n)) | (((x) & 0xFFFFFFFF) >> (32 - (n))))
A = ctx->state[0];
B = ctx->state[1];
C = ctx->state[2];
D = ctx->state[3];
-#define F(x, y, z) ((x & y) | ((~x) & z))
-#define P(a,b,c,d,x,s) { a += F(b,c,d) + x; a = S(a,s); }
+#define F(x, y, z) (((x) & (y)) | ((~(x)) & (z)))
+#define P(a,b,c,d,x,s) \
+ do \
+ { \
+ (a) += F((b),(c),(d)) + (x); \
+ (a) = S((a),(s)); \
+ } while( 0 )
+
P( A, B, C, D, X[ 0], 3 );
P( D, A, B, C, X[ 1], 7 );
@@ -167,8 +173,13 @@ int mbedtls_internal_md4_process( mbedtls_md4_context *ctx,
#undef P
#undef F
-#define F(x,y,z) ((x & y) | (x & z) | (y & z))
-#define P(a,b,c,d,x,s) { a += F(b,c,d) + x + 0x5A827999; a = S(a,s); }
+#define F(x,y,z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
+#define P(a,b,c,d,x,s) \
+ do \
+ { \
+ (a) += F((b),(c),(d)) + (x) + 0x5A827999; \
+ (a) = S((a),(s)); \
+ } while( 0 )
P( A, B, C, D, X[ 0], 3 );
P( D, A, B, C, X[ 4], 5 );
@@ -190,8 +201,13 @@ int mbedtls_internal_md4_process( mbedtls_md4_context *ctx,
#undef P
#undef F
-#define F(x,y,z) (x ^ y ^ z)
-#define P(a,b,c,d,x,s) { a += F(b,c,d) + x + 0x6ED9EBA1; a = S(a,s); }
+#define F(x,y,z) ((x) ^ (y) ^ (z))
+#define P(a,b,c,d,x,s) \
+ do \
+ { \
+ (a) += F((b),(c),(d)) + (x) + 0x6ED9EBA1; \
+ (a) = S((a),(s)); \
+ } while( 0 )
P( A, B, C, D, X[ 0], 3 );
P( D, A, B, C, X[ 8], 9 );
diff --git a/thirdparty/mbedtls/library/md5.c b/thirdparty/mbedtls/library/md5.c
index 2a740cda81..a93da8a061 100644
--- a/thirdparty/mbedtls/library/md5.c
+++ b/thirdparty/mbedtls/library/md5.c
@@ -136,19 +136,22 @@ int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
GET_UINT32_LE( X[14], data, 56 );
GET_UINT32_LE( X[15], data, 60 );
-#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
+#define S(x,n) \
+ ( ( (x) << (n) ) | ( ( (x) & 0xFFFFFFFF) >> ( 32 - (n) ) ) )
-#define P(a,b,c,d,k,s,t) \
-{ \
- a += F(b,c,d) + X[k] + t; a = S(a,s) + b; \
-}
+#define P(a,b,c,d,k,s,t) \
+ do \
+ { \
+ (a) += F((b),(c),(d)) + X[(k)] + (t); \
+ (a) = S((a),(s)) + (b); \
+ } while( 0 )
A = ctx->state[0];
B = ctx->state[1];
C = ctx->state[2];
D = ctx->state[3];
-#define F(x,y,z) (z ^ (x & (y ^ z)))
+#define F(x,y,z) ((z) ^ ((x) & ((y) ^ (z))))
P( A, B, C, D, 0, 7, 0xD76AA478 );
P( D, A, B, C, 1, 12, 0xE8C7B756 );
@@ -169,7 +172,7 @@ int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
#undef F
-#define F(x,y,z) (y ^ (z & (x ^ y)))
+#define F(x,y,z) ((y) ^ ((z) & ((x) ^ (y))))
P( A, B, C, D, 1, 5, 0xF61E2562 );
P( D, A, B, C, 6, 9, 0xC040B340 );
@@ -190,7 +193,7 @@ int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
#undef F
-#define F(x,y,z) (x ^ y ^ z)
+#define F(x,y,z) ((x) ^ (y) ^ (z))
P( A, B, C, D, 5, 4, 0xFFFA3942 );
P( D, A, B, C, 8, 11, 0x8771F681 );
@@ -211,7 +214,7 @@ int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
#undef F
-#define F(x,y,z) (y ^ (x | ~z))
+#define F(x,y,z) ((y) ^ ((x) | ~(z)))
P( A, B, C, D, 0, 6, 0xF4292244 );
P( D, A, B, C, 7, 10, 0x432AFF97 );
diff --git a/thirdparty/mbedtls/library/oid.c b/thirdparty/mbedtls/library/oid.c
index edea950f8f..33f437cbe6 100644
--- a/thirdparty/mbedtls/library/oid.c
+++ b/thirdparty/mbedtls/library/oid.c
@@ -54,22 +54,24 @@
* Macro to generate an internal function for oid_XXX_from_asn1() (used by
* the other functions)
*/
-#define FN_OID_TYPED_FROM_ASN1( TYPE_T, NAME, LIST ) \
-static const TYPE_T * oid_ ## NAME ## _from_asn1( const mbedtls_asn1_buf *oid ) \
-{ \
- const TYPE_T *p = LIST; \
- const mbedtls_oid_descriptor_t *cur = (const mbedtls_oid_descriptor_t *) p; \
- if( p == NULL || oid == NULL ) return( NULL ); \
- while( cur->asn1 != NULL ) { \
- if( cur->asn1_len == oid->len && \
- memcmp( cur->asn1, oid->p, oid->len ) == 0 ) { \
- return( p ); \
- } \
- p++; \
- cur = (const mbedtls_oid_descriptor_t *) p; \
- } \
- return( NULL ); \
-}
+#define FN_OID_TYPED_FROM_ASN1( TYPE_T, NAME, LIST ) \
+ static const TYPE_T * oid_ ## NAME ## _from_asn1( \
+ const mbedtls_asn1_buf *oid ) \
+ { \
+ const TYPE_T *p = (LIST); \
+ const mbedtls_oid_descriptor_t *cur = \
+ (const mbedtls_oid_descriptor_t *) p; \
+ if( p == NULL || oid == NULL ) return( NULL ); \
+ while( cur->asn1 != NULL ) { \
+ if( cur->asn1_len == oid->len && \
+ memcmp( cur->asn1, oid->p, oid->len ) == 0 ) { \
+ return( p ); \
+ } \
+ p++; \
+ cur = (const mbedtls_oid_descriptor_t *) p; \
+ } \
+ return( NULL ); \
+ }
/*
* Macro to generate a function for retrieving a single attribute from the
@@ -103,12 +105,13 @@ int FN_NAME( const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1 )
*/
#define FN_OID_GET_ATTR2(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, ATTR1, \
ATTR2_TYPE, ATTR2) \
-int FN_NAME( const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1, ATTR2_TYPE * ATTR2 ) \
+int FN_NAME( const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1, \
+ ATTR2_TYPE * ATTR2 ) \
{ \
const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid ); \
- if( data == NULL ) return( MBEDTLS_ERR_OID_NOT_FOUND ); \
- *ATTR1 = data->ATTR1; \
- *ATTR2 = data->ATTR2; \
+ if( data == NULL ) return( MBEDTLS_ERR_OID_NOT_FOUND ); \
+ *(ATTR1) = data->ATTR1; \
+ *(ATTR2) = data->ATTR2; \
return( 0 ); \
}
@@ -119,16 +122,16 @@ int FN_NAME( const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1, ATTR2_TYPE * ATTR2
#define FN_OID_GET_OID_BY_ATTR1(FN_NAME, TYPE_T, LIST, ATTR1_TYPE, ATTR1) \
int FN_NAME( ATTR1_TYPE ATTR1, const char **oid, size_t *olen ) \
{ \
- const TYPE_T *cur = LIST; \
+ const TYPE_T *cur = (LIST); \
while( cur->descriptor.asn1 != NULL ) { \
- if( cur->ATTR1 == ATTR1 ) { \
+ if( cur->ATTR1 == (ATTR1) ) { \
*oid = cur->descriptor.asn1; \
*olen = cur->descriptor.asn1_len; \
return( 0 ); \
} \
cur++; \
} \
- return( MBEDTLS_ERR_OID_NOT_FOUND ); \
+ return( MBEDTLS_ERR_OID_NOT_FOUND ); \
}
/*
@@ -140,9 +143,9 @@ int FN_NAME( ATTR1_TYPE ATTR1, const char **oid, size_t *olen ) \
int FN_NAME( ATTR1_TYPE ATTR1, ATTR2_TYPE ATTR2, const char **oid , \
size_t *olen ) \
{ \
- const TYPE_T *cur = LIST; \
+ const TYPE_T *cur = (LIST); \
while( cur->descriptor.asn1 != NULL ) { \
- if( cur->ATTR1 == ATTR1 && cur->ATTR2 == ATTR2 ) { \
+ if( cur->ATTR1 == (ATTR1) && cur->ATTR2 == (ATTR2) ) { \
*oid = cur->descriptor.asn1; \
*olen = cur->descriptor.asn1_len; \
return( 0 ); \
diff --git a/thirdparty/mbedtls/library/poly1305.c b/thirdparty/mbedtls/library/poly1305.c
index b274119181..2b56c5f7ef 100644
--- a/thirdparty/mbedtls/library/poly1305.c
+++ b/thirdparty/mbedtls/library/poly1305.c
@@ -58,10 +58,10 @@
#define POLY1305_BLOCK_SIZE_BYTES ( 16U )
#define BYTES_TO_U32_LE( data, offset ) \
- ( (uint32_t) data[offset] \
- | (uint32_t) ( (uint32_t) data[( offset ) + 1] << 8 ) \
- | (uint32_t) ( (uint32_t) data[( offset ) + 2] << 16 ) \
- | (uint32_t) ( (uint32_t) data[( offset ) + 3] << 24 ) \
+ ( (uint32_t) (data)[offset] \
+ | (uint32_t) ( (uint32_t) (data)[( offset ) + 1] << 8 ) \
+ | (uint32_t) ( (uint32_t) (data)[( offset ) + 2] << 16 ) \
+ | (uint32_t) ( (uint32_t) (data)[( offset ) + 3] << 24 ) \
)
/*
diff --git a/thirdparty/mbedtls/library/ripemd160.c b/thirdparty/mbedtls/library/ripemd160.c
index bd25ada62c..0791ae4cc9 100644
--- a/thirdparty/mbedtls/library/ripemd160.c
+++ b/thirdparty/mbedtls/library/ripemd160.c
@@ -147,22 +147,29 @@ int mbedtls_internal_ripemd160_process( mbedtls_ripemd160_context *ctx,
D = Dp = ctx->state[3];
E = Ep = ctx->state[4];
-#define F1( x, y, z ) ( x ^ y ^ z )
-#define F2( x, y, z ) ( ( x & y ) | ( ~x & z ) )
-#define F3( x, y, z ) ( ( x | ~y ) ^ z )
-#define F4( x, y, z ) ( ( x & z ) | ( y & ~z ) )
-#define F5( x, y, z ) ( x ^ ( y | ~z ) )
-
-#define S( x, n ) ( ( x << n ) | ( x >> (32 - n) ) )
-
-#define P( a, b, c, d, e, r, s, f, k ) \
- a += f( b, c, d ) + X[r] + k; \
- a = S( a, s ) + e; \
- c = S( c, 10 );
-
-#define P2( a, b, c, d, e, r, s, rp, sp ) \
- P( a, b, c, d, e, r, s, F, K ); \
- P( a ## p, b ## p, c ## p, d ## p, e ## p, rp, sp, Fp, Kp );
+#define F1( x, y, z ) ( (x) ^ (y) ^ (z) )
+#define F2( x, y, z ) ( ( (x) & (y) ) | ( ~(x) & (z) ) )
+#define F3( x, y, z ) ( ( (x) | ~(y) ) ^ (z) )
+#define F4( x, y, z ) ( ( (x) & (z) ) | ( (y) & ~(z) ) )
+#define F5( x, y, z ) ( (x) ^ ( (y) | ~(z) ) )
+
+#define S( x, n ) ( ( (x) << (n) ) | ( (x) >> (32 - (n)) ) )
+
+#define P( a, b, c, d, e, r, s, f, k ) \
+ do \
+ { \
+ (a) += f( (b), (c), (d) ) + X[r] + (k); \
+ (a) = S( (a), (s) ) + (e); \
+ (c) = S( (c), 10 ); \
+ } while( 0 )
+
+#define P2( a, b, c, d, e, r, s, rp, sp ) \
+ do \
+ { \
+ P( (a), (b), (c), (d), (e), (r), (s), F, K ); \
+ P( a ## p, b ## p, c ## p, d ## p, e ## p, \
+ (rp), (sp), Fp, Kp ); \
+ } while( 0 )
#define F F1
#define K 0x00000000
diff --git a/thirdparty/mbedtls/library/sha1.c b/thirdparty/mbedtls/library/sha1.c
index e8d4096fbb..355c83d2f7 100644
--- a/thirdparty/mbedtls/library/sha1.c
+++ b/thirdparty/mbedtls/library/sha1.c
@@ -152,19 +152,21 @@ int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx,
GET_UINT32_BE( W[14], data, 56 );
GET_UINT32_BE( W[15], data, 60 );
-#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
-
-#define R(t) \
-( \
- temp = W[( t - 3 ) & 0x0F] ^ W[( t - 8 ) & 0x0F] ^ \
- W[( t - 14 ) & 0x0F] ^ W[ t & 0x0F], \
- ( W[t & 0x0F] = S(temp,1) ) \
-)
-
-#define P(a,b,c,d,e,x) \
-{ \
- e += S(a,5) + F(b,c,d) + K + x; b = S(b,30); \
-}
+#define S(x,n) (((x) << (n)) | (((x) & 0xFFFFFFFF) >> (32 - (n))))
+
+#define R(t) \
+ ( \
+ temp = W[( (t) - 3 ) & 0x0F] ^ W[( (t) - 8 ) & 0x0F] ^ \
+ W[( (t) - 14 ) & 0x0F] ^ W[ (t) & 0x0F], \
+ ( W[(t) & 0x0F] = S(temp,1) ) \
+ )
+
+#define P(a,b,c,d,e,x) \
+ do \
+ { \
+ (e) += S((a),5) + F((b),(c),(d)) + K + (x); \
+ (b) = S((b),30); \
+ } while( 0 )
A = ctx->state[0];
B = ctx->state[1];
@@ -172,7 +174,7 @@ int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx,
D = ctx->state[3];
E = ctx->state[4];
-#define F(x,y,z) (z ^ (x & (y ^ z)))
+#define F(x,y,z) ((z) ^ ((x) & ((y) ^ (z))))
#define K 0x5A827999
P( A, B, C, D, E, W[0] );
@@ -199,7 +201,7 @@ int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx,
#undef K
#undef F
-#define F(x,y,z) (x ^ y ^ z)
+#define F(x,y,z) ((x) ^ (y) ^ (z))
#define K 0x6ED9EBA1
P( A, B, C, D, E, R(20) );
@@ -226,7 +228,7 @@ int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx,
#undef K
#undef F
-#define F(x,y,z) ((x & y) | (z & (x | y)))
+#define F(x,y,z) (((x) & (y)) | ((z) & ((x) | (y))))
#define K 0x8F1BBCDC
P( A, B, C, D, E, R(40) );
@@ -253,7 +255,7 @@ int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx,
#undef K
#undef F
-#define F(x,y,z) (x ^ y ^ z)
+#define F(x,y,z) ((x) ^ (y) ^ (z))
#define K 0xCA62C1D6
P( A, B, C, D, E, R(60) );
diff --git a/thirdparty/mbedtls/library/sha256.c b/thirdparty/mbedtls/library/sha256.c
index 8a540adfbe..2dc0e1a2c9 100644
--- a/thirdparty/mbedtls/library/sha256.c
+++ b/thirdparty/mbedtls/library/sha256.c
@@ -172,8 +172,8 @@ static const uint32_t K[] =
0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2,
};
-#define SHR(x,n) ((x & 0xFFFFFFFF) >> n)
-#define ROTR(x,n) (SHR(x,n) | (x << (32 - n)))
+#define SHR(x,n) (((x) & 0xFFFFFFFF) >> (n))
+#define ROTR(x,n) (SHR(x,n) | ((x) << (32 - (n))))
#define S0(x) (ROTR(x, 7) ^ ROTR(x,18) ^ SHR(x, 3))
#define S1(x) (ROTR(x,17) ^ ROTR(x,19) ^ SHR(x,10))
@@ -181,21 +181,22 @@ static const uint32_t K[] =
#define S2(x) (ROTR(x, 2) ^ ROTR(x,13) ^ ROTR(x,22))
#define S3(x) (ROTR(x, 6) ^ ROTR(x,11) ^ ROTR(x,25))
-#define F0(x,y,z) ((x & y) | (z & (x | y)))
-#define F1(x,y,z) (z ^ (x & (y ^ z)))
+#define F0(x,y,z) (((x) & (y)) | ((z) & ((x) | (y))))
+#define F1(x,y,z) ((z) ^ ((x) & ((y) ^ (z))))
#define R(t) \
-( \
- W[t] = S1(W[t - 2]) + W[t - 7] + \
- S0(W[t - 15]) + W[t - 16] \
-)
-
-#define P(a,b,c,d,e,f,g,h,x,K) \
-{ \
- temp1 = h + S3(e) + F1(e,f,g) + K + x; \
- temp2 = S2(a) + F0(a,b,c); \
- d += temp1; h = temp1 + temp2; \
-}
+ ( \
+ W[t] = S1(W[(t) - 2]) + W[(t) - 7] + \
+ S0(W[(t) - 15]) + W[(t) - 16] \
+ )
+
+#define P(a,b,c,d,e,f,g,h,x,K) \
+ do \
+ { \
+ temp1 = (h) + S3(e) + F1((e),(f),(g)) + (K) + (x); \
+ temp2 = S2(a) + F0((a),(b),(c)); \
+ (d) += temp1; (h) = temp1 + temp2; \
+ } while( 0 )
int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
const unsigned char data[64] )
diff --git a/thirdparty/mbedtls/library/sha512.c b/thirdparty/mbedtls/library/sha512.c
index 941ecda762..bdd20b284a 100644
--- a/thirdparty/mbedtls/library/sha512.c
+++ b/thirdparty/mbedtls/library/sha512.c
@@ -224,8 +224,8 @@ int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx,
SHA512_VALIDATE_RET( ctx != NULL );
SHA512_VALIDATE_RET( (const unsigned char *)data != NULL );
-#define SHR(x,n) (x >> n)
-#define ROTR(x,n) (SHR(x,n) | (x << (64 - n)))
+#define SHR(x,n) ((x) >> (n))
+#define ROTR(x,n) (SHR((x),(n)) | ((x) << (64 - (n))))
#define S0(x) (ROTR(x, 1) ^ ROTR(x, 8) ^ SHR(x, 7))
#define S1(x) (ROTR(x,19) ^ ROTR(x,61) ^ SHR(x, 6))
@@ -233,15 +233,16 @@ int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx,
#define S2(x) (ROTR(x,28) ^ ROTR(x,34) ^ ROTR(x,39))
#define S3(x) (ROTR(x,14) ^ ROTR(x,18) ^ ROTR(x,41))
-#define F0(x,y,z) ((x & y) | (z & (x | y)))
-#define F1(x,y,z) (z ^ (x & (y ^ z)))
+#define F0(x,y,z) (((x) & (y)) | ((z) & ((x) | (y))))
+#define F1(x,y,z) ((z) ^ ((x) & ((y) ^ (z))))
-#define P(a,b,c,d,e,f,g,h,x,K) \
-{ \
- temp1 = h + S3(e) + F1(e,f,g) + K + x; \
- temp2 = S2(a) + F0(a,b,c); \
- d += temp1; h = temp1 + temp2; \
-}
+#define P(a,b,c,d,e,f,g,h,x,K) \
+ do \
+ { \
+ temp1 = (h) + S3(e) + F1((e),(f),(g)) + (K) + (x); \
+ temp2 = S2(a) + F0((a),(b),(c)); \
+ (d) += temp1; (h) = temp1 + temp2; \
+ } while( 0 )
for( i = 0; i < 16; i++ )
{
diff --git a/thirdparty/mbedtls/library/ssl_ciphersuites.c b/thirdparty/mbedtls/library/ssl_ciphersuites.c
index 745474effe..518f7dde00 100644
--- a/thirdparty/mbedtls/library/ssl_ciphersuites.c
+++ b/thirdparty/mbedtls/library/ssl_ciphersuites.c
@@ -43,11 +43,11 @@
/*
* Ordered from most preferred to least preferred in terms of security.
*
- * Current rule (except rc4, weak and null which come last):
+ * Current rule (except RC4 and 3DES, weak and null which come last):
* 1. By key exchange:
* Forward-secure non-PSK > forward-secure PSK > ECJPAKE > other non-PSK > other PSK
* 2. By key length and cipher:
- * ChaCha > AES-256 > Camellia-256 > ARIA-256 > AES-128 > Camellia-128 > ARIA-128 > 3DES
+ * ChaCha > AES-256 > Camellia-256 > ARIA-256 > AES-128 > Camellia-128 > ARIA-128
* 3. By cipher mode when relevant GCM > CCM > CBC > CCM_8
* 4. By hash function used when relevant
* 5. By key exchange/auth again: EC > non-EC
@@ -126,11 +126,6 @@ static const int ciphersuite_preference[] =
MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256,
MBEDTLS_TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256,
- /* All remaining >= 128-bit ephemeral suites */
- MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA,
- MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA,
- MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA,
-
/* The PSK ephemeral suites */
MBEDTLS_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256,
MBEDTLS_TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256,
@@ -162,9 +157,6 @@ static const int ciphersuite_preference[] =
MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256,
MBEDTLS_TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256,
- MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA,
- MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA,
-
/* The ECJPAKE suite */
MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8,
@@ -228,11 +220,6 @@ static const int ciphersuite_preference[] =
MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256,
MBEDTLS_TLS_RSA_WITH_ARIA_128_CBC_SHA256,
- /* All remaining >= 128-bit suites */
- MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA,
- MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA,
- MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA,
-
/* The RSA PSK suites */
MBEDTLS_TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256,
MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384,
@@ -251,8 +238,6 @@ static const int ciphersuite_preference[] =
MBEDTLS_TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256,
MBEDTLS_TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256,
- MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA,
-
/* The PSK suites */
MBEDTLS_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256,
MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384,
@@ -275,6 +260,16 @@ static const int ciphersuite_preference[] =
MBEDTLS_TLS_PSK_WITH_ARIA_128_GCM_SHA256,
MBEDTLS_TLS_PSK_WITH_ARIA_128_CBC_SHA256,
+ /* 3DES suites */
+ MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA,
+ MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA,
+ MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA,
+ MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA,
+ MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA,
+ MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA,
+ MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA,
+ MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA,
+ MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA,
MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA,
/* RC4 suites */
@@ -2187,6 +2182,26 @@ const int *mbedtls_ssl_list_ciphersuites( void )
static int supported_ciphersuites[MAX_CIPHERSUITES];
static int supported_init = 0;
+static int ciphersuite_is_removed( const mbedtls_ssl_ciphersuite_t *cs_info )
+{
+ (void)cs_info;
+
+#if defined(MBEDTLS_REMOVE_ARC4_CIPHERSUITES)
+ if( cs_info->cipher == MBEDTLS_CIPHER_ARC4_128 )
+ return( 1 );
+#endif /* MBEDTLS_REMOVE_ARC4_CIPHERSUITES */
+
+#if defined(MBEDTLS_REMOVE_3DES_CIPHERSUITES)
+ if( cs_info->cipher == MBEDTLS_CIPHER_DES_EDE3_ECB ||
+ cs_info->cipher == MBEDTLS_CIPHER_DES_EDE3_CBC )
+ {
+ return( 1 );
+ }
+#endif /* MBEDTLS_REMOVE_3DES_CIPHERSUITES */
+
+ return( 0 );
+}
+
const int *mbedtls_ssl_list_ciphersuites( void )
{
/*
@@ -2202,14 +2217,12 @@ const int *mbedtls_ssl_list_ciphersuites( void )
*p != 0 && q < supported_ciphersuites + MAX_CIPHERSUITES - 1;
p++ )
{
-#if defined(MBEDTLS_REMOVE_ARC4_CIPHERSUITES)
const mbedtls_ssl_ciphersuite_t *cs_info;
if( ( cs_info = mbedtls_ssl_ciphersuite_from_id( *p ) ) != NULL &&
- cs_info->cipher != MBEDTLS_CIPHER_ARC4_128 )
-#else
- if( mbedtls_ssl_ciphersuite_from_id( *p ) != NULL )
-#endif
+ !ciphersuite_is_removed( cs_info ) )
+ {
*(q++) = *p;
+ }
}
*q = 0;
diff --git a/thirdparty/mbedtls/library/version_features.c b/thirdparty/mbedtls/library/version_features.c
index 4c36d3caaa..24143d052c 100644
--- a/thirdparty/mbedtls/library/version_features.c
+++ b/thirdparty/mbedtls/library/version_features.c
@@ -300,6 +300,9 @@ static const char *features[] = {
#if defined(MBEDTLS_REMOVE_ARC4_CIPHERSUITES)
"MBEDTLS_REMOVE_ARC4_CIPHERSUITES",
#endif /* MBEDTLS_REMOVE_ARC4_CIPHERSUITES */
+#if defined(MBEDTLS_REMOVE_3DES_CIPHERSUITES)
+ "MBEDTLS_REMOVE_3DES_CIPHERSUITES",
+#endif /* MBEDTLS_REMOVE_3DES_CIPHERSUITES */
#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
"MBEDTLS_ECP_DP_SECP192R1_ENABLED",
#endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */
diff --git a/thirdparty/mbedtls/library/x509.c b/thirdparty/mbedtls/library/x509.c
index 52b5b649f7..a562df7ca3 100644
--- a/thirdparty/mbedtls/library/x509.c
+++ b/thirdparty/mbedtls/library/x509.c
@@ -67,8 +67,15 @@
#include <time.h>
#endif
-#define CHECK(code) if( ( ret = code ) != 0 ){ return( ret ); }
-#define CHECK_RANGE(min, max, val) if( val < min || val > max ){ return( ret ); }
+#define CHECK(code) if( ( ret = ( code ) ) != 0 ){ return( ret ); }
+#define CHECK_RANGE(min, max, val) \
+ do \
+ { \
+ if( ( val ) < ( min ) || ( val ) > ( max ) ) \
+ { \
+ return( ret ); \
+ } \
+ } while( 0 )
/*
* CertificateSerialNumber ::= INTEGER
@@ -354,6 +361,8 @@ static int x509_get_attr_type_value( unsigned char **p,
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
return( MBEDTLS_ERR_X509_INVALID_NAME + ret );
+ end = *p + len;
+
if( ( end - *p ) < 1 )
return( MBEDTLS_ERR_X509_INVALID_NAME +
MBEDTLS_ERR_ASN1_OUT_OF_DATA );
@@ -387,6 +396,12 @@ static int x509_get_attr_type_value( unsigned char **p,
val->p = *p;
*p += val->len;
+ if( *p != end )
+ {
+ return( MBEDTLS_ERR_X509_INVALID_NAME +
+ MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
+ }
+
cur->next = NULL;
return( 0 );
@@ -693,30 +708,25 @@ int mbedtls_x509_get_sig_alg( const mbedtls_x509_buf *sig_oid, const mbedtls_x50
* be either manually updated or extensions should be parsed!)
*/
int mbedtls_x509_get_ext( unsigned char **p, const unsigned char *end,
- mbedtls_x509_buf *ext, int tag )
+ mbedtls_x509_buf *ext, int tag )
{
int ret;
size_t len;
- if( *p == end )
- return( 0 );
-
- ext->tag = **p;
-
- if( ( ret = mbedtls_asn1_get_tag( p, end, &ext->len,
- MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | tag ) ) != 0 )
- return( ret );
+ /* Extension structure use EXPLICIT tagging. That is, the actual
+ * `Extensions` structure is wrapped by a tag-length pair using
+ * the respective context-specific tag. */
+ ret = mbedtls_asn1_get_tag( p, end, &ext->len,
+ MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | tag );
+ if( ret != 0 )
+ return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
- ext->p = *p;
- end = *p + ext->len;
+ ext->tag = MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | tag;
+ ext->p = *p;
+ end = *p + ext->len;
/*
* Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension
- *
- * Extension ::= SEQUENCE {
- * extnID OBJECT IDENTIFIER,
- * critical BOOLEAN DEFAULT FALSE,
- * extnValue OCTET STRING }
*/
if( ( ret = mbedtls_asn1_get_tag( p, end, &len,
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
@@ -1001,8 +1011,8 @@ int mbedtls_x509_time_is_future( const mbedtls_x509_time *from )
*/
int mbedtls_x509_self_test( int verbose )
{
+ int ret = 0;
#if defined(MBEDTLS_CERTS_C) && defined(MBEDTLS_SHA256_C)
- int ret;
uint32_t flags;
mbedtls_x509_crt cacert;
mbedtls_x509_crt clicert;
@@ -1010,6 +1020,7 @@ int mbedtls_x509_self_test( int verbose )
if( verbose != 0 )
mbedtls_printf( " X.509 certificate load: " );
+ mbedtls_x509_crt_init( &cacert );
mbedtls_x509_crt_init( &clicert );
ret = mbedtls_x509_crt_parse( &clicert, (const unsigned char *) mbedtls_test_cli_crt,
@@ -1019,11 +1030,9 @@ int mbedtls_x509_self_test( int verbose )
if( verbose != 0 )
mbedtls_printf( "failed\n" );
- return( ret );
+ goto cleanup;
}
- mbedtls_x509_crt_init( &cacert );
-
ret = mbedtls_x509_crt_parse( &cacert, (const unsigned char *) mbedtls_test_ca_crt,
mbedtls_test_ca_crt_len );
if( ret != 0 )
@@ -1031,7 +1040,7 @@ int mbedtls_x509_self_test( int verbose )
if( verbose != 0 )
mbedtls_printf( "failed\n" );
- return( ret );
+ goto cleanup;
}
if( verbose != 0 )
@@ -1043,20 +1052,19 @@ int mbedtls_x509_self_test( int verbose )
if( verbose != 0 )
mbedtls_printf( "failed\n" );
- return( ret );
+ goto cleanup;
}
if( verbose != 0 )
mbedtls_printf( "passed\n\n");
+cleanup:
mbedtls_x509_crt_free( &cacert );
mbedtls_x509_crt_free( &clicert );
-
- return( 0 );
#else
((void) verbose);
- return( 0 );
#endif /* MBEDTLS_CERTS_C && MBEDTLS_SHA1_C */
+ return( ret );
}
#endif /* MBEDTLS_SELF_TEST */
diff --git a/thirdparty/mbedtls/library/x509_crl.c b/thirdparty/mbedtls/library/x509_crl.c
index 8450f87e03..00f8545d7c 100644
--- a/thirdparty/mbedtls/library/x509_crl.c
+++ b/thirdparty/mbedtls/library/x509_crl.c
@@ -103,17 +103,17 @@ static int x509_get_crl_ext( unsigned char **p,
{
int ret;
+ if( *p == end )
+ return( 0 );
+
/*
* crlExtensions [0] EXPLICIT Extensions OPTIONAL
* -- if present, version MUST be v2
*/
if( ( ret = mbedtls_x509_get_ext( p, end, ext, 0 ) ) != 0 )
- {
- if( ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG )
- return( 0 );
-
return( ret );
- }
+
+ end = ext->p + ext->len;
while( *p < end )
{
diff --git a/thirdparty/mbedtls/library/x509_crt.c b/thirdparty/mbedtls/library/x509_crt.c
index 35a134950e..97e1d72e3c 100644
--- a/thirdparty/mbedtls/library/x509_crt.c
+++ b/thirdparty/mbedtls/library/x509_crt.c
@@ -65,19 +65,6 @@
#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
#include <windows.h>
-#if defined(_MSC_VER) && _MSC_VER <= 1600
-/* Visual Studio 2010 and earlier issue a warning when both <stdint.h> and
- * <intsafe.h> are included, as they redefine a number of <TYPE>_MAX constants.
- * These constants are guaranteed to be the same, though, so we suppress the
- * warning when including intsafe.h.
- */
-#pragma warning( push )
-#pragma warning( disable : 4005 )
-#endif
-#include <intsafe.h>
-#if defined(_MSC_VER) && _MSC_VER <= 1600
-#pragma warning( pop )
-#endif
#else
#include <time.h>
#endif
@@ -381,7 +368,7 @@ static void x509_crt_verify_chain_reset(
for( i = 0; i < MBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE; i++ )
{
ver_chain->items[i].crt = NULL;
- ver_chain->items[i].flags = -1;
+ ver_chain->items[i].flags = (uint32_t) -1;
}
ver_chain->len = 0;
@@ -406,7 +393,7 @@ static int x509_get_version( unsigned char **p,
return( 0 );
}
- return( ret );
+ return( MBEDTLS_ERR_X509_INVALID_FORMAT + ret );
}
end = *p + len;
@@ -473,7 +460,7 @@ static int x509_get_uid( unsigned char **p,
if( ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG )
return( 0 );
- return( ret );
+ return( MBEDTLS_ERR_X509_INVALID_FORMAT + ret );
}
uid->p = *p;
@@ -712,14 +699,13 @@ static int x509_get_crt_ext( unsigned char **p,
size_t len;
unsigned char *end_ext_data, *end_ext_octet;
- if( ( ret = mbedtls_x509_get_ext( p, end, &crt->v3_ext, 3 ) ) != 0 )
- {
- if( ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG )
- return( 0 );
+ if( *p == end )
+ return( 0 );
+ if( ( ret = mbedtls_x509_get_ext( p, end, &crt->v3_ext, 3 ) ) != 0 )
return( ret );
- }
+ end = crt->v3_ext.p + crt->v3_ext.len;
while( *p < end )
{
/*
@@ -1291,7 +1277,6 @@ int mbedtls_x509_crt_parse_path( mbedtls_x509_crt *chain, const char *path )
char filename[MAX_PATH];
char *p;
size_t len = strlen( path );
- int lengthAsInt = 0;
WIN32_FIND_DATAW file_data;
HANDLE hFind;
@@ -1306,18 +1291,7 @@ int mbedtls_x509_crt_parse_path( mbedtls_x509_crt *chain, const char *path )
p = filename + len;
filename[len++] = '*';
- if ( FAILED ( SizeTToInt( len, &lengthAsInt ) ) )
- return( MBEDTLS_ERR_X509_FILE_IO_ERROR );
-
- /*
- * Note this function uses the code page CP_ACP, and assumes the incoming
- * string is encoded in ANSI, before translating it into Unicode. If the
- * incoming string were changed to be UTF-8, then the length check needs to
- * change to check the number of characters, not the number of bytes, in the
- * incoming string are less than MAX_PATH to avoid a buffer overrun with
- * MultiByteToWideChar().
- */
- w_ret = MultiByteToWideChar( CP_ACP, 0, filename, lengthAsInt, szDir,
+ w_ret = MultiByteToWideChar( CP_ACP, 0, filename, (int)len, szDir,
MAX_PATH - 3 );
if( w_ret == 0 )
return( MBEDTLS_ERR_X509_BAD_INPUT_DATA );
@@ -1334,11 +1308,8 @@ int mbedtls_x509_crt_parse_path( mbedtls_x509_crt *chain, const char *path )
if( file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
continue;
- if ( FAILED( SizeTToInt( wcslen( file_data.cFileName ), &lengthAsInt ) ) )
- return( MBEDTLS_ERR_X509_FILE_IO_ERROR );
-
w_ret = WideCharToMultiByte( CP_ACP, 0, file_data.cFileName,
- lengthAsInt,
+ lstrlenW( file_data.cFileName ),
p, (int) len - 1,
NULL, NULL );
if( w_ret == 0 )
@@ -1467,7 +1438,7 @@ static int x509_info_subject_alt_name( char **buf, size_t *size,
}
#define CERT_TYPE(type,name) \
- if( ns_cert_type & type ) \
+ if( ns_cert_type & (type) ) \
PRINT_ITEM( name );
static int x509_info_cert_type( char **buf, size_t *size,
@@ -1494,7 +1465,7 @@ static int x509_info_cert_type( char **buf, size_t *size,
}
#define KEY_USAGE(code,name) \
- if( key_usage & code ) \
+ if( key_usage & (code) ) \
PRINT_ITEM( name );
static int x509_info_key_usage( char **buf, size_t *size,
diff --git a/thirdparty/mbedtls/library/x509_csr.c b/thirdparty/mbedtls/library/x509_csr.c
index f84425728a..c8c08c87b2 100644
--- a/thirdparty/mbedtls/library/x509_csr.c
+++ b/thirdparty/mbedtls/library/x509_csr.c
@@ -279,15 +279,24 @@ int mbedtls_x509_csr_parse( mbedtls_x509_csr *csr, const unsigned char *buf, siz
{
mbedtls_pem_init( &pem );
ret = mbedtls_pem_read_buffer( &pem,
- "-----BEGIN CERTIFICATE REQUEST-----",
- "-----END CERTIFICATE REQUEST-----",
- buf, NULL, 0, &use_len );
+ "-----BEGIN CERTIFICATE REQUEST-----",
+ "-----END CERTIFICATE REQUEST-----",
+ buf, NULL, 0, &use_len );
+ if( ret == MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT )
+ {
+ ret = mbedtls_pem_read_buffer( &pem,
+ "-----BEGIN NEW CERTIFICATE REQUEST-----",
+ "-----END NEW CERTIFICATE REQUEST-----",
+ buf, NULL, 0, &use_len );
+ }
if( ret == 0 )
+ {
/*
* Was PEM encoded, parse the result
*/
ret = mbedtls_x509_csr_parse_der( csr, pem.buf, pem.buflen );
+ }
mbedtls_pem_free( &pem );
if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT )
diff --git a/thirdparty/mbedtls/library/x509write_crt.c b/thirdparty/mbedtls/library/x509write_crt.c
index b1ef216c95..10497e752b 100644
--- a/thirdparty/mbedtls/library/x509write_crt.c
+++ b/thirdparty/mbedtls/library/x509write_crt.c
@@ -218,26 +218,51 @@ int mbedtls_x509write_crt_set_authority_key_identifier( mbedtls_x509write_cert *
}
#endif /* MBEDTLS_SHA1_C */
+static size_t crt_get_unused_bits_for_named_bitstring( unsigned char bitstring,
+ size_t bit_offset )
+{
+ size_t unused_bits;
+
+ /* Count the unused bits removing trailing 0s */
+ for( unused_bits = bit_offset; unused_bits < 8; unused_bits++ )
+ if( ( ( bitstring >> unused_bits ) & 0x1 ) != 0 )
+ break;
+
+ return( unused_bits );
+}
+
int mbedtls_x509write_crt_set_key_usage( mbedtls_x509write_cert *ctx,
unsigned int key_usage )
{
unsigned char buf[4], ku;
unsigned char *c;
int ret;
-
- /* We currently only support 7 bits, from 0x80 to 0x02 */
- if( ( key_usage & ~0xfe ) != 0 )
+ size_t unused_bits;
+ const unsigned int allowed_bits = MBEDTLS_X509_KU_DIGITAL_SIGNATURE |
+ MBEDTLS_X509_KU_NON_REPUDIATION |
+ MBEDTLS_X509_KU_KEY_ENCIPHERMENT |
+ MBEDTLS_X509_KU_DATA_ENCIPHERMENT |
+ MBEDTLS_X509_KU_KEY_AGREEMENT |
+ MBEDTLS_X509_KU_KEY_CERT_SIGN |
+ MBEDTLS_X509_KU_CRL_SIGN;
+
+ /* Check that nothing other than the allowed flags is set */
+ if( ( key_usage & ~allowed_bits ) != 0 )
return( MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE );
c = buf + 4;
- ku = (unsigned char) key_usage;
+ ku = (unsigned char)key_usage;
+ unused_bits = crt_get_unused_bits_for_named_bitstring( ku, 1 );
+ ret = mbedtls_asn1_write_bitstring( &c, buf, &ku, 8 - unused_bits );
- if( ( ret = mbedtls_asn1_write_bitstring( &c, buf, &ku, 7 ) ) != 4 )
+ if( ret < 0 )
return( ret );
+ else if( ret < 3 || ret > 4 )
+ return( MBEDTLS_ERR_X509_INVALID_FORMAT );
ret = mbedtls_x509write_crt_set_extension( ctx, MBEDTLS_OID_KEY_USAGE,
MBEDTLS_OID_SIZE( MBEDTLS_OID_KEY_USAGE ),
- 1, buf, 4 );
+ 1, c, (size_t)ret );
if( ret != 0 )
return( ret );
@@ -249,16 +274,22 @@ int mbedtls_x509write_crt_set_ns_cert_type( mbedtls_x509write_cert *ctx,
{
unsigned char buf[4];
unsigned char *c;
+ size_t unused_bits;
int ret;
c = buf + 4;
- if( ( ret = mbedtls_asn1_write_bitstring( &c, buf, &ns_cert_type, 8 ) ) != 4 )
+ unused_bits = crt_get_unused_bits_for_named_bitstring( ns_cert_type, 0 );
+ ret = mbedtls_asn1_write_bitstring( &c,
+ buf,
+ &ns_cert_type,
+ 8 - unused_bits );
+ if( ret < 3 || ret > 4 )
return( ret );
ret = mbedtls_x509write_crt_set_extension( ctx, MBEDTLS_OID_NS_CERT_TYPE,
MBEDTLS_OID_SIZE( MBEDTLS_OID_NS_CERT_TYPE ),
- 0, buf, 4 );
+ 0, c, (size_t)ret );
if( ret != 0 )
return( ret );
diff --git a/thirdparty/mbedtls/library/x509write_csr.c b/thirdparty/mbedtls/library/x509write_csr.c
index 66cee56014..d70ba0ed92 100644
--- a/thirdparty/mbedtls/library/x509write_csr.c
+++ b/thirdparty/mbedtls/library/x509write_csr.c
@@ -81,20 +81,39 @@ int mbedtls_x509write_csr_set_extension( mbedtls_x509write_csr *ctx,
0, val, val_len );
}
+static size_t csr_get_unused_bits_for_named_bitstring( unsigned char bitstring,
+ size_t bit_offset )
+{
+ size_t unused_bits;
+
+ /* Count the unused bits removing trailing 0s */
+ for( unused_bits = bit_offset; unused_bits < 8; unused_bits++ )
+ if( ( ( bitstring >> unused_bits ) & 0x1 ) != 0 )
+ break;
+
+ return( unused_bits );
+}
+
int mbedtls_x509write_csr_set_key_usage( mbedtls_x509write_csr *ctx, unsigned char key_usage )
{
unsigned char buf[4];
unsigned char *c;
+ size_t unused_bits;
int ret;
c = buf + 4;
- if( ( ret = mbedtls_asn1_write_bitstring( &c, buf, &key_usage, 7 ) ) != 4 )
+ unused_bits = csr_get_unused_bits_for_named_bitstring( key_usage, 0 );
+ ret = mbedtls_asn1_write_bitstring( &c, buf, &key_usage, 8 - unused_bits );
+
+ if( ret < 0 )
return( ret );
+ else if( ret < 3 || ret > 4 )
+ return( MBEDTLS_ERR_X509_INVALID_FORMAT );
ret = mbedtls_x509write_csr_set_extension( ctx, MBEDTLS_OID_KEY_USAGE,
MBEDTLS_OID_SIZE( MBEDTLS_OID_KEY_USAGE ),
- buf, 4 );
+ c, (size_t)ret );
if( ret != 0 )
return( ret );
@@ -106,16 +125,25 @@ int mbedtls_x509write_csr_set_ns_cert_type( mbedtls_x509write_csr *ctx,
{
unsigned char buf[4];
unsigned char *c;
+ size_t unused_bits;
int ret;
c = buf + 4;
- if( ( ret = mbedtls_asn1_write_bitstring( &c, buf, &ns_cert_type, 8 ) ) != 4 )
+ unused_bits = csr_get_unused_bits_for_named_bitstring( ns_cert_type, 0 );
+ ret = mbedtls_asn1_write_bitstring( &c,
+ buf,
+ &ns_cert_type,
+ 8 - unused_bits );
+
+ if( ret < 0 )
+ return( ret );
+ else if( ret < 3 || ret > 4 )
return( ret );
ret = mbedtls_x509write_csr_set_extension( ctx, MBEDTLS_OID_NS_CERT_TYPE,
MBEDTLS_OID_SIZE( MBEDTLS_OID_NS_CERT_TYPE ),
- buf, 4 );
+ c, (size_t)ret );
if( ret != 0 )
return( ret );
diff --git a/thirdparty/misc/stb_vorbis.c b/thirdparty/misc/stb_vorbis.c
index 88276026ef..71af404dae 100644
--- a/thirdparty/misc/stb_vorbis.c
+++ b/thirdparty/misc/stb_vorbis.c
@@ -1,4 +1,4 @@
-// Ogg Vorbis audio decoder - v1.15 - public domain
+// Ogg Vorbis audio decoder - v1.16 - public domain
// http://nothings.org/stb_vorbis/
//
// Original version written by Sean Barrett in 2007.
@@ -33,6 +33,7 @@
// Timur Gagiev
//
// Partial history:
+// 1.16 - 2019-03-04 - fix warnings
// 1.15 - 2019-02-07 - explicit failure if Ogg Skeleton data is found
// 1.14 - 2018-02-11 - delete bogus dealloca usage
// 1.13 - 2018-01-29 - fix truncation of last frame (hopefully)
@@ -4990,7 +4991,13 @@ stb_vorbis * stb_vorbis_open_file(FILE *file, int close_on_free, int *error, con
stb_vorbis * stb_vorbis_open_filename(const char *filename, int *error, const stb_vorbis_alloc *alloc)
{
- FILE *f = fopen(filename, "rb");
+ FILE *f;
+#if defined(_WIN32) && defined(__STDC_WANT_SECURE_LIB__)
+ if (0 != fopen_s(&f, filename, "rb"))
+ f = NULL;
+#else
+ f = fopen(filename, "rb");
+#endif
if (f)
return stb_vorbis_open_file(f, TRUE, error, alloc);
if (error) *error = VORBIS_file_open_failure;
diff --git a/thirdparty/pcre2/AUTHORS b/thirdparty/pcre2/AUTHORS
index d5592bbc5b..8d4e15a247 100644
--- a/thirdparty/pcre2/AUTHORS
+++ b/thirdparty/pcre2/AUTHORS
@@ -8,7 +8,7 @@ Email domain: cam.ac.uk
University of Cambridge Computing Service,
Cambridge, England.
-Copyright (c) 1997-2018 University of Cambridge
+Copyright (c) 1997-2019 University of Cambridge
All rights reserved
@@ -19,7 +19,7 @@ Written by: Zoltan Herczeg
Email local part: hzmester
Emain domain: freemail.hu
-Copyright(c) 2010-2018 Zoltan Herczeg
+Copyright(c) 2010-2019 Zoltan Herczeg
All rights reserved.
@@ -30,7 +30,7 @@ Written by: Zoltan Herczeg
Email local part: hzmester
Emain domain: freemail.hu
-Copyright(c) 2009-2018 Zoltan Herczeg
+Copyright(c) 2009-2019 Zoltan Herczeg
All rights reserved.
####
diff --git a/thirdparty/pcre2/LICENCE b/thirdparty/pcre2/LICENCE
index b0f8804fff..142b3b3f9a 100644
--- a/thirdparty/pcre2/LICENCE
+++ b/thirdparty/pcre2/LICENCE
@@ -26,7 +26,7 @@ Email domain: cam.ac.uk
University of Cambridge Computing Service,
Cambridge, England.
-Copyright (c) 1997-2018 University of Cambridge
+Copyright (c) 1997-2019 University of Cambridge
All rights reserved.
@@ -37,7 +37,7 @@ Written by: Zoltan Herczeg
Email local part: hzmester
Email domain: freemail.hu
-Copyright(c) 2010-2018 Zoltan Herczeg
+Copyright(c) 2010-2019 Zoltan Herczeg
All rights reserved.
@@ -48,7 +48,7 @@ Written by: Zoltan Herczeg
Email local part: hzmester
Email domain: freemail.hu
-Copyright(c) 2009-2018 Zoltan Herczeg
+Copyright(c) 2009-2019 Zoltan Herczeg
All rights reserved.
diff --git a/thirdparty/pcre2/src/config.h b/thirdparty/pcre2/src/config.h
index 89a52ef848..25d45eeb38 100644
--- a/thirdparty/pcre2/src/config.h
+++ b/thirdparty/pcre2/src/config.h
@@ -35,6 +35,10 @@ sure both macros are undefined; an emulation function will then be used. */
*/
/* #undef BSR_ANYCRLF */
+/* Define to any value to disable the use of the z and t modifiers in
+ formatting settings such as %zu or %td (this is rarely needed). */
+/* #undef DISABLE_PERCENT_ZT */
+
/* If you are compiling for a system that uses EBCDIC instead of ASCII
character codes, define this macro to any value. When EBCDIC is set, PCRE2
assumes that all input strings are in EBCDIC. If you do not define this
@@ -214,7 +218,7 @@ sure both macros are undefined; an emulation function will then be used. */
#define PACKAGE_NAME "PCRE2"
/* Define to the full name and version of this package. */
-#define PACKAGE_STRING "PCRE2 10.32"
+#define PACKAGE_STRING "PCRE2 10.33"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "pcre2"
@@ -223,7 +227,7 @@ sure both macros are undefined; an emulation function will then be used. */
#define PACKAGE_URL ""
/* Define to the version of this package. */
-#define PACKAGE_VERSION "10.32"
+#define PACKAGE_VERSION "10.33"
/* The value of PARENS_NEST_LIMIT specifies the maximum depth of nested
parentheses (of any kind) in a pattern. This limits the amount of system
@@ -299,6 +303,11 @@ sure both macros are undefined; an emulation function will then be used. */
/* Define to any value to enable callout script support in pcre2grep. */
/* #undef SUPPORT_PCRE2GREP_CALLOUT */
+/* Define to any value to enable fork support in pcre2grep callout scripts.
+ This will have no effect unless SUPPORT_PCRE2GREP_CALLOUT is also defined.
+ */
+/* #undef SUPPORT_PCRE2GREP_CALLOUT_FORK */
+
/* Define to any value to enable JIT support in pcre2grep. Note that this will
have no effect unless SUPPORT_JIT is also defined. */
/* #undef SUPPORT_PCRE2GREP_JIT */
@@ -343,7 +352,7 @@ sure both macros are undefined; an emulation function will then be used. */
#endif
/* Version number of package */
-#define VERSION "10.32"
+#define VERSION "10.33"
/* Define to 1 if on MINIX. */
/* #undef _MINIX */
diff --git a/thirdparty/pcre2/src/pcre2.h b/thirdparty/pcre2/src/pcre2.h
index 3d2feb7a6b..102b5d91f1 100644
--- a/thirdparty/pcre2/src/pcre2.h
+++ b/thirdparty/pcre2/src/pcre2.h
@@ -42,15 +42,9 @@ POSSIBILITY OF SUCH DAMAGE.
/* The current PCRE version information. */
#define PCRE2_MAJOR 10
-#define PCRE2_MINOR 32
+#define PCRE2_MINOR 33
#define PCRE2_PRERELEASE
-#define PCRE2_DATE 2018-09-10
-
-/* For the benefit of systems without stdint.h, an alternative is to use
-inttypes.h. The existence of these headers is checked by configure or CMake. */
-
-#define PCRE2_HAVE_STDINT_H 1
-#define PCRE2_HAVE_INTTYPES_H 1
+#define PCRE2_DATE 2019-04-16
/* When an application links to a PCRE DLL in Windows, the symbols that are
imported have to be identified as such. When building PCRE2, the appropriate
@@ -87,18 +81,15 @@ set, we ensure here that it has no effect. */
#define PCRE2_CALL_CONVENTION
#endif
-/* Have to include limits.h, stdlib.h and stdint.h (or inttypes.h) to ensure
-that size_t and uint8_t, UCHAR_MAX, etc are defined. If the system has neither
-header, the relevant values must be provided by some other means. */
+/* Have to include limits.h, stdlib.h, and inttypes.h to ensure that size_t and
+uint8_t, UCHAR_MAX, etc are defined. Some systems that do have inttypes.h do
+not have stdint.h, which is why we use inttypes.h, which according to the C
+standard is a superset of stdint.h. If none of these headers are available,
+the relevant values must be provided by some other means. */
#include <limits.h>
#include <stdlib.h>
-
-#if PCRE2_HAVE_STDINT_H
-#include <stdint.h>
-#elif PCRE2_HAVE_INTTYPES_H
#include <inttypes.h>
-#endif
/* Allow for C++ users compiling this directly. */
@@ -158,43 +149,37 @@ D is inspected during pcre2_dfa_match() execution
#define PCRE2_EXTRA_BAD_ESCAPE_IS_LITERAL 0x00000002u /* C */
#define PCRE2_EXTRA_MATCH_WORD 0x00000004u /* C */
#define PCRE2_EXTRA_MATCH_LINE 0x00000008u /* C */
+#define PCRE2_EXTRA_ESCAPED_CR_IS_LF 0x00000010u /* C */
+#define PCRE2_EXTRA_ALT_BSUX 0x00000020u /* C */
/* These are for pcre2_jit_compile(). */
#define PCRE2_JIT_COMPLETE 0x00000001u /* For full matching */
#define PCRE2_JIT_PARTIAL_SOFT 0x00000002u
#define PCRE2_JIT_PARTIAL_HARD 0x00000004u
-
-/* These are for pcre2_match(), pcre2_dfa_match(), and pcre2_jit_match(). Note
-that PCRE2_ANCHORED and PCRE2_NO_UTF_CHECK can also be passed to these
-functions (though pcre2_jit_match() ignores the latter since it bypasses all
-sanity checks). */
-
-#define PCRE2_NOTBOL 0x00000001u
-#define PCRE2_NOTEOL 0x00000002u
-#define PCRE2_NOTEMPTY 0x00000004u /* ) These two must be kept */
-#define PCRE2_NOTEMPTY_ATSTART 0x00000008u /* ) adjacent to each other. */
-#define PCRE2_PARTIAL_SOFT 0x00000010u
-#define PCRE2_PARTIAL_HARD 0x00000020u
-
-/* These are additional options for pcre2_dfa_match(). */
-
-#define PCRE2_DFA_RESTART 0x00000040u
-#define PCRE2_DFA_SHORTEST 0x00000080u
-
-/* These are additional options for pcre2_substitute(), which passes any others
-through to pcre2_match(). */
-
-#define PCRE2_SUBSTITUTE_GLOBAL 0x00000100u
-#define PCRE2_SUBSTITUTE_EXTENDED 0x00000200u
-#define PCRE2_SUBSTITUTE_UNSET_EMPTY 0x00000400u
-#define PCRE2_SUBSTITUTE_UNKNOWN_UNSET 0x00000800u
-#define PCRE2_SUBSTITUTE_OVERFLOW_LENGTH 0x00001000u
-
-/* A further option for pcre2_match(), not allowed for pcre2_dfa_match(),
-ignored for pcre2_jit_match(). */
-
-#define PCRE2_NO_JIT 0x00002000u
+#define PCRE2_JIT_INVALID_UTF 0x00000100u
+
+/* These are for pcre2_match(), pcre2_dfa_match(), pcre2_jit_match(), and
+pcre2_substitute(). Some are allowed only for one of the functions, and in
+these cases it is noted below. Note that PCRE2_ANCHORED, PCRE2_ENDANCHORED and
+PCRE2_NO_UTF_CHECK can also be passed to these functions (though
+pcre2_jit_match() ignores the latter since it bypasses all sanity checks). */
+
+#define PCRE2_NOTBOL 0x00000001u
+#define PCRE2_NOTEOL 0x00000002u
+#define PCRE2_NOTEMPTY 0x00000004u /* ) These two must be kept */
+#define PCRE2_NOTEMPTY_ATSTART 0x00000008u /* ) adjacent to each other. */
+#define PCRE2_PARTIAL_SOFT 0x00000010u
+#define PCRE2_PARTIAL_HARD 0x00000020u
+#define PCRE2_DFA_RESTART 0x00000040u /* pcre2_dfa_match() only */
+#define PCRE2_DFA_SHORTEST 0x00000080u /* pcre2_dfa_match() only */
+#define PCRE2_SUBSTITUTE_GLOBAL 0x00000100u /* pcre2_substitute() only */
+#define PCRE2_SUBSTITUTE_EXTENDED 0x00000200u /* pcre2_substitute() only */
+#define PCRE2_SUBSTITUTE_UNSET_EMPTY 0x00000400u /* pcre2_substitute() only */
+#define PCRE2_SUBSTITUTE_UNKNOWN_UNSET 0x00000800u /* pcre2_substitute() only */
+#define PCRE2_SUBSTITUTE_OVERFLOW_LENGTH 0x00001000u /* pcre2_substitute() only */
+#define PCRE2_NO_JIT 0x00002000u /* Not for pcre2_dfa_match() */
+#define PCRE2_COPY_MATCHED_SUBJECT 0x00004000u
/* Options for pcre2_pattern_convert(). */
@@ -318,6 +303,8 @@ pcre2_pattern_convert(). */
#define PCRE2_ERROR_BAD_LITERAL_OPTIONS 192
#define PCRE2_ERROR_SUPPORTED_ONLY_IN_UNICODE 193
#define PCRE2_ERROR_INVALID_HYPHEN_IN_OPTIONS 194
+#define PCRE2_ERROR_ALPHA_ASSERTION_UNKNOWN 195
+#define PCRE2_ERROR_SCRIPT_RUN_NOT_AVAILABLE 196
/* "Expected" matching error codes: no match and partial match. */
@@ -504,10 +491,10 @@ typedef struct pcre2_real_jit_stack pcre2_jit_stack; \
typedef pcre2_jit_stack *(*pcre2_jit_callback)(void *);
-/* The structure for passing out data via the pcre_callout_function. We use a
-structure so that new fields can be added on the end in future versions,
-without changing the API of the function, thereby allowing old clients to work
-without modification. Define the generic version in a macro; the width-specific
+/* The structures for passing out data via callout functions. We use structures
+so that new fields can be added on the end in future versions, without changing
+the API of the function, thereby allowing old clients to work without
+modification. Define the generic versions in a macro; the width-specific
versions are generated from this macro below. */
/* Flags for the callout_flags field. These are cleared after a callout. */
@@ -549,7 +536,19 @@ typedef struct pcre2_callout_enumerate_block { \
PCRE2_SIZE callout_string_length; /* Length of string compiled into pattern */ \
PCRE2_SPTR callout_string; /* String compiled into pattern */ \
/* ------------------------------------------------------------------ */ \
-} pcre2_callout_enumerate_block;
+} pcre2_callout_enumerate_block; \
+\
+typedef struct pcre2_substitute_callout_block { \
+ uint32_t version; /* Identifies version of block */ \
+ /* ------------------------ Version 0 ------------------------------- */ \
+ PCRE2_SPTR input; /* Pointer to input subject string */ \
+ PCRE2_SPTR output; /* Pointer to output buffer */ \
+ PCRE2_SIZE output_offsets[2]; /* Changed portion of the output */ \
+ PCRE2_SIZE *ovector; /* Pointer to current ovector */ \
+ uint32_t oveccount; /* Count of pairs set in ovector */ \
+ uint32_t subscount; /* Substitution number */ \
+ /* ------------------------------------------------------------------ */ \
+} pcre2_substitute_callout_block;
/* List the generic forms of all other functions in macros, which will be
@@ -605,6 +604,9 @@ PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \
pcre2_set_callout(pcre2_match_context *, \
int (*)(pcre2_callout_block *, void *), void *); \
PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \
+ pcre2_set_substitute_callout(pcre2_match_context *, \
+ int (*)(pcre2_substitute_callout_block *, void *), void *); \
+PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \
pcre2_set_depth_limit(pcre2_match_context *, uint32_t); \
PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \
pcre2_set_heap_limit(pcre2_match_context *, uint32_t); \
@@ -807,6 +809,7 @@ pcre2_compile are called by application code. */
#define pcre2_callout_block PCRE2_SUFFIX(pcre2_callout_block_)
#define pcre2_callout_enumerate_block PCRE2_SUFFIX(pcre2_callout_enumerate_block_)
+#define pcre2_substitute_callout_block PCRE2_SUFFIX(pcre2_substitute_callout_block_)
#define pcre2_general_context PCRE2_SUFFIX(pcre2_general_context_)
#define pcre2_compile_context PCRE2_SUFFIX(pcre2_compile_context_)
#define pcre2_convert_context PCRE2_SUFFIX(pcre2_convert_context_)
@@ -872,6 +875,7 @@ pcre2_compile are called by application code. */
#define pcre2_set_newline PCRE2_SUFFIX(pcre2_set_newline_)
#define pcre2_set_parens_nest_limit PCRE2_SUFFIX(pcre2_set_parens_nest_limit_)
#define pcre2_set_offset_limit PCRE2_SUFFIX(pcre2_set_offset_limit_)
+#define pcre2_set_substitute_callout PCRE2_SUFFIX(pcre2_set_substitute_callout_)
#define pcre2_substitute PCRE2_SUFFIX(pcre2_substitute_)
#define pcre2_substring_copy_byname PCRE2_SUFFIX(pcre2_substring_copy_byname_)
#define pcre2_substring_copy_bynumber PCRE2_SUFFIX(pcre2_substring_copy_bynumber_)
diff --git a/thirdparty/pcre2/src/pcre2_auto_possess.c b/thirdparty/pcre2/src/pcre2_auto_possess.c
index 2ce152e952..6d7b7c4a4d 100644
--- a/thirdparty/pcre2/src/pcre2_auto_possess.c
+++ b/thirdparty/pcre2/src/pcre2_auto_possess.c
@@ -7,7 +7,7 @@ and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
Original API code Copyright (c) 1997-2012 University of Cambridge
- New API code Copyright (c) 2016-2018 University of Cambridge
+ New API code Copyright (c) 2016-2019 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -605,6 +605,15 @@ for(;;)
if (cb->had_recurse) return FALSE;
break;
+ /* A script run might have to backtrack if the iterated item can match
+ characters from more than one script. So give up unless repeating an
+ explicit character. */
+
+ case OP_SCRIPT_RUN:
+ if (base_list[0] != OP_CHAR && base_list[0] != OP_CHARI)
+ return FALSE;
+ break;
+
/* Atomic sub-patterns and assertions can always auto-possessify their
last iterator. However, if the group was entered as a result of checking
a previous iterator, this is not possible. */
@@ -614,7 +623,6 @@ for(;;)
case OP_ASSERTBACK:
case OP_ASSERTBACK_NOT:
case OP_ONCE:
-
return !entered_a_group;
}
@@ -1043,7 +1051,7 @@ for(;;)
if (chr > 255) break;
class_bitset = (uint8_t *)
((list_ptr == list ? code : base_end) - list_ptr[2]);
- if ((class_bitset[chr >> 3] & (1 << (chr & 7))) != 0) return FALSE;
+ if ((class_bitset[chr >> 3] & (1u << (chr & 7))) != 0) return FALSE;
break;
#ifdef SUPPORT_WIDE_CHARS
diff --git a/thirdparty/pcre2/src/pcre2_chartables.c b/thirdparty/pcre2/src/pcre2_chartables.c
index 4046500c00..0e07edb494 100644
--- a/thirdparty/pcre2/src/pcre2_chartables.c
+++ b/thirdparty/pcre2/src/pcre2_chartables.c
@@ -157,8 +157,8 @@ graph print, punct, and cntrl. Other classes are built from combinations. */
/* This table identifies various classes of character by individual bits:
0x01 white space character
0x02 letter
- 0x04 decimal digit
- 0x08 hexadecimal digit
+ 0x04 lower case letter
+ 0x08 decimal digit
0x10 alphanumeric or '_'
*/
@@ -168,16 +168,16 @@ graph print, punct, and cntrl. Other classes are built from combinations. */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 24- 31 */
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* - ' */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* ( - / */
- 0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c, /* 0 - 7 */
- 0x1c,0x1c,0x00,0x00,0x00,0x00,0x00,0x00, /* 8 - ? */
- 0x00,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x12, /* @ - G */
+ 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, /* 0 - 7 */
+ 0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00, /* 8 - ? */
+ 0x00,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* @ - G */
0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* H - O */
0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* P - W */
0x12,0x12,0x12,0x00,0x00,0x00,0x00,0x10, /* X - _ */
- 0x00,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x12, /* ` - g */
- 0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* h - o */
- 0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* p - w */
- 0x12,0x12,0x12,0x00,0x00,0x00,0x00,0x00, /* x -127 */
+ 0x00,0x16,0x16,0x16,0x16,0x16,0x16,0x16, /* ` - g */
+ 0x16,0x16,0x16,0x16,0x16,0x16,0x16,0x16, /* h - o */
+ 0x16,0x16,0x16,0x16,0x16,0x16,0x16,0x16, /* p - w */
+ 0x16,0x16,0x16,0x00,0x00,0x00,0x00,0x00, /* x -127 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 128-135 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 136-143 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 144-151 */
diff --git a/thirdparty/pcre2/src/pcre2_compile.c b/thirdparty/pcre2/src/pcre2_compile.c
index 6bb1de3610..068735ae8e 100644
--- a/thirdparty/pcre2/src/pcre2_compile.c
+++ b/thirdparty/pcre2/src/pcre2_compile.c
@@ -7,7 +7,7 @@ and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
Original API code Copyright (c) 1997-2012 University of Cambridge
- New API code Copyright (c) 2016-2018 University of Cambridge
+ New API code Copyright (c) 2016-2019 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -240,49 +240,57 @@ code (meta_extra_lengths, just below) must be updated to remain in step. */
#define META_RANGE_LITERAL 0x801f0000u /* range defined literally */
#define META_RECURSE 0x80200000u /* Recursion */
#define META_RECURSE_BYNAME 0x80210000u /* (?&name) */
+#define META_SCRIPT_RUN 0x80220000u /* (*script_run:...) */
/* These must be kept together to make it easy to check that an assertion
is present where expected in a conditional group. */
-#define META_LOOKAHEAD 0x80220000u /* (?= */
-#define META_LOOKAHEADNOT 0x80230000u /* (?! */
-#define META_LOOKBEHIND 0x80240000u /* (?<= */
-#define META_LOOKBEHINDNOT 0x80250000u /* (?<! */
+#define META_LOOKAHEAD 0x80230000u /* (?= */
+#define META_LOOKAHEADNOT 0x80240000u /* (?! */
+#define META_LOOKBEHIND 0x80250000u /* (?<= */
+#define META_LOOKBEHINDNOT 0x80260000u /* (?<! */
/* These must be kept in this order, with consecutive values, and the _ARG
versions of COMMIT, PRUNE, SKIP, and THEN immediately after their non-argument
versions. */
-#define META_MARK 0x80260000u /* (*MARK) */
-#define META_ACCEPT 0x80270000u /* (*ACCEPT) */
-#define META_FAIL 0x80280000u /* (*FAIL) */
-#define META_COMMIT 0x80290000u /* These */
-#define META_COMMIT_ARG 0x802a0000u /* pairs */
-#define META_PRUNE 0x802b0000u /* must */
-#define META_PRUNE_ARG 0x802c0000u /* be */
-#define META_SKIP 0x802d0000u /* kept */
-#define META_SKIP_ARG 0x802e0000u /* in */
-#define META_THEN 0x802f0000u /* this */
-#define META_THEN_ARG 0x80300000u /* order */
+#define META_MARK 0x80270000u /* (*MARK) */
+#define META_ACCEPT 0x80280000u /* (*ACCEPT) */
+#define META_FAIL 0x80290000u /* (*FAIL) */
+#define META_COMMIT 0x802a0000u /* These */
+#define META_COMMIT_ARG 0x802b0000u /* pairs */
+#define META_PRUNE 0x802c0000u /* must */
+#define META_PRUNE_ARG 0x802d0000u /* be */
+#define META_SKIP 0x802e0000u /* kept */
+#define META_SKIP_ARG 0x802f0000u /* in */
+#define META_THEN 0x80300000u /* this */
+#define META_THEN_ARG 0x80310000u /* order */
/* These must be kept in groups of adjacent 3 values, and all together. */
-#define META_ASTERISK 0x80310000u /* * */
-#define META_ASTERISK_PLUS 0x80320000u /* *+ */
-#define META_ASTERISK_QUERY 0x80330000u /* *? */
-#define META_PLUS 0x80340000u /* + */
-#define META_PLUS_PLUS 0x80350000u /* ++ */
-#define META_PLUS_QUERY 0x80360000u /* +? */
-#define META_QUERY 0x80370000u /* ? */
-#define META_QUERY_PLUS 0x80380000u /* ?+ */
-#define META_QUERY_QUERY 0x80390000u /* ?? */
-#define META_MINMAX 0x803a0000u /* {n,m} repeat */
-#define META_MINMAX_PLUS 0x803b0000u /* {n,m}+ repeat */
-#define META_MINMAX_QUERY 0x803c0000u /* {n,m}? repeat */
+#define META_ASTERISK 0x80320000u /* * */
+#define META_ASTERISK_PLUS 0x80330000u /* *+ */
+#define META_ASTERISK_QUERY 0x80340000u /* *? */
+#define META_PLUS 0x80350000u /* + */
+#define META_PLUS_PLUS 0x80360000u /* ++ */
+#define META_PLUS_QUERY 0x80370000u /* +? */
+#define META_QUERY 0x80380000u /* ? */
+#define META_QUERY_PLUS 0x80390000u /* ?+ */
+#define META_QUERY_QUERY 0x803a0000u /* ?? */
+#define META_MINMAX 0x803b0000u /* {n,m} repeat */
+#define META_MINMAX_PLUS 0x803c0000u /* {n,m}+ repeat */
+#define META_MINMAX_QUERY 0x803d0000u /* {n,m}? repeat */
#define META_FIRST_QUANTIFIER META_ASTERISK
#define META_LAST_QUANTIFIER META_MINMAX_QUERY
+/* This is a special "meta code" that is used only to distinguish (*asr: from
+(*sr: in the table of aphabetic assertions. It is never stored in the parsed
+pattern because (*asr: is turned into (*sr:(*atomic: at that stage. There is
+therefore no need for it to have a length entry, so use a high value. */
+
+#define META_ATOMIC_SCRIPT_RUN 0x8fff0000u
+
/* Table of extra lengths for each of the meta codes. Must be kept in step with
the definitions above. For some items these values are a basic length to which
a variable amount has to be added. */
@@ -322,6 +330,7 @@ static unsigned char meta_extra_lengths[] = {
0, /* META_RANGE_LITERAL */
SIZEOFFSET, /* META_RECURSE */
1+SIZEOFFSET, /* META_RECURSE_BYNAME */
+ 0, /* META_SCRIPT_RUN */
0, /* META_LOOKAHEAD */
0, /* META_LOOKAHEADNOT */
SIZEOFFSET, /* META_LOOKBEHIND */
@@ -359,17 +368,17 @@ enum { PSKIP_ALT, PSKIP_CLASS, PSKIP_KET };
experimenting to figure out how to stop gcc 5.3.0 from warning with
-Wconversion. This version gets a warning:
- #define SETBIT(a,b) a[(b)/8] |= (uint8_t)(1 << ((b)&7))
+ #define SETBIT(a,b) a[(b)/8] |= (uint8_t)(1u << ((b)&7))
Let's hope the apparently less efficient version isn't actually so bad if the
compiler is clever with identical subexpressions. */
-#define SETBIT(a,b) a[(b)/8] = (uint8_t)(a[(b)/8] | (1 << ((b)&7)))
+#define SETBIT(a,b) a[(b)/8] = (uint8_t)(a[(b)/8] | (1u << ((b)&7)))
/* Private flags added to firstcu and reqcu. */
-#define REQ_CASELESS (1 << 0) /* Indicates caselessness */
-#define REQ_VARY (1 << 1) /* reqcu followed non-literal item */
+#define REQ_CASELESS (1u << 0) /* Indicates caselessness */
+#define REQ_VARY (1u << 1) /* reqcu followed non-literal item */
/* Negative values for the firstcu and reqcu flags */
#define REQ_UNSET (-2) /* Not yet found anything */
#define REQ_NONE (-1) /* Found not fixed char */
@@ -615,6 +624,46 @@ static const uint32_t verbops[] = {
OP_MARK, OP_ACCEPT, OP_FAIL, OP_COMMIT, OP_COMMIT_ARG, OP_PRUNE,
OP_PRUNE_ARG, OP_SKIP, OP_SKIP_ARG, OP_THEN, OP_THEN_ARG };
+/* Table of "alpha assertions" like (*pla:...), similar to the (*VERB) table. */
+
+typedef struct alasitem {
+ unsigned int len; /* Length of name */
+ uint32_t meta; /* Base META_ code */
+} alasitem;
+
+static const char alasnames[] =
+ STRING_pla0
+ STRING_plb0
+ STRING_nla0
+ STRING_nlb0
+ STRING_positive_lookahead0
+ STRING_positive_lookbehind0
+ STRING_negative_lookahead0
+ STRING_negative_lookbehind0
+ STRING_atomic0
+ STRING_sr0
+ STRING_asr0
+ STRING_script_run0
+ STRING_atomic_script_run;
+
+static const alasitem alasmeta[] = {
+ { 3, META_LOOKAHEAD },
+ { 3, META_LOOKBEHIND },
+ { 3, META_LOOKAHEADNOT },
+ { 3, META_LOOKBEHINDNOT },
+ { 18, META_LOOKAHEAD },
+ { 19, META_LOOKBEHIND },
+ { 18, META_LOOKAHEADNOT },
+ { 19, META_LOOKBEHINDNOT },
+ { 6, META_ATOMIC },
+ { 2, META_SCRIPT_RUN }, /* sr = script run */
+ { 3, META_ATOMIC_SCRIPT_RUN }, /* asr = atomic script run */
+ { 10, META_SCRIPT_RUN }, /* script run */
+ { 17, META_ATOMIC_SCRIPT_RUN } /* atomic script run */
+};
+
+static const int alascount = sizeof(alasmeta)/sizeof(alasitem);
+
/* Offsets from OP_STAR for case-independent and negative repeat opcodes. */
static uint32_t chartypeoffset[] = {
@@ -714,7 +763,8 @@ are allowed. */
#define PUBLIC_COMPILE_EXTRA_OPTIONS \
(PUBLIC_LITERAL_COMPILE_EXTRA_OPTIONS| \
- PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES|PCRE2_EXTRA_BAD_ESCAPE_IS_LITERAL)
+ PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES|PCRE2_EXTRA_BAD_ESCAPE_IS_LITERAL| \
+ PCRE2_EXTRA_ESCAPED_CR_IS_LF|PCRE2_EXTRA_ALT_BSUX)
/* Compile time error code numbers. They are given names so that they can more
easily be tracked. When a new number is added, the tables called eint1 and
@@ -731,7 +781,7 @@ enum { ERR0 = COMPILE_ERROR_BASE,
ERR61, ERR62, ERR63, ERR64, ERR65, ERR66, ERR67, ERR68, ERR69, ERR70,
ERR71, ERR72, ERR73, ERR74, ERR75, ERR76, ERR77, ERR78, ERR79, ERR80,
ERR81, ERR82, ERR83, ERR84, ERR85, ERR86, ERR87, ERR88, ERR89, ERR90,
- ERR91, ERR92, ERR93, ERR94 };
+ ERR91, ERR92, ERR93, ERR94, ERR95, ERR96 };
/* This is a table of start-of-pattern options such as (*UTF) and settings such
as (*LIMIT_MATCH=nnnn) and (*CRLF). For completeness and backward
@@ -962,6 +1012,7 @@ for (;;)
case META_NOCAPTURE: fprintf(stderr, "META (?:"); break;
case META_LOOKAHEAD: fprintf(stderr, "META (?="); break;
case META_LOOKAHEADNOT: fprintf(stderr, "META (?!"); break;
+ case META_SCRIPT_RUN: fprintf(stderr, "META (*sr:"); break;
case META_KET: fprintf(stderr, "META )"); break;
case META_ALT: fprintf(stderr, "META | %d", meta_arg); break;
@@ -1191,7 +1242,7 @@ if (code != NULL)
if ((code->flags & PCRE2_DEREF_TABLES) != 0)
{
/* Decoded tables belong to the codes after deserialization, and they must
- be freed when there are no more reference to them. The *ref_count should
+ be freed when there are no more references to them. The *ref_count should
always be > 0. */
ref_count = (PCRE2_SIZE *)(code->tables + tables_length);
@@ -1398,7 +1449,7 @@ Arguments:
errorcodeptr points to the errorcode variable (containing zero)
options the current options bits
isclass TRUE if inside a character class
- cb compile data block
+ cb compile data block or NULL when called from pcre2_substitute()
Returns: zero => a data character
positive => a special escape sequence
@@ -1408,7 +1459,8 @@ Returns: zero => a data character
int
PRIV(check_escape)(PCRE2_SPTR *ptrptr, PCRE2_SPTR ptrend, uint32_t *chptr,
- int *errorcodeptr, uint32_t options, BOOL isclass, compile_block *cb)
+ int *errorcodeptr, uint32_t options, uint32_t extra_options, BOOL isclass,
+ compile_block *cb)
{
BOOL utf = (options & PCRE2_UTF) != 0;
PCRE2_SPTR ptr = *ptrptr;
@@ -1429,14 +1481,25 @@ GETCHARINCTEST(c, ptr); /* Get character value, increment pointer */
/* Non-alphanumerics are literals, so we just leave the value in c. An initial
value test saves a memory lookup for code points outside the alphanumeric
-range. Otherwise, do a table lookup. A non-zero result is something that can be
-returned immediately. Otherwise further processing is required. */
+range. */
if (c < ESCAPES_FIRST || c > ESCAPES_LAST) {} /* Definitely literal */
+/* Otherwise, do a table lookup. Non-zero values need little processing here. A
+positive value is a literal value for something like \n. A negative value is
+the negation of one of the ESC_ macros that is passed back for handling by the
+calling function. Some extra checking is needed for \N because only \N{U+dddd}
+is supported. If the value is zero, further processing is handled below. */
+
else if ((i = escapes[c - ESCAPES_FIRST]) != 0)
{
- if (i > 0) c = (uint32_t)i; else /* Positive is a data character */
+ if (i > 0)
+ {
+ c = (uint32_t)i;
+ if (c == CHAR_CR && (extra_options & PCRE2_EXTRA_ESCAPED_CR_IS_LF) != 0)
+ c = CHAR_LF;
+ }
+ else /* Negative table entry */
{
escape = -i; /* Else return a special escape */
if (cb != NULL && (escape == ESC_P || escape == ESC_p || escape == ESC_X))
@@ -1486,23 +1549,29 @@ else if ((i = escapes[c - ESCAPES_FIRST]) != 0)
}
}
-/* Escapes that need further processing, including those that are unknown.
-When called from pcre2_substitute(), only \c, \o, and \x are recognized (and \u
-when BSUX is set). */
+/* Escapes that need further processing, including those that are unknown, have
+a zero entry in the lookup table. When called from pcre2_substitute(), only \c,
+\o, and \x are recognized (\u and \U can never appear as they are used for case
+forcing). */
else
{
+ int s;
PCRE2_SPTR oldptr;
BOOL overflow;
- int s;
+ BOOL alt_bsux =
+ ((options & PCRE2_ALT_BSUX) | (extra_options & PCRE2_EXTRA_ALT_BSUX)) != 0;
/* Filter calls from pcre2_substitute(). */
- if (cb == NULL && c != CHAR_c && c != CHAR_o && c != CHAR_x &&
- (c != CHAR_u || (options & PCRE2_ALT_BSUX) != 0))
+ if (cb == NULL)
{
- *errorcodeptr = ERR3;
- return 0;
+ if (c != CHAR_c && c != CHAR_o && c != CHAR_x)
+ {
+ *errorcodeptr = ERR3;
+ return 0;
+ }
+ alt_bsux = FALSE; /* Do not modify \x handling */
}
switch (c)
@@ -1516,40 +1585,75 @@ else
*errorcodeptr = ERR37;
break;
- /* \u is unrecognized when PCRE2_ALT_BSUX is not set. When it is treated
- specially, \u must be followed by four hex digits. Otherwise it is a
- lowercase u letter. */
+ /* \u is unrecognized when neither PCRE2_ALT_BSUX nor PCRE2_EXTRA_ALT_BSUX
+ is set. Otherwise, \u must be followed by exactly four hex digits or, if
+ PCRE2_EXTRA_ALT_BSUX is set, by any number of hex digits in braces.
+ Otherwise it is a lowercase u letter. This gives some compatibility with
+ ECMAScript (aka JavaScript). */
case CHAR_u:
- if ((options & PCRE2_ALT_BSUX) == 0) *errorcodeptr = ERR37; else
+ if (!alt_bsux) *errorcodeptr = ERR37; else
{
uint32_t xc;
- if (ptrend - ptr < 4) break; /* Less than 4 chars */
- if ((cc = XDIGIT(ptr[0])) == 0xff) break; /* Not a hex digit */
- if ((xc = XDIGIT(ptr[1])) == 0xff) break; /* Not a hex digit */
- cc = (cc << 4) | xc;
- if ((xc = XDIGIT(ptr[2])) == 0xff) break; /* Not a hex digit */
- cc = (cc << 4) | xc;
- if ((xc = XDIGIT(ptr[3])) == 0xff) break; /* Not a hex digit */
- c = (cc << 4) | xc;
- ptr += 4;
+
+ if (ptr >= ptrend) break;
+ if (*ptr == CHAR_LEFT_CURLY_BRACKET &&
+ (extra_options & PCRE2_EXTRA_ALT_BSUX) != 0)
+ {
+ PCRE2_SPTR hptr = ptr + 1;
+ cc = 0;
+
+ while (hptr < ptrend && (xc = XDIGIT(*hptr)) != 0xff)
+ {
+ if ((cc & 0xf0000000) != 0) /* Test for 32-bit overflow */
+ {
+ *errorcodeptr = ERR77;
+ ptr = hptr; /* Show where */
+ break; /* *hptr != } will cause another break below */
+ }
+ cc = (cc << 4) | xc;
+ hptr++;
+ }
+
+ if (hptr == ptr + 1 || /* No hex digits */
+ hptr >= ptrend || /* Hit end of input */
+ *hptr != CHAR_RIGHT_CURLY_BRACKET) /* No } terminator */
+ break; /* Hex escape not recognized */
+
+ c = cc; /* Accept the code point */
+ ptr = hptr + 1;
+ }
+
+ else /* Must be exactly 4 hex digits */
+ {
+ if (ptrend - ptr < 4) break; /* Less than 4 chars */
+ if ((cc = XDIGIT(ptr[0])) == 0xff) break; /* Not a hex digit */
+ if ((xc = XDIGIT(ptr[1])) == 0xff) break; /* Not a hex digit */
+ cc = (cc << 4) | xc;
+ if ((xc = XDIGIT(ptr[2])) == 0xff) break; /* Not a hex digit */
+ cc = (cc << 4) | xc;
+ if ((xc = XDIGIT(ptr[3])) == 0xff) break; /* Not a hex digit */
+ c = (cc << 4) | xc;
+ ptr += 4;
+ }
+
if (utf)
{
if (c > 0x10ffffU) *errorcodeptr = ERR77;
else
if (c >= 0xd800 && c <= 0xdfff &&
- (cb->cx->extra_options & PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES) == 0)
- *errorcodeptr = ERR73;
+ (extra_options & PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES) == 0)
+ *errorcodeptr = ERR73;
}
else if (c > MAX_NON_UTF_CHAR) *errorcodeptr = ERR77;
}
break;
- /* \U is unrecognized unless PCRE2_ALT_BSUX is set, in which case it is an
- upper case letter. */
+ /* \U is unrecognized unless PCRE2_ALT_BSUX or PCRE2_EXTRA_ALT_BSUX is set,
+ in which case it is an upper case letter. */
case CHAR_U:
- if ((options & PCRE2_ALT_BSUX) == 0) *errorcodeptr = ERR37;
+ if (!alt_bsux) *errorcodeptr = ERR37;
break;
/* In a character class, \g is just a literal "g". Outside a character
@@ -1728,8 +1832,8 @@ else
}
else if (ptr < ptrend && *ptr++ == CHAR_RIGHT_CURLY_BRACKET)
{
- if (utf && c >= 0xd800 && c <= 0xdfff && (cb == NULL ||
- (cb->cx->extra_options & PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES) == 0))
+ if (utf && c >= 0xd800 && c <= 0xdfff &&
+ (extra_options & PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES) == 0)
{
ptr--;
*errorcodeptr = ERR73;
@@ -1743,11 +1847,11 @@ else
}
break;
- /* \x is complicated. When PCRE2_ALT_BSUX is set, \x must be followed by
- two hexadecimal digits. Otherwise it is a lowercase x letter. */
+ /* When PCRE2_ALT_BSUX or PCRE2_EXTRA_ALT_BSUX is set, \x must be followed
+ by two hexadecimal digits. Otherwise it is a lowercase x letter. */
case CHAR_x:
- if ((options & PCRE2_ALT_BSUX) != 0)
+ if (alt_bsux)
{
uint32_t xc;
if (ptrend - ptr < 2) break; /* Less than 2 characters */
@@ -1755,9 +1859,9 @@ else
if ((xc = XDIGIT(ptr[1])) == 0xff) break; /* Not a hex digit */
c = (cc << 4) | xc;
ptr += 2;
- } /* End PCRE2_ALT_BSUX handling */
+ }
- /* Handle \x in Perl's style. \x{ddd} is a character number which can be
+ /* Handle \x in Perl's style. \x{ddd} is a character code which can be
greater than 0xff in UTF-8 or non-8bit mode, but only if the ddd are hex
digits. If not, { used to be treated as a data character. However, Perl
seems to read hex digits up to the first non-such, and ignore the rest, so
@@ -1801,8 +1905,8 @@ else
}
else if (ptr < ptrend && *ptr++ == CHAR_RIGHT_CURLY_BRACKET)
{
- if (utf && c >= 0xd800 && c <= 0xdfff && (cb == NULL ||
- (cb->cx->extra_options & PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES) == 0))
+ if (utf && c >= 0xd800 && c <= 0xdfff &&
+ (extra_options & PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES) == 0)
{
ptr--;
*errorcodeptr = ERR73;
@@ -1874,9 +1978,9 @@ else
c ^= 0x40;
/* Handle \c in an EBCDIC environment. The special case \c? is converted to
- 255 (0xff) or 95 (0x5f) if other character suggest we are using th POSIX-BC
- encoding. (This is the way Perl indicates that it handles \c?.) The other
- valid sequences correspond to a list of specific characters. */
+ 255 (0xff) or 95 (0x5f) if other characters suggest we are using the
+ POSIX-BC encoding. (This is the way Perl indicates that it handles \c?.)
+ The other valid sequences correspond to a list of specific characters. */
#else
if (c == CHAR_QUESTION_MARK)
@@ -2120,9 +2224,10 @@ return -1;
*************************************************/
/* This function is called from parse_regex() below whenever it needs to read
-the name of a subpattern or a (*VERB). The initial pointer must be to the
-character before the name. If that character is '*' we are reading a verb name.
-The pointer is updated to point after the name, for a VERB, or after tha name's
+the name of a subpattern or a (*VERB) or an (*alpha_assertion). The initial
+pointer must be to the character before the name. If that character is '*' we
+are reading a verb or alpha assertion name. The pointer is updated to point
+after the name, for a VERB or alpha assertion name, or after tha name's
terminator for a subpattern name. Returning both the offset and the name
pointer is redundant information, but some callers use one and some the other,
so it is simplest just to return both.
@@ -2130,6 +2235,7 @@ so it is simplest just to return both.
Arguments:
ptrptr points to the character pointer variable
ptrend points to the end of the input string
+ utf true if the input is UTF-encoded
terminator the terminator of a subpattern name must be this
offsetptr where to put the offset from the start of the pattern
nameptr where to put a pointer to the name in the input
@@ -2142,48 +2248,88 @@ Returns: TRUE if a name was read
*/
static BOOL
-read_name(PCRE2_SPTR *ptrptr, PCRE2_SPTR ptrend, uint32_t terminator,
+read_name(PCRE2_SPTR *ptrptr, PCRE2_SPTR ptrend, BOOL utf, uint32_t terminator,
PCRE2_SIZE *offsetptr, PCRE2_SPTR *nameptr, uint32_t *namelenptr,
int *errorcodeptr, compile_block *cb)
{
PCRE2_SPTR ptr = *ptrptr;
-BOOL is_verb = (*ptr == CHAR_ASTERISK);
-uint32_t namelen = 0;
-uint32_t ctype = is_verb? ctype_letter : ctype_word;
+BOOL is_group = (*ptr != CHAR_ASTERISK);
-if (++ptr >= ptrend)
+if (++ptr >= ptrend) /* No characters in name */
{
- *errorcodeptr = is_verb? ERR60: /* Verb not recognized or malformed */
- ERR62; /* Subpattern name expected */
+ *errorcodeptr = is_group? ERR62: /* Subpattern name expected */
+ ERR60; /* Verb not recognized or malformed */
goto FAILED;
}
*nameptr = ptr;
*offsetptr = (PCRE2_SIZE)(ptr - cb->start_pattern);
-if (IS_DIGIT(*ptr))
+/* In UTF mode, a group name may contain letters and decimal digits as defined
+by Unicode properties, and underscores, but must not start with a digit. */
+
+#ifdef SUPPORT_UNICODE
+if (utf && is_group)
{
- *errorcodeptr = ERR44; /* Group name must not start with digit */
- goto FAILED;
+ uint32_t c, type;
+
+ GETCHAR(c, ptr);
+ type = UCD_CHARTYPE(c);
+
+ if (type == ucp_Nd)
+ {
+ *errorcodeptr = ERR44;
+ goto FAILED;
+ }
+
+ for(;;)
+ {
+ if (type != ucp_Nd && PRIV(ucp_gentype)[type] != ucp_L &&
+ c != CHAR_UNDERSCORE) break;
+ ptr++;
+ FORWARDCHARTEST(ptr, ptrend);
+ if (ptr >= ptrend) break;
+ GETCHAR(c, ptr);
+ type = UCD_CHARTYPE(c);
+ }
}
+else
+#else
+(void)utf; /* Avoid compiler warning */
+#endif /* SUPPORT_UNICODE */
+
+/* Handle non-group names and group names in non-UTF modes. A group name must
+not start with a digit. If either of the others start with a digit it just
+won't be recognized. */
-while (ptr < ptrend && MAX_255(*ptr) && (cb->ctypes[*ptr] & ctype) != 0)
{
- ptr++;
- namelen++;
- if (namelen > MAX_NAME_SIZE)
+ if (is_group && IS_DIGIT(*ptr))
{
- *errorcodeptr = ERR48;
+ *errorcodeptr = ERR44;
goto FAILED;
}
+
+ while (ptr < ptrend && MAX_255(*ptr) && (cb->ctypes[*ptr] & ctype_word) != 0)
+ {
+ ptr++;
+ }
}
+/* Check name length */
+
+if (ptr > *nameptr + MAX_NAME_SIZE)
+ {
+ *errorcodeptr = ERR48;
+ goto FAILED;
+ }
+*namelenptr = ptr - *nameptr;
+
/* Subpattern names must not be empty, and their terminator is checked here.
-(What follows a verb name is checked separately.) */
+(What follows a verb or alpha assertion name is checked separately.) */
-if (!is_verb)
+if (is_group)
{
- if (namelen == 0)
+ if (ptr == *nameptr)
{
*errorcodeptr = ERR62; /* Subpattern name expected */
goto FAILED;
@@ -2196,7 +2342,6 @@ if (!is_verb)
ptr++;
}
-*namelenptr = namelen;
*ptrptr = ptr;
return TRUE;
@@ -2289,6 +2434,7 @@ typedef struct nest_save {
#define NSF_RESET 0x0001u
#define NSF_CONDASSERT 0x0002u
+#define NSF_ATOMICSR 0x0004u
/* Options that are changeable within the pattern must be tracked during
parsing. Some (e.g. PCRE2_EXTENDED) are implemented entirely during parsing,
@@ -2333,6 +2479,7 @@ uint32_t *parsed_pattern = cb->parsed_pattern;
uint32_t *parsed_pattern_end = cb->parsed_pattern_end;
uint32_t meta_quantifier = 0;
uint32_t add_after_mark = 0;
+uint32_t extra_options = cb->cx->extra_options;
uint16_t nest_depth = 0;
int after_manual_callout = 0;
int expect_cond_assert = 0;
@@ -2356,12 +2503,12 @@ nest_save *top_nest, *end_nests;
/* Insert leading items for word and line matching (features provided for the
benefit of pcre2grep). */
-if ((cb->cx->extra_options & PCRE2_EXTRA_MATCH_LINE) != 0)
+if ((extra_options & PCRE2_EXTRA_MATCH_LINE) != 0)
{
*parsed_pattern++ = META_CIRCUMFLEX;
*parsed_pattern++ = META_NOCAPTURE;
}
-else if ((cb->cx->extra_options & PCRE2_EXTRA_MATCH_WORD) != 0)
+else if ((extra_options & PCRE2_EXTRA_MATCH_WORD) != 0)
{
*parsed_pattern++ = META_ESCAPE + ESC_b;
*parsed_pattern++ = META_NOCAPTURE;
@@ -2526,7 +2673,7 @@ while (ptr < ptrend)
if ((options & PCRE2_ALT_VERBNAMES) != 0)
{
escape = PRIV(check_escape)(&ptr, ptrend, &c, &errorcode, options,
- FALSE, cb);
+ cb->cx->extra_options, FALSE, cb);
if (errorcode != 0) goto FAILED;
}
else escape = 0; /* Treat all as literal */
@@ -2639,23 +2786,30 @@ while (ptr < ptrend)
if (expect_cond_assert > 0)
{
BOOL ok = c == CHAR_LEFT_PARENTHESIS && ptrend - ptr >= 3 &&
- ptr[0] == CHAR_QUESTION_MARK;
- if (ok) switch(ptr[1])
+ (ptr[0] == CHAR_QUESTION_MARK || ptr[0] == CHAR_ASTERISK);
+ if (ok)
{
- case CHAR_C:
- ok = expect_cond_assert == 2;
- break;
+ if (ptr[0] == CHAR_ASTERISK) /* New alpha assertion format, possibly */
+ {
+ ok = MAX_255(ptr[1]) && (cb->ctypes[ptr[1]] & ctype_lcletter) != 0;
+ }
+ else switch(ptr[1]) /* Traditional symbolic format */
+ {
+ case CHAR_C:
+ ok = expect_cond_assert == 2;
+ break;
- case CHAR_EQUALS_SIGN:
- case CHAR_EXCLAMATION_MARK:
- break;
+ case CHAR_EQUALS_SIGN:
+ case CHAR_EXCLAMATION_MARK:
+ break;
- case CHAR_LESS_THAN_SIGN:
- ok = ptr[2] == CHAR_EQUALS_SIGN || ptr[2] == CHAR_EXCLAMATION_MARK;
- break;
+ case CHAR_LESS_THAN_SIGN:
+ ok = ptr[2] == CHAR_EQUALS_SIGN || ptr[2] == CHAR_EXCLAMATION_MARK;
+ break;
- default:
- ok = FALSE;
+ default:
+ ok = FALSE;
+ }
}
if (!ok)
@@ -2709,11 +2863,11 @@ while (ptr < ptrend)
case CHAR_BACKSLASH:
tempptr = ptr;
escape = PRIV(check_escape)(&ptr, ptrend, &c, &errorcode, options,
- FALSE, cb);
+ cb->cx->extra_options, FALSE, cb);
if (errorcode != 0)
{
ESCAPE_FAILED:
- if ((cb->cx->extra_options & PCRE2_EXTRA_BAD_ESCAPE_IS_LITERAL) == 0)
+ if ((extra_options & PCRE2_EXTRA_BAD_ESCAPE_IS_LITERAL) == 0)
goto FAILED;
ptr = tempptr;
if (ptr >= ptrend) c = CHAR_BACKSLASH; else
@@ -2907,7 +3061,7 @@ while (ptr < ptrend)
/* Not a numerical recursion */
- if (!read_name(&ptr, ptrend, terminator, &offset, &name, &namelen,
+ if (!read_name(&ptr, ptrend, utf, terminator, &offset, &name, &namelen,
&errorcode, cb)) goto ESCAPE_FAILED;
/* \k and \g when used with braces are back references, whereas \g used
@@ -3270,12 +3424,12 @@ while (ptr < ptrend)
else
{
tempptr = ptr;
- escape = PRIV(check_escape)(&ptr, ptrend, &c, &errorcode,
- options, TRUE, cb);
+ escape = PRIV(check_escape)(&ptr, ptrend, &c, &errorcode, options,
+ cb->cx->extra_options, TRUE, cb);
+
if (errorcode != 0)
{
- CLASS_ESCAPE_FAILED:
- if ((cb->cx->extra_options & PCRE2_EXTRA_BAD_ESCAPE_IS_LITERAL) == 0)
+ if ((extra_options & PCRE2_EXTRA_BAD_ESCAPE_IS_LITERAL) == 0)
goto FAILED;
ptr = tempptr;
if (ptr >= ptrend) c = CHAR_BACKSLASH; else
@@ -3285,30 +3439,32 @@ while (ptr < ptrend)
escape = 0; /* Treat as literal character */
}
- if (escape == 0) /* Escaped character code point is in c */
+ switch(escape)
{
+ case 0: /* Escaped character code point is in c */
char_is_literal = FALSE;
goto CLASS_LITERAL;
- }
-
- /* These three escapes do not alter the class range state. */
- if (escape == ESC_b)
- {
- c = CHAR_BS; /* \b is backspace in a class */
+ case ESC_b:
+ c = CHAR_BS; /* \b is backspace in a class */
char_is_literal = FALSE;
goto CLASS_LITERAL;
- }
- else if (escape == ESC_Q)
- {
+ case ESC_Q:
inescq = TRUE; /* Enter literal mode */
goto CLASS_CONTINUE;
- }
- else if (escape == ESC_E) /* Ignore orphan \E */
+ case ESC_E: /* Ignore orphan \E */
goto CLASS_CONTINUE;
+ case ESC_B: /* Always an error in a class */
+ case ESC_R:
+ case ESC_X:
+ errorcode = ERR7;
+ ptr--;
+ goto FAILED;
+ }
+
/* The second part of a range can be a single-character escape
sequence (detected above), but not any of the other escapes. Perl
treats a hyphen as a literal in such circumstances. However, in Perl's
@@ -3318,7 +3474,7 @@ while (ptr < ptrend)
if (class_range_state == RANGE_STARTED)
{
errorcode = ERR50;
- goto CLASS_ESCAPE_FAILED;
+ goto FAILED; /* Not CLASS_ESCAPE_FAILED; always an error */
}
/* Of the remaining escapes, only those that define characters are
@@ -3328,8 +3484,8 @@ while (ptr < ptrend)
switch(escape)
{
case ESC_N:
- errorcode = ERR71; /* Not supported in a class */
- goto CLASS_ESCAPE_FAILED;
+ errorcode = ERR71;
+ goto FAILED;
case ESC_H:
case ESC_h:
@@ -3392,14 +3548,14 @@ while (ptr < ptrend)
}
#else
errorcode = ERR45;
- goto CLASS_ESCAPE_FAILED;
+ goto FAILED;
#endif
break; /* End \P and \p */
default: /* All others are not allowed in a class */
errorcode = ERR7;
ptr--;
- goto CLASS_ESCAPE_FAILED;
+ goto FAILED;
}
/* Perl gives a warning unless a following hyphen is the last character
@@ -3440,7 +3596,8 @@ while (ptr < ptrend)
case CHAR_LEFT_PARENTHESIS:
if (ptr >= ptrend) goto UNCLOSED_PARENTHESIS;
- /* If ( is not followed by ? it is either a capture or a special verb. */
+ /* If ( is not followed by ? it is either a capture or a special verb or an
+ alpha assertion. */
if (*ptr != CHAR_QUESTION_MARK)
{
@@ -3460,17 +3617,122 @@ while (ptr < ptrend)
else *parsed_pattern++ = META_NOCAPTURE;
}
+ /* Do nothing for (* followed by end of pattern or ) so it gives a "bad
+ quantifier" error rather than "(*MARK) must have an argument". */
- /* ---- Handle (*VERB) and (*VERB:NAME) ---- */
+ else if (ptrend - ptr <= 1 || (c = ptr[1]) == CHAR_RIGHT_PARENTHESIS)
+ break;
+
+ /* Handle "alpha assertions" such as (*pla:...). Most of these are
+ synonyms for the historical symbolic assertions, but the script run ones
+ are new. They are distinguished by starting with a lower case letter.
+ Checking both ends of the alphabet makes this work in all character
+ codes. */
+
+ else if (CHMAX_255(c) && (cb->ctypes[c] & ctype_lcletter) != 0)
+ {
+ uint32_t meta;
+
+ vn = alasnames;
+ if (!read_name(&ptr, ptrend, utf, 0, &offset, &name, &namelen,
+ &errorcode, cb)) goto FAILED;
+ if (ptr >= ptrend || *ptr != CHAR_COLON)
+ {
+ errorcode = ERR95; /* Malformed */
+ goto FAILED;
+ }
+
+ /* Scan the table of alpha assertion names */
+
+ for (i = 0; i < alascount; i++)
+ {
+ if (namelen == alasmeta[i].len &&
+ PRIV(strncmp_c8)(name, vn, namelen) == 0)
+ break;
+ vn += alasmeta[i].len + 1;
+ }
+
+ if (i >= alascount)
+ {
+ errorcode = ERR95; /* Alpha assertion not recognized */
+ goto FAILED;
+ }
+
+ /* Check for expecting an assertion condition. If so, only lookaround
+ assertions are valid. */
+
+ meta = alasmeta[i].meta;
+ if (prev_expect_cond_assert > 0 &&
+ (meta < META_LOOKAHEAD || meta > META_LOOKBEHINDNOT))
+ {
+ errorcode = ERR28; /* Assertion expected */
+ goto FAILED;
+ }
+
+ /* The lookaround alphabetic synonyms can be almost entirely handled by
+ jumping to the code that handles the traditional symbolic forms. */
+
+ switch(meta)
+ {
+ default:
+ errorcode = ERR89; /* Unknown code; should never occur because */
+ goto FAILED; /* the meta values come from a table above. */
+
+ case META_ATOMIC:
+ goto ATOMIC_GROUP;
+
+ case META_LOOKAHEAD:
+ goto POSITIVE_LOOK_AHEAD;
+
+ case META_LOOKAHEADNOT:
+ goto NEGATIVE_LOOK_AHEAD;
+
+ case META_LOOKBEHIND:
+ case META_LOOKBEHINDNOT:
+ *parsed_pattern++ = meta;
+ ptr--;
+ goto POST_LOOKBEHIND;
- /* Do nothing for (*) so it gives a "bad quantifier" error rather than
- "(*MARK) must have an argument". */
+ /* The script run facilities are handled here. Unicode support is
+ required (give an error if not, as this is a security issue). Always
+ record a META_SCRIPT_RUN item. Then, for the atomic version, insert
+ META_ATOMIC and remember that we need two META_KETs at the end. */
- else if (ptrend - ptr > 1 && ptr[1] != CHAR_RIGHT_PARENTHESIS)
+ case META_SCRIPT_RUN:
+ case META_ATOMIC_SCRIPT_RUN:
+#ifdef SUPPORT_UNICODE
+ *parsed_pattern++ = META_SCRIPT_RUN;
+ nest_depth++;
+ ptr++;
+ if (meta == META_ATOMIC_SCRIPT_RUN)
+ {
+ *parsed_pattern++ = META_ATOMIC;
+ if (top_nest == NULL) top_nest = (nest_save *)(cb->start_workspace);
+ else if (++top_nest >= end_nests)
+ {
+ errorcode = ERR84;
+ goto FAILED;
+ }
+ top_nest->nest_depth = nest_depth;
+ top_nest->flags = NSF_ATOMICSR;
+ top_nest->options = options & PARSE_TRACKED_OPTIONS;
+ }
+ break;
+#else /* SUPPORT_UNICODE */
+ errorcode = ERR96;
+ goto FAILED;
+#endif
+ }
+ }
+
+
+ /* ---- Handle (*VERB) and (*VERB:NAME) ---- */
+
+ else
{
vn = verbnames;
- if (!read_name(&ptr, ptrend, 0, &offset, &name, &namelen, &errorcode,
- cb)) goto FAILED;
+ if (!read_name(&ptr, ptrend, utf, 0, &offset, &name, &namelen,
+ &errorcode, cb)) goto FAILED;
if (ptr >= ptrend || (*ptr != CHAR_COLON &&
*ptr != CHAR_RIGHT_PARENTHESIS))
{
@@ -3725,7 +3987,7 @@ while (ptr < ptrend)
errorcode = ERR41;
goto FAILED;
}
- if (!read_name(&ptr, ptrend, CHAR_RIGHT_PARENTHESIS, &offset, &name,
+ if (!read_name(&ptr, ptrend, utf, CHAR_RIGHT_PARENTHESIS, &offset, &name,
&namelen, &errorcode, cb)) goto FAILED;
*parsed_pattern++ = META_BACKREF_BYNAME;
*parsed_pattern++ = namelen;
@@ -3785,7 +4047,7 @@ while (ptr < ptrend)
case CHAR_AMPERSAND:
RECURSE_BY_NAME:
- if (!read_name(&ptr, ptrend, CHAR_RIGHT_PARENTHESIS, &offset, &name,
+ if (!read_name(&ptr, ptrend, utf, CHAR_RIGHT_PARENTHESIS, &offset, &name,
&namelen, &errorcode, cb)) goto FAILED;
*parsed_pattern++ = META_RECURSE_BYNAME;
*parsed_pattern++ = namelen;
@@ -3933,14 +4195,15 @@ while (ptr < ptrend)
if (++ptr >= ptrend) goto UNCLOSED_PARENTHESIS;
nest_depth++;
- /* If the next character is ? there must be an assertion next (optionally
- preceded by a callout). We do not check this here, but instead we set
- expect_cond_assert to 2. If this is still greater than zero (callouts
- decrement it) when the next assertion is read, it will be marked as a
- condition that must not be repeated. A value greater than zero also
- causes checking that an assertion (possibly with callout) follows. */
+ /* If the next character is ? or * there must be an assertion next
+ (optionally preceded by a callout). We do not check this here, but
+ instead we set expect_cond_assert to 2. If this is still greater than
+ zero (callouts decrement it) when the next assertion is read, it will be
+ marked as a condition that must not be repeated. A value greater than
+ zero also causes checking that an assertion (possibly with callout)
+ follows. */
- if (*ptr == CHAR_QUESTION_MARK)
+ if (*ptr == CHAR_QUESTION_MARK || *ptr == CHAR_ASTERISK)
{
*parsed_pattern++ = META_COND_ASSERT;
ptr--; /* Pull pointer back to the opening parenthesis. */
@@ -4032,7 +4295,7 @@ while (ptr < ptrend)
terminator = CHAR_RIGHT_PARENTHESIS;
ptr--; /* Point to char before name */
}
- if (!read_name(&ptr, ptrend, terminator, &offset, &name, &namelen,
+ if (!read_name(&ptr, ptrend, utf, terminator, &offset, &name, &namelen,
&errorcode, cb)) goto FAILED;
/* Handle (?(R&name) */
@@ -4086,6 +4349,7 @@ while (ptr < ptrend)
/* ---- Atomic group ---- */
case CHAR_GREATER_THAN_SIGN:
+ ATOMIC_GROUP: /* Come from (*atomic: */
*parsed_pattern++ = META_ATOMIC;
nest_depth++;
ptr++;
@@ -4095,11 +4359,13 @@ while (ptr < ptrend)
/* ---- Lookahead assertions ---- */
case CHAR_EQUALS_SIGN:
+ POSITIVE_LOOK_AHEAD: /* Come from (*pla: */
*parsed_pattern++ = META_LOOKAHEAD;
ptr++;
goto POST_ASSERTION;
case CHAR_EXCLAMATION_MARK:
+ NEGATIVE_LOOK_AHEAD: /* Come from (*nla: */
*parsed_pattern++ = META_LOOKAHEADNOT;
ptr++;
goto POST_ASSERTION;
@@ -4119,6 +4385,8 @@ while (ptr < ptrend)
}
*parsed_pattern++ = (ptr[1] == CHAR_EQUALS_SIGN)?
META_LOOKBEHIND : META_LOOKBEHINDNOT;
+
+ POST_LOOKBEHIND: /* Come from (*plb: and (*nlb: */
*has_lookbehind = TRUE;
offset = (PCRE2_SIZE)(ptr - cb->start_pattern - 2);
PUTOFFSET(offset, parsed_pattern);
@@ -4161,7 +4429,7 @@ while (ptr < ptrend)
terminator = CHAR_APOSTROPHE; /* Terminator */
DEFINE_NAME:
- if (!read_name(&ptr, ptrend, terminator, &offset, &name, &namelen,
+ if (!read_name(&ptr, ptrend, utf, terminator, &offset, &name, &namelen,
&errorcode, cb)) goto FAILED;
/* We have a name for this capturing group. It is also assigned a number,
@@ -4280,6 +4548,14 @@ while (ptr < ptrend)
cb->bracount = top_nest->max_group;
if ((top_nest->flags & NSF_CONDASSERT) != 0)
okquantifier = FALSE;
+
+ if ((top_nest->flags & NSF_ATOMICSR) != 0)
+ {
+ *parsed_pattern++ = META_KET;
+ }
+
+
+
if (top_nest == (nest_save *)(cb->start_workspace)) top_nest = NULL;
else top_nest--;
}
@@ -4311,12 +4587,12 @@ parsed_pattern = manage_callouts(ptr, &previous_callout, auto_callout,
/* Insert trailing items for word and line matching (features provided for the
benefit of pcre2grep). */
-if ((cb->cx->extra_options & PCRE2_EXTRA_MATCH_LINE) != 0)
+if ((extra_options & PCRE2_EXTRA_MATCH_LINE) != 0)
{
*parsed_pattern++ = META_KET;
*parsed_pattern++ = META_DOLLAR;
}
-else if ((cb->cx->extra_options & PCRE2_EXTRA_MATCH_WORD) != 0)
+else if ((extra_options & PCRE2_EXTRA_MATCH_WORD) != 0)
{
*parsed_pattern++ = META_KET;
*parsed_pattern++ = META_ESCAPE + ESC_b;
@@ -4421,6 +4697,14 @@ for (;;)
code += GET(code, 1) + 1 + LINK_SIZE;
break;
+ case OP_MARK:
+ case OP_COMMIT_ARG:
+ case OP_PRUNE_ARG:
+ case OP_SKIP_ARG:
+ case OP_THEN_ARG:
+ code += code[1] + PRIV(OP_lengths)[*code];
+ break;
+
default:
return code;
}
@@ -5516,10 +5800,10 @@ for (;; pptr++)
if (range_is_literal &&
(cb->ctypes[c] & ctype_letter) != 0 &&
(cb->ctypes[d] & ctype_letter) != 0 &&
- (d <= CHAR_z) == (d <= CHAR_z))
+ (c <= CHAR_z) == (d <= CHAR_z))
{
uint32_t uc = (d <= CHAR_z)? 0 : 64;
- uint32_t C = d - uc;
+ uint32_t C = c - uc;
uint32_t D = d - uc;
if (C <= CHAR_i)
@@ -5664,7 +5948,10 @@ for (;; pptr++)
(void)memmove(code + (32 / sizeof(PCRE2_UCHAR)), code,
CU2BYTES(class_uchardata - code));
if (negate_class && !xclass_has_prop)
- for (i = 0; i < 32; i++) classbits[i] = ~classbits[i];
+ {
+ /* Using 255 ^ instead of ~ avoids clang sanitize warning. */
+ for (i = 0; i < 32; i++) classbits[i] = 255 ^ classbits[i];
+ }
memcpy(code, classbits, 32);
code = class_uchardata + (32 / sizeof(PCRE2_UCHAR));
}
@@ -5687,7 +5974,10 @@ for (;; pptr++)
if (lengthptr == NULL) /* Save time in the pre-compile phase */
{
if (negate_class)
- for (i = 0; i < 32; i++) classbits[i] = ~classbits[i];
+ {
+ /* Using 255 ^ instead of ~ avoids clang sanitize warning. */
+ for (i = 0; i < 32; i++) classbits[i] = 255 ^ classbits[i];
+ }
memcpy(code, classbits, 32);
}
code += 32 / sizeof(PCRE2_UCHAR);
@@ -5901,7 +6191,7 @@ for (;; pptr++)
}
goto GROUP_PROCESS_NOTE_EMPTY;
- /* The DEFINE condition is always false. It's internal groups may never
+ /* The DEFINE condition is always false. Its internal groups may never
be called, so matched_char must remain false, hence the jump to
GROUP_PROCESS rather than GROUP_PROCESS_NOTE_EMPTY. */
@@ -5997,6 +6287,10 @@ for (;; pptr++)
bravalue = OP_ONCE;
goto GROUP_PROCESS_NOTE_EMPTY;
+ case META_SCRIPT_RUN:
+ bravalue = OP_SCRIPT_RUN;
+ goto GROUP_PROCESS_NOTE_EMPTY;
+
case META_NOCAPTURE:
bravalue = OP_BRA;
/* Fall through */
@@ -6237,8 +6531,8 @@ for (;; pptr++)
groupnumber = ng->number;
/* For a recursion, that's all that is needed. We can now go to
- the code above that handles numerical recursion, applying it to
- the first group with the given name. */
+ the code that handles numerical recursion, applying it to the first
+ group with the given name. */
if (meta == META_RECURSE_BYNAME)
{
@@ -6632,6 +6926,7 @@ for (;; pptr++)
case OP_ASSERTBACK:
case OP_ASSERTBACK_NOT:
case OP_ONCE:
+ case OP_SCRIPT_RUN:
case OP_BRA:
case OP_CBRA:
case OP_COND:
@@ -6844,16 +7139,16 @@ for (;; pptr++)
}
/* If the maximum is unlimited, set a repeater in the final copy. For
- ONCE brackets, that's all we need to do. However, possessively repeated
- ONCE brackets can be converted into non-capturing brackets, as the
- behaviour of (?:xx)++ is the same as (?>xx)++ and this saves having to
- deal with possessive ONCEs specially.
+ SCRIPT_RUN and ONCE brackets, that's all we need to do. However,
+ possessively repeated ONCE brackets can be converted into non-capturing
+ brackets, as the behaviour of (?:xx)++ is the same as (?>xx)++ and this
+ saves having to deal with possessive ONCEs specially.
Otherwise, when we are doing the actual compile phase, check to see
whether this group is one that could match an empty string. If so,
convert the initial operator to the S form (e.g. OP_BRA -> OP_SBRA) so
that runtime checking can be done. [This check is also applied to ONCE
- groups at runtime, but in a different way.]
+ and SCRIPT_RUN groups at runtime, but in a different way.]
Then, if the quantifier was possessive and the bracket is not a
conditional, we convert the BRA code to the POS form, and the KET code to
@@ -6877,13 +7172,14 @@ for (;; pptr++)
if (*bracode == OP_ONCE && possessive_quantifier) *bracode = OP_BRA;
- /* For non-possessive ONCE brackets, all we need to do is to
- set the KET. */
+ /* For non-possessive ONCE and for SCRIPT_RUN brackets, all we need
+ to do is to set the KET. */
- if (*bracode == OP_ONCE) *ketcode = OP_KETRMAX + repeat_type;
+ if (*bracode == OP_ONCE || *bracode == OP_SCRIPT_RUN)
+ *ketcode = OP_KETRMAX + repeat_type;
- /* Handle non-ONCE brackets and possessive ONCEs (which have been
- converted to non-capturing above). */
+ /* Handle non-SCRIPT_RUN and non-ONCE brackets and possessive ONCEs
+ (which have been converted to non-capturing above). */
else
{
@@ -7267,9 +7563,8 @@ for (;; pptr++)
scanned and these numbers are replaced by offsets within the pattern. It is
done like this to avoid problems with forward references and adjusting
offsets when groups are duplicated and moved (as discovered in previous
- implementations). Note that a recursion does not have a set first character
- (relevant if it is repeated, because it will then be wrapped with ONCE
- brackets). */
+ implementations). Note that a recursion does not have a set first
+ character. */
case META_RECURSE:
GETPLUSOFFSET(offset, pptr);
@@ -7286,6 +7581,8 @@ for (;; pptr++)
groupsetfirstcu = FALSE;
cb->had_recurse = TRUE;
if (firstcuflags == REQ_UNSET) firstcuflags = REQ_NONE;
+ zerofirstcu = firstcu;
+ zerofirstcuflags = firstcuflags;
break;
@@ -7340,9 +7637,20 @@ for (;; pptr++)
{
uint32_t ptype = *(++pptr) >> 16;
uint32_t pdata = *pptr & 0xffff;
- *code++ = (meta_arg == ESC_p)? OP_PROP : OP_NOTPROP;
- *code++ = ptype;
- *code++ = pdata;
+
+ /* The special case of \p{Any} is compiled to OP_ALLANY so as to benefit
+ from the auto-anchoring code. */
+
+ if (meta_arg == ESC_p && ptype == PT_ANY)
+ {
+ *code++ = OP_ALLANY;
+ }
+ else
+ {
+ *code++ = (meta_arg == ESC_p)? OP_PROP : OP_NOTPROP;
+ *code++ = ptype;
+ *code++ = pdata;
+ }
break; /* End META_ESCAPE */
}
#endif
@@ -8240,6 +8548,7 @@ do {
case OP_SCBRAPOS:
case OP_ASSERT:
case OP_ONCE:
+ case OP_SCRIPT_RUN:
d = find_firstassertedcu(scode, &dflags, inassert + ((op==OP_ASSERT)?1:0));
if (dflags < 0)
return 0;
@@ -8439,6 +8748,7 @@ for (;; pptr++)
case META_LOOKBEHIND:
case META_LOOKBEHINDNOT:
case META_NOCAPTURE:
+ case META_SCRIPT_RUN:
nestlevel++;
break;
@@ -8851,6 +9161,7 @@ for (;; pptr++)
case META_ATOMIC:
case META_NOCAPTURE:
+ case META_SCRIPT_RUN:
pptr++;
CHECK_GROUP:
grouplength = get_grouplength(&pptr, TRUE, errcodeptr, lcptr, group,
@@ -9030,6 +9341,7 @@ for (pptr = cb->parsed_pattern; *pptr != META_END; pptr++)
case META_QUERY_QUERY:
case META_RANGE_ESCAPED:
case META_RANGE_LITERAL:
+ case META_SCRIPT_RUN:
case META_SKIP:
case META_THEN:
break;
diff --git a/thirdparty/pcre2/src/pcre2_context.c b/thirdparty/pcre2/src/pcre2_context.c
index 2c14df0080..9c2886a6d0 100644
--- a/thirdparty/pcre2/src/pcre2_context.c
+++ b/thirdparty/pcre2/src/pcre2_context.c
@@ -7,7 +7,7 @@ and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
Original API code Copyright (c) 1997-2012 University of Cambridge
- New API code Copyright (c) 2016-2017 University of Cambridge
+ New API code Copyright (c) 2016-2018 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -163,11 +163,13 @@ when no context is supplied to a match function. */
const pcre2_match_context PRIV(default_match_context) = {
{ default_malloc, default_free, NULL },
#ifdef SUPPORT_JIT
- NULL,
- NULL,
+ NULL, /* JIT callback */
+ NULL, /* JIT callback data */
#endif
- NULL,
- NULL,
+ NULL, /* Callout function */
+ NULL, /* Callout data */
+ NULL, /* Substitute callout function */
+ NULL, /* Substitute callout data */
PCRE2_UNSET, /* Offset limit */
HEAP_LIMIT,
MATCH_LIMIT,
@@ -404,6 +406,16 @@ return 0;
}
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
+pcre2_set_substitute_callout(pcre2_match_context *mcontext,
+ int (*substitute_callout)(pcre2_substitute_callout_block *, void *),
+ void *substitute_callout_data)
+{
+mcontext->substitute_callout = substitute_callout;
+mcontext->substitute_callout_data = substitute_callout_data;
+return 0;
+}
+
+PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
pcre2_set_heap_limit(pcre2_match_context *mcontext, uint32_t limit)
{
mcontext->heap_limit = limit;
diff --git a/thirdparty/pcre2/src/pcre2_convert.c b/thirdparty/pcre2/src/pcre2_convert.c
index 1dd5c337dc..d45b6fee97 100644
--- a/thirdparty/pcre2/src/pcre2_convert.c
+++ b/thirdparty/pcre2/src/pcre2_convert.c
@@ -276,7 +276,7 @@ while (plength > 0)
break;
case CHAR_BACKSLASH:
- if (plength <= 0) return PCRE2_ERROR_END_BACKSLASH;
+ if (plength == 0) return PCRE2_ERROR_END_BACKSLASH;
if (extended) nextisliteral = TRUE; else
{
if (*posix < 127 && strchr(posix_meta_escapes, *posix) != NULL)
diff --git a/thirdparty/pcre2/src/pcre2_dfa_match.c b/thirdparty/pcre2/src/pcre2_dfa_match.c
index 9b43237da7..bbf3e21064 100644
--- a/thirdparty/pcre2/src/pcre2_dfa_match.c
+++ b/thirdparty/pcre2/src/pcre2_dfa_match.c
@@ -7,7 +7,7 @@ and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
Original API code Copyright (c) 1997-2012 University of Cambridge
- New API code Copyright (c) 2016-2018 University of Cambridge
+ New API code Copyright (c) 2016-2019 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -85,7 +85,8 @@ in others, so I abandoned this code. */
#define PUBLIC_DFA_MATCH_OPTIONS \
(PCRE2_ANCHORED|PCRE2_ENDANCHORED|PCRE2_NOTBOL|PCRE2_NOTEOL|PCRE2_NOTEMPTY| \
PCRE2_NOTEMPTY_ATSTART|PCRE2_NO_UTF_CHECK|PCRE2_PARTIAL_HARD| \
- PCRE2_PARTIAL_SOFT|PCRE2_DFA_SHORTEST|PCRE2_DFA_RESTART)
+ PCRE2_PARTIAL_SOFT|PCRE2_DFA_SHORTEST|PCRE2_DFA_RESTART| \
+ PCRE2_COPY_MATCHED_SUBJECT)
/*************************************************
@@ -173,6 +174,7 @@ static const uint8_t coptable[] = {
0, /* Assert behind */
0, /* Assert behind not */
0, /* ONCE */
+ 0, /* SCRIPT_RUN */
0, 0, 0, 0, 0, /* BRA, BRAPOS, CBRA, CBRAPOS, COND */
0, 0, 0, 0, 0, /* SBRA, SBRAPOS, SCBRA, SCBRAPOS, SCOND */
0, 0, /* CREF, DNCREF */
@@ -247,6 +249,7 @@ static const uint8_t poptable[] = {
0, /* Assert behind */
0, /* Assert behind not */
0, /* ONCE */
+ 0, /* SCRIPT_RUN */
0, 0, 0, 0, 0, /* BRA, BRAPOS, CBRA, CBRAPOS, COND */
0, 0, 0, 0, 0, /* SBRA, SBRAPOS, SCBRA, SCBRAPOS, SCOND */
0, 0, /* CREF, DNCREF */
@@ -316,8 +319,8 @@ finding the minimum heap requirement for a match. */
typedef struct RWS_anchor {
struct RWS_anchor *next;
- unsigned int size; /* Number of ints */
- unsigned int free; /* Number of ints */
+ uint32_t size; /* Number of ints */
+ uint32_t free; /* Number of ints */
} RWS_anchor;
#define RWS_ANCHOR_SIZE (sizeof(RWS_anchor)/sizeof(int))
@@ -413,20 +416,24 @@ if (rws->next != NULL)
new = rws->next;
}
-/* All sizes are in units of sizeof(int), except for mb->heaplimit, which is in
-kibibytes. */
+/* Sizes in the RWS_anchor blocks are in units of sizeof(int), but
+mb->heap_limit and mb->heap_used are in kibibytes. Play carefully, to avoid
+overflow. */
else
{
- unsigned int newsize = rws->size * 2;
- unsigned int heapleft = (unsigned int)
- (((1024/sizeof(int))*mb->heap_limit - mb->heap_used));
- if (newsize > heapleft) newsize = heapleft;
+ uint32_t newsize = (rws->size >= UINT32_MAX/2)? UINT32_MAX/2 : rws->size * 2;
+ uint32_t newsizeK = newsize/(1024/sizeof(int));
+
+ if (newsizeK + mb->heap_used > mb->heap_limit)
+ newsizeK = (uint32_t)(mb->heap_limit - mb->heap_used);
+ newsize = newsizeK*(1024/sizeof(int));
+
if (newsize < RWS_RSIZE + ovecsize + RWS_ANCHOR_SIZE)
return PCRE2_ERROR_HEAPLIMIT;
new = mb->memctl.malloc(newsize*sizeof(int), mb->memctl.memory_data);
if (new == NULL) return PCRE2_ERROR_NOMEMORY;
- mb->heap_used += newsize;
+ mb->heap_used += newsizeK;
new->next = NULL;
new->size = newsize;
rws->next = new;
@@ -2560,7 +2567,7 @@ for (;;)
if (clen > 0)
{
isinclass = (c > 255)? (codevalue == OP_NCLASS) :
- ((((uint8_t *)(code + 1))[c/8] & (1 << (c&7))) != 0);
+ ((((uint8_t *)(code + 1))[c/8] & (1u << (c&7))) != 0);
}
}
@@ -2753,7 +2760,7 @@ for (;;)
/* There is also an always-true condition */
else if (condcode == OP_TRUE)
- { ADD_ACTIVE(state_offset + LINK_SIZE + 2 + IMM2_SIZE, 0); }
+ { ADD_ACTIVE(state_offset + LINK_SIZE + 2, 0); }
/* The only supported version of OP_RREF is for the value RREF_ANY,
which means "test if in any recursion". We can't test for specifically
@@ -3226,6 +3233,8 @@ pcre2_dfa_match(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length,
pcre2_match_context *mcontext, int *workspace, PCRE2_SIZE wscount)
{
int rc;
+int was_zero_terminated = 0;
+
const pcre2_real_code *re = (const pcre2_real_code *)code;
PCRE2_SPTR start_match;
@@ -3265,7 +3274,11 @@ rws->free = RWS_BASE_SIZE - RWS_ANCHOR_SIZE;
/* A length equal to PCRE2_ZERO_TERMINATED implies a zero-terminated
subject string. */
-if (length == PCRE2_ZERO_TERMINATED) length = PRIV(strlen)(subject);
+if (length == PCRE2_ZERO_TERMINATED)
+ {
+ length = PRIV(strlen)(subject);
+ was_zero_terminated = 1;
+ }
/* Plausibility checks */
@@ -3518,10 +3531,20 @@ if ((re->flags & PCRE2_LASTSET) != 0)
}
}
+/* If the match data block was previously used with PCRE2_COPY_MATCHED_SUBJECT,
+free the memory that was obtained. */
+
+if ((match_data->flags & PCRE2_MD_COPIED_SUBJECT) != 0)
+ {
+ match_data->memctl.free((void *)match_data->subject,
+ match_data->memctl.memory_data);
+ match_data->flags &= ~PCRE2_MD_COPIED_SUBJECT;
+ }
+
/* Fill in fields that are always returned in the match data. */
match_data->code = re;
-match_data->subject = subject;
+match_data->subject = NULL; /* Default for no match */
match_data->mark = NULL;
match_data->matchedby = PCRE2_MATCHEDBY_DFA_INTERPRETER;
@@ -3586,7 +3609,7 @@ for (;;)
#if PCRE2_CODE_UNIT_WIDTH != 8
if (c > 255) c = 255;
#endif
- ok = (start_bits[c/8] & (1 << (c&7))) != 0;
+ ok = (start_bits[c/8] & (1u << (c&7))) != 0;
}
}
if (!ok) break;
@@ -3697,7 +3720,7 @@ for (;;)
#if PCRE2_CODE_UNIT_WIDTH != 8
if (c > 255) c = 255;
#endif
- if ((start_bits[c/8] & (1 << (c&7))) != 0) break;
+ if ((start_bits[c/8] & (1u << (c&7))) != 0) break;
start_match++;
}
@@ -3816,6 +3839,20 @@ for (;;)
match_data->rightchar = (PCRE2_SIZE)( mb->last_used_ptr - subject);
match_data->startchar = (PCRE2_SIZE)(start_match - subject);
match_data->rc = rc;
+
+ if (rc >= 0 &&(options & PCRE2_COPY_MATCHED_SUBJECT) != 0)
+ {
+ length = CU2BYTES(length + was_zero_terminated);
+ match_data->subject = match_data->memctl.malloc(length,
+ match_data->memctl.memory_data);
+ if (match_data->subject == NULL) return PCRE2_ERROR_NOMEMORY;
+ memcpy((void *)match_data->subject, subject, length);
+ match_data->flags |= PCRE2_MD_COPIED_SUBJECT;
+ }
+ else
+ {
+ if (rc >= 0 || rc == PCRE2_ERROR_PARTIAL) match_data->subject = subject;
+ }
goto EXIT;
}
diff --git a/thirdparty/pcre2/src/pcre2_error.c b/thirdparty/pcre2/src/pcre2_error.c
index 4b3b3f1bc0..1d02cf14a3 100644
--- a/thirdparty/pcre2/src/pcre2_error.c
+++ b/thirdparty/pcre2/src/pcre2_error.c
@@ -7,7 +7,7 @@ and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
Original API code Copyright (c) 1997-2012 University of Cambridge
- New API code Copyright (c) 2016-2018 University of Cambridge
+ New API code Copyright (c) 2016-2019 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -71,7 +71,7 @@ static const unsigned char compile_error_texts[] =
/* 5 */
"number too big in {} quantifier\0"
"missing terminating ] for character class\0"
- "invalid escape sequence in character class\0"
+ "escape sequence is invalid in character class\0"
"range out of order in character class\0"
"quantifier does not follow a repeatable item\0"
/* 10 */
@@ -95,7 +95,7 @@ static const unsigned char compile_error_texts[] =
/* 25 */
"lookbehind assertion is not fixed length\0"
"a relative value of zero is not allowed\0"
- "conditional group contains more than two branches\0"
+ "conditional subpattern contains more than two branches\0"
"assertion expected after (?( or (?(?C)\0"
"digit expected after (?+ or (?-\0"
/* 30 */
@@ -113,21 +113,21 @@ static const unsigned char compile_error_texts[] =
/* 40 */
"invalid escape sequence in (*VERB) name\0"
"unrecognized character after (?P\0"
- "syntax error in subpattern name (missing terminator)\0"
+ "syntax error in subpattern name (missing terminator?)\0"
"two named subpatterns have the same name (PCRE2_DUPNAMES not set)\0"
- "group name must start with a non-digit\0"
+ "subpattern name must start with a non-digit\0"
/* 45 */
"this version of PCRE2 does not have support for \\P, \\p, or \\X\0"
"malformed \\P or \\p sequence\0"
"unknown property name after \\P or \\p\0"
- "subpattern name is too long (maximum " XSTRING(MAX_NAME_SIZE) " characters)\0"
+ "subpattern name is too long (maximum " XSTRING(MAX_NAME_SIZE) " code units)\0"
"too many named subpatterns (maximum " XSTRING(MAX_NAME_COUNT) ")\0"
/* 50 */
"invalid range in character class\0"
"octal value is greater than \\377 in 8-bit non-UTF-8 mode\0"
"internal error: overran compiling workspace\0"
"internal error: previously-checked referenced subpattern not found\0"
- "DEFINE group contains more than one branch\0"
+ "DEFINE subpattern contains more than one branch\0"
/* 55 */
"missing opening brace after \\o\0"
"internal error: unknown newline setting\0"
@@ -137,7 +137,7 @@ static const unsigned char compile_error_texts[] =
"obsolete error (should not occur)\0" /* Was the above */
/* 60 */
"(*VERB) not recognized or malformed\0"
- "group number is too big\0"
+ "subpattern number is too big\0"
"subpattern name expected\0"
"internal error: parsed pattern overflow\0"
"non-octal character in \\o{} (closing brace missing?)\0"
@@ -181,6 +181,9 @@ static const unsigned char compile_error_texts[] =
"invalid option bits with PCRE2_LITERAL\0"
"\\N{U+dddd} is supported only in Unicode (UTF) mode\0"
"invalid hyphen in option setting\0"
+ /* 95 */
+ "(*alpha_assertion) not recognized\0"
+ "script runs require Unicode support, which this version of PCRE2 does not have\0"
;
/* Match-time and UTF error texts are in the same format. */
diff --git a/thirdparty/pcre2/src/pcre2_extuni.c b/thirdparty/pcre2/src/pcre2_extuni.c
index 237211abf7..5a719e9cb4 100644
--- a/thirdparty/pcre2/src/pcre2_extuni.c
+++ b/thirdparty/pcre2/src/pcre2_extuni.c
@@ -7,7 +7,7 @@ and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
Original API code Copyright (c) 1997-2012 University of Cambridge
- New API code Copyright (c) 2016-2018 University of Cambridge
+ New API code Copyright (c) 2016-2019 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -100,7 +100,7 @@ while (eptr < end_subject)
int len = 1;
if (!utf) c = *eptr; else { GETCHARLEN(c, eptr, len); }
rgb = UCD_GRAPHBREAK(c);
- if ((PRIV(ucp_gbtable)[lgb] & (1 << rgb)) == 0) break;
+ if ((PRIV(ucp_gbtable)[lgb] & (1u << rgb)) == 0) break;
/* Not breaking between Regional Indicators is allowed only if there
are an even number of preceding RIs. */
diff --git a/thirdparty/pcre2/src/pcre2_internal.h b/thirdparty/pcre2/src/pcre2_internal.h
index 8750f2f174..814d91bddb 100644
--- a/thirdparty/pcre2/src/pcre2_internal.h
+++ b/thirdparty/pcre2/src/pcre2_internal.h
@@ -7,7 +7,7 @@ and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
Original API code Copyright (c) 1997-2012 University of Cambridge
- New API code Copyright (c) 2016-2018 University of Cambridge
+ New API code Copyright (c) 2016-2019 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -148,16 +148,7 @@ pcre2_match() because of the way it backtracks. */
/* When checking for integer overflow in pcre2_compile(), we need to handle
large integers. If a 64-bit integer type is available, we can use that.
Otherwise we have to cast to double, which of course requires floating point
-arithmetic. Handle this by defining a macro for the appropriate type. If
-stdint.h is available, include it; it may define INT64_MAX. Systems that do not
-have stdint.h (e.g. Solaris) may have inttypes.h. The macro int64_t may be set
-by "configure". */
-
-#if defined HAVE_STDINT_H
-#include <stdint.h>
-#elif defined HAVE_INTTYPES_H
-#include <inttypes.h>
-#endif
+arithmetic. Handle this by defining a macro for the appropriate type. */
#if defined INT64_MAX || defined int64_t
#define INT64_OR_DOUBLE int64_t
@@ -535,6 +526,10 @@ enum { PCRE2_MATCHEDBY_INTERPRETER, /* pcre2_match() */
PCRE2_MATCHEDBY_DFA_INTERPRETER, /* pcre2_dfa_match() */
PCRE2_MATCHEDBY_JIT }; /* pcre2_jit_match() */
+/* Values for the flags field in a match data block. */
+
+#define PCRE2_MD_COPIED_SUBJECT 0x01u
+
/* Magic number to provide a small check against being handed junk. */
#define MAGIC_NUMBER 0x50435245UL /* 'PCRE' */
@@ -569,11 +564,11 @@ these tables. */
without checking pcre2_jit_compile.c, which has an assertion to ensure that
ctype_word has the value 16. */
-#define ctype_space 0x01
-#define ctype_letter 0x02
-#define ctype_digit 0x04
-#define ctype_xdigit 0x08 /* not actually used any more */
-#define ctype_word 0x10 /* alphanumeric or '_' */
+#define ctype_space 0x01
+#define ctype_letter 0x02
+#define ctype_lcletter 0x04
+#define ctype_digit 0x08
+#define ctype_word 0x10 /* alphanumeric or '_' */
/* Offsets of the various tables from the base tables pointer, and
total length of the tables. */
@@ -874,34 +869,48 @@ a positive value. */
#define STR_RIGHT_CURLY_BRACKET "}"
#define STR_TILDE "~"
-#define STRING_ACCEPT0 "ACCEPT\0"
-#define STRING_COMMIT0 "COMMIT\0"
-#define STRING_F0 "F\0"
-#define STRING_FAIL0 "FAIL\0"
-#define STRING_MARK0 "MARK\0"
-#define STRING_PRUNE0 "PRUNE\0"
-#define STRING_SKIP0 "SKIP\0"
-#define STRING_THEN "THEN"
-
-#define STRING_alpha0 "alpha\0"
-#define STRING_lower0 "lower\0"
-#define STRING_upper0 "upper\0"
-#define STRING_alnum0 "alnum\0"
-#define STRING_ascii0 "ascii\0"
-#define STRING_blank0 "blank\0"
-#define STRING_cntrl0 "cntrl\0"
-#define STRING_digit0 "digit\0"
-#define STRING_graph0 "graph\0"
-#define STRING_print0 "print\0"
-#define STRING_punct0 "punct\0"
-#define STRING_space0 "space\0"
-#define STRING_word0 "word\0"
-#define STRING_xdigit "xdigit"
-
-#define STRING_DEFINE "DEFINE"
-#define STRING_VERSION "VERSION"
-#define STRING_WEIRD_STARTWORD "[:<:]]"
-#define STRING_WEIRD_ENDWORD "[:>:]]"
+#define STRING_ACCEPT0 "ACCEPT\0"
+#define STRING_COMMIT0 "COMMIT\0"
+#define STRING_F0 "F\0"
+#define STRING_FAIL0 "FAIL\0"
+#define STRING_MARK0 "MARK\0"
+#define STRING_PRUNE0 "PRUNE\0"
+#define STRING_SKIP0 "SKIP\0"
+#define STRING_THEN "THEN"
+
+#define STRING_atomic0 "atomic\0"
+#define STRING_pla0 "pla\0"
+#define STRING_plb0 "plb\0"
+#define STRING_nla0 "nla\0"
+#define STRING_nlb0 "nlb\0"
+#define STRING_sr0 "sr\0"
+#define STRING_asr0 "asr\0"
+#define STRING_positive_lookahead0 "positive_lookahead\0"
+#define STRING_positive_lookbehind0 "positive_lookbehind\0"
+#define STRING_negative_lookahead0 "negative_lookahead\0"
+#define STRING_negative_lookbehind0 "negative_lookbehind\0"
+#define STRING_script_run0 "script_run\0"
+#define STRING_atomic_script_run "atomic_script_run"
+
+#define STRING_alpha0 "alpha\0"
+#define STRING_lower0 "lower\0"
+#define STRING_upper0 "upper\0"
+#define STRING_alnum0 "alnum\0"
+#define STRING_ascii0 "ascii\0"
+#define STRING_blank0 "blank\0"
+#define STRING_cntrl0 "cntrl\0"
+#define STRING_digit0 "digit\0"
+#define STRING_graph0 "graph\0"
+#define STRING_print0 "print\0"
+#define STRING_punct0 "punct\0"
+#define STRING_space0 "space\0"
+#define STRING_word0 "word\0"
+#define STRING_xdigit "xdigit"
+
+#define STRING_DEFINE "DEFINE"
+#define STRING_VERSION "VERSION"
+#define STRING_WEIRD_STARTWORD "[:<:]]"
+#define STRING_WEIRD_ENDWORD "[:>:]]"
#define STRING_CR_RIGHTPAR "CR)"
#define STRING_LF_RIGHTPAR "LF)"
@@ -1150,34 +1159,48 @@ only. */
#define STR_RIGHT_CURLY_BRACKET "\175"
#define STR_TILDE "\176"
-#define STRING_ACCEPT0 STR_A STR_C STR_C STR_E STR_P STR_T "\0"
-#define STRING_COMMIT0 STR_C STR_O STR_M STR_M STR_I STR_T "\0"
-#define STRING_F0 STR_F "\0"
-#define STRING_FAIL0 STR_F STR_A STR_I STR_L "\0"
-#define STRING_MARK0 STR_M STR_A STR_R STR_K "\0"
-#define STRING_PRUNE0 STR_P STR_R STR_U STR_N STR_E "\0"
-#define STRING_SKIP0 STR_S STR_K STR_I STR_P "\0"
-#define STRING_THEN STR_T STR_H STR_E STR_N
-
-#define STRING_alpha0 STR_a STR_l STR_p STR_h STR_a "\0"
-#define STRING_lower0 STR_l STR_o STR_w STR_e STR_r "\0"
-#define STRING_upper0 STR_u STR_p STR_p STR_e STR_r "\0"
-#define STRING_alnum0 STR_a STR_l STR_n STR_u STR_m "\0"
-#define STRING_ascii0 STR_a STR_s STR_c STR_i STR_i "\0"
-#define STRING_blank0 STR_b STR_l STR_a STR_n STR_k "\0"
-#define STRING_cntrl0 STR_c STR_n STR_t STR_r STR_l "\0"
-#define STRING_digit0 STR_d STR_i STR_g STR_i STR_t "\0"
-#define STRING_graph0 STR_g STR_r STR_a STR_p STR_h "\0"
-#define STRING_print0 STR_p STR_r STR_i STR_n STR_t "\0"
-#define STRING_punct0 STR_p STR_u STR_n STR_c STR_t "\0"
-#define STRING_space0 STR_s STR_p STR_a STR_c STR_e "\0"
-#define STRING_word0 STR_w STR_o STR_r STR_d "\0"
-#define STRING_xdigit STR_x STR_d STR_i STR_g STR_i STR_t
-
-#define STRING_DEFINE STR_D STR_E STR_F STR_I STR_N STR_E
-#define STRING_VERSION STR_V STR_E STR_R STR_S STR_I STR_O STR_N
-#define STRING_WEIRD_STARTWORD STR_LEFT_SQUARE_BRACKET STR_COLON STR_LESS_THAN_SIGN STR_COLON STR_RIGHT_SQUARE_BRACKET STR_RIGHT_SQUARE_BRACKET
-#define STRING_WEIRD_ENDWORD STR_LEFT_SQUARE_BRACKET STR_COLON STR_GREATER_THAN_SIGN STR_COLON STR_RIGHT_SQUARE_BRACKET STR_RIGHT_SQUARE_BRACKET
+#define STRING_ACCEPT0 STR_A STR_C STR_C STR_E STR_P STR_T "\0"
+#define STRING_COMMIT0 STR_C STR_O STR_M STR_M STR_I STR_T "\0"
+#define STRING_F0 STR_F "\0"
+#define STRING_FAIL0 STR_F STR_A STR_I STR_L "\0"
+#define STRING_MARK0 STR_M STR_A STR_R STR_K "\0"
+#define STRING_PRUNE0 STR_P STR_R STR_U STR_N STR_E "\0"
+#define STRING_SKIP0 STR_S STR_K STR_I STR_P "\0"
+#define STRING_THEN STR_T STR_H STR_E STR_N
+
+#define STRING_atomic0 STR_a STR_t STR_o STR_m STR_i STR_c "\0"
+#define STRING_pla0 STR_p STR_l STR_a "\0"
+#define STRING_plb0 STR_p STR_l STR_b "\0"
+#define STRING_nla0 STR_n STR_l STR_a "\0"
+#define STRING_nlb0 STR_n STR_l STR_b "\0"
+#define STRING_sr0 STR_s STR_r "\0"
+#define STRING_asr0 STR_a STR_s STR_r "\0"
+#define STRING_positive_lookahead0 STR_p STR_o STR_s STR_i STR_t STR_i STR_v STR_e STR_UNDERSCORE STR_l STR_o STR_o STR_k STR_a STR_h STR_e STR_a STR_d "\0"
+#define STRING_positive_lookbehind0 STR_p STR_o STR_s STR_i STR_t STR_i STR_v STR_e STR_UNDERSCORE STR_l STR_o STR_o STR_k STR_b STR_e STR_h STR_i STR_n STR_d "\0"
+#define STRING_negative_lookahead0 STR_n STR_e STR_g STR_a STR_t STR_i STR_v STR_e STR_UNDERSCORE STR_l STR_o STR_o STR_k STR_a STR_h STR_e STR_a STR_d "\0"
+#define STRING_negative_lookbehind0 STR_n STR_e STR_g STR_a STR_t STR_i STR_v STR_e STR_UNDERSCORE STR_l STR_o STR_o STR_k STR_b STR_e STR_h STR_i STR_n STR_d "\0"
+#define STRING_script_run0 STR_s STR_c STR_r STR_i STR_p STR_t STR_UNDERSCORE STR_r STR_u STR_n "\0"
+#define STRING_atomic_script_run STR_a STR_t STR_o STR_m STR_i STR_c STR_UNDERSCORE STR_s STR_c STR_r STR_i STR_p STR_t STR_UNDERSCORE STR_r STR_u STR_n
+
+#define STRING_alpha0 STR_a STR_l STR_p STR_h STR_a "\0"
+#define STRING_lower0 STR_l STR_o STR_w STR_e STR_r "\0"
+#define STRING_upper0 STR_u STR_p STR_p STR_e STR_r "\0"
+#define STRING_alnum0 STR_a STR_l STR_n STR_u STR_m "\0"
+#define STRING_ascii0 STR_a STR_s STR_c STR_i STR_i "\0"
+#define STRING_blank0 STR_b STR_l STR_a STR_n STR_k "\0"
+#define STRING_cntrl0 STR_c STR_n STR_t STR_r STR_l "\0"
+#define STRING_digit0 STR_d STR_i STR_g STR_i STR_t "\0"
+#define STRING_graph0 STR_g STR_r STR_a STR_p STR_h "\0"
+#define STRING_print0 STR_p STR_r STR_i STR_n STR_t "\0"
+#define STRING_punct0 STR_p STR_u STR_n STR_c STR_t "\0"
+#define STRING_space0 STR_s STR_p STR_a STR_c STR_e "\0"
+#define STRING_word0 STR_w STR_o STR_r STR_d "\0"
+#define STRING_xdigit STR_x STR_d STR_i STR_g STR_i STR_t
+
+#define STRING_DEFINE STR_D STR_E STR_F STR_I STR_N STR_E
+#define STRING_VERSION STR_V STR_E STR_R STR_S STR_I STR_O STR_N
+#define STRING_WEIRD_STARTWORD STR_LEFT_SQUARE_BRACKET STR_COLON STR_LESS_THAN_SIGN STR_COLON STR_RIGHT_SQUARE_BRACKET STR_RIGHT_SQUARE_BRACKET
+#define STRING_WEIRD_ENDWORD STR_LEFT_SQUARE_BRACKET STR_COLON STR_GREATER_THAN_SIGN STR_COLON STR_RIGHT_SQUARE_BRACKET STR_RIGHT_SQUARE_BRACKET
#define STRING_CR_RIGHTPAR STR_C STR_R STR_RIGHT_PARENTHESIS
#define STRING_LF_RIGHTPAR STR_L STR_F STR_RIGHT_PARENTHESIS
@@ -1485,70 +1508,71 @@ enum {
OP_ASSERTBACK, /* 128 Positive lookbehind */
OP_ASSERTBACK_NOT, /* 129 Negative lookbehind */
- /* ONCE, BRA, BRAPOS, CBRA, CBRAPOS, and COND must come immediately after the
- assertions, with ONCE first, as there's a test for >= ONCE for a subpattern
- that isn't an assertion. The POS versions must immediately follow the non-POS
- versions in each case. */
+ /* ONCE, SCRIPT_RUN, BRA, BRAPOS, CBRA, CBRAPOS, and COND must come
+ immediately after the assertions, with ONCE first, as there's a test for >=
+ ONCE for a subpattern that isn't an assertion. The POS versions must
+ immediately follow the non-POS versions in each case. */
OP_ONCE, /* 130 Atomic group, contains captures */
- OP_BRA, /* 131 Start of non-capturing bracket */
- OP_BRAPOS, /* 132 Ditto, with unlimited, possessive repeat */
- OP_CBRA, /* 133 Start of capturing bracket */
- OP_CBRAPOS, /* 134 Ditto, with unlimited, possessive repeat */
- OP_COND, /* 135 Conditional group */
+ OP_SCRIPT_RUN, /* 131 Non-capture, but check characters' scripts */
+ OP_BRA, /* 132 Start of non-capturing bracket */
+ OP_BRAPOS, /* 133 Ditto, with unlimited, possessive repeat */
+ OP_CBRA, /* 134 Start of capturing bracket */
+ OP_CBRAPOS, /* 135 Ditto, with unlimited, possessive repeat */
+ OP_COND, /* 136 Conditional group */
/* These five must follow the previous five, in the same order. There's a
check for >= SBRA to distinguish the two sets. */
- OP_SBRA, /* 136 Start of non-capturing bracket, check empty */
- OP_SBRAPOS, /* 137 Ditto, with unlimited, possessive repeat */
- OP_SCBRA, /* 138 Start of capturing bracket, check empty */
- OP_SCBRAPOS, /* 139 Ditto, with unlimited, possessive repeat */
- OP_SCOND, /* 140 Conditional group, check empty */
+ OP_SBRA, /* 137 Start of non-capturing bracket, check empty */
+ OP_SBRAPOS, /* 138 Ditto, with unlimited, possessive repeat */
+ OP_SCBRA, /* 139 Start of capturing bracket, check empty */
+ OP_SCBRAPOS, /* 140 Ditto, with unlimited, possessive repeat */
+ OP_SCOND, /* 141 Conditional group, check empty */
/* The next two pairs must (respectively) be kept together. */
- OP_CREF, /* 141 Used to hold a capture number as condition */
- OP_DNCREF, /* 142 Used to point to duplicate names as a condition */
- OP_RREF, /* 143 Used to hold a recursion number as condition */
- OP_DNRREF, /* 144 Used to point to duplicate names as a condition */
- OP_FALSE, /* 145 Always false (used by DEFINE and VERSION) */
- OP_TRUE, /* 146 Always true (used by VERSION) */
+ OP_CREF, /* 142 Used to hold a capture number as condition */
+ OP_DNCREF, /* 143 Used to point to duplicate names as a condition */
+ OP_RREF, /* 144 Used to hold a recursion number as condition */
+ OP_DNRREF, /* 145 Used to point to duplicate names as a condition */
+ OP_FALSE, /* 146 Always false (used by DEFINE and VERSION) */
+ OP_TRUE, /* 147 Always true (used by VERSION) */
- OP_BRAZERO, /* 147 These two must remain together and in this */
- OP_BRAMINZERO, /* 148 order. */
- OP_BRAPOSZERO, /* 149 */
+ OP_BRAZERO, /* 148 These two must remain together and in this */
+ OP_BRAMINZERO, /* 149 order. */
+ OP_BRAPOSZERO, /* 150 */
/* These are backtracking control verbs */
- OP_MARK, /* 150 always has an argument */
- OP_PRUNE, /* 151 */
- OP_PRUNE_ARG, /* 152 same, but with argument */
- OP_SKIP, /* 153 */
- OP_SKIP_ARG, /* 154 same, but with argument */
- OP_THEN, /* 155 */
- OP_THEN_ARG, /* 156 same, but with argument */
- OP_COMMIT, /* 157 */
- OP_COMMIT_ARG, /* 158 same, but with argument */
+ OP_MARK, /* 151 always has an argument */
+ OP_PRUNE, /* 152 */
+ OP_PRUNE_ARG, /* 153 same, but with argument */
+ OP_SKIP, /* 154 */
+ OP_SKIP_ARG, /* 155 same, but with argument */
+ OP_THEN, /* 156 */
+ OP_THEN_ARG, /* 157 same, but with argument */
+ OP_COMMIT, /* 158 */
+ OP_COMMIT_ARG, /* 159 same, but with argument */
/* These are forced failure and success verbs. FAIL and ACCEPT do accept an
argument, but these cases can be compiled as, for example, (*MARK:X)(*FAIL)
without the need for a special opcode. */
- OP_FAIL, /* 159 */
- OP_ACCEPT, /* 160 */
- OP_ASSERT_ACCEPT, /* 161 Used inside assertions */
- OP_CLOSE, /* 162 Used before OP_ACCEPT to close open captures */
+ OP_FAIL, /* 160 */
+ OP_ACCEPT, /* 161 */
+ OP_ASSERT_ACCEPT, /* 162 Used inside assertions */
+ OP_CLOSE, /* 163 Used before OP_ACCEPT to close open captures */
/* This is used to skip a subpattern with a {0} quantifier */
- OP_SKIPZERO, /* 163 */
+ OP_SKIPZERO, /* 164 */
/* This is used to identify a DEFINE group during compilation so that it can
be checked for having only one branch. It is changed to OP_FALSE before
compilation finishes. */
- OP_DEFINE, /* 164 */
+ OP_DEFINE, /* 165 */
/* This is not an opcode, but is used to check that tables indexed by opcode
are the correct length, in order to catch updating errors - there have been
@@ -1596,6 +1620,7 @@ some cases doesn't actually use these names at all). */
"Alt", "Ket", "KetRmax", "KetRmin", "KetRpos", \
"Reverse", "Assert", "Assert not", "AssertB", "AssertB not", \
"Once", \
+ "Script run", \
"Bra", "BraPos", "CBra", "CBraPos", \
"Cond", \
"SBra", "SBraPos", "SCBra", "SCBraPos", \
@@ -1679,6 +1704,7 @@ in UTF-8 mode. The code that uses this table must know about such things. */
1+LINK_SIZE, /* Assert behind */ \
1+LINK_SIZE, /* Assert behind not */ \
1+LINK_SIZE, /* ONCE */ \
+ 1+LINK_SIZE, /* SCRIPT_RUN */ \
1+LINK_SIZE, /* BRA */ \
1+LINK_SIZE, /* BRAPOS */ \
1+LINK_SIZE+IMM2_SIZE, /* CBRA */ \
@@ -1747,6 +1773,8 @@ typedef struct {
uint8_t gbprop; /* ucp_gbControl, etc. (grapheme break property) */
uint8_t caseset; /* offset to multichar other cases or zero */
int32_t other_case; /* offset to other case, or zero if none */
+ int16_t scriptx; /* script extension value */
+ int16_t dummy; /* spare - to round to multiple of 4 bytes */
} ucd_record;
/* UCD access macros */
@@ -1769,6 +1797,7 @@ typedef struct {
#define UCD_GRAPHBREAK(ch) GET_UCD(ch)->gbprop
#define UCD_CASESET(ch) GET_UCD(ch)->caseset
#define UCD_OTHERCASE(ch) ((uint32_t)((int)ch + (int)(GET_UCD(ch)->other_case)))
+#define UCD_SCRIPTX(ch) GET_UCD(ch)->scriptx
/* Header for serialized pcre2 codes. */
@@ -1826,6 +1855,8 @@ extern const uint8_t PRIV(utf8_table4)[];
#define _pcre2_hspace_list PCRE2_SUFFIX(_pcre2_hspace_list_)
#define _pcre2_vspace_list PCRE2_SUFFIX(_pcre2_vspace_list_)
#define _pcre2_ucd_caseless_sets PCRE2_SUFFIX(_pcre2_ucd_caseless_sets_)
+#define _pcre2_ucd_digit_sets PCRE2_SUFFIX(_pcre2_ucd_digit_sets_)
+#define _pcre2_ucd_script_sets PCRE2_SUFFIX(_pcre2_ucd_script_sets_)
#define _pcre2_ucd_records PCRE2_SUFFIX(_pcre2_ucd_records_)
#define _pcre2_ucd_stage1 PCRE2_SUFFIX(_pcre2_ucd_stage1_)
#define _pcre2_ucd_stage2 PCRE2_SUFFIX(_pcre2_ucd_stage2_)
@@ -1847,6 +1878,8 @@ extern const uint8_t PRIV(default_tables)[];
extern const uint32_t PRIV(hspace_list)[];
extern const uint32_t PRIV(vspace_list)[];
extern const uint32_t PRIV(ucd_caseless_sets)[];
+extern const uint32_t PRIV(ucd_digit_sets)[];
+extern const uint8_t PRIV(ucd_script_sets)[];
extern const ucd_record PRIV(ucd_records)[];
#if PCRE2_CODE_UNIT_WIDTH == 32
extern const ucd_record PRIV(dummy_ucd_record)[];
@@ -1894,6 +1927,7 @@ is available. */
#define _pcre2_jit_get_target PCRE2_SUFFIX(_pcre2_jit_get_target_)
#define _pcre2_memctl_malloc PCRE2_SUFFIX(_pcre2_memctl_malloc_)
#define _pcre2_ord2utf PCRE2_SUFFIX(_pcre2_ord2utf_)
+#define _pcre2_script_run PCRE2_SUFFIX(_pcre2_script_run_)
#define _pcre2_strcmp PCRE2_SUFFIX(_pcre2_strcmp_)
#define _pcre2_strcmp_c8 PCRE2_SUFFIX(_pcre2_strcmp_c8_)
#define _pcre2_strcpy_c8 PCRE2_SUFFIX(_pcre2_strcpy_c8_)
@@ -1908,7 +1942,7 @@ is available. */
extern int _pcre2_auto_possessify(PCRE2_UCHAR *, BOOL,
const compile_block *);
extern int _pcre2_check_escape(PCRE2_SPTR *, PCRE2_SPTR, uint32_t *,
- int *, uint32_t, BOOL, compile_block *);
+ int *, uint32_t, uint32_t, BOOL, compile_block *);
extern PCRE2_SPTR _pcre2_extuni(uint32_t, PCRE2_SPTR, PCRE2_SPTR, PCRE2_SPTR,
BOOL, int *);
extern PCRE2_SPTR _pcre2_find_bracket(PCRE2_SPTR, BOOL, int);
@@ -1920,6 +1954,7 @@ extern size_t _pcre2_jit_get_size(void *);
const char * _pcre2_jit_get_target(void);
extern void * _pcre2_memctl_malloc(size_t, pcre2_memctl *);
extern unsigned int _pcre2_ord2utf(uint32_t, PCRE2_UCHAR *);
+extern BOOL _pcre2_script_run(PCRE2_SPTR, PCRE2_SPTR, BOOL);
extern int _pcre2_strcmp(PCRE2_SPTR, PCRE2_SPTR);
extern int _pcre2_strcmp_c8(PCRE2_SPTR, const char *);
extern PCRE2_SIZE _pcre2_strcpy_c8(PCRE2_UCHAR *, const char *);
diff --git a/thirdparty/pcre2/src/pcre2_intmodedep.h b/thirdparty/pcre2/src/pcre2_intmodedep.h
index 62626d0a8a..bf3a235984 100644
--- a/thirdparty/pcre2/src/pcre2_intmodedep.h
+++ b/thirdparty/pcre2/src/pcre2_intmodedep.h
@@ -585,6 +585,8 @@ typedef struct pcre2_real_match_context {
#endif
int (*callout)(pcre2_callout_block *, void *);
void *callout_data;
+ int (*substitute_callout)(pcre2_substitute_callout_block *, void *);
+ void *substitute_callout_data;
PCRE2_SIZE offset_limit;
uint32_t heap_limit;
uint32_t match_limit;
@@ -656,7 +658,8 @@ typedef struct pcre2_real_match_data {
PCRE2_SIZE leftchar; /* Offset to leftmost code unit */
PCRE2_SIZE rightchar; /* Offset to rightmost code unit */
PCRE2_SIZE startchar; /* Offset to starting code unit */
- uint16_t matchedby; /* Type of match (normal, JIT, DFA) */
+ uint8_t matchedby; /* Type of match (normal, JIT, DFA) */
+ uint8_t flags; /* Various flags */
uint16_t oveccount; /* Number of pairs */
int rc; /* The return code from the match */
PCRE2_SIZE ovector[131072]; /* Must be last in the structure */
diff --git a/thirdparty/pcre2/src/pcre2_jit_compile.c b/thirdparty/pcre2/src/pcre2_jit_compile.c
index 32e985b793..1f21bfb6ad 100644
--- a/thirdparty/pcre2/src/pcre2_jit_compile.c
+++ b/thirdparty/pcre2/src/pcre2_jit_compile.c
@@ -477,12 +477,22 @@ typedef struct compiler_common {
BOOL alt_circumflex;
#ifdef SUPPORT_UNICODE
BOOL utf;
+ BOOL invalid_utf;
BOOL use_ucp;
+ /* Points to saving area for iref. */
+ sljit_s32 iref_ptr;
jump_list *getucd;
+ jump_list *getucdtype;
#if PCRE2_CODE_UNIT_WIDTH == 8
jump_list *utfreadchar;
- jump_list *utfreadchar16;
jump_list *utfreadtype8;
+ jump_list *utfpeakcharback;
+#endif
+#if PCRE2_CODE_UNIT_WIDTH == 8 || PCRE2_CODE_UNIT_WIDTH == 16
+ jump_list *utfreadchar_invalid;
+ jump_list *utfreadnewline_invalid;
+ jump_list *utfmoveback_invalid;
+ jump_list *utfpeakcharback_invalid;
#endif
#endif /* SUPPORT_UNICODE */
} compiler_common;
@@ -616,7 +626,183 @@ the start pointers when the end of the capturing group has not yet reached. */
#define READ_CHAR_MAX 0x7fffffff
-#define INVALID_UTF_CHAR 888
+#define INVALID_UTF_CHAR -1
+#define UNASSIGNED_UTF_CHAR 888
+
+#if defined SUPPORT_UNICODE
+#if PCRE2_CODE_UNIT_WIDTH == 8
+
+#define GETCHARINC_INVALID(c, ptr, end, invalid_action) \
+ { \
+ if (ptr[0] <= 0x7f) \
+ c = *ptr++; \
+ else if (ptr + 1 < end && ptr[1] >= 0x80 && ptr[1] < 0xc0) \
+ { \
+ c = ptr[1] - 0x80; \
+ \
+ if (ptr[0] >= 0xc2 && ptr[0] <= 0xdf) \
+ { \
+ c |= (ptr[0] - 0xc0) << 6; \
+ ptr += 2; \
+ } \
+ else if (ptr + 2 < end && ptr[2] >= 0x80 && ptr[2] < 0xc0) \
+ { \
+ c = c << 6 | (ptr[2] - 0x80); \
+ \
+ if (ptr[0] >= 0xe0 && ptr[0] <= 0xef) \
+ { \
+ c |= (ptr[0] - 0xe0) << 12; \
+ ptr += 3; \
+ \
+ if (c < 0x800 || (c >= 0xd800 && c < 0xe000)) \
+ { \
+ invalid_action; \
+ } \
+ } \
+ else if (ptr + 3 < end && ptr[3] >= 0x80 && ptr[3] < 0xc0) \
+ { \
+ c = c << 6 | (ptr[3] - 0x80); \
+ \
+ if (ptr[0] >= 0xf0 && ptr[0] <= 0xf4) \
+ { \
+ c |= (ptr[0] - 0xf0) << 18; \
+ ptr += 4; \
+ \
+ if (c >= 0x110000 || c < 0x10000) \
+ { \
+ invalid_action; \
+ } \
+ } \
+ else \
+ { \
+ invalid_action; \
+ } \
+ } \
+ else \
+ { \
+ invalid_action; \
+ } \
+ } \
+ else \
+ { \
+ invalid_action; \
+ } \
+ } \
+ else \
+ { \
+ invalid_action; \
+ } \
+ }
+
+#define GETCHARBACK_INVALID(c, ptr, start, invalid_action) \
+ { \
+ if (ptr[-1] <= 0x7f) \
+ c = *ptr--; \
+ else if (ptr - 1 > start && ptr[-1] >= 0x80 && ptr[-1] < 0xc0) \
+ { \
+ c = ptr[-1] - 0x80; \
+ \
+ if (ptr[-2] >= 0xc2 && ptr[-2] <= 0xdf) \
+ { \
+ c |= (ptr[-2] - 0xc0) << 6; \
+ ptr -= 2; \
+ } \
+ else if (ptr - 2 > start && ptr[-2] >= 0x80 && ptr[-2] < 0xc0) \
+ { \
+ c = c << 6 | (ptr[-2] - 0x80); \
+ \
+ if (ptr[-3] >= 0xe0 && ptr[-3] <= 0xef) \
+ { \
+ c |= (ptr[-3] - 0xe0) << 12; \
+ ptr -= 3; \
+ \
+ if (c < 0x800 || (c >= 0xd800 && c < 0xe000)) \
+ { \
+ invalid_action; \
+ } \
+ } \
+ else if (ptr - 3 > start && ptr[-3] >= 0x80 && ptr[-3] < 0xc0) \
+ { \
+ c = c << 6 | (ptr[-3] - 0x80); \
+ \
+ if (ptr[-4] >= 0xf0 && ptr[-4] <= 0xf4) \
+ { \
+ c |= (ptr[-4] - 0xf0) << 18; \
+ ptr -= 4; \
+ \
+ if (c >= 0x110000 || c < 0x10000) \
+ { \
+ invalid_action; \
+ } \
+ } \
+ else \
+ { \
+ invalid_action; \
+ } \
+ } \
+ else \
+ { \
+ invalid_action; \
+ } \
+ } \
+ else \
+ { \
+ invalid_action; \
+ } \
+ } \
+ else \
+ { \
+ invalid_action; \
+ } \
+ }
+
+#elif PCRE2_CODE_UNIT_WIDTH == 16
+
+#define GETCHARINC_INVALID(c, ptr, end, invalid_action) \
+ { \
+ if (ptr[0] < 0xd800 || ptr[0] >= 0xe000) \
+ c = *ptr++; \
+ else if (ptr[0] < 0xdc00 && ptr + 1 < end && ptr[1] >= 0xdc00 && ptr[1] < 0xe000) \
+ { \
+ c = (((ptr[0] - 0xd800) << 10) | (ptr[1] - 0xdc00)) + 0x10000; \
+ ptr += 2; \
+ } \
+ else \
+ { \
+ invalid_action; \
+ } \
+ }
+
+#define GETCHARBACK_INVALID(c, ptr, start, invalid_action) \
+ { \
+ if (ptr[-1] < 0xd800 || ptr[-1] >= 0xe000) \
+ c = *ptr--; \
+ else if (ptr[-1] >= 0xdc00 && ptr - 1 > start && ptr[-2] >= 0xd800 && ptr[-2] < 0xdc00) \
+ { \
+ c = (((ptr[-2] - 0xd800) << 10) | (ptr[-1] - 0xdc00)) + 0x10000; \
+ ptr -= 2; \
+ } \
+ else \
+ { \
+ invalid_action; \
+ } \
+ }
+
+
+#elif PCRE2_CODE_UNIT_WIDTH == 32
+
+#define GETCHARINC_INVALID(c, ptr, end, invalid_action) \
+ { \
+ if (ptr[0] < 0x110000) \
+ c = *ptr++; \
+ else \
+ { \
+ invalid_action; \
+ } \
+ }
+
+#endif /* PCRE2_CODE_UNIT_WIDTH == [8|16|32] */
+#endif /* SUPPORT_UNICODE */
static PCRE2_SPTR bracketend(PCRE2_SPTR cc)
{
@@ -716,6 +902,7 @@ switch(*cc)
case OP_ASSERTBACK:
case OP_ASSERTBACK_NOT:
case OP_ONCE:
+ case OP_SCRIPT_RUN:
case OP_BRA:
case OP_BRAPOS:
case OP_CBRA:
@@ -869,8 +1056,16 @@ while (cc < ccend)
cc += 1;
break;
- case OP_REF:
case OP_REFI:
+#ifdef SUPPORT_UNICODE
+ if (common->iref_ptr == 0)
+ {
+ common->iref_ptr = common->ovector_start;
+ common->ovector_start += 3 * sizeof(sljit_sw);
+ }
+#endif /* SUPPORT_UNICODE */
+ /* Fall through. */
+ case OP_REF:
common->optimized_cbracket[GET2(cc, 1)] = 0;
cc += 1 + IMM2_SIZE;
break;
@@ -1375,6 +1570,7 @@ while (cc < ccend)
case OP_ASSERTBACK:
case OP_ASSERTBACK_NOT:
case OP_ONCE:
+ case OP_SCRIPT_RUN:
case OP_BRAPOS:
case OP_SBRA:
case OP_SBRAPOS:
@@ -1951,6 +2147,7 @@ while (cc < ccend)
case OP_ASSERTBACK:
case OP_ASSERTBACK_NOT:
case OP_ONCE:
+ case OP_SCRIPT_RUN:
case OP_BRAPOS:
case OP_SBRA:
case OP_SBRAPOS:
@@ -2174,14 +2371,14 @@ if (base_reg != TMP2)
else
{
status.saved_tmp_regs[1] = RETURN_ADDR;
- if (sljit_get_register_index (RETURN_ADDR) == -1)
+ if (sljit_get_register_index(RETURN_ADDR) == -1)
status.tmp_regs[1] = STR_PTR;
else
status.tmp_regs[1] = RETURN_ADDR;
}
status.saved_tmp_regs[2] = TMP3;
-if (sljit_get_register_index (TMP3) == -1)
+if (sljit_get_register_index(TMP3) == -1)
status.tmp_regs[2] = STR_END;
else
status.tmp_regs[2] = TMP3;
@@ -2274,6 +2471,7 @@ while (cc < ccend)
case OP_ASSERTBACK:
case OP_ASSERTBACK_NOT:
case OP_ONCE:
+ case OP_SCRIPT_RUN:
case OP_BRAPOS:
case OP_SBRA:
case OP_SBRAPOS:
@@ -3059,13 +3257,13 @@ return (0 << 8) | bit;
#ifdef SUPPORT_UNICODE
if (common->utf && c > 65535)
{
- if (bit >= (1 << 10))
+ if (bit >= (1u << 10))
bit >>= 10;
else
return (bit < 256) ? ((2 << 8) | bit) : ((3 << 8) | (bit >> 8));
}
#endif /* SUPPORT_UNICODE */
-return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
+return (bit < 256) ? ((0u << 8) | bit) : ((1u << 8) | (bit >> 8));
#endif /* PCRE2_CODE_UNIT_WIDTH == [8|16|32] */
}
@@ -3159,95 +3357,152 @@ else
JUMPHERE(jump);
}
-static void peek_char(compiler_common *common, sljit_u32 max)
+static void peek_char(compiler_common *common, sljit_u32 max, sljit_s32 dst, sljit_sw dstw, jump_list **backtracks)
{
/* Reads the character into TMP1, keeps STR_PTR.
-Does not check STR_END. TMP2 Destroyed. */
+Does not check STR_END. TMP2, dst, RETURN_ADDR Destroyed. */
DEFINE_COMPILER;
#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32
struct sljit_jump *jump;
-#endif
+#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 */
SLJIT_UNUSED_ARG(max);
+SLJIT_UNUSED_ARG(dst);
+SLJIT_UNUSED_ARG(dstw);
+SLJIT_UNUSED_ARG(backtracks);
-OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
-#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8
+OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
+
+#ifdef SUPPORT_UNICODE
+#if PCRE2_CODE_UNIT_WIDTH == 8
if (common->utf)
{
if (max < 128) return;
- jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
+ jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x80);
+ OP1(SLJIT_MOV, dst, dstw, STR_PTR, 0);
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
- add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
- OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
+ add_jump(compiler, common->invalid_utf ? &common->utfreadchar_invalid : &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
+ OP1(SLJIT_MOV, STR_PTR, 0, dst, dstw);
+ if (backtracks && common->invalid_utf)
+ add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR));
JUMPHERE(jump);
}
-#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 */
-
-#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 16
+#elif PCRE2_CODE_UNIT_WIDTH == 16
if (common->utf)
{
if (max < 0xd800) return;
OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
- jump = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
- /* TMP2 contains the high surrogate. */
- OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
- OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
- OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
- OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
- OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
- JUMPHERE(jump);
- }
-#endif
-}
-#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8
-
-static BOOL is_char7_bitset(const sljit_u8 *bitset, BOOL nclass)
-{
-/* Tells whether the character codes below 128 are enough
-to determine a match. */
-const sljit_u8 value = nclass ? 0xff : 0;
-const sljit_u8 *end = bitset + 32;
+ if (common->invalid_utf)
+ {
+ jump = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0xe000 - 0xd800);
+ OP1(SLJIT_MOV, dst, dstw, STR_PTR, 0);
+ OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+ add_jump(compiler, &common->utfreadchar_invalid, JUMP(SLJIT_FAST_CALL));
+ OP1(SLJIT_MOV, STR_PTR, 0, dst, dstw);
+ if (backtracks && common->invalid_utf)
+ add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR));
+ }
+ else
+ {
+ /* TMP2 contains the high surrogate. */
+ jump = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800);
+ OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
+ OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
+ OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000 - 0xdc00);
+ OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
+ }
-bitset += 16;
-do
+ JUMPHERE(jump);
+ }
+#elif PCRE2_CODE_UNIT_WIDTH == 32
+if (common->invalid_utf)
{
- if (*bitset++ != value)
- return FALSE;
+ if (backtracks != NULL)
+ add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x110000));
+ else
+ {
+ OP2(SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x110000);
+ CMOV(SLJIT_GREATER_EQUAL, TMP1, SLJIT_IMM, INVALID_UTF_CHAR);
+ }
}
-while (bitset < end);
-return TRUE;
+#endif /* PCRE2_CODE_UNIT_WIDTH == [8|16|32] */
+#endif /* SUPPORT_UNICODE */
}
-static void read_char7_type(compiler_common *common, BOOL full_read)
+static void peek_char_back(compiler_common *common, sljit_u32 max, jump_list **backtracks)
{
-/* Reads the precise character type of a character into TMP1, if the character
-is less than 128. Otherwise it returns with zero. Does not check STR_END. The
-full_read argument tells whether characters above max are accepted or not. */
+/* Reads one character back without moving STR_PTR. TMP2 must
+contain the start of the subject buffer. Affects TMP1, TMP2, and RETURN_ADDR. */
DEFINE_COMPILER;
-struct sljit_jump *jump;
-SLJIT_ASSERT(common->utf);
+#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32
+struct sljit_jump *jump;
+#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 */
-OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
-OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+SLJIT_UNUSED_ARG(max);
+SLJIT_UNUSED_ARG(backtracks);
-OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
+OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
-if (full_read)
+#ifdef SUPPORT_UNICODE
+#if PCRE2_CODE_UNIT_WIDTH == 8
+if (common->utf)
{
- jump = CMP(SLJIT_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
- OP1(SLJIT_MOV_U8, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
- OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
+ if (max < 128) return;
+
+ jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x80);
+ if (common->invalid_utf)
+ {
+ add_jump(compiler, &common->utfpeakcharback_invalid, JUMP(SLJIT_FAST_CALL));
+ if (backtracks != NULL)
+ add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR));
+ }
+ else
+ add_jump(compiler, &common->utfpeakcharback, JUMP(SLJIT_FAST_CALL));
JUMPHERE(jump);
}
+#elif PCRE2_CODE_UNIT_WIDTH == 16
+if (common->utf)
+ {
+ if (max < 0xd800) return;
+
+ if (common->invalid_utf)
+ {
+ jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
+ add_jump(compiler, &common->utfpeakcharback_invalid, JUMP(SLJIT_FAST_CALL));
+ if (backtracks != NULL)
+ add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR));
+ }
+ else
+ {
+ OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xdc00);
+ jump = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0xe000 - 0xdc00);
+ /* TMP2 contains the low surrogate. */
+ OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
+ OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x10000);
+ OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xd800);
+ OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 10);
+ OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
+ }
+ JUMPHERE(jump);
+ }
+#elif PCRE2_CODE_UNIT_WIDTH == 32
+ if (common->invalid_utf)
+ add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x110000));
+#endif /* PCRE2_CODE_UNIT_WIDTH == [8|16|32] */
+#endif /* SUPPORT_UNICODE */
}
-#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 */
+#define READ_CHAR_UPDATE_STR_PTR 0x1
+#define READ_CHAR_UTF8_NEWLINE 0x2
+#define READ_CHAR_NEWLINE (READ_CHAR_UPDATE_STR_PTR | READ_CHAR_UTF8_NEWLINE)
+#define READ_CHAR_VALID_UTF 0x4
-static void read_char_range(compiler_common *common, sljit_u32 min, sljit_u32 max, BOOL update_str_ptr)
+static void read_char(compiler_common *common, sljit_u32 min, sljit_u32 max,
+ jump_list **backtracks, sljit_u32 options)
{
/* Reads the precise value of a character into TMP1, if the character is
between min and max (c >= min && c <= max). Otherwise it returns with a value
@@ -3260,24 +3515,41 @@ struct sljit_jump *jump;
struct sljit_jump *jump2;
#endif
-SLJIT_UNUSED_ARG(update_str_ptr);
SLJIT_UNUSED_ARG(min);
SLJIT_UNUSED_ARG(max);
+SLJIT_UNUSED_ARG(backtracks);
+SLJIT_UNUSED_ARG(options);
SLJIT_ASSERT(min <= max);
OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
-#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8
+#ifdef SUPPORT_UNICODE
+#if PCRE2_CODE_UNIT_WIDTH == 8
if (common->utf)
{
- if (max < 128 && !update_str_ptr) return;
+ if (max < 128 && !(options & READ_CHAR_UPDATE_STR_PTR)) return;
+
+ if (common->invalid_utf && !(options & READ_CHAR_VALID_UTF))
+ {
+ jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x80);
+
+ if (options & READ_CHAR_UTF8_NEWLINE)
+ add_jump(compiler, &common->utfreadnewline_invalid, JUMP(SLJIT_FAST_CALL));
+ else
+ add_jump(compiler, &common->utfreadchar_invalid, JUMP(SLJIT_FAST_CALL));
+
+ if (backtracks != NULL)
+ add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR));
+ JUMPHERE(jump);
+ return;
+ }
jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
if (min >= 0x10000)
{
OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xf0);
- if (update_str_ptr)
+ if (options & READ_CHAR_UPDATE_STR_PTR)
OP1(SLJIT_MOV_U8, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
jump2 = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0x7);
@@ -3289,19 +3561,19 @@ if (common->utf)
OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
- if (!update_str_ptr)
+ if (!(options & READ_CHAR_UPDATE_STR_PTR))
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
JUMPHERE(jump2);
- if (update_str_ptr)
+ if (options & READ_CHAR_UPDATE_STR_PTR)
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
}
else if (min >= 0x800 && max <= 0xffff)
{
OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xe0);
- if (update_str_ptr)
+ if (options & READ_CHAR_UPDATE_STR_PTR)
OP1(SLJIT_MOV_U8, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
jump2 = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0xf);
@@ -3309,17 +3581,19 @@ if (common->utf)
OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
- if (!update_str_ptr)
+ if (!(options & READ_CHAR_UPDATE_STR_PTR))
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
JUMPHERE(jump2);
- if (update_str_ptr)
+ if (options & READ_CHAR_UPDATE_STR_PTR)
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
}
else if (max >= 0x800)
- add_jump(compiler, (max < 0x10000) ? &common->utfreadchar16 : &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
+ {
+ add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
+ }
else if (max < 128)
{
OP1(SLJIT_MOV_U8, TMP2, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
@@ -3328,7 +3602,7 @@ if (common->utf)
else
{
OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
- if (!update_str_ptr)
+ if (!(options & READ_CHAR_UPDATE_STR_PTR))
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
else
OP1(SLJIT_MOV_U8, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
@@ -3336,51 +3610,141 @@ if (common->utf)
OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
- if (update_str_ptr)
+ if (options & READ_CHAR_UPDATE_STR_PTR)
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
}
JUMPHERE(jump);
}
-#endif
-
-#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 16
+#elif PCRE2_CODE_UNIT_WIDTH == 16
if (common->utf)
{
+ if (max < 0xd800 && !(options & READ_CHAR_UPDATE_STR_PTR)) return;
+
+ if (common->invalid_utf && !(options & READ_CHAR_VALID_UTF))
+ {
+ OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
+ jump = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0xe000 - 0xd800);
+
+ if (options & READ_CHAR_UTF8_NEWLINE)
+ add_jump(compiler, &common->utfreadnewline_invalid, JUMP(SLJIT_FAST_CALL));
+ else
+ add_jump(compiler, &common->utfreadchar_invalid, JUMP(SLJIT_FAST_CALL));
+
+ if (backtracks != NULL)
+ add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR));
+ JUMPHERE(jump);
+ return;
+ }
+
if (max >= 0x10000)
{
OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
- jump = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
+ jump = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800);
/* TMP2 contains the high surrogate. */
OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
- OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
- OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
- OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
+ OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000 - 0xdc00);
+ OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
JUMPHERE(jump);
return;
}
- if (max < 0xd800 && !update_str_ptr) return;
-
/* Skip low surrogate if necessary. */
OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
- jump = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
- if (update_str_ptr)
- OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
- if (max >= 0xd800)
- OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x10000);
- JUMPHERE(jump);
+
+ if (sljit_has_cpu_feature(SLJIT_HAS_CMOV) && sljit_get_register_index(RETURN_ADDR) >= 0)
+ {
+ if (options & READ_CHAR_UPDATE_STR_PTR)
+ OP2(SLJIT_ADD, RETURN_ADDR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+ OP2(SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x400);
+ if (options & READ_CHAR_UPDATE_STR_PTR)
+ CMOV(SLJIT_LESS, STR_PTR, RETURN_ADDR, 0);
+ if (max >= 0xd800)
+ CMOV(SLJIT_LESS, TMP1, SLJIT_IMM, 0x10000);
+ }
+ else
+ {
+ jump = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x400);
+ if (options & READ_CHAR_UPDATE_STR_PTR)
+ OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+ if (max >= 0xd800)
+ OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x10000);
+ JUMPHERE(jump);
+ }
}
-#endif
+#elif PCRE2_CODE_UNIT_WIDTH == 32
+if (common->invalid_utf)
+ {
+ if (backtracks != NULL)
+ add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x110000));
+ else
+ {
+ OP2(SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x110000);
+ CMOV(SLJIT_GREATER_EQUAL, TMP1, SLJIT_IMM, INVALID_UTF_CHAR);
+ }
+ }
+#endif /* PCRE2_CODE_UNIT_WIDTH == [8|16|32] */
+#endif /* SUPPORT_UNICODE */
+}
+
+#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8
+
+static BOOL is_char7_bitset(const sljit_u8 *bitset, BOOL nclass)
+{
+/* Tells whether the character codes below 128 are enough
+to determine a match. */
+const sljit_u8 value = nclass ? 0xff : 0;
+const sljit_u8 *end = bitset + 32;
+
+bitset += 16;
+do
+ {
+ if (*bitset++ != value)
+ return FALSE;
+ }
+while (bitset < end);
+return TRUE;
}
-static SLJIT_INLINE void read_char(compiler_common *common)
+static void read_char7_type(compiler_common *common, jump_list **backtracks, BOOL negated)
{
-read_char_range(common, 0, READ_CHAR_MAX, TRUE);
+/* Reads the precise character type of a character into TMP1, if the character
+is less than 128. Otherwise it returns with zero. Does not check STR_END. The
+full_read argument tells whether characters above max are accepted or not. */
+DEFINE_COMPILER;
+struct sljit_jump *jump;
+
+SLJIT_ASSERT(common->utf);
+
+OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
+OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+
+/* All values > 127 are zero in ctypes. */
+OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
+
+if (negated)
+ {
+ jump = CMP(SLJIT_LESS, TMP2, 0, SLJIT_IMM, 0x80);
+
+ if (common->invalid_utf)
+ {
+ add_jump(compiler, &common->utfreadchar_invalid, JUMP(SLJIT_FAST_CALL));
+ add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR));
+ OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
+ }
+ else
+ {
+ OP1(SLJIT_MOV_U8, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
+ OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
+ }
+ JUMPHERE(jump);
+ }
}
-static void read_char8_type(compiler_common *common, BOOL update_str_ptr)
+#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 */
+
+static void read_char8_type(compiler_common *common, jump_list **backtracks, BOOL negated)
{
/* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */
DEFINE_COMPILER;
@@ -3391,7 +3755,8 @@ struct sljit_jump *jump;
struct sljit_jump *jump2;
#endif
-SLJIT_UNUSED_ARG(update_str_ptr);
+SLJIT_UNUSED_ARG(backtracks);
+SLJIT_UNUSED_ARG(negated);
OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
@@ -3399,18 +3764,38 @@ OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8
if (common->utf)
{
- /* This can be an extra read in some situations, but hopefully
- it is needed in most cases. */
+ /* The result of this read may be unused, but saves an "else" part. */
OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
- jump = CMP(SLJIT_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
- if (!update_str_ptr)
+ jump = CMP(SLJIT_LESS, TMP2, 0, SLJIT_IMM, 0x80);
+
+ if (!negated)
{
+ if (common->invalid_utf)
+ add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
+
OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
- OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
+ OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xc2);
+ if (common->invalid_utf)
+ add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0xe0 - 0xc2));
+
OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
- OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
- OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
+ OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP1, 0);
+ OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x80);
+ if (common->invalid_utf)
+ add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x40));
+
+ OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
+ jump2 = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 255);
+ OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
+ JUMPHERE(jump2);
+ }
+ else if (common->invalid_utf)
+ {
+ add_jump(compiler, &common->utfreadchar_invalid, JUMP(SLJIT_FAST_CALL));
+ OP1(SLJIT_MOV, TMP2, 0, TMP1, 0);
+ add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR));
+
OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
jump2 = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 255);
OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
@@ -3418,43 +3803,98 @@ if (common->utf)
}
else
add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
+
JUMPHERE(jump);
return;
}
#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 */
+#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 32
+if (common->invalid_utf && negated)
+ add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x110000));
+#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 32 */
+
#if PCRE2_CODE_UNIT_WIDTH != 8
/* The ctypes array contains only 256 values. */
OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
jump = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 255);
-#endif
+#endif /* PCRE2_CODE_UNIT_WIDTH != 8 */
OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
#if PCRE2_CODE_UNIT_WIDTH != 8
JUMPHERE(jump);
-#endif
+#endif /* PCRE2_CODE_UNIT_WIDTH != 8 */
#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 16
-if (common->utf && update_str_ptr)
+if (common->utf && negated)
{
/* Skip low surrogate if necessary. */
+ if (!common->invalid_utf)
+ {
+ OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);
+
+ if (sljit_has_cpu_feature(SLJIT_HAS_CMOV) && sljit_get_register_index(RETURN_ADDR) >= 0)
+ {
+ OP2(SLJIT_ADD, RETURN_ADDR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+ OP2(SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x400);
+ CMOV(SLJIT_LESS, STR_PTR, RETURN_ADDR, 0);
+ }
+ else
+ {
+ jump = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x400);
+ OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+ JUMPHERE(jump);
+ }
+ return;
+ }
+
OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);
- jump = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
+ jump = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0xe000 - 0xd800);
+ add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x400));
+ add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
+
+ OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+ OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xdc00);
+ add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x400));
+
JUMPHERE(jump);
+ return;
}
#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 16 */
}
-static void skip_char_back(compiler_common *common)
+static void move_back(compiler_common *common, jump_list **backtracks, BOOL must_be_valid)
{
-/* Goes one character back. Affects STR_PTR and TMP1. Does not check begin. */
+/* Goes one character back. TMP2 must contain the start of
+the subject buffer. Affects STR_PTR and TMP1. Does not modify
+STR_PTR for invalid character sequences. */
DEFINE_COMPILER;
+
+SLJIT_UNUSED_ARG(backtracks);
+SLJIT_UNUSED_ARG(must_be_valid);
+
#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32
+struct sljit_jump *jump;
+#endif
+
+#ifdef SUPPORT_UNICODE
#if PCRE2_CODE_UNIT_WIDTH == 8
struct sljit_label *label;
if (common->utf)
{
+ if (!must_be_valid && common->invalid_utf)
+ {
+ OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
+ OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+ jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x80);
+ add_jump(compiler, &common->utfmoveback_invalid, JUMP(SLJIT_FAST_CALL));
+ if (backtracks != NULL)
+ add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, 0));
+ JUMPHERE(jump);
+ return;
+ }
+
label = LABEL();
OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
@@ -3467,16 +3907,45 @@ if (common->utf)
{
OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+
+ if (!must_be_valid && common->invalid_utf)
+ {
+ OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xd800);
+ jump = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0xe000 - 0xd800);
+ add_jump(compiler, &common->utfmoveback_invalid, JUMP(SLJIT_FAST_CALL));
+ if (backtracks != NULL)
+ add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, 0));
+ JUMPHERE(jump);
+ return;
+ }
+
/* Skip low surrogate if necessary. */
OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
OP2(SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xdc00);
OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_EQUAL);
- OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
+ OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
return;
}
-#endif /* PCRE2_CODE_UNIT_WIDTH == [8|16] */
-#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 */
+#elif PCRE2_CODE_UNIT_WIDTH == 32
+if (common->invalid_utf && !must_be_valid)
+ {
+ OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
+ if (backtracks != NULL)
+ {
+ add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x110000));
+ OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+ return;
+ }
+
+ OP2(SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x110000);
+ OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_LESS);
+ OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
+ OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
+ return;
+ }
+#endif /* PCRE2_CODE_UNIT_WIDTH == [8|16|32] */
+#endif /* SUPPORT_UNICODE */
OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
}
@@ -3519,13 +3988,12 @@ else
static void do_utfreadchar(compiler_common *common)
{
/* Fast decoding a UTF-8 character. TMP1 contains the first byte
-of the character (>= 0xc0). Return char value in TMP1, length in TMP2. */
+of the character (>= 0xc0). Return char value in TMP1. */
DEFINE_COMPILER;
struct sljit_jump *jump;
sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
-OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
@@ -3534,13 +4002,12 @@ OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
OP2(SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
jump = JUMP(SLJIT_NOT_ZERO);
/* Two byte sequence. */
+OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3000);
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
-OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));
sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
JUMPHERE(jump);
OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
-OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
@@ -3548,55 +4015,18 @@ OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
OP2(SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10000);
jump = JUMP(SLJIT_NOT_ZERO);
/* Three byte sequence. */
+OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xe0000);
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
-OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));
sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
/* Four byte sequence. */
JUMPHERE(jump);
OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
-OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
-OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
+OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xf0000);
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
-OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
-OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
-OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(4));
-sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
-}
-
-static void do_utfreadchar16(compiler_common *common)
-{
-/* Fast decoding a UTF-8 character. TMP1 contains the first byte
-of the character (>= 0xc0). Return value in TMP1. */
-DEFINE_COMPILER;
-struct sljit_jump *jump;
-
-sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
-OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
-OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
-
-/* Searching for the first zero. */
-OP2(SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
-jump = JUMP(SLJIT_NOT_ZERO);
-/* Two byte sequence. */
-OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
-sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
-
-JUMPHERE(jump);
-OP2(SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x400);
-OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_NOT_ZERO);
-/* This code runs only in 8 bit mode. No need to shift the value. */
-OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
-OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
-OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
-OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
-OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
-OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
-/* Three byte sequence. */
-OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
}
@@ -3636,8 +4066,644 @@ OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
}
+static void do_utfreadchar_invalid(compiler_common *common)
+{
+/* Slow decoding a UTF-8 character. TMP1 contains the first byte
+of the character (>= 0xc0). Return char value in TMP1. STR_PTR is
+undefined for invalid characters. */
+DEFINE_COMPILER;
+sljit_s32 i;
+sljit_s32 has_cmov = sljit_has_cpu_feature(SLJIT_HAS_CMOV);
+struct sljit_jump *jump;
+struct sljit_jump *buffer_end_close;
+struct sljit_label *three_byte_entry;
+struct sljit_label *exit_invalid_label;
+struct sljit_jump *exit_invalid[11];
+
+sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
+
+OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc2);
+
+/* Usually more than 3 characters remained in the subject buffer. */
+OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
+
+/* Not a valid start of a multi-byte sequence, no more bytes read. */
+exit_invalid[0] = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0xf5 - 0xc2);
+
+buffer_end_close = CMP(SLJIT_GREATER, STR_PTR, 0, STR_END, 0);
+
+OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-3));
+OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
+/* If TMP2 is in 0x80-0xbf range, TMP1 is also increased by (0x2 << 6). */
+OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
+OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x80);
+exit_invalid[1] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x40);
+
+OP2(SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
+jump = JUMP(SLJIT_NOT_ZERO);
+
+OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+
+JUMPHERE(jump);
+
+/* Three-byte sequence. */
+OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
+OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
+OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x80);
+OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
+if (has_cmov)
+ {
+ OP2(SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x40);
+ CMOV(SLJIT_GREATER_EQUAL, TMP1, SLJIT_IMM, 0x20000);
+ exit_invalid[2] = NULL;
+ }
+else
+ exit_invalid[2] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x40);
+
+OP2(SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10000);
+jump = JUMP(SLJIT_NOT_ZERO);
+
+three_byte_entry = LABEL();
+
+OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2d800);
+if (has_cmov)
+ {
+ OP2(SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
+ CMOV(SLJIT_LESS, TMP1, SLJIT_IMM, INVALID_UTF_CHAR - 0xd800);
+ exit_invalid[3] = NULL;
+ }
+else
+ exit_invalid[3] = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x800);
+OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xd800);
+OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+
+if (has_cmov)
+ {
+ OP2(SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
+ CMOV(SLJIT_LESS, TMP1, SLJIT_IMM, INVALID_UTF_CHAR);
+ exit_invalid[4] = NULL;
+ }
+else
+ exit_invalid[4] = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x800);
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+
+JUMPHERE(jump);
+
+/* Four-byte sequence. */
+OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
+OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
+OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x80);
+OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
+if (has_cmov)
+ {
+ OP2(SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x40);
+ CMOV(SLJIT_GREATER_EQUAL, TMP1, SLJIT_IMM, 0);
+ exit_invalid[5] = NULL;
+ }
+else
+ exit_invalid[5] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x40);
+
+OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc10000);
+if (has_cmov)
+ {
+ OP2(SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x100000);
+ CMOV(SLJIT_GREATER_EQUAL, TMP1, SLJIT_IMM, INVALID_UTF_CHAR - 0x10000);
+ exit_invalid[6] = NULL;
+ }
+else
+ exit_invalid[6] = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x100000);
+
+OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+
+JUMPHERE(buffer_end_close);
+OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
+exit_invalid[7] = CMP(SLJIT_GREATER, STR_PTR, 0, STR_END, 0);
+
+/* Two-byte sequence. */
+OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
+OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
+/* If TMP2 is in 0x80-0xbf range, TMP1 is also increased by (0x2 << 6). */
+OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
+OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x80);
+exit_invalid[8] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x40);
+
+OP2(SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
+jump = JUMP(SLJIT_NOT_ZERO);
+
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+
+/* Three-byte sequence. */
+JUMPHERE(jump);
+exit_invalid[9] = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
+
+OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
+OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
+OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x80);
+OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
+if (has_cmov)
+ {
+ OP2(SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x40);
+ CMOV(SLJIT_GREATER_EQUAL, TMP1, SLJIT_IMM, INVALID_UTF_CHAR);
+ exit_invalid[10] = NULL;
+ }
+else
+ exit_invalid[10] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x40);
+
+/* One will be substracted from STR_PTR later. */
+OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
+
+/* Four byte sequences are not possible. */
+CMPTO(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x30000, three_byte_entry);
+
+exit_invalid_label = LABEL();
+for (i = 0; i < 11; i++)
+ sljit_set_label(exit_invalid[i], exit_invalid_label);
+
+OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR);
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+}
+
+static void do_utfreadnewline_invalid(compiler_common *common)
+{
+/* Slow decoding a UTF-8 character, specialized for newlines.
+TMP1 contains the first byte of the character (>= 0xc0). Return
+char value in TMP1. */
+DEFINE_COMPILER;
+struct sljit_label *loop;
+struct sljit_label *skip_start;
+struct sljit_label *three_byte_exit;
+struct sljit_jump *jump[5];
+
+sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
+
+if (common->nltype != NLTYPE_ANY)
+ {
+ SLJIT_ASSERT(common->nltype != NLTYPE_FIXED || common->newline < 128);
+
+ /* All newlines are ascii, just skip intermediate octets. */
+ jump[0] = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
+ loop = LABEL();
+ OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
+ OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xc0);
+ CMPTO(SLJIT_EQUAL, TMP2, 0, SLJIT_IMM, 0x80, loop);
+ OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+
+ JUMPHERE(jump[0]);
+
+ OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR);
+ sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+ return;
+ }
+
+jump[0] = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
+OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
+OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+
+jump[1] = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, 0xc2);
+jump[2] = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, 0xe2);
+
+skip_start = LABEL();
+OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xc0);
+jump[3] = CMP(SLJIT_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0x80);
+
+/* Skip intermediate octets. */
+loop = LABEL();
+jump[4] = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
+OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
+OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xc0);
+CMPTO(SLJIT_EQUAL, TMP2, 0, SLJIT_IMM, 0x80, loop);
+
+JUMPHERE(jump[3]);
+OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+
+three_byte_exit = LABEL();
+JUMPHERE(jump[0]);
+JUMPHERE(jump[4]);
+
+OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR);
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+
+/* Two byte long newline: 0x85. */
+JUMPHERE(jump[1]);
+CMPTO(SLJIT_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0x85, skip_start);
+
+OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x85);
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+
+/* Three byte long newlines: 0x2028 and 0x2029. */
+JUMPHERE(jump[2]);
+CMPTO(SLJIT_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0x80, skip_start);
+CMPTO(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0, three_byte_exit);
+
+OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
+OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+
+OP2(SLJIT_SUB, TMP1, 0, TMP2, 0, SLJIT_IMM, 0x80);
+CMPTO(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x40, skip_start);
+
+OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0x2000);
+OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+}
+
+static void do_utfmoveback_invalid(compiler_common *common)
+{
+/* Goes one character back. */
+DEFINE_COMPILER;
+sljit_s32 i;
+struct sljit_jump *jump;
+struct sljit_jump *buffer_start_close;
+struct sljit_label *exit_ok_label;
+struct sljit_label *exit_invalid_label;
+struct sljit_jump *exit_invalid[7];
+
+sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
+
+OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
+exit_invalid[0] = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0xc0);
+
+/* Two-byte sequence. */
+buffer_start_close = CMP(SLJIT_LESS, STR_PTR, 0, TMP2, 0);
+
+OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
+
+OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0);
+jump = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x20);
+
+OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 1);
+OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+
+/* Three-byte sequence. */
+JUMPHERE(jump);
+exit_invalid[1] = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, -0x40);
+
+OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
+
+OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xe0);
+jump = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x10);
+
+OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 1);
+OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+
+/* Four-byte sequence. */
+JUMPHERE(jump);
+OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xe0 - 0x80);
+exit_invalid[2] = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x40);
+
+OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
+OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xf0);
+exit_invalid[3] = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x05);
+
+exit_ok_label = LABEL();
+OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 1);
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+
+/* Two-byte sequence. */
+JUMPHERE(buffer_start_close);
+OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
+
+exit_invalid[4] = CMP(SLJIT_LESS, STR_PTR, 0, TMP2, 0);
+
+OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
+
+OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0);
+CMPTO(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x20, exit_ok_label);
+
+/* Three-byte sequence. */
+OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+exit_invalid[5] = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, -0x40);
+exit_invalid[6] = CMP(SLJIT_LESS, STR_PTR, 0, TMP2, 0);
+
+OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
+
+OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xe0);
+CMPTO(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x10, exit_ok_label);
+
+/* Four-byte sequences are not possible. */
+
+exit_invalid_label = LABEL();
+sljit_set_label(exit_invalid[5], exit_invalid_label);
+sljit_set_label(exit_invalid[6], exit_invalid_label);
+OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
+OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+
+JUMPHERE(exit_invalid[4]);
+/* -2 + 4 = 2 */
+OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
+
+exit_invalid_label = LABEL();
+for (i = 0; i < 4; i++)
+ sljit_set_label(exit_invalid[i], exit_invalid_label);
+OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
+OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(4));
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+}
+
+static void do_utfpeakcharback(compiler_common *common)
+{
+/* Peak a character back. */
+DEFINE_COMPILER;
+struct sljit_jump *jump[2];
+
+sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
+
+OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
+OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0);
+jump[0] = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x20);
+
+OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-3));
+OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xe0);
+jump[1] = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x10);
+
+OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-4));
+OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xe0 - 0x80);
+OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xf0);
+OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
+OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
+
+JUMPHERE(jump[1]);
+OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
+OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
+OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x80);
+OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
+
+JUMPHERE(jump[0]);
+OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
+OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
+OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x80);
+OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
+
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+}
+
+static void do_utfpeakcharback_invalid(compiler_common *common)
+{
+/* Peak a character back. */
+DEFINE_COMPILER;
+sljit_s32 i;
+sljit_s32 has_cmov = sljit_has_cpu_feature(SLJIT_HAS_CMOV);
+struct sljit_jump *jump[2];
+struct sljit_label *two_byte_entry;
+struct sljit_label *three_byte_entry;
+struct sljit_label *exit_invalid_label;
+struct sljit_jump *exit_invalid[8];
+
+sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
+
+OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));
+exit_invalid[0] = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0xc0);
+jump[0] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, STR_PTR, 0);
+
+/* Two-byte sequence. */
+OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
+OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xc2);
+jump[1] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x1e);
+
+two_byte_entry = LABEL();
+OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
+/* If TMP1 is in 0x80-0xbf range, TMP1 is also increased by (0x2 << 6). */
+OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+
+JUMPHERE(jump[1]);
+OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xc2 - 0x80);
+OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x80);
+exit_invalid[1] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x40);
+OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
+OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
+
+/* Three-byte sequence. */
+OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-3));
+OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xe0);
+jump[1] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x10);
+
+three_byte_entry = LABEL();
+OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);
+OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
+
+OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xd800);
+if (has_cmov)
+ {
+ OP2(SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
+ CMOV(SLJIT_LESS, TMP1, SLJIT_IMM, -0xd800);
+ exit_invalid[2] = NULL;
+ }
+else
+ exit_invalid[2] = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x800);
+
+OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xd800);
+if (has_cmov)
+ {
+ OP2(SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
+ CMOV(SLJIT_LESS, TMP1, SLJIT_IMM, INVALID_UTF_CHAR);
+ exit_invalid[3] = NULL;
+ }
+else
+ exit_invalid[3] = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x800);
+
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+
+JUMPHERE(jump[1]);
+OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xe0 - 0x80);
+exit_invalid[4] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x40);
+OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);
+OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
+
+/* Four-byte sequence. */
+OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-4));
+OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
+OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xf0);
+OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 18);
+/* ADD is used instead of OR because of the SUB 0x10000 above. */
+OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
+
+if (has_cmov)
+ {
+ OP2(SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x100000);
+ CMOV(SLJIT_GREATER_EQUAL, TMP1, SLJIT_IMM, INVALID_UTF_CHAR - 0x10000);
+ exit_invalid[5] = NULL;
+ }
+else
+ exit_invalid[5] = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x100000);
+
+OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+
+JUMPHERE(jump[0]);
+OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));
+jump[0] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, STR_PTR, 0);
+
+/* Two-byte sequence. */
+OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
+OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xc2);
+CMPTO(SLJIT_LESS, TMP2, 0, SLJIT_IMM, 0x1e, two_byte_entry);
+
+OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xc2 - 0x80);
+OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x80);
+exit_invalid[6] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x40);
+OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
+OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
+
+/* Three-byte sequence. */
+OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-3));
+OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xe0);
+CMPTO(SLJIT_LESS, TMP2, 0, SLJIT_IMM, 0x10, three_byte_entry);
+
+OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR);
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+
+JUMPHERE(jump[0]);
+exit_invalid[7] = CMP(SLJIT_GREATER, TMP2, 0, STR_PTR, 0);
+
+/* Two-byte sequence. */
+OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
+OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xc2);
+CMPTO(SLJIT_LESS, TMP2, 0, SLJIT_IMM, 0x1e, two_byte_entry);
+
+exit_invalid_label = LABEL();
+for (i = 0; i < 8; i++)
+ sljit_set_label(exit_invalid[i], exit_invalid_label);
+
+OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR);
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+}
+
#endif /* PCRE2_CODE_UNIT_WIDTH == 8 */
+#if PCRE2_CODE_UNIT_WIDTH == 16
+
+static void do_utfreadchar_invalid(compiler_common *common)
+{
+/* Slow decoding a UTF-16 character. TMP1 contains the first half
+of the character (>= 0xd800). Return char value in TMP1. STR_PTR is
+undefined for invalid characters. */
+DEFINE_COMPILER;
+struct sljit_jump *exit_invalid[3];
+
+sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
+
+/* TMP2 contains the high surrogate. */
+exit_invalid[0] = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0xdc00);
+exit_invalid[1] = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
+
+OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
+OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
+OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+
+OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xdc00);
+OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x10000);
+exit_invalid[2] = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x400);
+
+OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+
+JUMPHERE(exit_invalid[0]);
+JUMPHERE(exit_invalid[1]);
+JUMPHERE(exit_invalid[2]);
+OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR);
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+}
+
+static void do_utfreadnewline_invalid(compiler_common *common)
+{
+/* Slow decoding a UTF-16 character, specialized for newlines.
+TMP1 contains the first half of the character (>= 0xd800). Return
+char value in TMP1. */
+
+DEFINE_COMPILER;
+struct sljit_jump *exit_invalid[2];
+
+sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
+
+/* TMP2 contains the high surrogate. */
+exit_invalid[0] = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
+
+OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
+exit_invalid[1] = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0xdc00);
+
+OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xdc00);
+OP2(SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x400);
+OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_LESS);
+OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x10000);
+OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
+OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
+
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+
+JUMPHERE(exit_invalid[0]);
+JUMPHERE(exit_invalid[1]);
+OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR);
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+}
+
+static void do_utfmoveback_invalid(compiler_common *common)
+{
+/* Goes one character back. */
+DEFINE_COMPILER;
+struct sljit_jump *exit_invalid[3];
+
+sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
+
+exit_invalid[0] = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x400);
+exit_invalid[1] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, STR_PTR, 0);
+
+OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
+OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xd800);
+exit_invalid[2] = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x400);
+
+OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 1);
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+
+JUMPHERE(exit_invalid[0]);
+JUMPHERE(exit_invalid[1]);
+JUMPHERE(exit_invalid[2]);
+
+OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+}
+
+static void do_utfpeakcharback_invalid(compiler_common *common)
+{
+/* Peak a character back. */
+DEFINE_COMPILER;
+struct sljit_jump *jump;
+struct sljit_jump *exit_invalid[3];
+
+sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
+
+jump = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0xe000);
+OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));
+exit_invalid[0] = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);
+exit_invalid[1] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, STR_PTR, 0);
+
+OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
+OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000 - 0xdc00);
+OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);
+exit_invalid[2] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x400);
+OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
+OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
+
+JUMPHERE(jump);
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+
+JUMPHERE(exit_invalid[0]);
+JUMPHERE(exit_invalid[1]);
+JUMPHERE(exit_invalid[2]);
+
+OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR);
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+}
+
+#endif /* PCRE2_CODE_UNIT_WIDTH == 16 */
+
/* UCD_BLOCK_SIZE must be 128 (see the assert below). */
#define UCD_BLOCK_MASK 127
#define UCD_BLOCK_SHIFT 7
@@ -3653,12 +4719,12 @@ struct sljit_jump *jump;
#if defined SLJIT_DEBUG && SLJIT_DEBUG
/* dummy_ucd_record */
-const ucd_record *record = GET_UCD(INVALID_UTF_CHAR);
-SLJIT_ASSERT(record->script == ucp_Common && record->chartype == ucp_Cn && record->gbprop == ucp_gbOther);
+const ucd_record *record = GET_UCD(UNASSIGNED_UTF_CHAR);
+SLJIT_ASSERT(record->script == ucp_Unknown && record->chartype == ucp_Cn && record->gbprop == ucp_gbOther);
SLJIT_ASSERT(record->caseset == 0 && record->other_case == 0);
#endif
-SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);
+SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 12);
sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
@@ -3666,7 +4732,47 @@ sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
if (!common->utf)
{
jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, MAX_UTF_CODE_POINT + 1);
- OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR);
+ OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, UNASSIGNED_UTF_CHAR);
+ JUMPHERE(jump);
+ }
+#endif
+
+OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
+OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
+OP1(SLJIT_MOV_U16, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(ucd_stage1));
+OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
+OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
+OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
+OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
+OP1(SLJIT_MOV_U16, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
+sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
+}
+
+static void do_getucdtype(compiler_common *common)
+{
+/* Search the UCD record for the character comes in TMP1.
+Returns chartype in TMP1 and UCD offset in TMP2. */
+DEFINE_COMPILER;
+#if PCRE2_CODE_UNIT_WIDTH == 32
+struct sljit_jump *jump;
+#endif
+
+#if defined SLJIT_DEBUG && SLJIT_DEBUG
+/* dummy_ucd_record */
+const ucd_record *record = GET_UCD(UNASSIGNED_UTF_CHAR);
+SLJIT_ASSERT(record->script == ucp_Unknown && record->chartype == ucp_Cn && record->gbprop == ucp_gbOther);
+SLJIT_ASSERT(record->caseset == 0 && record->other_case == 0);
+#endif
+
+SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 12);
+
+sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
+
+#if PCRE2_CODE_UNIT_WIDTH == 32
+if (!common->utf)
+ {
+ jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, MAX_UTF_CODE_POINT + 1);
+ OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, UNASSIGNED_UTF_CHAR);
JUMPHERE(jump);
}
#endif
@@ -3679,8 +4785,19 @@ OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
OP1(SLJIT_MOV_U16, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
+
+// PH hacking
+//fprintf(stderr, "~~A\n");
+ OP2(SLJIT_SHL, TMP1, 0, TMP2, 0, SLJIT_IMM, 2);
+ OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);
+ OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP1, 0);
+ OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, chartype));
+
OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, chartype));
-OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
+
+ OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 0);
+
+// OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
}
@@ -3695,8 +4812,9 @@ struct sljit_jump *start;
struct sljit_jump *end = NULL;
struct sljit_jump *end2 = NULL;
#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32
-struct sljit_jump *singlechar;
-#endif
+struct sljit_label *loop;
+struct sljit_jump *jump;
+#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 */
jump_list *newline = NULL;
sljit_u32 overall_options = common->re->overall_options;
BOOL hascrorlf = (common->re->flags & PCRE2_HASCRORLF) != 0;
@@ -3733,7 +4851,7 @@ if ((overall_options & PCRE2_FIRSTLINE) != 0)
mainloop = LABEL();
/* Continual stores does not cause data dependency. */
OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->match_end_ptr, STR_PTR, 0);
- read_char_range(common, common->nlmin, common->nlmax, TRUE);
+ read_char(common, common->nlmin, common->nlmax, NULL, READ_CHAR_NEWLINE);
check_newlinechar(common, common->nltype, &newline, TRUE);
CMPTO(SLJIT_LESS, STR_PTR, 0, STR_END, 0, mainloop);
JUMPHERE(end);
@@ -3753,11 +4871,9 @@ else if ((overall_options & PCRE2_USE_OFFSET_LIMIT) != 0)
OP1(SLJIT_MOV, TMP2, 0, STR_END, 0);
end = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, (sljit_sw) PCRE2_UNSET);
OP1(SLJIT_MOV, TMP2, 0, ARGUMENTS, 0);
-#if PCRE2_CODE_UNIT_WIDTH == 16
- OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
-#elif PCRE2_CODE_UNIT_WIDTH == 32
- OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 2);
-#endif
+#if PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32
+ OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
+#endif /* PCRE2_CODE_UNIT_WIDTH == [16|32] */
OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, begin));
OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP1, 0);
end2 = CMP(SLJIT_LESS_EQUAL, TMP2, 0, STR_END, 0);
@@ -3781,7 +4897,7 @@ if (newlinecheck)
OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_EQUAL);
#if PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32
OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
-#endif
+#endif /* PCRE2_CODE_UNIT_WIDTH == [16|32] */
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
end2 = JUMP(SLJIT_JUMP);
}
@@ -3789,9 +4905,9 @@ if (newlinecheck)
mainloop = LABEL();
/* Increasing the STR_PTR here requires one less jump in the most common case. */
-#ifdef SUPPORT_UNICODE
-if (common->utf) readuchar = TRUE;
-#endif
+#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32
+if (common->utf && !common->invalid_utf) readuchar = TRUE;
+#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 */
if (newlinecheck) readuchar = TRUE;
if (readuchar)
@@ -3803,23 +4919,55 @@ if (newlinecheck)
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32
#if PCRE2_CODE_UNIT_WIDTH == 8
-if (common->utf)
+if (common->invalid_utf)
+ {
+ /* Skip continuation code units. */
+ loop = LABEL();
+ jump = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
+ OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
+ OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+ OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x80);
+ CMPTO(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x40, loop);
+ OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+ JUMPHERE(jump);
+ }
+else if (common->utf)
{
- singlechar = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
+ jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
- JUMPHERE(singlechar);
+ JUMPHERE(jump);
}
#elif PCRE2_CODE_UNIT_WIDTH == 16
-if (common->utf)
+if (common->invalid_utf)
{
- singlechar = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
- OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
- OP2(SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
- OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_EQUAL);
- OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
- OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
- JUMPHERE(singlechar);
+ /* Skip continuation code units. */
+ loop = LABEL();
+ jump = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
+ OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
+ OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+ OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xdc00);
+ CMPTO(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x400, loop);
+ OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+ JUMPHERE(jump);
+ }
+else if (common->utf)
+ {
+ OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xd800);
+
+ if (sljit_has_cpu_feature(SLJIT_HAS_CMOV))
+ {
+ OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
+ OP2(SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x400);
+ CMOV(SLJIT_LESS, STR_PTR, TMP2, 0);
+ }
+ else
+ {
+ OP2(SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x400);
+ OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_LESS);
+ OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
+ OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
+ }
}
#endif /* PCRE2_CODE_UNIT_WIDTH == [8|16] */
#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 */
@@ -4305,16 +5453,16 @@ return CMP(SLJIT_NOT_EQUAL, reg, 0, SLJIT_IMM, 0xdc00);
static sljit_s32 character_to_int32(PCRE2_UCHAR chr)
{
-sljit_s32 value = (sljit_s32)chr;
+sljit_u32 value = chr;
#if PCRE2_CODE_UNIT_WIDTH == 8
#define SSE2_COMPARE_TYPE_INDEX 0
-return (value << 24) | (value << 16) | (value << 8) | value;
+return (sljit_s32)((value << 24) | (value << 16) | (value << 8) | value);
#elif PCRE2_CODE_UNIT_WIDTH == 16
#define SSE2_COMPARE_TYPE_INDEX 1
-return (value << 16) | value;
+return (sljit_s32)((value << 16) | value);
#elif PCRE2_CODE_UNIT_WIDTH == 32
#define SSE2_COMPARE_TYPE_INDEX 2
-return value;
+return (sljit_s32)(value);
#else
#error "Unsupported unit width"
#endif
@@ -5120,7 +6268,7 @@ for (i = 0; i < max; i++)
}
#if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) && !(defined SUPPORT_VALGRIND) && !(defined _WIN64)
-if (check_fast_forward_char_pair_sse2(common, chars, max))
+if (sljit_has_cpu_feature(SLJIT_HAS_SSE2) && check_fast_forward_char_pair_sse2(common, chars, max))
return TRUE;
#endif
@@ -5356,14 +6504,15 @@ if (common->nltype == NLTYPE_FIXED && common->newline > 255)
}
OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
+/* Example: match /^/ to \r\n from offset 1. */
OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
firstchar = CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, TMP2, 0);
-skip_char_back(common);
+move_back(common, NULL, FALSE);
loop = LABEL();
common->ff_newline_shortcut = loop;
-read_char_range(common, common->nlmin, common->nlmax, TRUE);
+read_char(common, common->nlmin, common->nlmax, NULL, READ_CHAR_NEWLINE);
lastchar = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
foundcr = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
@@ -5544,7 +6693,7 @@ OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), -sizeof(sljit_sw));
jump = CMP(SLJIT_SIG_LESS_EQUAL, TMP2, 0, SLJIT_IMM, 0);
OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP1, 0);
-if (sljit_get_register_index (TMP3) < 0)
+if (sljit_get_register_index(TMP3) < 0)
{
OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(STACK_TOP), -(2 * sizeof(sljit_sw)));
OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(STACK_TOP), -(3 * sizeof(sljit_sw)));
@@ -5569,7 +6718,7 @@ sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
JUMPHERE(jump);
OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP1, 0);
-if (sljit_get_register_index (TMP3) < 0)
+if (sljit_get_register_index(TMP3) < 0)
{
OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(STACK_TOP), -(2 * sizeof(sljit_sw)));
OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));
@@ -5588,21 +6737,29 @@ static void check_wordboundary(compiler_common *common)
DEFINE_COMPILER;
struct sljit_jump *skipread;
jump_list *skipread_list = NULL;
+jump_list *invalid_utf = NULL;
#if PCRE2_CODE_UNIT_WIDTH != 8 || defined SUPPORT_UNICODE
struct sljit_jump *jump;
-#endif
+#endif /* PCRE2_CODE_UNIT_WIDTH != 8 || SUPPORT_UNICODE */
SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);
sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_SP), LOCALS0);
-/* Get type of the previous char, and put it to LOCALS1. */
+/* Get type of the previous char, and put it to TMP3. */
OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
-OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
-OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS1, SLJIT_IMM, 0);
-skipread = CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, TMP1, 0);
-skip_char_back(common);
-check_start_used_ptr(common);
-read_char(common);
+OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
+OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, 0);
+skipread = CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, TMP2, 0);
+
+if (common->mode == PCRE2_JIT_COMPLETE)
+ peek_char_back(common, READ_CHAR_MAX, &invalid_utf);
+else
+ {
+ move_back(common, &invalid_utf, FALSE);
+ check_start_used_ptr(common);
+ /* No need precise read since match fails anyway. */
+ read_char(common, 0, READ_CHAR_MAX, &invalid_utf, READ_CHAR_UPDATE_STR_PTR);
+ }
/* Testing char type. */
#ifdef SUPPORT_UNICODE
@@ -5610,7 +6767,7 @@ if (common->use_ucp)
{
OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);
jump = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);
- add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
+ add_jump(compiler, &common->getucdtype, JUMP(SLJIT_FAST_CALL));
OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
OP2(SLJIT_SUB | SLJIT_SET_LESS_EQUAL, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);
OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_LESS_EQUAL);
@@ -5618,23 +6775,22 @@ if (common->use_ucp)
OP2(SLJIT_SUB | SLJIT_SET_LESS_EQUAL, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);
OP_FLAGS(SLJIT_OR, TMP2, 0, SLJIT_LESS_EQUAL);
JUMPHERE(jump);
- OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS1, TMP2, 0);
+ OP1(SLJIT_MOV, TMP3, 0, TMP2, 0);
}
else
-#endif
+#endif /* SUPPORT_UNICODE */
{
#if PCRE2_CODE_UNIT_WIDTH != 8
jump = CMP(SLJIT_GREATER, TMP1, 0, SLJIT_IMM, 255);
#elif defined SUPPORT_UNICODE
- /* Here LOCALS1 has already been zeroed. */
+ /* Here TMP3 has already been zeroed. */
jump = NULL;
if (common->utf)
jump = CMP(SLJIT_GREATER, TMP1, 0, SLJIT_IMM, 255);
#endif /* PCRE2_CODE_UNIT_WIDTH == 8 */
OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM1(TMP1), common->ctypes);
OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 4 /* ctype_word */);
- OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
- OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS1, TMP1, 0);
+ OP2(SLJIT_AND, TMP3, 0, TMP1, 0, SLJIT_IMM, 1);
#if PCRE2_CODE_UNIT_WIDTH != 8
JUMPHERE(jump);
#elif defined SUPPORT_UNICODE
@@ -5646,7 +6802,7 @@ JUMPHERE(skipread);
OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
check_str_end(common, &skipread_list);
-peek_char(common, READ_CHAR_MAX);
+peek_char(common, READ_CHAR_MAX, SLJIT_MEM1(SLJIT_SP), LOCALS1, &invalid_utf);
/* Testing char type. This is a code duplication. */
#ifdef SUPPORT_UNICODE
@@ -5654,7 +6810,7 @@ if (common->use_ucp)
{
OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);
jump = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);
- add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
+ add_jump(compiler, &common->getucdtype, JUMP(SLJIT_FAST_CALL));
OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
OP2(SLJIT_SUB | SLJIT_SET_LESS_EQUAL, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);
OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_LESS_EQUAL);
@@ -5664,7 +6820,7 @@ if (common->use_ucp)
JUMPHERE(jump);
}
else
-#endif
+#endif /* SUPPORT_UNICODE */
{
#if PCRE2_CODE_UNIT_WIDTH != 8
/* TMP2 may be destroyed by peek_char. */
@@ -5688,8 +6844,22 @@ else
}
set_jumps(skipread_list, LABEL());
-OP2(SLJIT_XOR | SLJIT_SET_Z, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_SP), LOCALS1);
-sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_SP), LOCALS0);
+OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), LOCALS0);
+OP2(SLJIT_XOR | SLJIT_SET_Z, TMP2, 0, TMP2, 0, TMP3, 0);
+sljit_emit_fast_return(compiler, TMP1, 0);
+
+#ifdef SUPPORT_UNICODE
+if (common->invalid_utf)
+ {
+ SLJIT_ASSERT(invalid_utf != NULL);
+
+ set_jumps(invalid_utf, LABEL());
+ OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), LOCALS0);
+ OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, -1);
+ sljit_emit_fast_return(compiler, TMP1, 0);
+ return;
+ }
+#endif /* SUPPORT_UNICODE */
}
static BOOL optimize_class_ranges(compiler_common *common, const sljit_u8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks)
@@ -5856,9 +7026,6 @@ int i, j, k, len, c;
if (!sljit_has_cpu_feature(SLJIT_HAS_CMOV))
return FALSE;
-if (invert)
- nclass = !nclass;
-
len = 0;
for (i = 0; i < 32; i++)
@@ -5940,6 +7107,9 @@ if (j != 0)
}
}
+if (invert)
+ nclass = !nclass;
+
type = nclass ? SLJIT_NOT_EQUAL : SLJIT_EQUAL;
add_jump(compiler, backtracks, CMP(type, TMP2, 0, SLJIT_IMM, 0));
return TRUE;
@@ -6225,37 +7395,6 @@ OP1(SLJIT_MOV, char1_reg, 0, SLJIT_MEM1(SLJIT_SP), LOCALS1);
sljit_emit_fast_return(compiler, TMP1, 0);
}
-#if defined SUPPORT_UNICODE
-
-static PCRE2_SPTR SLJIT_FUNC do_utf_caselesscmp(PCRE2_SPTR src1, PCRE2_SPTR src2, PCRE2_SPTR end1, PCRE2_SPTR end2)
-{
-/* This function would be ineffective to do in JIT level. */
-sljit_u32 c1, c2;
-const ucd_record *ur;
-const sljit_u32 *pp;
-
-while (src1 < end1)
- {
- if (src2 >= end2)
- return (PCRE2_SPTR)1;
- GETCHARINC(c1, src1);
- GETCHARINC(c2, src2);
- ur = GET_UCD(c2);
- if (c1 != c2 && c1 != c2 + ur->other_case)
- {
- pp = PRIV(ucd_caseless_sets) + ur->caseset;
- for (;;)
- {
- if (c1 < *pp) return NULL;
- if (c1 == *pp++) break;
- }
- }
- }
-return src2;
-}
-
-#endif /* SUPPORT_UNICODE */
-
static PCRE2_SPTR byte_sequence_compare(compiler_common *common, BOOL caseless, PCRE2_SPTR cc,
compare_context *context, jump_list **backtracks)
{
@@ -6297,7 +7436,7 @@ if (context->sourcereg == -1)
OP1(SLJIT_MOV_U16, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
else
#endif
- OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
+ OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
#elif PCRE2_CODE_UNIT_WIDTH == 16
#if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
if (context->length >= 4)
@@ -6444,7 +7583,7 @@ PCRE2_SPTR ccbegin;
int compares, invertcmp, numberofcmps;
#if defined SUPPORT_UNICODE && (PCRE2_CODE_UNIT_WIDTH == 8 || PCRE2_CODE_UNIT_WIDTH == 16)
BOOL utf = common->utf;
-#endif
+#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == [8|16] */
#ifdef SUPPORT_UNICODE
BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
@@ -6452,7 +7591,7 @@ BOOL charsaved = FALSE;
int typereg = TMP1;
const sljit_u32 *other_cases;
sljit_uw typeoffset;
-#endif
+#endif /* SUPPORT_UNICODE */
/* Scanning the necessary info. */
cc++;
@@ -6476,7 +7615,7 @@ while (*cc != XCL_END)
if (c < min) min = c;
#ifdef SUPPORT_UNICODE
needschar = TRUE;
-#endif
+#endif /* SUPPORT_UNICODE */
}
else if (*cc == XCL_RANGE)
{
@@ -6487,7 +7626,7 @@ while (*cc != XCL_END)
if (c > max) max = c;
#ifdef SUPPORT_UNICODE
needschar = TRUE;
-#endif
+#endif /* SUPPORT_UNICODE */
}
#ifdef SUPPORT_UNICODE
else
@@ -6555,13 +7694,16 @@ while (*cc != XCL_END)
}
cc += 2;
}
-#endif
+#endif /* SUPPORT_UNICODE */
}
SLJIT_ASSERT(compares > 0);
/* We are not necessary in utf mode even in 8 bit mode. */
cc = ccbegin;
-read_char_range(common, min, max, (cc[-1] & XCL_NOT) != 0);
+if ((cc[-1] & XCL_NOT) != 0)
+ read_char(common, min, max, backtracks, READ_CHAR_UPDATE_STR_PTR);
+else
+ read_char(common, min, max, NULL, 0);
if ((cc[-1] & XCL_HASPROP) == 0)
{
@@ -6594,13 +7736,13 @@ else if ((cc[-1] & XCL_MAP) != 0)
OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
#ifdef SUPPORT_UNICODE
charsaved = TRUE;
-#endif
+#endif /* SUPPORT_UNICODE */
if (!optimize_class(common, (const sljit_u8 *)cc, FALSE, TRUE, list))
{
#if PCRE2_CODE_UNIT_WIDTH == 8
jump = NULL;
if (common->utf)
-#endif
+#endif /* PCRE2_CODE_UNIT_WIDTH == 8 */
jump = CMP(SLJIT_GREATER, TMP1, 0, SLJIT_IMM, 255);
OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
@@ -6612,7 +7754,7 @@ else if ((cc[-1] & XCL_MAP) != 0)
#if PCRE2_CODE_UNIT_WIDTH == 8
if (common->utf)
-#endif
+#endif /* PCRE2_CODE_UNIT_WIDTH == 8 */
JUMPHERE(jump);
}
@@ -6630,10 +7772,10 @@ if (needstype || needsscript)
if (!common->utf)
{
jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, MAX_UTF_CODE_POINT + 1);
- OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR);
+ OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, UNASSIGNED_UTF_CHAR);
JUMPHERE(jump);
}
-#endif
+#endif /* PCRE2_CODE_UNIT_WIDTH == 32 */
OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
@@ -6647,8 +7789,18 @@ if (needstype || needsscript)
/* Before anything else, we deal with scripts. */
if (needsscript)
{
+// PH hacking
+//fprintf(stderr, "~~B\n");
+
+ OP2(SLJIT_SHL, TMP1, 0, TMP2, 0, SLJIT_IMM, 2);
+ OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);
+ OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP1, 0);
+
OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script));
- OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
+
+ OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 0);
+
+ // OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
ccbegin = cc;
@@ -6686,33 +7838,49 @@ if (needstype || needsscript)
}
if (needschar)
- {
OP1(SLJIT_MOV, TMP1, 0, RETURN_ADDR, 0);
- }
if (needstype)
{
if (!needschar)
{
+// PH hacking
+//fprintf(stderr, "~~C\n");
+ OP2(SLJIT_SHL, TMP1, 0, TMP2, 0, SLJIT_IMM, 2);
+ OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);
+ OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP1, 0);
+ OP2(SLJIT_ADD, TMP1, 0, TMP2, 0, TMP1, 0);
+
OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, chartype));
- OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
+
+ OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 0);
+
+// OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
}
else
{
+// PH hacking
+//fprintf(stderr, "~~D\n");
+ OP2(SLJIT_SHL, TMP1, 0, TMP2, 0, SLJIT_IMM, 2);
+
OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);
+
+ OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP1, 0);
+ OP1(SLJIT_MOV, TMP1, 0, RETURN_ADDR, 0);
+
OP1(SLJIT_MOV_U8, RETURN_ADDR, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, chartype));
typereg = RETURN_ADDR;
}
}
}
-#endif
+#endif /* SUPPORT_UNICODE */
/* Generating code. */
charoffset = 0;
numberofcmps = 0;
#ifdef SUPPORT_UNICODE
typeoffset = 0;
-#endif
+#endif /* SUPPORT_UNICODE */
while (*cc != XCL_END)
{
@@ -6979,7 +8147,7 @@ while (*cc != XCL_END)
}
cc += 2;
}
-#endif
+#endif /* SUPPORT_UNICODE */
if (jump != NULL)
add_jump(compiler, compares > 0 ? list : backtracks, jump);
@@ -7020,6 +8188,15 @@ switch(type)
case OP_NOT_WORD_BOUNDARY:
case OP_WORD_BOUNDARY:
add_jump(compiler, &common->wordboundary, JUMP(SLJIT_FAST_CALL));
+#ifdef SUPPORT_UNICODE
+ if (common->invalid_utf)
+ {
+ OP2(SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_SIG_LESS, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0);
+ add_jump(compiler, backtracks, JUMP(SLJIT_SIG_LESS));
+ add_jump(compiler, backtracks, JUMP(type == OP_NOT_WORD_BOUNDARY ? SLJIT_NOT_ZERO : SLJIT_ZERO));
+ return cc;
+ }
+#endif /* SUPPORT_UNICODE */
sljit_set_current_flags(compiler, SLJIT_SET_Z);
add_jump(compiler, backtracks, JUMP(type == OP_NOT_WORD_BOUNDARY ? SLJIT_NOT_ZERO : SLJIT_ZERO));
return cc;
@@ -7078,13 +8255,13 @@ switch(type)
}
else
{
- OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS1, STR_PTR, 0);
- read_char_range(common, common->nlmin, common->nlmax, TRUE);
+ OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
+ read_char(common, common->nlmin, common->nlmax, backtracks, READ_CHAR_UPDATE_STR_PTR);
add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, STR_PTR, 0, STR_END, 0));
add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
sljit_set_current_flags(compiler, SLJIT_SET_Z);
add_jump(compiler, backtracks, JUMP(SLJIT_ZERO));
- OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), LOCALS1);
+ OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
}
JUMPHERE(jump[2]);
JUMPHERE(jump[3]);
@@ -7143,7 +8320,7 @@ switch(type)
}
else
{
- peek_char(common, common->nlmax);
+ peek_char(common, common->nlmax, TMP3, 0, NULL);
check_newlinechar(common, common->nltype, backtracks, FALSE);
}
JUMPHERE(jump[0]);
@@ -7158,10 +8335,10 @@ switch(type)
return cc;
case OP_CIRCM:
- OP1(SLJIT_MOV, TMP2, 0, ARGUMENTS, 0);
- OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, begin));
- jump[1] = CMP(SLJIT_GREATER, STR_PTR, 0, TMP1, 0);
- OP2(SLJIT_AND32 | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, options), SLJIT_IMM, PCRE2_NOTBOL);
+ OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
+ OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
+ jump[1] = CMP(SLJIT_GREATER, STR_PTR, 0, TMP2, 0);
+ OP2(SLJIT_AND32 | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, options), SLJIT_IMM, PCRE2_NOTBOL);
add_jump(compiler, backtracks, JUMP(SLJIT_NOT_ZERO32));
jump[0] = JUMP(SLJIT_JUMP);
JUMPHERE(jump[1]);
@@ -7171,8 +8348,8 @@ switch(type)
if (common->nltype == NLTYPE_FIXED && common->newline > 255)
{
- OP2(SLJIT_SUB, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
- add_jump(compiler, backtracks, CMP(SLJIT_LESS, TMP2, 0, TMP1, 0));
+ OP2(SLJIT_SUB, TMP1, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
+ add_jump(compiler, backtracks, CMP(SLJIT_LESS, TMP1, 0, TMP2, 0));
OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff));
@@ -7180,8 +8357,7 @@ switch(type)
}
else
{
- skip_char_back(common);
- read_char_range(common, common->nlmin, common->nlmax, TRUE);
+ peek_char_back(common, common->nlmax, backtracks);
check_newlinechar(common, common->nltype, backtracks, FALSE);
}
JUMPHERE(jump[0]);
@@ -7195,12 +8371,12 @@ switch(type)
#ifdef SUPPORT_UNICODE
if (common->utf)
{
- OP1(SLJIT_MOV, TMP3, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
- OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, length);
+ OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
+ OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, length);
label = LABEL();
- add_jump(compiler, backtracks, CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, TMP3, 0));
- skip_char_back(common);
- OP2(SLJIT_SUB | SLJIT_SET_Z, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
+ add_jump(compiler, backtracks, CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, TMP2, 0));
+ move_back(common, backtracks, FALSE);
+ OP2(SLJIT_SUB | SLJIT_SET_Z, TMP3, 0, TMP3, 0, SLJIT_IMM, 1);
JUMPTO(SLJIT_NOT_ZERO, label);
}
else
@@ -7225,21 +8401,28 @@ static PCRE2_SPTR SLJIT_FUNC do_extuni_utf(jit_arguments *args, PCRE2_SPTR cc)
{
PCRE2_SPTR start_subject = args->begin;
PCRE2_SPTR end_subject = args->end;
-int lgb, rgb, len, ricount;
-PCRE2_SPTR prevcc, bptr;
+int lgb, rgb, ricount;
+PCRE2_SPTR prevcc, startcc, bptr;
+BOOL first = TRUE;
uint32_t c;
prevcc = cc;
-GETCHARINC(c, cc);
-lgb = UCD_GRAPHBREAK(c);
-
-while (cc < end_subject)
+startcc = NULL;
+do
{
- len = 1;
- GETCHARLEN(c, cc, len);
+ GETCHARINC(c, cc);
rgb = UCD_GRAPHBREAK(c);
- if ((PRIV(ucp_gbtable)[lgb] & (1 << rgb)) == 0) break;
+ if (first)
+ {
+ lgb = rgb;
+ startcc = cc;
+ first = FALSE;
+ continue;
+ }
+
+ if ((PRIV(ucp_gbtable)[lgb] & (1 << rgb)) == 0)
+ break;
/* Not breaking between Regional Indicators is allowed only if there
are an even number of preceding RIs. */
@@ -7256,7 +8439,8 @@ while (cc < end_subject)
BACKCHAR(bptr);
GETCHAR(c, bptr);
- if (UCD_GRAPHBREAK(c) != ucp_gbRegionalIndicator) break;
+ if (UCD_GRAPHBREAK(c) != ucp_gbRegionalIndicator)
+ break;
ricount++;
}
@@ -7271,14 +8455,80 @@ while (cc < end_subject)
lgb != ucp_gbExtended_Pictographic)
lgb = rgb;
- prevcc = cc;
- cc += len;
+ prevcc = startcc;
+ startcc = cc;
}
+while (cc < end_subject);
-return cc;
+return startcc;
}
-#endif
+static PCRE2_SPTR SLJIT_FUNC do_extuni_utf_invalid(jit_arguments *args, PCRE2_SPTR cc)
+{
+PCRE2_SPTR start_subject = args->begin;
+PCRE2_SPTR end_subject = args->end;
+int lgb, rgb, ricount;
+PCRE2_SPTR prevcc, startcc, bptr;
+BOOL first = TRUE;
+uint32_t c;
+
+prevcc = cc;
+startcc = NULL;
+do
+ {
+ GETCHARINC_INVALID(c, cc, end_subject, break);
+ rgb = UCD_GRAPHBREAK(c);
+
+ if (first)
+ {
+ lgb = rgb;
+ startcc = cc;
+ first = FALSE;
+ continue;
+ }
+
+ if ((PRIV(ucp_gbtable)[lgb] & (1 << rgb)) == 0)
+ break;
+
+ /* Not breaking between Regional Indicators is allowed only if there
+ are an even number of preceding RIs. */
+
+ if (lgb == ucp_gbRegionalIndicator && rgb == ucp_gbRegionalIndicator)
+ {
+ ricount = 0;
+ bptr = prevcc;
+
+ /* bptr is pointing to the left-hand character */
+ while (bptr > start_subject)
+ {
+ GETCHARBACK_INVALID(c, bptr, start_subject, break);
+
+ if (UCD_GRAPHBREAK(c) != ucp_gbRegionalIndicator)
+ break;
+
+ ricount++;
+ }
+
+ if ((ricount & 1) != 0)
+ break; /* Grapheme break required */
+ }
+
+ /* If Extend or ZWJ follows Extended_Pictographic, do not update lgb; this
+ allows any number of them before a following Extended_Pictographic. */
+
+ if ((rgb != ucp_gbExtend && rgb != ucp_gbZWJ) ||
+ lgb != ucp_gbExtended_Pictographic)
+ lgb = rgb;
+
+ prevcc = startcc;
+ startcc = cc;
+ }
+while (cc < end_subject);
+
+return startcc;
+}
+
+#endif /* PCRE2_CODE_UNIT_WIDTH != 32 */
static PCRE2_SPTR SLJIT_FUNC do_extuni_no_utf(jit_arguments *args, PCRE2_SPTR cc)
{
@@ -7289,14 +8539,23 @@ PCRE2_SPTR bptr;
uint32_t c;
GETCHARINC(c, cc);
+#if PCRE2_CODE_UNIT_WIDTH == 32
+if (c >= 0x110000)
+ return NULL;
+#endif /* PCRE2_CODE_UNIT_WIDTH == 32 */
lgb = UCD_GRAPHBREAK(c);
while (cc < end_subject)
{
c = *cc;
+#if PCRE2_CODE_UNIT_WIDTH == 32
+ if (c >= 0x110000)
+ break;
+#endif /* PCRE2_CODE_UNIT_WIDTH == 32 */
rgb = UCD_GRAPHBREAK(c);
- if ((PRIV(ucp_gbtable)[lgb] & (1 << rgb)) == 0) break;
+ if ((PRIV(ucp_gbtable)[lgb] & (1 << rgb)) == 0)
+ break;
/* Not breaking between Regional Indicators is allowed only if there
are an even number of preceding RIs. */
@@ -7311,13 +8570,18 @@ while (cc < end_subject)
{
bptr--;
c = *bptr;
+#if PCRE2_CODE_UNIT_WIDTH == 32
+ if (c >= 0x110000)
+ break;
+#endif /* PCRE2_CODE_UNIT_WIDTH == 32 */
if (UCD_GRAPHBREAK(c) != ucp_gbRegionalIndicator) break;
ricount++;
}
- if ((ricount & 1) != 0) break; /* Grapheme break required */
+ if ((ricount & 1) != 0)
+ break; /* Grapheme break required */
}
/* If Extend or ZWJ follows Extended_Pictographic, do not update lgb; this
@@ -7333,7 +8597,7 @@ while (cc < end_subject)
return cc;
}
-#endif
+#endif /* SUPPORT_UNICODE */
static PCRE2_SPTR compile_char1_matchingpath(compiler_common *common, PCRE2_UCHAR type, PCRE2_SPTR cc, jump_list **backtracks, BOOL check_str_ptr)
{
@@ -7356,10 +8620,10 @@ switch(type)
detect_partial_match(common, backtracks);
#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8
if (common->utf && is_char7_bitset((const sljit_u8*)common->ctypes - cbit_length + cbit_digit, FALSE))
- read_char7_type(common, type == OP_NOT_DIGIT);
+ read_char7_type(common, backtracks, type == OP_NOT_DIGIT);
else
#endif
- read_char8_type(common, type == OP_NOT_DIGIT);
+ read_char8_type(common, backtracks, type == OP_NOT_DIGIT);
/* Flip the starting bit in the negative case. */
OP2(SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_digit);
add_jump(compiler, backtracks, JUMP(type == OP_DIGIT ? SLJIT_ZERO : SLJIT_NOT_ZERO));
@@ -7371,10 +8635,10 @@ switch(type)
detect_partial_match(common, backtracks);
#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8
if (common->utf && is_char7_bitset((const sljit_u8*)common->ctypes - cbit_length + cbit_space, FALSE))
- read_char7_type(common, type == OP_NOT_WHITESPACE);
+ read_char7_type(common, backtracks, type == OP_NOT_WHITESPACE);
else
#endif
- read_char8_type(common, type == OP_NOT_WHITESPACE);
+ read_char8_type(common, backtracks, type == OP_NOT_WHITESPACE);
OP2(SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_space);
add_jump(compiler, backtracks, JUMP(type == OP_WHITESPACE ? SLJIT_ZERO : SLJIT_NOT_ZERO));
return cc;
@@ -7385,10 +8649,10 @@ switch(type)
detect_partial_match(common, backtracks);
#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8
if (common->utf && is_char7_bitset((const sljit_u8*)common->ctypes - cbit_length + cbit_word, FALSE))
- read_char7_type(common, type == OP_NOT_WORDCHAR);
+ read_char7_type(common, backtracks, type == OP_NOT_WORDCHAR);
else
#endif
- read_char8_type(common, type == OP_NOT_WORDCHAR);
+ read_char8_type(common, backtracks, type == OP_NOT_WORDCHAR);
OP2(SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_word);
add_jump(compiler, backtracks, JUMP(type == OP_WORDCHAR ? SLJIT_ZERO : SLJIT_NOT_ZERO));
return cc;
@@ -7396,7 +8660,7 @@ switch(type)
case OP_ANY:
if (check_str_ptr)
detect_partial_match(common, backtracks);
- read_char_range(common, common->nlmin, common->nlmax, TRUE);
+ read_char(common, common->nlmin, common->nlmax, backtracks, READ_CHAR_UPDATE_STR_PTR);
if (common->nltype == NLTYPE_FIXED && common->newline > 255)
{
jump[0] = CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);
@@ -7418,12 +8682,18 @@ switch(type)
case OP_ALLANY:
if (check_str_ptr)
detect_partial_match(common, backtracks);
-#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32
+#ifdef SUPPORT_UNICODE
if (common->utf)
{
+ if (common->invalid_utf)
+ {
+ read_char(common, 0, READ_CHAR_MAX, backtracks, READ_CHAR_UPDATE_STR_PTR);
+ return cc;
+ }
+
+#if PCRE2_CODE_UNIT_WIDTH == 8 || PCRE2_CODE_UNIT_WIDTH == 16
OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
-#if PCRE2_CODE_UNIT_WIDTH == 8 || PCRE2_CODE_UNIT_WIDTH == 16
#if PCRE2_CODE_UNIT_WIDTH == 8
jump[0] = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
@@ -7435,12 +8705,12 @@ switch(type)
OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_EQUAL);
OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
-#endif
+#endif /* PCRE2_CODE_UNIT_WIDTH == 8 */
JUMPHERE(jump[0]);
-#endif /* PCRE2_CODE_UNIT_WIDTH == [8|16] */
return cc;
+#endif /* PCRE2_CODE_UNIT_WIDTH == [8|16] */
}
-#endif
+#endif /* SUPPORT_UNICODE */
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
return cc;
@@ -7467,7 +8737,7 @@ switch(type)
case OP_ANYNL:
if (check_str_ptr)
detect_partial_match(common, backtracks);
- read_char_range(common, common->bsr_nlmin, common->bsr_nlmax, FALSE);
+ read_char(common, common->bsr_nlmin, common->bsr_nlmax, NULL, 0);
jump[0] = CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
/* We don't need to handle soft partial matching case. */
end_list = NULL;
@@ -7490,7 +8760,12 @@ switch(type)
case OP_HSPACE:
if (check_str_ptr)
detect_partial_match(common, backtracks);
- read_char_range(common, 0x9, 0x3000, type == OP_NOT_HSPACE);
+
+ if (type == OP_NOT_HSPACE)
+ read_char(common, 0x9, 0x3000, backtracks, READ_CHAR_UPDATE_STR_PTR);
+ else
+ read_char(common, 0x9, 0x3000, NULL, 0);
+
add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));
sljit_set_current_flags(compiler, SLJIT_SET_Z);
add_jump(compiler, backtracks, JUMP(type == OP_NOT_HSPACE ? SLJIT_NOT_ZERO : SLJIT_ZERO));
@@ -7500,7 +8775,12 @@ switch(type)
case OP_VSPACE:
if (check_str_ptr)
detect_partial_match(common, backtracks);
- read_char_range(common, 0xa, 0x2029, type == OP_NOT_VSPACE);
+
+ if (type == OP_NOT_VSPACE)
+ read_char(common, 0xa, 0x2029, backtracks, READ_CHAR_UPDATE_STR_PTR);
+ else
+ read_char(common, 0xa, 0x2029, NULL, 0);
+
add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));
sljit_set_current_flags(compiler, SLJIT_SET_Z);
add_jump(compiler, backtracks, JUMP(type == OP_NOT_VSPACE ? SLJIT_NOT_ZERO : SLJIT_ZERO));
@@ -7516,9 +8796,12 @@ switch(type)
#if PCRE2_CODE_UNIT_WIDTH != 32
sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW), SLJIT_IMM,
- common->utf ? SLJIT_FUNC_OFFSET(do_extuni_utf) : SLJIT_FUNC_OFFSET(do_extuni_no_utf));
+ common->utf ? (common->invalid_utf ? SLJIT_FUNC_OFFSET(do_extuni_utf_invalid) : SLJIT_FUNC_OFFSET(do_extuni_utf)) : SLJIT_FUNC_OFFSET(do_extuni_no_utf));
+ if (common->invalid_utf)
+ add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0));
#else
sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW), SLJIT_IMM, SLJIT_FUNC_OFFSET(do_extuni_no_utf));
+ add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0));
#endif
OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_RETURN_REG, 0);
@@ -7539,11 +8822,15 @@ switch(type)
#ifdef SUPPORT_UNICODE
if (common->utf && HAS_EXTRALEN(*cc)) length += GET_EXTRALEN(*cc);
#endif
- if (common->mode == PCRE2_JIT_COMPLETE && check_str_ptr
- && (type == OP_CHAR || !char_has_othercase(common, cc) || char_get_othercase_bit(common, cc) != 0))
+
+ if (check_str_ptr && common->mode != PCRE2_JIT_COMPLETE)
+ detect_partial_match(common, backtracks);
+
+ if (type == OP_CHAR || !char_has_othercase(common, cc) || char_get_othercase_bit(common, cc) != 0)
{
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(length));
- add_jump(compiler, backtracks, CMP(SLJIT_GREATER, STR_PTR, 0, STR_END, 0));
+ if (length > 1 || (check_str_ptr && common->mode == PCRE2_JIT_COMPLETE))
+ add_jump(compiler, backtracks, CMP(SLJIT_GREATER, STR_PTR, 0, STR_END, 0));
context.length = IN_UCHARS(length);
context.sourcereg = -1;
@@ -7553,8 +8840,6 @@ switch(type)
return byte_sequence_compare(common, type == OP_CHARI, cc, &context, backtracks);
}
- if (check_str_ptr)
- detect_partial_match(common, backtracks);
#ifdef SUPPORT_UNICODE
if (common->utf)
{
@@ -7564,24 +8849,28 @@ switch(type)
#endif
c = *cc;
- if (type == OP_CHAR || !char_has_othercase(common, cc))
+ SLJIT_ASSERT(type == OP_CHARI && char_has_othercase(common, cc));
+
+ if (check_str_ptr && common->mode == PCRE2_JIT_COMPLETE)
+ add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
+
+ oc = char_othercase(common, c);
+ read_char(common, c < oc ? c : oc, c > oc ? c : oc, NULL, 0);
+
+ SLJIT_ASSERT(!is_powerof2(c ^ oc));
+
+ if (sljit_has_cpu_feature(SLJIT_HAS_CMOV))
{
- read_char_range(common, c, c, FALSE);
+ OP2(SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);
+ CMOV(SLJIT_EQUAL, TMP1, SLJIT_IMM, c);
add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c));
- return cc + length;
}
- oc = char_othercase(common, c);
- read_char_range(common, c < oc ? c : oc, c > oc ? c : oc, FALSE);
- bit = c ^ oc;
- if (is_powerof2(bit))
+ else
{
- OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);
- add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c | bit));
- return cc + length;
+ jump[0] = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, c);
+ add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, oc));
+ JUMPHERE(jump[0]);
}
- jump[0] = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, c);
- add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, oc));
- JUMPHERE(jump[0]);
return cc + length;
case OP_NOT:
@@ -7595,7 +8884,7 @@ switch(type)
{
#if PCRE2_CODE_UNIT_WIDTH == 8
c = *cc;
- if (c < 128)
+ if (c < 128 && !common->invalid_utf)
{
OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
if (type == OP_NOT || !char_has_othercase(common, cc))
@@ -7626,13 +8915,13 @@ switch(type)
if (type == OP_NOT || !char_has_othercase(common, cc))
{
- read_char_range(common, c, c, TRUE);
+ read_char(common, c, c, backtracks, READ_CHAR_UPDATE_STR_PTR);
add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, c));
}
else
{
oc = char_othercase(common, c);
- read_char_range(common, c < oc ? c : oc, c > oc ? c : oc, TRUE);
+ read_char(common, c < oc ? c : oc, c > oc ? c : oc, backtracks, READ_CHAR_UPDATE_STR_PTR);
bit = c ^ oc;
if (is_powerof2(bit))
{
@@ -7654,9 +8943,15 @@ switch(type)
#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8
bit = (common->utf && is_char7_bitset((const sljit_u8 *)cc, type == OP_NCLASS)) ? 127 : 255;
- read_char_range(common, 0, bit, type == OP_NCLASS);
+ if (type == OP_NCLASS)
+ read_char(common, 0, bit, backtracks, READ_CHAR_UPDATE_STR_PTR);
+ else
+ read_char(common, 0, bit, NULL, 0);
#else
- read_char_range(common, 0, 255, type == OP_NCLASS);
+ if (type == OP_NCLASS)
+ read_char(common, 0, 255, backtracks, READ_CHAR_UPDATE_STR_PTR);
+ else
+ read_char(common, 0, 255, NULL, 0);
#endif
if (optimize_class(common, (const sljit_u8 *)cc, type == OP_NCLASS, FALSE, backtracks))
@@ -7843,6 +9138,14 @@ int offset = 0;
struct sljit_jump *jump = NULL;
struct sljit_jump *partial;
struct sljit_jump *nopartial;
+#if defined SUPPORT_UNICODE
+struct sljit_label *loop;
+struct sljit_label *caseless_loop;
+jump_list *no_match = NULL;
+int source_reg = COUNT_MATCH;
+int source_end_reg = ARGUMENTS;
+int char1_reg = STACK_LIMIT;
+#endif /* SUPPORT_UNICODE */
if (ref)
{
@@ -7858,34 +9161,98 @@ else
#if defined SUPPORT_UNICODE
if (common->utf && *cc == OP_REFI)
{
- SLJIT_ASSERT(TMP1 == SLJIT_R0 && STR_PTR == SLJIT_R1);
+ SLJIT_ASSERT(common->iref_ptr != 0);
+
if (ref)
- OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1));
+ OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1));
else
- OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
+ OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
- if (withchecks)
- jump = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_R2, 0);
- /* No free saved registers so save data on stack. */
+ if (withchecks && emptyfail)
+ add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, TMP2, 0));
- OP1(SLJIT_MOV, SLJIT_R3, 0, STR_END, 0);
- sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW) | SLJIT_ARG4(SW), SLJIT_IMM, SLJIT_FUNC_OFFSET(do_utf_caselesscmp));
- OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_RETURN_REG, 0);
+ OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->iref_ptr, source_reg, 0);
+ OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->iref_ptr + sizeof(sljit_sw), source_end_reg, 0);
+ OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->iref_ptr + sizeof(sljit_sw) * 2, char1_reg, 0);
+
+ OP1(SLJIT_MOV, source_reg, 0, TMP1, 0);
+ OP1(SLJIT_MOV, source_end_reg, 0, TMP2, 0);
+
+ loop = LABEL();
+ jump = CMP(SLJIT_GREATER_EQUAL, source_reg, 0, source_end_reg, 0);
+ partial = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
+ /* Read original character. It must be a valid UTF character. */
+ OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
+ OP1(SLJIT_MOV, STR_PTR, 0, source_reg, 0);
+
+ read_char(common, 0, READ_CHAR_MAX, NULL, READ_CHAR_UPDATE_STR_PTR | READ_CHAR_VALID_UTF);
+
+ OP1(SLJIT_MOV, source_reg, 0, STR_PTR, 0);
+ OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
+ OP1(SLJIT_MOV, char1_reg, 0, TMP1, 0);
+
+ /* Read second character. */
+ read_char(common, 0, READ_CHAR_MAX, &no_match, READ_CHAR_UPDATE_STR_PTR);
+
+ CMPTO(SLJIT_EQUAL, TMP1, 0, char1_reg, 0, loop);
+
+// PH hacking
+//fprintf(stderr, "~~E\n");
+
+ OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
+
+ add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
+
+ OP2(SLJIT_SHL, TMP1, 0, TMP2, 0, SLJIT_IMM, 2);
+
+ OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);
+
+ OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP1, 0);
+
+ OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records));
+
+ OP1(SLJIT_MOV_S32, TMP1, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(ucd_record, other_case));
+ OP1(SLJIT_MOV_U8, TMP2, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(ucd_record, caseset));
+ OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP3, 0);
+ CMPTO(SLJIT_EQUAL, TMP1, 0, char1_reg, 0, loop);
+
+ add_jump(compiler, &no_match, CMP(SLJIT_EQUAL, TMP2, 0, SLJIT_IMM, 0));
+ OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 2);
+ OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_caseless_sets));
+
+ caseless_loop = LABEL();
+ OP1(SLJIT_MOV_U32, TMP1, 0, SLJIT_MEM1(TMP2), 0);
+ OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, sizeof(uint32_t));
+ OP2(SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_LESS, SLJIT_UNUSED, 0, TMP1, 0, char1_reg, 0);
+ JUMPTO(SLJIT_EQUAL, loop);
+ JUMPTO(SLJIT_LESS, caseless_loop);
+
+ set_jumps(no_match, LABEL());
if (common->mode == PCRE2_JIT_COMPLETE)
- add_jump(compiler, backtracks, CMP(SLJIT_LESS_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1));
- else
- {
- OP2(SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
+ JUMPHERE(partial);
- add_jump(compiler, backtracks, JUMP(SLJIT_LESS));
+ OP1(SLJIT_MOV, source_reg, 0, SLJIT_MEM1(SLJIT_SP), common->iref_ptr);
+ OP1(SLJIT_MOV, source_end_reg, 0, SLJIT_MEM1(SLJIT_SP), common->iref_ptr + sizeof(sljit_sw));
+ OP1(SLJIT_MOV, char1_reg, 0, SLJIT_MEM1(SLJIT_SP), common->iref_ptr + sizeof(sljit_sw) * 2);
+ add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
+
+ if (common->mode != PCRE2_JIT_COMPLETE)
+ {
+ JUMPHERE(partial);
+ OP1(SLJIT_MOV, source_reg, 0, SLJIT_MEM1(SLJIT_SP), common->iref_ptr);
+ OP1(SLJIT_MOV, source_end_reg, 0, SLJIT_MEM1(SLJIT_SP), common->iref_ptr + sizeof(sljit_sw));
+ OP1(SLJIT_MOV, char1_reg, 0, SLJIT_MEM1(SLJIT_SP), common->iref_ptr + sizeof(sljit_sw) * 2);
- nopartial = JUMP(SLJIT_NOT_EQUAL);
- OP1(SLJIT_MOV, STR_PTR, 0, STR_END, 0);
check_partial(common, FALSE);
add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
- JUMPHERE(nopartial);
}
+
+ JUMPHERE(jump);
+ OP1(SLJIT_MOV, source_reg, 0, SLJIT_MEM1(SLJIT_SP), common->iref_ptr);
+ OP1(SLJIT_MOV, source_end_reg, 0, SLJIT_MEM1(SLJIT_SP), common->iref_ptr + sizeof(sljit_sw));
+ OP1(SLJIT_MOV, char1_reg, 0, SLJIT_MEM1(SLJIT_SP), common->iref_ptr + sizeof(sljit_sw) * 2);
+ return;
}
else
#endif /* SUPPORT_UNICODE */
@@ -8862,6 +10229,42 @@ if (common->optimized_cbracket[offset >> 1] == 0)
return stacksize;
}
+static PCRE2_SPTR SLJIT_FUNC do_script_run(PCRE2_SPTR ptr, PCRE2_SPTR endptr)
+{
+ if (PRIV(script_run)(ptr, endptr, FALSE))
+ return endptr;
+ return NULL;
+}
+
+#ifdef SUPPORT_UNICODE
+
+static PCRE2_SPTR SLJIT_FUNC do_script_run_utf(PCRE2_SPTR ptr, PCRE2_SPTR endptr)
+{
+ if (PRIV(script_run)(ptr, endptr, TRUE))
+ return endptr;
+ return NULL;
+}
+
+#endif /* SUPPORT_UNICODE */
+
+static SLJIT_INLINE void match_script_run_common(compiler_common *common, int private_data_ptr, backtrack_common *parent)
+{
+DEFINE_COMPILER;
+
+SLJIT_ASSERT(TMP1 == SLJIT_R0 && STR_PTR == SLJIT_R1);
+
+OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
+#ifdef SUPPORT_UNICODE
+sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW), SLJIT_IMM,
+ common->utf ? SLJIT_FUNC_OFFSET(do_script_run_utf) : SLJIT_FUNC_OFFSET(do_script_run));
+#else
+sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW), SLJIT_IMM, SLJIT_FUNC_OFFSET(do_script_run));
+#endif
+
+OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_RETURN_REG, 0);
+add_jump(compiler, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, CMP(SLJIT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0));
+}
+
/*
Handling bracketed expressions is probably the most complex part.
@@ -8997,7 +10400,7 @@ if (opcode == OP_CBRA || opcode == OP_SCBRA)
BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr;
matchingpath += IMM2_SIZE;
}
-else if (opcode == OP_ONCE || opcode == OP_SBRA || opcode == OP_SCOND)
+else if (opcode == OP_ONCE || opcode == OP_SCRIPT_RUN || opcode == OP_SBRA || opcode == OP_SCOND)
{
/* Other brackets simply allocate the next entry. */
private_data_ptr = PRIVATE_DATA(ccbegin);
@@ -9036,35 +10439,32 @@ if (bra == OP_BRAMINZERO)
free_stack(common, 1);
braminzero = CMP(SLJIT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0);
}
- else
+ else if (opcode == OP_ONCE || opcode >= OP_SBRA)
{
- if (opcode == OP_ONCE || opcode >= OP_SBRA)
+ jump = CMP(SLJIT_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0);
+ OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
+ /* Nothing stored during the first run. */
+ skip = JUMP(SLJIT_JUMP);
+ JUMPHERE(jump);
+ /* Checking zero-length iteration. */
+ if (opcode != OP_ONCE || BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)
{
- jump = CMP(SLJIT_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0);
- OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
- /* Nothing stored during the first run. */
- skip = JUMP(SLJIT_JUMP);
- JUMPHERE(jump);
- /* Checking zero-length iteration. */
- if (opcode != OP_ONCE || BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)
- {
- /* When we come from outside, private_data_ptr contains the previous STR_PTR. */
- braminzero = CMP(SLJIT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
- }
- else
- {
- /* Except when the whole stack frame must be saved. */
- OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
- braminzero = CMP(SLJIT_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), STACK(-BACKTRACK_AS(bracket_backtrack)->u.framesize - 2));
- }
- JUMPHERE(skip);
+ /* When we come from outside, private_data_ptr contains the previous STR_PTR. */
+ braminzero = CMP(SLJIT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
}
else
{
- jump = CMP(SLJIT_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0);
- OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
- JUMPHERE(jump);
+ /* Except when the whole stack frame must be saved. */
+ OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
+ braminzero = CMP(SLJIT_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), STACK(-BACKTRACK_AS(bracket_backtrack)->u.framesize - 2));
}
+ JUMPHERE(skip);
+ }
+ else
+ {
+ jump = CMP(SLJIT_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0);
+ OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
+ JUMPHERE(jump);
}
}
@@ -9081,7 +10481,7 @@ if (ket == OP_KETRMIN)
if (ket == OP_KETRMAX)
{
rmax_label = LABEL();
- if (has_alternatives && opcode != OP_ONCE && opcode < OP_SBRA && repeat_type == 0)
+ if (has_alternatives && opcode >= OP_BRA && opcode < OP_SBRA && repeat_type == 0)
BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = rmax_label;
}
@@ -9185,7 +10585,7 @@ else if (opcode == OP_CBRA || opcode == OP_SCBRA)
OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
}
}
-else if (opcode == OP_SBRA || opcode == OP_SCOND)
+else if (opcode == OP_SCRIPT_RUN || opcode == OP_SBRA || opcode == OP_SCOND)
{
/* Saving the previous value. */
OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
@@ -9314,6 +10714,9 @@ if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
if (opcode == OP_ONCE)
match_once_common(common, ket, BACKTRACK_AS(bracket_backtrack)->u.framesize, private_data_ptr, has_alternatives, needs_control_head);
+if (opcode == OP_SCRIPT_RUN)
+ match_script_run_common(common, private_data_ptr, backtrack);
+
stacksize = 0;
if (repeat_type == OP_MINUPTO)
{
@@ -9383,13 +10786,15 @@ if (ket == OP_KETRMAX)
if (opcode != OP_ONCE)
free_stack(common, 1);
}
- else if (opcode == OP_ONCE || opcode >= OP_SBRA)
+ else if (opcode < OP_BRA || opcode >= OP_SBRA)
{
if (has_alternatives)
BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = LABEL();
+
/* Checking zero-length iteration. */
if (opcode != OP_ONCE)
{
+ /* This case includes opcodes such as OP_SCRIPT_RUN. */
CMPTO(SLJIT_NOT_EQUAL, SLJIT_MEM1(SLJIT_SP), private_data_ptr, STR_PTR, 0, rmax_label);
/* Drop STR_PTR for greedy plus quantifier. */
if (bra != OP_BRAZERO)
@@ -9456,7 +10861,7 @@ if (opcode == OP_ONCE)
/* We temporarily encode the needs_control_head in the lowest bit.
Note: on the target architectures of SLJIT the ((x << 1) >> 1) returns
the same value for small signed numbers (including negative numbers). */
- BACKTRACK_AS(bracket_backtrack)->u.framesize = (BACKTRACK_AS(bracket_backtrack)->u.framesize << 1) | (needs_control_head ? 1 : 0);
+ BACKTRACK_AS(bracket_backtrack)->u.framesize = (int)((unsigned)BACKTRACK_AS(bracket_backtrack)->u.framesize << 1) | (needs_control_head ? 1 : 0);
}
return cc + repeat_length;
}
@@ -9951,7 +11356,7 @@ if (exact > 1)
#ifdef SUPPORT_UNICODE
&& !common->utf
#endif
- )
+ && type != OP_ANYNL && type != OP_EXTUNI)
{
OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(exact));
add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_GREATER, TMP1, 0, STR_END, 0));
@@ -10634,6 +12039,7 @@ while (cc < ccend)
break;
case OP_ONCE:
+ case OP_SCRIPT_RUN:
case OP_BRA:
case OP_CBRA:
case OP_COND:
@@ -10787,14 +12193,14 @@ switch(opcode)
if (CURRENT_AS(char_iterator_backtrack)->u.charpos.othercasebit != 0)
OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, CURRENT_AS(char_iterator_backtrack)->u.charpos.othercasebit);
CMPTO(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, CURRENT_AS(char_iterator_backtrack)->u.charpos.chr, CURRENT_AS(char_iterator_backtrack)->matchingpath);
- skip_char_back(common);
+ move_back(common, NULL, TRUE);
CMPTO(SLJIT_GREATER, STR_PTR, 0, TMP2, 0, label);
}
else
{
OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
jump = CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, base, offset1);
- skip_char_back(common);
+ move_back(common, NULL, TRUE);
OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);
JUMPTO(SLJIT_JUMP, CURRENT_AS(char_iterator_backtrack)->matchingpath);
}
@@ -11240,6 +12646,9 @@ if (has_alternatives)
compile_matchingpath(common, ccprev, cc, current);
if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
return;
+
+ if (opcode == OP_SCRIPT_RUN)
+ match_script_run_common(common, private_data_ptr, current);
}
/* Instructions after the current alternative is successfully matched. */
@@ -11368,7 +12777,7 @@ if (offset != 0)
OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, TMP1, 0);
}
}
-else if (opcode == OP_SBRA || opcode == OP_SCOND)
+else if (opcode == OP_SCRIPT_RUN || opcode == OP_SBRA || opcode == OP_SCOND)
{
OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, SLJIT_MEM1(STACK_TOP), STACK(0));
free_stack(common, 1);
@@ -11717,6 +13126,7 @@ while (current)
break;
case OP_ONCE:
+ case OP_SCRIPT_RUN:
case OP_BRA:
case OP_CBRA:
case OP_COND:
@@ -12016,6 +13426,9 @@ sljit_emit_fast_return(compiler, TMP2, 0);
#undef COMPILE_BACKTRACKINGPATH
#undef CURRENT_AS
+#define PUBLIC_JIT_COMPILE_CONFIGURATION_OPTIONS \
+ (PCRE2_JIT_INVALID_UTF)
+
static int jit_compile(pcre2_code *code, sljit_u32 mode)
{
pcre2_real_code *re = (pcre2_real_code *)code;
@@ -12052,6 +13465,11 @@ common->re = re;
common->name_table = (PCRE2_SPTR)((uint8_t *)re + sizeof(pcre2_real_code));
rootbacktrack.cc = common->name_table + re->name_count * re->name_entry_size;
+#ifdef SUPPORT_UNICODE
+common->invalid_utf = (mode & PCRE2_JIT_INVALID_UTF) != 0;
+#endif /* SUPPORT_UNICODE */
+mode &= ~PUBLIC_JIT_COMPILE_CONFIGURATION_OPTIONS;
+
common->start = rootbacktrack.cc;
common->read_only_data_head = NULL;
common->fcc = tables + fcc_offset;
@@ -12066,6 +13484,7 @@ switch(re->newline_convention)
case PCRE2_NEWLINE_CRLF: common->newline = (CHAR_CR << 8) | CHAR_NL; break;
case PCRE2_NEWLINE_ANY: common->newline = (CHAR_CR << 8) | CHAR_NL; common->nltype = NLTYPE_ANY; break;
case PCRE2_NEWLINE_ANYCRLF: common->newline = (CHAR_CR << 8) | CHAR_NL; common->nltype = NLTYPE_ANYCRLF; break;
+ case PCRE2_NEWLINE_NUL: common->newline = CHAR_NUL; break;
default: return PCRE2_ERROR_INTERNAL;
}
common->nlmax = READ_CHAR_MAX;
@@ -12117,6 +13536,8 @@ if (common->utf)
common->bsr_nlmax = (CHAR_CR > CHAR_NL) ? CHAR_CR : CHAR_NL;
common->bsr_nlmin = (CHAR_CR < CHAR_NL) ? CHAR_CR : CHAR_NL;
}
+else
+ common->invalid_utf = FALSE;
#endif /* SUPPORT_UNICODE */
ccend = bracketend(common->start);
@@ -12557,22 +13978,49 @@ if (common->utfreadchar != NULL)
set_jumps(common->utfreadchar, LABEL());
do_utfreadchar(common);
}
-if (common->utfreadchar16 != NULL)
- {
- set_jumps(common->utfreadchar16, LABEL());
- do_utfreadchar16(common);
- }
if (common->utfreadtype8 != NULL)
{
set_jumps(common->utfreadtype8, LABEL());
do_utfreadtype8(common);
}
+if (common->utfpeakcharback != NULL)
+ {
+ set_jumps(common->utfpeakcharback, LABEL());
+ do_utfpeakcharback(common);
+ }
#endif /* PCRE2_CODE_UNIT_WIDTH == 8 */
+#if PCRE2_CODE_UNIT_WIDTH == 8 || PCRE2_CODE_UNIT_WIDTH == 16
+if (common->utfreadchar_invalid != NULL)
+ {
+ set_jumps(common->utfreadchar_invalid, LABEL());
+ do_utfreadchar_invalid(common);
+ }
+if (common->utfreadnewline_invalid != NULL)
+ {
+ set_jumps(common->utfreadnewline_invalid, LABEL());
+ do_utfreadnewline_invalid(common);
+ }
+if (common->utfmoveback_invalid)
+ {
+ set_jumps(common->utfmoveback_invalid, LABEL());
+ do_utfmoveback_invalid(common);
+ }
+if (common->utfpeakcharback_invalid)
+ {
+ set_jumps(common->utfpeakcharback_invalid, LABEL());
+ do_utfpeakcharback_invalid(common);
+ }
+#endif /* PCRE2_CODE_UNIT_WIDTH == 8 || PCRE2_CODE_UNIT_WIDTH == 16 */
if (common->getucd != NULL)
{
set_jumps(common->getucd, LABEL());
do_getucd(common);
}
+if (common->getucdtype != NULL)
+ {
+ set_jumps(common->getucdtype, LABEL());
+ do_getucdtype(common);
+ }
#endif /* SUPPORT_UNICODE */
SLJIT_FREE(common->optimized_cbracket, allocator_data);
@@ -12644,7 +14092,7 @@ Returns: 0: success or (*NOJIT) was used
*/
#define PUBLIC_JIT_COMPILE_OPTIONS \
- (PCRE2_JIT_COMPLETE|PCRE2_JIT_PARTIAL_SOFT|PCRE2_JIT_PARTIAL_HARD)
+ (PCRE2_JIT_COMPLETE|PCRE2_JIT_PARTIAL_SOFT|PCRE2_JIT_PARTIAL_HARD|PCRE2_JIT_INVALID_UTF)
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
pcre2_jit_compile(pcre2_code *code, uint32_t options)
@@ -12659,6 +14107,7 @@ return PCRE2_ERROR_JIT_BADOPTION;
pcre2_real_code *re = (pcre2_real_code *)code;
executable_functions *functions;
+uint32_t excluded_options;
int result;
if (code == NULL)
@@ -12673,21 +14122,24 @@ functions = (executable_functions *)re->executable_jit;
if ((options & PCRE2_JIT_COMPLETE) != 0 && (functions == NULL
|| functions->executable_funcs[0] == NULL)) {
- result = jit_compile(code, PCRE2_JIT_COMPLETE);
+ excluded_options = (PCRE2_JIT_PARTIAL_SOFT | PCRE2_JIT_PARTIAL_HARD);
+ result = jit_compile(code, options & ~excluded_options);
if (result != 0)
return result;
}
if ((options & PCRE2_JIT_PARTIAL_SOFT) != 0 && (functions == NULL
|| functions->executable_funcs[1] == NULL)) {
- result = jit_compile(code, PCRE2_JIT_PARTIAL_SOFT);
+ excluded_options = (PCRE2_JIT_COMPLETE | PCRE2_JIT_PARTIAL_HARD);
+ result = jit_compile(code, options & ~excluded_options);
if (result != 0)
return result;
}
if ((options & PCRE2_JIT_PARTIAL_HARD) != 0 && (functions == NULL
|| functions->executable_funcs[2] == NULL)) {
- result = jit_compile(code, PCRE2_JIT_PARTIAL_HARD);
+ excluded_options = (PCRE2_JIT_COMPLETE | PCRE2_JIT_PARTIAL_SOFT);
+ result = jit_compile(code, options & ~excluded_options);
if (result != 0)
return result;
}
diff --git a/thirdparty/pcre2/src/pcre2_jit_match.c b/thirdparty/pcre2/src/pcre2_jit_match.c
index 5a66545bae..eee038644d 100644
--- a/thirdparty/pcre2/src/pcre2_jit_match.c
+++ b/thirdparty/pcre2/src/pcre2_jit_match.c
@@ -7,7 +7,7 @@ and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
Original API code Copyright (c) 1997-2012 University of Cambridge
- New API code Copyright (c) 2016 University of Cambridge
+ New API code Copyright (c) 2016-2018 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -152,8 +152,6 @@ else
jit_stack = NULL;
}
-/* JIT only need two offsets for each ovector entry. Hence
- the last 1/3 of the ovector will never be touched. */
max_oveccount = functions->top_bracket;
if (oveccount > max_oveccount)
@@ -173,7 +171,7 @@ else
if (rc > (int)oveccount)
rc = 0;
match_data->code = re;
-match_data->subject = subject;
+match_data->subject = (rc >= 0 || rc == PCRE2_ERROR_PARTIAL)? subject : NULL;
match_data->rc = rc;
match_data->startchar = arguments.startchar_ptr - subject;
match_data->leftchar = 0;
diff --git a/thirdparty/pcre2/src/pcre2_maketables.c b/thirdparty/pcre2/src/pcre2_maketables.c
index 537edba8c3..5921e90793 100644
--- a/thirdparty/pcre2/src/pcre2_maketables.c
+++ b/thirdparty/pcre2/src/pcre2_maketables.c
@@ -7,7 +7,7 @@ and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
Original API code Copyright (c) 1997-2012 University of Cambridge
- New API code Copyright (c) 2016-2018 University of Cambridge
+ New API code Copyright (c) 2016-2019 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -114,17 +114,17 @@ test for alnum specially. */
memset(p, 0, cbit_length);
for (i = 0; i < 256; i++)
{
- if (isdigit(i)) p[cbit_digit + i/8] |= 1 << (i&7);
- if (isupper(i)) p[cbit_upper + i/8] |= 1 << (i&7);
- if (islower(i)) p[cbit_lower + i/8] |= 1 << (i&7);
- if (isalnum(i)) p[cbit_word + i/8] |= 1 << (i&7);
- if (i == '_') p[cbit_word + i/8] |= 1 << (i&7);
- if (isspace(i)) p[cbit_space + i/8] |= 1 << (i&7);
- if (isxdigit(i))p[cbit_xdigit + i/8] |= 1 << (i&7);
- if (isgraph(i)) p[cbit_graph + i/8] |= 1 << (i&7);
- if (isprint(i)) p[cbit_print + i/8] |= 1 << (i&7);
- if (ispunct(i)) p[cbit_punct + i/8] |= 1 << (i&7);
- if (iscntrl(i)) p[cbit_cntrl + i/8] |= 1 << (i&7);
+ if (isdigit(i)) p[cbit_digit + i/8] |= 1u << (i&7);
+ if (isupper(i)) p[cbit_upper + i/8] |= 1u << (i&7);
+ if (islower(i)) p[cbit_lower + i/8] |= 1u << (i&7);
+ if (isalnum(i)) p[cbit_word + i/8] |= 1u << (i&7);
+ if (i == '_') p[cbit_word + i/8] |= 1u << (i&7);
+ if (isspace(i)) p[cbit_space + i/8] |= 1u << (i&7);
+ if (isxdigit(i))p[cbit_xdigit + i/8] |= 1u << (i&7);
+ if (isgraph(i)) p[cbit_graph + i/8] |= 1u << (i&7);
+ if (isprint(i)) p[cbit_print + i/8] |= 1u << (i&7);
+ if (ispunct(i)) p[cbit_punct + i/8] |= 1u << (i&7);
+ if (iscntrl(i)) p[cbit_cntrl + i/8] |= 1u << (i&7);
}
p += cbit_length;
@@ -138,8 +138,8 @@ for (i = 0; i < 256; i++)
int x = 0;
if (isspace(i)) x += ctype_space;
if (isalpha(i)) x += ctype_letter;
+ if (islower(i)) x += ctype_lcletter;
if (isdigit(i)) x += ctype_digit;
- if (isxdigit(i)) x += ctype_xdigit;
if (isalnum(i) || i == '_') x += ctype_word;
*p++ = x;
}
diff --git a/thirdparty/pcre2/src/pcre2_match.c b/thirdparty/pcre2/src/pcre2_match.c
index 8741e1432d..419561fd64 100644
--- a/thirdparty/pcre2/src/pcre2_match.c
+++ b/thirdparty/pcre2/src/pcre2_match.c
@@ -7,7 +7,7 @@ and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
Original API code Copyright (c) 1997-2012 University of Cambridge
- New API code Copyright (c) 2015-2018 University of Cambridge
+ New API code Copyright (c) 2015-2019 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -69,11 +69,12 @@ information, and fields within it. */
#define PUBLIC_MATCH_OPTIONS \
(PCRE2_ANCHORED|PCRE2_ENDANCHORED|PCRE2_NOTBOL|PCRE2_NOTEOL|PCRE2_NOTEMPTY| \
PCRE2_NOTEMPTY_ATSTART|PCRE2_NO_UTF_CHECK|PCRE2_PARTIAL_HARD| \
- PCRE2_PARTIAL_SOFT|PCRE2_NO_JIT)
+ PCRE2_PARTIAL_SOFT|PCRE2_NO_JIT|PCRE2_COPY_MATCHED_SUBJECT)
#define PUBLIC_JIT_MATCH_OPTIONS \
(PCRE2_NO_UTF_CHECK|PCRE2_NOTBOL|PCRE2_NOTEOL|PCRE2_NOTEMPTY|\
- PCRE2_NOTEMPTY_ATSTART|PCRE2_PARTIAL_SOFT|PCRE2_PARTIAL_HARD)
+ PCRE2_NOTEMPTY_ATSTART|PCRE2_PARTIAL_SOFT|PCRE2_PARTIAL_HARD|\
+ PCRE2_COPY_MATCHED_SUBJECT)
/* Non-error returns from and within the match() function. Error returns are
externally defined PCRE2_ERROR_xxx codes, which are all negative. */
@@ -1848,7 +1849,7 @@ fprintf(stderr, "++ op=%d\n", *Fecode);
if (Fop == OP_CLASS) RRETURN(MATCH_NOMATCH);
}
else
- if ((Lbyte_map[fc/8] & (1 << (fc&7))) == 0) RRETURN(MATCH_NOMATCH);
+ if ((Lbyte_map[fc/8] & (1u << (fc&7))) == 0) RRETURN(MATCH_NOMATCH);
}
}
else
@@ -1870,7 +1871,7 @@ fprintf(stderr, "++ op=%d\n", *Fecode);
}
else
#endif
- if ((Lbyte_map[fc/8] & (1 << (fc&7))) == 0) RRETURN(MATCH_NOMATCH);
+ if ((Lbyte_map[fc/8] & (1u << (fc&7))) == 0) RRETURN(MATCH_NOMATCH);
}
}
@@ -1902,7 +1903,7 @@ fprintf(stderr, "++ op=%d\n", *Fecode);
if (Fop == OP_CLASS) RRETURN(MATCH_NOMATCH);
}
else
- if ((Lbyte_map[fc/8] & (1 << (fc&7))) == 0) RRETURN(MATCH_NOMATCH);
+ if ((Lbyte_map[fc/8] & (1u << (fc&7))) == 0) RRETURN(MATCH_NOMATCH);
}
}
else
@@ -1927,7 +1928,7 @@ fprintf(stderr, "++ op=%d\n", *Fecode);
}
else
#endif
- if ((Lbyte_map[fc/8] & (1 << (fc&7))) == 0) RRETURN(MATCH_NOMATCH);
+ if ((Lbyte_map[fc/8] & (1u << (fc&7))) == 0) RRETURN(MATCH_NOMATCH);
}
}
/* Control never gets here */
@@ -1956,7 +1957,7 @@ fprintf(stderr, "++ op=%d\n", *Fecode);
if (Fop == OP_CLASS) break;
}
else
- if ((Lbyte_map[fc/8] & (1 << (fc&7))) == 0) break;
+ if ((Lbyte_map[fc/8] & (1u << (fc&7))) == 0) break;
Feptr += len;
}
@@ -1993,7 +1994,7 @@ fprintf(stderr, "++ op=%d\n", *Fecode);
}
else
#endif
- if ((Lbyte_map[fc/8] & (1 << (fc&7))) == 0) break;
+ if ((Lbyte_map[fc/8] & (1u << (fc&7))) == 0) break;
Feptr++;
}
@@ -4084,7 +4085,7 @@ fprintf(stderr, "++ op=%d\n", *Fecode);
GETCHAR(fc, fptr);
}
lgb = UCD_GRAPHBREAK(fc);
- if ((PRIV(ucp_gbtable)[lgb] & (1 << rgb)) == 0) break;
+ if ((PRIV(ucp_gbtable)[lgb] & (1u << rgb)) == 0) break;
Feptr = fptr;
rgb = lgb;
}
@@ -5014,6 +5015,7 @@ fprintf(stderr, "++ op=%d\n", *Fecode);
must record a backtracking point and also set up a chained frame. */
case OP_ONCE:
+ case OP_SCRIPT_RUN:
case OP_SBRA:
Lframe_type = GF_NOCAPTURE | Fop;
@@ -5526,6 +5528,14 @@ fprintf(stderr, "++ op=%d\n", *Fecode);
case OP_ASSERTBACK_NOT:
RRETURN(MATCH_MATCH);
+ /* At the end of a script run, apply the script-checking rules. This code
+ will never by exercised if Unicode support it not compiled, because in
+ that environment script runs cause an error at compile time. */
+
+ case OP_SCRIPT_RUN:
+ if (!PRIV(script_run)(P->eptr, Feptr, utf)) RRETURN(MATCH_NOMATCH);
+ break;
+
/* Whole-pattern recursion is coded as a recurse into group 0, so it
won't be picked up here. Instead, we catch it when the OP_END is reached.
Other recursion is handled here. */
@@ -6000,10 +6010,11 @@ pcre2_match(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length,
pcre2_match_context *mcontext)
{
int rc;
+int was_zero_terminated = 0;
const uint8_t *start_bits = NULL;
-
const pcre2_real_code *re = (const pcre2_real_code *)code;
+
BOOL anchored;
BOOL firstline;
BOOL has_first_cu = FALSE;
@@ -6043,7 +6054,11 @@ mb->stack_frames = (heapframe *)stack_frames_vector;
/* A length equal to PCRE2_ZERO_TERMINATED implies a zero-terminated
subject string. */
-if (length == PCRE2_ZERO_TERMINATED) length = PRIV(strlen)(subject);
+if (length == PCRE2_ZERO_TERMINATED)
+ {
+ length = PRIV(strlen)(subject);
+ was_zero_terminated = 1;
+ }
end_subject = subject + length;
/* Plausibility checks */
@@ -6158,6 +6173,17 @@ if (mcontext != NULL && mcontext->offset_limit != PCRE2_UNSET &&
(re->overall_options & PCRE2_USE_OFFSET_LIMIT) == 0)
return PCRE2_ERROR_BADOFFSETLIMIT;
+/* If the match data block was previously used with PCRE2_COPY_MATCHED_SUBJECT,
+free the memory that was obtained. Set the field to NULL for no match cases. */
+
+if ((match_data->flags & PCRE2_MD_COPIED_SUBJECT) != 0)
+ {
+ match_data->memctl.free((void *)match_data->subject,
+ match_data->memctl.memory_data);
+ match_data->flags &= ~PCRE2_MD_COPIED_SUBJECT;
+ }
+match_data->subject = NULL;
+
/* If the pattern was successfully studied with JIT support, run the JIT
executable instead of the rest of this function. Most options must be set at
compile time for the JIT code to be usable. Fallback to the normal code path if
@@ -6169,7 +6195,19 @@ if (re->executable_jit != NULL && (options & ~PUBLIC_JIT_MATCH_OPTIONS) == 0)
{
rc = pcre2_jit_match(code, subject, length, start_offset, options,
match_data, mcontext);
- if (rc != PCRE2_ERROR_JIT_BADOPTION) return rc;
+ if (rc != PCRE2_ERROR_JIT_BADOPTION)
+ {
+ if (rc >= 0 && (options & PCRE2_COPY_MATCHED_SUBJECT) != 0)
+ {
+ length = CU2BYTES(length + was_zero_terminated);
+ match_data->subject = match_data->memctl.malloc(length,
+ match_data->memctl.memory_data);
+ if (match_data->subject == NULL) return PCRE2_ERROR_NOMEMORY;
+ memcpy((void *)match_data->subject, subject, length);
+ match_data->flags |= PCRE2_MD_COPIED_SUBJECT;
+ }
+ return rc;
+ }
}
#endif
@@ -6421,7 +6459,7 @@ for(;;)
#if PCRE2_CODE_UNIT_WIDTH != 8
if (c > 255) c = 255;
#endif
- ok = (start_bits[c/8] & (1 << (c&7))) != 0;
+ ok = (start_bits[c/8] & (1u << (c&7))) != 0;
}
}
if (!ok)
@@ -6538,7 +6576,7 @@ for(;;)
#if PCRE2_CODE_UNIT_WIDTH != 8
if (c > 255) c = 255;
#endif
- if ((start_bits[c/8] & (1 << (c&7))) != 0) break;
+ if ((start_bits[c/8] & (1u << (c&7))) != 0) break;
start_match++;
}
@@ -6809,13 +6847,13 @@ if (mb->match_frames != mb->stack_frames)
/* Fill in fields that are always returned in the match data. */
match_data->code = re;
-match_data->subject = subject;
match_data->mark = mb->mark;
match_data->matchedby = PCRE2_MATCHEDBY_INTERPRETER;
/* Handle a fully successful match. Set the return code to the number of
captured strings, or 0 if there were too many to fit into the ovector, and then
-set the remaining returned values before returning. */
+set the remaining returned values before returning. Make a copy of the subject
+string if requested. */
if (rc == MATCH_MATCH)
{
@@ -6825,6 +6863,16 @@ if (rc == MATCH_MATCH)
match_data->leftchar = mb->start_used_ptr - subject;
match_data->rightchar = ((mb->last_used_ptr > mb->end_match_ptr)?
mb->last_used_ptr : mb->end_match_ptr) - subject;
+ if ((options & PCRE2_COPY_MATCHED_SUBJECT) != 0)
+ {
+ length = CU2BYTES(length + was_zero_terminated);
+ match_data->subject = match_data->memctl.malloc(length,
+ match_data->memctl.memory_data);
+ if (match_data->subject == NULL) return PCRE2_ERROR_NOMEMORY;
+ memcpy((void *)match_data->subject, subject, length);
+ match_data->flags |= PCRE2_MD_COPIED_SUBJECT;
+ }
+ else match_data->subject = subject;
return match_data->rc;
}
@@ -6838,10 +6886,14 @@ match_data->mark = mb->nomatch_mark;
if (rc != MATCH_NOMATCH && rc != PCRE2_ERROR_PARTIAL) match_data->rc = rc;
-/* Handle a partial match. */
+/* Handle a partial match. If a "soft" partial match was requested, searching
+for a complete match will have continued, and the value of rc at this point
+will be MATCH_NOMATCH. For a "hard" partial match, it will already be
+PCRE2_ERROR_PARTIAL. */
else if (match_partial != NULL)
{
+ match_data->subject = subject;
match_data->ovector[0] = match_partial - subject;
match_data->ovector[1] = end_subject - subject;
match_data->startchar = match_partial - subject;
diff --git a/thirdparty/pcre2/src/pcre2_match_data.c b/thirdparty/pcre2/src/pcre2_match_data.c
index b297f326b5..ccc5f6740e 100644
--- a/thirdparty/pcre2/src/pcre2_match_data.c
+++ b/thirdparty/pcre2/src/pcre2_match_data.c
@@ -7,7 +7,7 @@ and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
Original API code Copyright (c) 1997-2012 University of Cambridge
- New API code Copyright (c) 2016-2017 University of Cambridge
+ New API code Copyright (c) 2016-2018 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -63,6 +63,7 @@ yield = PRIV(memctl_malloc)(
(pcre2_memctl *)gcontext);
if (yield == NULL) return NULL;
yield->oveccount = oveccount;
+yield->flags = 0;
return yield;
}
@@ -93,7 +94,12 @@ PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION
pcre2_match_data_free(pcre2_match_data *match_data)
{
if (match_data != NULL)
+ {
+ if ((match_data->flags & PCRE2_MD_COPIED_SUBJECT) != 0)
+ match_data->memctl.free((void *)match_data->subject,
+ match_data->memctl.memory_data);
match_data->memctl.free(match_data, match_data->memctl.memory_data);
+ }
}
diff --git a/thirdparty/pcre2/src/pcre2_script_run.c b/thirdparty/pcre2/src/pcre2_script_run.c
new file mode 100644
index 0000000000..91a4833028
--- /dev/null
+++ b/thirdparty/pcre2/src/pcre2_script_run.c
@@ -0,0 +1,441 @@
+/*************************************************
+* Perl-Compatible Regular Expressions *
+*************************************************/
+
+/* PCRE is a library of functions to support regular expressions whose syntax
+and semantics are as close as possible to those of the Perl 5 language.
+
+ Written by Philip Hazel
+ Original API code Copyright (c) 1997-2012 University of Cambridge
+ New API code Copyright (c) 2016-2018 University of Cambridge
+
+-----------------------------------------------------------------------------
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of the University of Cambridge nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+-----------------------------------------------------------------------------
+*/
+
+/* This module contains the function for checking a script run. */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "pcre2_internal.h"
+
+
+/*************************************************
+* Check script run *
+*************************************************/
+
+/* A script run is conceptually a sequence of characters all in the same
+Unicode script. However, it isn't quite that simple. There are special rules
+for scripts that are commonly used together, and also special rules for digits.
+This function implements the appropriate checks, which is possible only when
+PCRE2 is compiled with Unicode support. The function returns TRUE if there is
+no Unicode support; however, it should never be called in that circumstance
+because an error is given by pcre2_compile() if a script run is called for in a
+version of PCRE2 compiled without Unicode support.
+
+Arguments:
+ pgr point to the first character
+ endptr point after the last character
+ utf TRUE if in UTF mode
+
+Returns: TRUE if this is a valid script run
+*/
+
+/* These dummy values must be less than the negation of the largest offset in
+the PRIV(ucd_script_sets) vector, which is held in a 16-bit field in UCD
+records (and is only likely to be a few hundred). */
+
+#define SCRIPT_UNSET (-99999)
+#define SCRIPT_HANPENDING (-99998)
+#define SCRIPT_HANHIRAKATA (-99997)
+#define SCRIPT_HANBOPOMOFO (-99996)
+#define SCRIPT_HANHANGUL (-99995)
+#define SCRIPT_LIST (-99994)
+
+#define INTERSECTION_LIST_SIZE 50
+
+BOOL
+PRIV(script_run)(PCRE2_SPTR ptr, PCRE2_SPTR endptr, BOOL utf)
+{
+#ifdef SUPPORT_UNICODE
+int require_script = SCRIPT_UNSET;
+uint8_t intersection_list[INTERSECTION_LIST_SIZE];
+const uint8_t *require_list = NULL;
+uint32_t require_digitset = 0;
+uint32_t c;
+
+#if PCRE2_CODE_UNIT_WIDTH == 32
+(void)utf; /* Avoid compiler warning */
+#endif
+
+/* Any string containing fewer than 2 characters is a valid script run. */
+
+if (ptr >= endptr) return TRUE;
+GETCHARINCTEST(c, ptr);
+if (ptr >= endptr) return TRUE;
+
+/* Scan strings of two or more characters, checking the Unicode characteristics
+of each code point. We make use of the Script Extensions property. There is
+special code for scripts that can be combined with characters from the Han
+Chinese script. This may be used in conjunction with four other scripts in
+these combinations:
+
+. Han with Hiragana and Katakana is allowed (for Japanese).
+. Han with Bopomofo is allowed (for Taiwanese Mandarin).
+. Han with Hangul is allowed (for Korean).
+
+If the first significant character's script is one of the four, the required
+script type is immediately known. However, if the first significant
+character's script is Han, we have to keep checking for a non-Han character.
+Hence the SCRIPT_HANPENDING state. */
+
+for (;;)
+ {
+ const ucd_record *ucd = GET_UCD(c);
+ int32_t scriptx = ucd->scriptx;
+
+ /* If the script extension is Unknown, the string is not a valid script run.
+ Such characters can only form script runs of length one. */
+
+ if (scriptx == ucp_Unknown) return FALSE;
+
+ /* A character whose script extension is Inherited is always accepted with
+ any script, and plays no further part in this testing. A character whose
+ script is Common is always accepted, but must still be tested for a digit
+ below. The scriptx value at this point is non-zero, because zero is
+ ucp_Unknown, tested for above. */
+
+ if (scriptx != ucp_Inherited)
+ {
+ if (scriptx != ucp_Common)
+ {
+ /* If the script extension value is positive, the character is not a mark
+ that can be used with many scripts. In the simple case we either set or
+ compare with the required script. However, handling the scripts that can
+ combine with Han are more complicated, as is the case when the previous
+ characters have been man-script marks. */
+
+ if (scriptx > 0)
+ {
+ switch(require_script)
+ {
+ /* Either the first significant character (require_script unset) or
+ after only Han characters. */
+
+ case SCRIPT_UNSET:
+ case SCRIPT_HANPENDING:
+ switch(scriptx)
+ {
+ case ucp_Han:
+ require_script = SCRIPT_HANPENDING;
+ break;
+
+ case ucp_Hiragana:
+ case ucp_Katakana:
+ require_script = SCRIPT_HANHIRAKATA;
+ break;
+
+ case ucp_Bopomofo:
+ require_script = SCRIPT_HANBOPOMOFO;
+ break;
+
+ case ucp_Hangul:
+ require_script = SCRIPT_HANHANGUL;
+ break;
+
+ /* Not a Han-related script. If expecting one, fail. Otherise set
+ the requirement to this script. */
+
+ default:
+ if (require_script == SCRIPT_HANPENDING) return FALSE;
+ require_script = scriptx;
+ break;
+ }
+ break;
+
+ /* Previously encountered one of the "with Han" scripts. Check that
+ this character is appropriate. */
+
+ case SCRIPT_HANHIRAKATA:
+ if (scriptx != ucp_Han && scriptx != ucp_Hiragana &&
+ scriptx != ucp_Katakana)
+ return FALSE;
+ break;
+
+ case SCRIPT_HANBOPOMOFO:
+ if (scriptx != ucp_Han && scriptx != ucp_Bopomofo) return FALSE;
+ break;
+
+ case SCRIPT_HANHANGUL:
+ if (scriptx != ucp_Han && scriptx != ucp_Hangul) return FALSE;
+ break;
+
+ /* We have a list of scripts to check that is derived from one or
+ more previous characters. This is either one of the lists in
+ ucd_script_sets[] (for one previous character) or the intersection of
+ several lists for multiple characters. */
+
+ case SCRIPT_LIST:
+ {
+ const uint8_t *list;
+ for (list = require_list; *list != 0; list++)
+ {
+ if (*list == scriptx) break;
+ }
+ if (*list == 0) return FALSE;
+ }
+
+ /* The rest of the string must be in this script, but we have to
+ allow for the Han complications. */
+
+ switch(scriptx)
+ {
+ case ucp_Han:
+ require_script = SCRIPT_HANPENDING;
+ break;
+
+ case ucp_Hiragana:
+ case ucp_Katakana:
+ require_script = SCRIPT_HANHIRAKATA;
+ break;
+
+ case ucp_Bopomofo:
+ require_script = SCRIPT_HANBOPOMOFO;
+ break;
+
+ case ucp_Hangul:
+ require_script = SCRIPT_HANHANGUL;
+ break;
+
+ default:
+ require_script = scriptx;
+ break;
+ }
+ break;
+
+ /* This is the easy case when a single script is required. */
+
+ default:
+ if (scriptx != require_script) return FALSE;
+ break;
+ }
+ } /* End of handing positive scriptx */
+
+ /* If scriptx is negative, this character is a mark-type character that
+ has a list of permitted scripts. */
+
+ else
+ {
+ uint32_t chspecial;
+ const uint8_t *clist, *rlist;
+ const uint8_t *list = PRIV(ucd_script_sets) - scriptx;
+
+ switch(require_script)
+ {
+ case SCRIPT_UNSET:
+ require_list = PRIV(ucd_script_sets) - scriptx;
+ require_script = SCRIPT_LIST;
+ break;
+
+ /* An inspection of the Unicode 11.0.0 files shows that there are the
+ following types of Script Extension list that involve the Han,
+ Bopomofo, Hiragana, Katakana, and Hangul scripts:
+
+ . Bopomofo + Han
+ . Han + Hiragana + Katakana
+ . Hiragana + Katakana
+ . Bopopmofo + Hangul + Han + Hiragana + Katakana
+
+ The following code tries to make sense of this. */
+
+#define FOUND_BOPOMOFO 1
+#define FOUND_HIRAGANA 2
+#define FOUND_KATAKANA 4
+#define FOUND_HANGUL 8
+
+ case SCRIPT_HANPENDING:
+ chspecial = 0;
+ for (; *list != 0; list++)
+ {
+ switch (*list)
+ {
+ case ucp_Bopomofo: chspecial |= FOUND_BOPOMOFO; break;
+ case ucp_Hiragana: chspecial |= FOUND_HIRAGANA; break;
+ case ucp_Katakana: chspecial |= FOUND_KATAKANA; break;
+ case ucp_Hangul: chspecial |= FOUND_HANGUL; break;
+ default: break;
+ }
+ }
+
+ if (chspecial == 0) return FALSE;
+
+ if (chspecial == FOUND_BOPOMOFO)
+ {
+ require_script = SCRIPT_HANBOPOMOFO;
+ }
+ else if (chspecial == (FOUND_HIRAGANA|FOUND_KATAKANA))
+ {
+ require_script = SCRIPT_HANHIRAKATA;
+ }
+
+ /* Otherwise it must be allowed with all of them, so remain in
+ the pending state. */
+
+ break;
+
+ case SCRIPT_HANHIRAKATA:
+ for (; *list != 0; list++)
+ {
+ if (*list == ucp_Hiragana || *list == ucp_Katakana) break;
+ }
+ if (*list == 0) return FALSE;
+ break;
+
+ case SCRIPT_HANBOPOMOFO:
+ for (; *list != 0; list++)
+ {
+ if (*list == ucp_Bopomofo) break;
+ }
+ if (*list == 0) return FALSE;
+ break;
+
+ case SCRIPT_HANHANGUL:
+ for (; *list != 0; list++)
+ {
+ if (*list == ucp_Hangul) break;
+ }
+ if (*list == 0) return FALSE;
+ break;
+
+ /* Previously encountered one or more characters that are allowed
+ with a list of scripts. Build the intersection of the required list
+ with this character's list in intersection_list[]. This code is
+ written so that it still works OK if the required list is already in
+ that vector. */
+
+ case SCRIPT_LIST:
+ {
+ int i = 0;
+ for (rlist = require_list; *rlist != 0; rlist++)
+ {
+ for (clist = list; *clist != 0; clist++)
+ {
+ if (*rlist == *clist)
+ {
+ intersection_list[i++] = *rlist;
+ break;
+ }
+ }
+ }
+ if (i == 0) return FALSE; /* No scripts in common */
+
+ /* If there's just one script in common, we can set it as the
+ unique required script. Otherwise, terminate the intersection list
+ and make it the required list. */
+
+ if (i == 1)
+ {
+ require_script = intersection_list[0];
+ }
+ else
+ {
+ intersection_list[i] = 0;
+ require_list = intersection_list;
+ }
+ }
+ break;
+
+ /* The previously set required script is a single script, not
+ Han-related. Check that it is in this character's list. */
+
+ default:
+ for (; *list != 0; list++)
+ {
+ if (*list == require_script) break;
+ }
+ if (*list == 0) return FALSE;
+ break;
+ }
+ } /* End of handling negative scriptx */
+ } /* End of checking non-Common character */
+
+ /* The character is in an acceptable script. We must now ensure that all
+ decimal digits in the string come from the same set. Some scripts (e.g.
+ Common, Arabic) have more than one set of decimal digits. This code does
+ not allow mixing sets, even within the same script. The vector called
+ PRIV(ucd_digit_sets)[] contains, in its first element, the number of
+ following elements, and then, in ascending order, the code points of the
+ '9' characters in every set of 10 digits. Each set is identified by the
+ offset in the vector of its '9' character. An initial check of the first
+ value picks up ASCII digits quickly. Otherwise, a binary chop is used. */
+
+ if (ucd->chartype == ucp_Nd)
+ {
+ uint32_t digitset;
+
+ if (c <= PRIV(ucd_digit_sets)[1]) digitset = 1; else
+ {
+ int mid;
+ int bot = 1;
+ int top = PRIV(ucd_digit_sets)[0];
+ for (;;)
+ {
+ if (top <= bot + 1) /* <= rather than == is paranoia */
+ {
+ digitset = top;
+ break;
+ }
+ mid = (top + bot) / 2;
+ if (c <= PRIV(ucd_digit_sets)[mid]) top = mid; else bot = mid;
+ }
+ }
+
+ /* A required value of 0 means "unset". */
+
+ if (require_digitset == 0) require_digitset = digitset;
+ else if (digitset != require_digitset) return FALSE;
+ } /* End digit handling */
+ } /* End checking non-Inherited character */
+
+ /* If we haven't yet got to the end, pick up the next character. */
+
+ if (ptr >= endptr) return TRUE;
+ GETCHARINCTEST(c, ptr);
+ } /* End checking loop */
+
+#else /* NOT SUPPORT_UNICODE */
+(void)ptr;
+(void)endptr;
+(void)utf;
+return TRUE;
+#endif /* SUPPORT_UNICODE */
+}
+
+/* End of pcre2_script_run.c */
diff --git a/thirdparty/pcre2/src/pcre2_study.c b/thirdparty/pcre2/src/pcre2_study.c
index acbf98b41b..e883c2eb4c 100644
--- a/thirdparty/pcre2/src/pcre2_study.c
+++ b/thirdparty/pcre2/src/pcre2_study.c
@@ -7,7 +7,7 @@ and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
Original API code Copyright (c) 1997-2012 University of Cambridge
- New API code Copyright (c) 2016-2018 University of Cambridge
+ New API code Copyright (c) 2016-2019 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -54,7 +54,7 @@ collecting data (e.g. minimum matching length). */
/* Set a bit in the starting code unit bit map. */
-#define SET_BIT(c) re->start_bitmap[(c)/8] |= (1 << ((c)&7))
+#define SET_BIT(c) re->start_bitmap[(c)/8] |= (1u << ((c)&7))
/* Returns from set_start_bits() */
@@ -171,6 +171,7 @@ for (;;)
/* Fall through */
case OP_ONCE:
+ case OP_SCRIPT_RUN:
case OP_SBRA:
case OP_BRAPOS:
case OP_SBRAPOS:
@@ -842,7 +843,7 @@ for (c = 0; c < table_limit; c++)
if (table_limit == 32) return;
for (c = 128; c < 256; c++)
{
- if ((re->tables[cbits_offset + c/8] & (1 << (c&7))) != 0)
+ if ((re->tables[cbits_offset + c/8] & (1u << (c&7))) != 0)
{
PCRE2_UCHAR buff[6];
(void)PRIV(ord2utf)(c, buff);
@@ -1075,6 +1076,7 @@ do
case OP_CBRAPOS:
case OP_SCBRAPOS:
case OP_ONCE:
+ case OP_SCRIPT_RUN:
case OP_ASSERT:
rc = set_start_bits(re, tcode, utf);
if (rc == SSB_FAIL || rc == SSB_UNKNOWN) return rc;
@@ -1505,11 +1507,11 @@ do
for (c = 0; c < 16; c++) re->start_bitmap[c] |= classmap[c];
for (c = 128; c < 256; c++)
{
- if ((classmap[c/8] & (1 << (c&7))) != 0)
+ if ((classmap[c/8] & (1u << (c&7))) != 0)
{
- int d = (c >> 6) | 0xc0; /* Set bit for this starter */
- re->start_bitmap[d/8] |= (1 << (d&7)); /* and then skip on to the */
- c = (c & 0xc0) + 0x40 - 1; /* next relevant character. */
+ int d = (c >> 6) | 0xc0; /* Set bit for this starter */
+ re->start_bitmap[d/8] |= (1u << (d&7)); /* and then skip on to the */
+ c = (c & 0xc0) + 0x40 - 1; /* next relevant character. */
}
}
}
diff --git a/thirdparty/pcre2/src/pcre2_substitute.c b/thirdparty/pcre2/src/pcre2_substitute.c
index ab8d10908a..ec3dd66df9 100644
--- a/thirdparty/pcre2/src/pcre2_substitute.c
+++ b/thirdparty/pcre2/src/pcre2_substitute.c
@@ -7,7 +7,7 @@ and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
Original API code Copyright (c) 1997-2012 University of Cambridge
- New API code Copyright (c) 2016-2018 University of Cambridge
+ New API code Copyright (c) 2016-2019 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -129,7 +129,7 @@ for (; ptr < ptrend; ptr++)
ptr += 1; /* Must point after \ */
erc = PRIV(check_escape)(&ptr, ptrend, &ch, &errorcode,
- code->overall_options, FALSE, NULL);
+ code->overall_options, code->extra_options, FALSE, NULL);
ptr -= 1; /* Back to last code unit of escape */
if (errorcode != 0)
{
@@ -239,13 +239,17 @@ PCRE2_SIZE extra_needed = 0;
PCRE2_SIZE buff_offset, buff_length, lengthleft, fraglength;
PCRE2_SIZE *ovector;
PCRE2_SIZE ovecsave[3];
+pcre2_substitute_callout_block scb;
+
+/* General initialization */
buff_offset = 0;
lengthleft = buff_length = *blength;
*blength = PCRE2_UNSET;
ovecsave[0] = ovecsave[1] = ovecsave[2] = PCRE2_UNSET;
-/* Partial matching is not valid. */
+/* Partial matching is not valid. This must come after setting *blength to
+PCRE2_UNSET, so as not to imply an offset in the replacement. */
if ((options & (PCRE2_PARTIAL_HARD|PCRE2_PARTIAL_SOFT)) != 0)
return PCRE2_ERROR_BADOPTION;
@@ -264,6 +268,13 @@ if (match_data == NULL)
ovector = pcre2_get_ovector_pointer(match_data);
ovector_count = pcre2_get_ovector_count(match_data);
+/* Fixed things in the callout block */
+
+scb.version = 0;
+scb.input = subject;
+scb.output = (PCRE2_SPTR)buffer;
+scb.ovector = ovector;
+
/* Find lengths of zero-terminated strings and the end of the replacement. */
if (length == PCRE2_ZERO_TERMINATED) length = PRIV(strlen)(subject);
@@ -390,7 +401,7 @@ do
rc = PCRE2_ERROR_INTERNAL_DUPMATCH;
goto EXIT;
}
-
+
/* Count substitutions with a paranoid check for integer overflow; surely no
real call to this function would ever hit this! */
@@ -401,11 +412,14 @@ do
}
subs++;
- /* Copy the text leading up to the match. */
+ /* Copy the text leading up to the match, and remember where the insert
+ begins and how many ovector pairs are set. */
if (rc == 0) rc = ovector_count;
fraglength = ovector[0] - start_offset;
CHECKMEMCPY(subject + start_offset, fraglength);
+ scb.output_offsets[0] = buff_offset;
+ scb.oveccount = rc;
/* Process the replacement string. Literal mode is set by \Q, but only in
extended mode when backslashes are being interpreted. In extended mode we
@@ -421,7 +435,7 @@ do
if (ptr >= repend)
{
- if (ptrstackptr <= 0) break; /* End of replacement string */
+ if (ptrstackptr == 0) break; /* End of replacement string */
repend = ptrstack[--ptrstackptr];
ptr = ptrstack[--ptrstackptr];
continue;
@@ -702,7 +716,7 @@ do
{
if (((code->tables + cbits_offset +
((forcecase > 0)? cbit_upper:cbit_lower)
- )[ch/8] & (1 << (ch%8))) == 0)
+ )[ch/8] & (1u << (ch%8))) == 0)
ch = (code->tables + fcc_offset)[ch];
}
forcecase = forcecasereset;
@@ -760,7 +774,7 @@ do
ptr++; /* Point after \ */
rc = PRIV(check_escape)(&ptr, repend, &ch, &errorcode,
- code->overall_options, FALSE, NULL);
+ code->overall_options, code->extra_options, FALSE, NULL);
if (errorcode != 0) goto BADESCAPE;
switch(rc)
@@ -804,7 +818,7 @@ do
{
if (((code->tables + cbits_offset +
((forcecase > 0)? cbit_upper:cbit_lower)
- )[ch/8] & (1 << (ch%8))) == 0)
+ )[ch/8] & (1u << (ch%8))) == 0)
ch = (code->tables + fcc_offset)[ch];
}
forcecase = forcecasereset;
@@ -821,10 +835,37 @@ do
} /* End handling a literal code unit */
} /* End of loop for scanning the replacement. */
- /* The replacement has been copied to the output. Save the details of this
- match. See above for how this data is used. If we matched an empty string, do
- the magic for global matches. Finally, update the start offset to point to
- the rest of the subject string. */
+ /* The replacement has been copied to the output, or its size has been
+ remembered. Do the callout if there is one and we have done an actual
+ replacement. */
+
+ if (!overflowed && mcontext != NULL && mcontext->substitute_callout != NULL)
+ {
+ scb.subscount = subs;
+ scb.output_offsets[1] = buff_offset;
+ rc = mcontext->substitute_callout(&scb, mcontext->substitute_callout_data);
+
+ /* A non-zero return means cancel this substitution. Instead, copy the
+ matched string fragment. */
+
+ if (rc != 0)
+ {
+ PCRE2_SIZE newlength = scb.output_offsets[1] - scb.output_offsets[0];
+ PCRE2_SIZE oldlength = ovector[1] - ovector[0];
+
+ buff_offset -= newlength;
+ lengthleft += newlength;
+ CHECKMEMCPY(subject + ovector[0], oldlength);
+
+ /* A negative return means do not do any more. */
+
+ if (rc < 0) suboptions &= (~PCRE2_SUBSTITUTE_GLOBAL);
+ }
+ }
+
+ /* Save the details of this match. See above for how this data is used. If we
+ matched an empty string, do the magic for global matches. Finally, update the
+ start offset to point to the rest of the subject string. */
ovecsave[0] = ovector[0];
ovecsave[1] = ovector[1];
diff --git a/thirdparty/pcre2/src/pcre2_tables.c b/thirdparty/pcre2/src/pcre2_tables.c
index 83d6f9de55..84019361fc 100644
--- a/thirdparty/pcre2/src/pcre2_tables.c
+++ b/thirdparty/pcre2/src/pcre2_tables.c
@@ -7,7 +7,7 @@ and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
Original API code Copyright (c) 1997-2012 University of Cambridge
- New API code Copyright (c) 2016-2018 University of Cambridge
+ New API code Copyright (c) 2016-2019 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -142,7 +142,7 @@ ucp_gbXX values defined in pcre2_ucp.h. These changed between Unicode versions
code points. The left property selects a word from the table, and the right
property selects a bit from that word like this:
- PRIV(ucp_gbtable)[left-property] & (1 << right-property)
+ PRIV(ucp_gbtable)[left-property] & (1u << right-property)
The value is non-zero if a grapheme break is NOT permitted between the relevant
two code points. The breaking rules are as follows:
@@ -183,25 +183,25 @@ are implementing).
#define ESZ (1<<ucp_gbExtend)|(1<<ucp_gbSpacingMark)|(1<<ucp_gbZWJ)
const uint32_t PRIV(ucp_gbtable)[] = {
- (1<<ucp_gbLF), /* 0 CR */
- 0, /* 1 LF */
- 0, /* 2 Control */
- ESZ, /* 3 Extend */
- ESZ|(1<<ucp_gbPrepend)| /* 4 Prepend */
- (1<<ucp_gbL)|(1<<ucp_gbV)|(1<<ucp_gbT)|
- (1<<ucp_gbLV)|(1<<ucp_gbLVT)|(1<<ucp_gbOther)|
- (1<<ucp_gbRegionalIndicator),
- ESZ, /* 5 SpacingMark */
- ESZ|(1<<ucp_gbL)|(1<<ucp_gbV)|(1<<ucp_gbLV)| /* 6 L */
- (1<<ucp_gbLVT),
- ESZ|(1<<ucp_gbV)|(1<<ucp_gbT), /* 7 V */
- ESZ|(1<<ucp_gbT), /* 8 T */
- ESZ|(1<<ucp_gbV)|(1<<ucp_gbT), /* 9 LV */
- ESZ|(1<<ucp_gbT), /* 10 LVT */
- (1<<ucp_gbRegionalIndicator), /* 11 RegionalIndicator */
- ESZ, /* 12 Other */
- ESZ, /* 13 ZWJ */
- ESZ|(1<<ucp_gbExtended_Pictographic) /* 14 Extended Pictographic */
+ (1u<<ucp_gbLF), /* 0 CR */
+ 0, /* 1 LF */
+ 0, /* 2 Control */
+ ESZ, /* 3 Extend */
+ ESZ|(1u<<ucp_gbPrepend)| /* 4 Prepend */
+ (1u<<ucp_gbL)|(1u<<ucp_gbV)|(1u<<ucp_gbT)|
+ (1u<<ucp_gbLV)|(1u<<ucp_gbLVT)|(1u<<ucp_gbOther)|
+ (1u<<ucp_gbRegionalIndicator),
+ ESZ, /* 5 SpacingMark */
+ ESZ|(1u<<ucp_gbL)|(1u<<ucp_gbV)|(1u<<ucp_gbLV)| /* 6 L */
+ (1u<<ucp_gbLVT),
+ ESZ|(1u<<ucp_gbV)|(1u<<ucp_gbT), /* 7 V */
+ ESZ|(1u<<ucp_gbT), /* 8 T */
+ ESZ|(1u<<ucp_gbV)|(1u<<ucp_gbT), /* 9 LV */
+ ESZ|(1u<<ucp_gbT), /* 10 LVT */
+ (1u<<ucp_gbRegionalIndicator), /* 11 RegionalIndicator */
+ ESZ, /* 12 Other */
+ ESZ, /* 13 ZWJ */
+ ESZ|(1u<<ucp_gbExtended_Pictographic) /* 14 Extended Pictographic */
};
#undef ESZ
@@ -417,6 +417,7 @@ strings to make sure that UTF-8 support works on EBCDIC platforms. */
#define STRING_Tifinagh0 STR_T STR_i STR_f STR_i STR_n STR_a STR_g STR_h "\0"
#define STRING_Tirhuta0 STR_T STR_i STR_r STR_h STR_u STR_t STR_a "\0"
#define STRING_Ugaritic0 STR_U STR_g STR_a STR_r STR_i STR_t STR_i STR_c "\0"
+#define STRING_Unknown0 STR_U STR_n STR_k STR_n STR_o STR_w STR_n "\0"
#define STRING_Vai0 STR_V STR_a STR_i "\0"
#define STRING_Warang_Citi0 STR_W STR_a STR_r STR_a STR_n STR_g STR_UNDERSCORE STR_C STR_i STR_t STR_i "\0"
#define STRING_Xan0 STR_X STR_a STR_n "\0"
@@ -611,6 +612,7 @@ const char PRIV(utt_names)[] =
STRING_Tifinagh0
STRING_Tirhuta0
STRING_Ugaritic0
+ STRING_Unknown0
STRING_Vai0
STRING_Warang_Citi0
STRING_Xan0
@@ -805,19 +807,20 @@ const ucp_type_table PRIV(utt)[] = {
{ 1424, PT_SC, ucp_Tifinagh },
{ 1433, PT_SC, ucp_Tirhuta },
{ 1441, PT_SC, ucp_Ugaritic },
- { 1450, PT_SC, ucp_Vai },
- { 1454, PT_SC, ucp_Warang_Citi },
- { 1466, PT_ALNUM, 0 },
- { 1470, PT_PXSPACE, 0 },
- { 1474, PT_SPACE, 0 },
- { 1478, PT_UCNC, 0 },
- { 1482, PT_WORD, 0 },
- { 1486, PT_SC, ucp_Yi },
- { 1489, PT_GC, ucp_Z },
- { 1491, PT_SC, ucp_Zanabazar_Square },
- { 1508, PT_PC, ucp_Zl },
- { 1511, PT_PC, ucp_Zp },
- { 1514, PT_PC, ucp_Zs }
+ { 1450, PT_SC, ucp_Unknown },
+ { 1458, PT_SC, ucp_Vai },
+ { 1462, PT_SC, ucp_Warang_Citi },
+ { 1474, PT_ALNUM, 0 },
+ { 1478, PT_PXSPACE, 0 },
+ { 1482, PT_SPACE, 0 },
+ { 1486, PT_UCNC, 0 },
+ { 1490, PT_WORD, 0 },
+ { 1494, PT_SC, ucp_Yi },
+ { 1497, PT_GC, ucp_Z },
+ { 1499, PT_SC, ucp_Zanabazar_Square },
+ { 1516, PT_PC, ucp_Zl },
+ { 1519, PT_PC, ucp_Zp },
+ { 1522, PT_PC, ucp_Zs }
};
const size_t PRIV(utt_size) = sizeof(PRIV(utt)) / sizeof(ucp_type_table);
diff --git a/thirdparty/pcre2/src/pcre2_ucd.c b/thirdparty/pcre2/src/pcre2_ucd.c
index 275a4be2fe..cc53c24001 100644
--- a/thirdparty/pcre2/src/pcre2_ucd.c
+++ b/thirdparty/pcre2/src/pcre2_ucd.c
@@ -20,7 +20,7 @@ needed. */
/* Unicode character database. */
/* This file was autogenerated by the MultiStage2.py script. */
-/* Total size: 92592 bytes, block size: 128. */
+/* Total size: 97152 bytes, block size: 128. */
/* The tables herein are needed only when UCP support is built,
and in PCRE2 that happens automatically with UTF support.
@@ -30,10 +30,10 @@ a comment was received about space saving - maybe the guy linked
all the modules rather than using a library - so we include a
condition to cut out the tables when not needed. But don't leave
a totally empty module because some compilers barf at that.
-Instead, just supply small dummy tables. */
+Instead, just supply some small dummy tables. */
#ifndef SUPPORT_UNICODE
-const ucd_record PRIV(ucd_records)[] = {{0,0,0,0,0 }};
+const ucd_record PRIV(ucd_records)[] = {{0,0,0,0,0,0,0 }};
const uint16_t PRIV(ucd_stage1)[] = {0};
const uint16_t PRIV(ucd_stage2)[] = {0};
const uint32_t PRIV(ucd_caseless_sets)[] = {0};
@@ -47,11 +47,13 @@ special record. */
#if PCRE2_CODE_UNIT_WIDTH == 32
const ucd_record PRIV(dummy_ucd_record)[] = {{
- ucp_Common, /* script */
- ucp_Cn, /* type unassigned */
- ucp_gbOther, /* grapheme break property */
- 0, /* case set */
- 0, /* other case */
+ ucp_Unknown, /* script */
+ ucp_Cn, /* type unassigned */
+ ucp_gbOther, /* grapheme break property */
+ 0, /* case set */
+ 0, /* other case */
+ ucp_Unknown, /* script extension */
+ 0, /* dummy filler */
}};
#endif
@@ -65,9 +67,13 @@ uint8_t property_1;
uint8_t property_2;
uint8_t property_3;
pcre_int32 property_4;
+pcre_int16 property_5;
+uint16_t property_6;
} ucd_record;
*/
+/* This table contains lists of characters that are caseless sets of
+more than one character. Each list is terminated by NOTACHAR. */
const uint32_t PRIV(ucd_caseless_sets)[] = {
NOTACHAR,
@@ -100,865 +106,1014 @@ const uint32_t PRIV(ucd_caseless_sets)[] = {
0x1c88, 0xa64a, 0xa64b, NOTACHAR,
};
-/* When #included in pcre2test, we don't need this large table. */
+/* When #included in pcre2test, we don't need the table of digit
+sets, nor the the large main UCD tables. */
#ifndef PCRE2_PCRE2TEST
-const ucd_record PRIV(ucd_records)[] = { /* 6832 bytes, record size 8 */
- { 9, 0, 2, 0, 0, }, /* 0 */
- { 9, 0, 1, 0, 0, }, /* 1 */
- { 9, 0, 0, 0, 0, }, /* 2 */
- { 9, 29, 12, 0, 0, }, /* 3 */
- { 9, 21, 12, 0, 0, }, /* 4 */
- { 9, 23, 12, 0, 0, }, /* 5 */
- { 9, 22, 12, 0, 0, }, /* 6 */
- { 9, 18, 12, 0, 0, }, /* 7 */
- { 9, 25, 12, 0, 0, }, /* 8 */
- { 9, 17, 12, 0, 0, }, /* 9 */
- { 9, 13, 12, 0, 0, }, /* 10 */
- { 33, 9, 12, 0, 32, }, /* 11 */
- { 33, 9, 12, 100, 32, }, /* 12 */
- { 33, 9, 12, 1, 32, }, /* 13 */
- { 9, 24, 12, 0, 0, }, /* 14 */
- { 9, 16, 12, 0, 0, }, /* 15 */
- { 33, 5, 12, 0, -32, }, /* 16 */
- { 33, 5, 12, 100, -32, }, /* 17 */
- { 33, 5, 12, 1, -32, }, /* 18 */
- { 9, 26, 12, 0, 0, }, /* 19 */
- { 9, 26, 14, 0, 0, }, /* 20 */
- { 33, 7, 12, 0, 0, }, /* 21 */
- { 9, 20, 12, 0, 0, }, /* 22 */
- { 9, 1, 2, 0, 0, }, /* 23 */
- { 9, 15, 12, 0, 0, }, /* 24 */
- { 9, 5, 12, 26, 775, }, /* 25 */
- { 9, 19, 12, 0, 0, }, /* 26 */
- { 33, 9, 12, 104, 32, }, /* 27 */
- { 33, 5, 12, 0, 7615, }, /* 28 */
- { 33, 5, 12, 104, -32, }, /* 29 */
- { 33, 5, 12, 0, 121, }, /* 30 */
- { 33, 9, 12, 0, 1, }, /* 31 */
- { 33, 5, 12, 0, -1, }, /* 32 */
- { 33, 9, 12, 0, 0, }, /* 33 */
- { 33, 5, 12, 0, 0, }, /* 34 */
- { 33, 9, 12, 0, -121, }, /* 35 */
- { 33, 5, 12, 1, -268, }, /* 36 */
- { 33, 5, 12, 0, 195, }, /* 37 */
- { 33, 9, 12, 0, 210, }, /* 38 */
- { 33, 9, 12, 0, 206, }, /* 39 */
- { 33, 9, 12, 0, 205, }, /* 40 */
- { 33, 9, 12, 0, 79, }, /* 41 */
- { 33, 9, 12, 0, 202, }, /* 42 */
- { 33, 9, 12, 0, 203, }, /* 43 */
- { 33, 9, 12, 0, 207, }, /* 44 */
- { 33, 5, 12, 0, 97, }, /* 45 */
- { 33, 9, 12, 0, 211, }, /* 46 */
- { 33, 9, 12, 0, 209, }, /* 47 */
- { 33, 5, 12, 0, 163, }, /* 48 */
- { 33, 9, 12, 0, 213, }, /* 49 */
- { 33, 5, 12, 0, 130, }, /* 50 */
- { 33, 9, 12, 0, 214, }, /* 51 */
- { 33, 9, 12, 0, 218, }, /* 52 */
- { 33, 9, 12, 0, 217, }, /* 53 */
- { 33, 9, 12, 0, 219, }, /* 54 */
- { 33, 5, 12, 0, 56, }, /* 55 */
- { 33, 9, 12, 5, 2, }, /* 56 */
- { 33, 8, 12, 5, 1, }, /* 57 */
- { 33, 5, 12, 5, -2, }, /* 58 */
- { 33, 9, 12, 9, 2, }, /* 59 */
- { 33, 8, 12, 9, 1, }, /* 60 */
- { 33, 5, 12, 9, -2, }, /* 61 */
- { 33, 9, 12, 13, 2, }, /* 62 */
- { 33, 8, 12, 13, 1, }, /* 63 */
- { 33, 5, 12, 13, -2, }, /* 64 */
- { 33, 5, 12, 0, -79, }, /* 65 */
- { 33, 9, 12, 17, 2, }, /* 66 */
- { 33, 8, 12, 17, 1, }, /* 67 */
- { 33, 5, 12, 17, -2, }, /* 68 */
- { 33, 9, 12, 0, -97, }, /* 69 */
- { 33, 9, 12, 0, -56, }, /* 70 */
- { 33, 9, 12, 0, -130, }, /* 71 */
- { 33, 9, 12, 0, 10795, }, /* 72 */
- { 33, 9, 12, 0, -163, }, /* 73 */
- { 33, 9, 12, 0, 10792, }, /* 74 */
- { 33, 5, 12, 0, 10815, }, /* 75 */
- { 33, 9, 12, 0, -195, }, /* 76 */
- { 33, 9, 12, 0, 69, }, /* 77 */
- { 33, 9, 12, 0, 71, }, /* 78 */
- { 33, 5, 12, 0, 10783, }, /* 79 */
- { 33, 5, 12, 0, 10780, }, /* 80 */
- { 33, 5, 12, 0, 10782, }, /* 81 */
- { 33, 5, 12, 0, -210, }, /* 82 */
- { 33, 5, 12, 0, -206, }, /* 83 */
- { 33, 5, 12, 0, -205, }, /* 84 */
- { 33, 5, 12, 0, -202, }, /* 85 */
- { 33, 5, 12, 0, -203, }, /* 86 */
- { 33, 5, 12, 0, 42319, }, /* 87 */
- { 33, 5, 12, 0, 42315, }, /* 88 */
- { 33, 5, 12, 0, -207, }, /* 89 */
- { 33, 5, 12, 0, 42280, }, /* 90 */
- { 33, 5, 12, 0, 42308, }, /* 91 */
- { 33, 5, 12, 0, -209, }, /* 92 */
- { 33, 5, 12, 0, -211, }, /* 93 */
- { 33, 5, 12, 0, 10743, }, /* 94 */
- { 33, 5, 12, 0, 42305, }, /* 95 */
- { 33, 5, 12, 0, 10749, }, /* 96 */
- { 33, 5, 12, 0, -213, }, /* 97 */
- { 33, 5, 12, 0, -214, }, /* 98 */
- { 33, 5, 12, 0, 10727, }, /* 99 */
- { 33, 5, 12, 0, -218, }, /* 100 */
- { 33, 5, 12, 0, 42282, }, /* 101 */
- { 33, 5, 12, 0, -69, }, /* 102 */
- { 33, 5, 12, 0, -217, }, /* 103 */
- { 33, 5, 12, 0, -71, }, /* 104 */
- { 33, 5, 12, 0, -219, }, /* 105 */
- { 33, 5, 12, 0, 42261, }, /* 106 */
- { 33, 5, 12, 0, 42258, }, /* 107 */
- { 33, 6, 12, 0, 0, }, /* 108 */
- { 9, 6, 12, 0, 0, }, /* 109 */
- { 3, 24, 12, 0, 0, }, /* 110 */
- { 27, 12, 3, 0, 0, }, /* 111 */
- { 27, 12, 3, 21, 116, }, /* 112 */
- { 19, 9, 12, 0, 1, }, /* 113 */
- { 19, 5, 12, 0, -1, }, /* 114 */
- { 19, 24, 12, 0, 0, }, /* 115 */
- { 9, 2, 12, 0, 0, }, /* 116 */
- { 19, 6, 12, 0, 0, }, /* 117 */
- { 19, 5, 12, 0, 130, }, /* 118 */
- { 19, 9, 12, 0, 116, }, /* 119 */
- { 19, 9, 12, 0, 38, }, /* 120 */
- { 19, 9, 12, 0, 37, }, /* 121 */
- { 19, 9, 12, 0, 64, }, /* 122 */
- { 19, 9, 12, 0, 63, }, /* 123 */
- { 19, 5, 12, 0, 0, }, /* 124 */
- { 19, 9, 12, 0, 32, }, /* 125 */
- { 19, 9, 12, 34, 32, }, /* 126 */
- { 19, 9, 12, 59, 32, }, /* 127 */
- { 19, 9, 12, 38, 32, }, /* 128 */
- { 19, 9, 12, 21, 32, }, /* 129 */
- { 19, 9, 12, 51, 32, }, /* 130 */
- { 19, 9, 12, 26, 32, }, /* 131 */
- { 19, 9, 12, 47, 32, }, /* 132 */
- { 19, 9, 12, 55, 32, }, /* 133 */
- { 19, 9, 12, 30, 32, }, /* 134 */
- { 19, 9, 12, 43, 32, }, /* 135 */
- { 19, 9, 12, 96, 32, }, /* 136 */
- { 19, 5, 12, 0, -38, }, /* 137 */
- { 19, 5, 12, 0, -37, }, /* 138 */
- { 19, 5, 12, 0, -32, }, /* 139 */
- { 19, 5, 12, 34, -32, }, /* 140 */
- { 19, 5, 12, 59, -32, }, /* 141 */
- { 19, 5, 12, 38, -32, }, /* 142 */
- { 19, 5, 12, 21, -116, }, /* 143 */
- { 19, 5, 12, 51, -32, }, /* 144 */
- { 19, 5, 12, 26, -775, }, /* 145 */
- { 19, 5, 12, 47, -32, }, /* 146 */
- { 19, 5, 12, 55, -32, }, /* 147 */
- { 19, 5, 12, 30, 1, }, /* 148 */
- { 19, 5, 12, 30, -32, }, /* 149 */
- { 19, 5, 12, 43, -32, }, /* 150 */
- { 19, 5, 12, 96, -32, }, /* 151 */
- { 19, 5, 12, 0, -64, }, /* 152 */
- { 19, 5, 12, 0, -63, }, /* 153 */
- { 19, 9, 12, 0, 8, }, /* 154 */
- { 19, 5, 12, 34, -30, }, /* 155 */
- { 19, 5, 12, 38, -25, }, /* 156 */
- { 19, 9, 12, 0, 0, }, /* 157 */
- { 19, 5, 12, 43, -15, }, /* 158 */
- { 19, 5, 12, 47, -22, }, /* 159 */
- { 19, 5, 12, 0, -8, }, /* 160 */
- { 10, 9, 12, 0, 1, }, /* 161 */
- { 10, 5, 12, 0, -1, }, /* 162 */
- { 19, 5, 12, 51, -54, }, /* 163 */
- { 19, 5, 12, 55, -48, }, /* 164 */
- { 19, 5, 12, 0, 7, }, /* 165 */
- { 19, 5, 12, 0, -116, }, /* 166 */
- { 19, 9, 12, 38, -60, }, /* 167 */
- { 19, 5, 12, 59, -64, }, /* 168 */
- { 19, 25, 12, 0, 0, }, /* 169 */
- { 19, 9, 12, 0, -7, }, /* 170 */
- { 19, 9, 12, 0, -130, }, /* 171 */
- { 12, 9, 12, 0, 80, }, /* 172 */
- { 12, 9, 12, 0, 32, }, /* 173 */
- { 12, 9, 12, 63, 32, }, /* 174 */
- { 12, 9, 12, 67, 32, }, /* 175 */
- { 12, 9, 12, 71, 32, }, /* 176 */
- { 12, 9, 12, 75, 32, }, /* 177 */
- { 12, 9, 12, 79, 32, }, /* 178 */
- { 12, 9, 12, 84, 32, }, /* 179 */
- { 12, 5, 12, 0, -32, }, /* 180 */
- { 12, 5, 12, 63, -32, }, /* 181 */
- { 12, 5, 12, 67, -32, }, /* 182 */
- { 12, 5, 12, 71, -32, }, /* 183 */
- { 12, 5, 12, 75, -32, }, /* 184 */
- { 12, 5, 12, 79, -32, }, /* 185 */
- { 12, 5, 12, 84, -32, }, /* 186 */
- { 12, 5, 12, 0, -80, }, /* 187 */
- { 12, 9, 12, 0, 1, }, /* 188 */
- { 12, 5, 12, 0, -1, }, /* 189 */
- { 12, 9, 12, 88, 1, }, /* 190 */
- { 12, 5, 12, 88, -1, }, /* 191 */
- { 12, 26, 12, 0, 0, }, /* 192 */
- { 12, 12, 3, 0, 0, }, /* 193 */
- { 12, 11, 3, 0, 0, }, /* 194 */
- { 12, 9, 12, 0, 15, }, /* 195 */
- { 12, 5, 12, 0, -15, }, /* 196 */
- { 1, 9, 12, 0, 48, }, /* 197 */
- { 1, 6, 12, 0, 0, }, /* 198 */
- { 1, 21, 12, 0, 0, }, /* 199 */
- { 1, 5, 12, 0, 0, }, /* 200 */
- { 1, 5, 12, 0, -48, }, /* 201 */
- { 1, 17, 12, 0, 0, }, /* 202 */
- { 1, 26, 12, 0, 0, }, /* 203 */
- { 1, 23, 12, 0, 0, }, /* 204 */
- { 25, 12, 3, 0, 0, }, /* 205 */
- { 25, 17, 12, 0, 0, }, /* 206 */
- { 25, 21, 12, 0, 0, }, /* 207 */
- { 25, 7, 12, 0, 0, }, /* 208 */
- { 0, 1, 4, 0, 0, }, /* 209 */
- { 9, 1, 4, 0, 0, }, /* 210 */
- { 0, 25, 12, 0, 0, }, /* 211 */
- { 0, 21, 12, 0, 0, }, /* 212 */
- { 0, 23, 12, 0, 0, }, /* 213 */
- { 0, 26, 12, 0, 0, }, /* 214 */
- { 0, 12, 3, 0, 0, }, /* 215 */
- { 0, 1, 2, 0, 0, }, /* 216 */
- { 0, 7, 12, 0, 0, }, /* 217 */
- { 0, 13, 12, 0, 0, }, /* 218 */
- { 0, 6, 12, 0, 0, }, /* 219 */
- { 49, 21, 12, 0, 0, }, /* 220 */
- { 49, 1, 4, 0, 0, }, /* 221 */
- { 49, 7, 12, 0, 0, }, /* 222 */
- { 49, 12, 3, 0, 0, }, /* 223 */
- { 55, 7, 12, 0, 0, }, /* 224 */
- { 55, 12, 3, 0, 0, }, /* 225 */
- { 63, 13, 12, 0, 0, }, /* 226 */
- { 63, 7, 12, 0, 0, }, /* 227 */
- { 63, 12, 3, 0, 0, }, /* 228 */
- { 63, 6, 12, 0, 0, }, /* 229 */
- { 63, 26, 12, 0, 0, }, /* 230 */
- { 63, 21, 12, 0, 0, }, /* 231 */
- { 63, 23, 12, 0, 0, }, /* 232 */
- { 89, 7, 12, 0, 0, }, /* 233 */
- { 89, 12, 3, 0, 0, }, /* 234 */
- { 89, 6, 12, 0, 0, }, /* 235 */
- { 89, 21, 12, 0, 0, }, /* 236 */
- { 94, 7, 12, 0, 0, }, /* 237 */
- { 94, 12, 3, 0, 0, }, /* 238 */
- { 94, 21, 12, 0, 0, }, /* 239 */
- { 14, 12, 3, 0, 0, }, /* 240 */
- { 14, 10, 5, 0, 0, }, /* 241 */
- { 14, 7, 12, 0, 0, }, /* 242 */
- { 14, 13, 12, 0, 0, }, /* 243 */
- { 14, 21, 12, 0, 0, }, /* 244 */
- { 14, 6, 12, 0, 0, }, /* 245 */
- { 2, 7, 12, 0, 0, }, /* 246 */
- { 2, 12, 3, 0, 0, }, /* 247 */
- { 2, 10, 5, 0, 0, }, /* 248 */
- { 2, 10, 3, 0, 0, }, /* 249 */
- { 2, 13, 12, 0, 0, }, /* 250 */
- { 2, 23, 12, 0, 0, }, /* 251 */
- { 2, 15, 12, 0, 0, }, /* 252 */
- { 2, 26, 12, 0, 0, }, /* 253 */
- { 2, 21, 12, 0, 0, }, /* 254 */
- { 21, 12, 3, 0, 0, }, /* 255 */
- { 21, 10, 5, 0, 0, }, /* 256 */
- { 21, 7, 12, 0, 0, }, /* 257 */
- { 21, 13, 12, 0, 0, }, /* 258 */
- { 21, 21, 12, 0, 0, }, /* 259 */
- { 20, 12, 3, 0, 0, }, /* 260 */
- { 20, 10, 5, 0, 0, }, /* 261 */
- { 20, 7, 12, 0, 0, }, /* 262 */
- { 20, 13, 12, 0, 0, }, /* 263 */
- { 20, 21, 12, 0, 0, }, /* 264 */
- { 20, 23, 12, 0, 0, }, /* 265 */
- { 43, 12, 3, 0, 0, }, /* 266 */
- { 43, 10, 5, 0, 0, }, /* 267 */
- { 43, 7, 12, 0, 0, }, /* 268 */
- { 43, 10, 3, 0, 0, }, /* 269 */
- { 43, 13, 12, 0, 0, }, /* 270 */
- { 43, 26, 12, 0, 0, }, /* 271 */
- { 43, 15, 12, 0, 0, }, /* 272 */
- { 53, 12, 3, 0, 0, }, /* 273 */
- { 53, 7, 12, 0, 0, }, /* 274 */
- { 53, 10, 3, 0, 0, }, /* 275 */
- { 53, 10, 5, 0, 0, }, /* 276 */
- { 53, 13, 12, 0, 0, }, /* 277 */
- { 53, 15, 12, 0, 0, }, /* 278 */
- { 53, 26, 12, 0, 0, }, /* 279 */
- { 53, 23, 12, 0, 0, }, /* 280 */
- { 54, 12, 3, 0, 0, }, /* 281 */
- { 54, 10, 5, 0, 0, }, /* 282 */
- { 54, 7, 12, 0, 0, }, /* 283 */
- { 54, 13, 12, 0, 0, }, /* 284 */
- { 54, 15, 12, 0, 0, }, /* 285 */
- { 54, 26, 12, 0, 0, }, /* 286 */
- { 28, 7, 12, 0, 0, }, /* 287 */
- { 28, 12, 3, 0, 0, }, /* 288 */
- { 28, 10, 5, 0, 0, }, /* 289 */
- { 28, 21, 12, 0, 0, }, /* 290 */
- { 28, 10, 3, 0, 0, }, /* 291 */
- { 28, 13, 12, 0, 0, }, /* 292 */
- { 36, 12, 3, 0, 0, }, /* 293 */
- { 36, 10, 5, 0, 0, }, /* 294 */
- { 36, 7, 12, 0, 0, }, /* 295 */
- { 36, 10, 3, 0, 0, }, /* 296 */
- { 36, 7, 4, 0, 0, }, /* 297 */
- { 36, 26, 12, 0, 0, }, /* 298 */
- { 36, 15, 12, 0, 0, }, /* 299 */
- { 36, 13, 12, 0, 0, }, /* 300 */
- { 47, 10, 5, 0, 0, }, /* 301 */
- { 47, 7, 12, 0, 0, }, /* 302 */
- { 47, 12, 3, 0, 0, }, /* 303 */
- { 47, 10, 3, 0, 0, }, /* 304 */
- { 47, 13, 12, 0, 0, }, /* 305 */
- { 47, 21, 12, 0, 0, }, /* 306 */
- { 56, 7, 12, 0, 0, }, /* 307 */
- { 56, 12, 3, 0, 0, }, /* 308 */
- { 56, 7, 5, 0, 0, }, /* 309 */
- { 56, 6, 12, 0, 0, }, /* 310 */
- { 56, 21, 12, 0, 0, }, /* 311 */
- { 56, 13, 12, 0, 0, }, /* 312 */
- { 32, 7, 12, 0, 0, }, /* 313 */
- { 32, 12, 3, 0, 0, }, /* 314 */
- { 32, 7, 5, 0, 0, }, /* 315 */
- { 32, 6, 12, 0, 0, }, /* 316 */
- { 32, 13, 12, 0, 0, }, /* 317 */
- { 57, 7, 12, 0, 0, }, /* 318 */
- { 57, 26, 12, 0, 0, }, /* 319 */
- { 57, 21, 12, 0, 0, }, /* 320 */
- { 57, 12, 3, 0, 0, }, /* 321 */
- { 57, 13, 12, 0, 0, }, /* 322 */
- { 57, 15, 12, 0, 0, }, /* 323 */
- { 57, 22, 12, 0, 0, }, /* 324 */
- { 57, 18, 12, 0, 0, }, /* 325 */
- { 57, 10, 5, 0, 0, }, /* 326 */
- { 38, 7, 12, 0, 0, }, /* 327 */
- { 38, 10, 12, 0, 0, }, /* 328 */
- { 38, 12, 3, 0, 0, }, /* 329 */
- { 38, 10, 5, 0, 0, }, /* 330 */
- { 38, 13, 12, 0, 0, }, /* 331 */
- { 38, 21, 12, 0, 0, }, /* 332 */
- { 38, 26, 12, 0, 0, }, /* 333 */
- { 16, 9, 12, 0, 7264, }, /* 334 */
- { 16, 5, 12, 0, 3008, }, /* 335 */
- { 16, 6, 12, 0, 0, }, /* 336 */
- { 23, 7, 6, 0, 0, }, /* 337 */
- { 23, 7, 7, 0, 0, }, /* 338 */
- { 23, 7, 8, 0, 0, }, /* 339 */
- { 15, 7, 12, 0, 0, }, /* 340 */
- { 15, 12, 3, 0, 0, }, /* 341 */
- { 15, 21, 12, 0, 0, }, /* 342 */
- { 15, 15, 12, 0, 0, }, /* 343 */
- { 15, 26, 12, 0, 0, }, /* 344 */
- { 8, 9, 12, 0, 38864, }, /* 345 */
- { 8, 9, 12, 0, 8, }, /* 346 */
- { 8, 5, 12, 0, -8, }, /* 347 */
- { 7, 17, 12, 0, 0, }, /* 348 */
- { 7, 7, 12, 0, 0, }, /* 349 */
- { 7, 21, 12, 0, 0, }, /* 350 */
- { 40, 29, 12, 0, 0, }, /* 351 */
- { 40, 7, 12, 0, 0, }, /* 352 */
- { 40, 22, 12, 0, 0, }, /* 353 */
- { 40, 18, 12, 0, 0, }, /* 354 */
- { 45, 7, 12, 0, 0, }, /* 355 */
- { 45, 14, 12, 0, 0, }, /* 356 */
- { 50, 7, 12, 0, 0, }, /* 357 */
- { 50, 12, 3, 0, 0, }, /* 358 */
- { 24, 7, 12, 0, 0, }, /* 359 */
- { 24, 12, 3, 0, 0, }, /* 360 */
- { 6, 7, 12, 0, 0, }, /* 361 */
- { 6, 12, 3, 0, 0, }, /* 362 */
- { 51, 7, 12, 0, 0, }, /* 363 */
- { 51, 12, 3, 0, 0, }, /* 364 */
- { 31, 7, 12, 0, 0, }, /* 365 */
- { 31, 12, 3, 0, 0, }, /* 366 */
- { 31, 10, 5, 0, 0, }, /* 367 */
- { 31, 21, 12, 0, 0, }, /* 368 */
- { 31, 6, 12, 0, 0, }, /* 369 */
- { 31, 23, 12, 0, 0, }, /* 370 */
- { 31, 13, 12, 0, 0, }, /* 371 */
- { 31, 15, 12, 0, 0, }, /* 372 */
- { 37, 21, 12, 0, 0, }, /* 373 */
- { 37, 17, 12, 0, 0, }, /* 374 */
- { 37, 12, 3, 0, 0, }, /* 375 */
- { 37, 1, 2, 0, 0, }, /* 376 */
- { 37, 13, 12, 0, 0, }, /* 377 */
- { 37, 7, 12, 0, 0, }, /* 378 */
- { 37, 6, 12, 0, 0, }, /* 379 */
- { 34, 7, 12, 0, 0, }, /* 380 */
- { 34, 12, 3, 0, 0, }, /* 381 */
- { 34, 10, 5, 0, 0, }, /* 382 */
- { 34, 26, 12, 0, 0, }, /* 383 */
- { 34, 21, 12, 0, 0, }, /* 384 */
- { 34, 13, 12, 0, 0, }, /* 385 */
- { 52, 7, 12, 0, 0, }, /* 386 */
- { 39, 7, 12, 0, 0, }, /* 387 */
- { 39, 13, 12, 0, 0, }, /* 388 */
- { 39, 15, 12, 0, 0, }, /* 389 */
- { 39, 26, 12, 0, 0, }, /* 390 */
- { 31, 26, 12, 0, 0, }, /* 391 */
- { 5, 7, 12, 0, 0, }, /* 392 */
- { 5, 12, 3, 0, 0, }, /* 393 */
- { 5, 10, 5, 0, 0, }, /* 394 */
- { 5, 21, 12, 0, 0, }, /* 395 */
- { 90, 7, 12, 0, 0, }, /* 396 */
- { 90, 10, 5, 0, 0, }, /* 397 */
- { 90, 12, 3, 0, 0, }, /* 398 */
- { 90, 10, 12, 0, 0, }, /* 399 */
- { 90, 13, 12, 0, 0, }, /* 400 */
- { 90, 21, 12, 0, 0, }, /* 401 */
- { 90, 6, 12, 0, 0, }, /* 402 */
- { 27, 11, 3, 0, 0, }, /* 403 */
- { 61, 12, 3, 0, 0, }, /* 404 */
- { 61, 10, 5, 0, 0, }, /* 405 */
- { 61, 7, 12, 0, 0, }, /* 406 */
- { 61, 13, 12, 0, 0, }, /* 407 */
- { 61, 21, 12, 0, 0, }, /* 408 */
- { 61, 26, 12, 0, 0, }, /* 409 */
- { 75, 12, 3, 0, 0, }, /* 410 */
- { 75, 10, 5, 0, 0, }, /* 411 */
- { 75, 7, 12, 0, 0, }, /* 412 */
- { 75, 13, 12, 0, 0, }, /* 413 */
- { 92, 7, 12, 0, 0, }, /* 414 */
- { 92, 12, 3, 0, 0, }, /* 415 */
- { 92, 10, 5, 0, 0, }, /* 416 */
- { 92, 21, 12, 0, 0, }, /* 417 */
- { 69, 7, 12, 0, 0, }, /* 418 */
- { 69, 10, 5, 0, 0, }, /* 419 */
- { 69, 12, 3, 0, 0, }, /* 420 */
- { 69, 21, 12, 0, 0, }, /* 421 */
- { 69, 13, 12, 0, 0, }, /* 422 */
- { 72, 13, 12, 0, 0, }, /* 423 */
- { 72, 7, 12, 0, 0, }, /* 424 */
- { 72, 6, 12, 0, 0, }, /* 425 */
- { 72, 21, 12, 0, 0, }, /* 426 */
- { 12, 5, 12, 63, -6222, }, /* 427 */
- { 12, 5, 12, 67, -6221, }, /* 428 */
- { 12, 5, 12, 71, -6212, }, /* 429 */
- { 12, 5, 12, 75, -6210, }, /* 430 */
- { 12, 5, 12, 79, -6210, }, /* 431 */
- { 12, 5, 12, 79, -6211, }, /* 432 */
- { 12, 5, 12, 84, -6204, }, /* 433 */
- { 12, 5, 12, 88, -6180, }, /* 434 */
- { 12, 5, 12, 108, 35267, }, /* 435 */
- { 16, 9, 12, 0, -3008, }, /* 436 */
- { 75, 21, 12, 0, 0, }, /* 437 */
- { 9, 10, 5, 0, 0, }, /* 438 */
- { 9, 7, 12, 0, 0, }, /* 439 */
- { 12, 5, 12, 0, 0, }, /* 440 */
- { 12, 6, 12, 0, 0, }, /* 441 */
- { 33, 5, 12, 0, 35332, }, /* 442 */
- { 33, 5, 12, 0, 3814, }, /* 443 */
- { 33, 9, 12, 92, 1, }, /* 444 */
- { 33, 5, 12, 92, -1, }, /* 445 */
- { 33, 5, 12, 92, -58, }, /* 446 */
- { 33, 9, 12, 0, -7615, }, /* 447 */
- { 19, 5, 12, 0, 8, }, /* 448 */
- { 19, 9, 12, 0, -8, }, /* 449 */
- { 19, 5, 12, 0, 74, }, /* 450 */
- { 19, 5, 12, 0, 86, }, /* 451 */
- { 19, 5, 12, 0, 100, }, /* 452 */
- { 19, 5, 12, 0, 128, }, /* 453 */
- { 19, 5, 12, 0, 112, }, /* 454 */
- { 19, 5, 12, 0, 126, }, /* 455 */
- { 19, 8, 12, 0, -8, }, /* 456 */
- { 19, 5, 12, 0, 9, }, /* 457 */
- { 19, 9, 12, 0, -74, }, /* 458 */
- { 19, 8, 12, 0, -9, }, /* 459 */
- { 19, 5, 12, 21, -7173, }, /* 460 */
- { 19, 9, 12, 0, -86, }, /* 461 */
- { 19, 9, 12, 0, -100, }, /* 462 */
- { 19, 9, 12, 0, -112, }, /* 463 */
- { 19, 9, 12, 0, -128, }, /* 464 */
- { 19, 9, 12, 0, -126, }, /* 465 */
- { 27, 1, 3, 0, 0, }, /* 466 */
- { 27, 1, 13, 0, 0, }, /* 467 */
- { 9, 27, 2, 0, 0, }, /* 468 */
- { 9, 28, 2, 0, 0, }, /* 469 */
- { 9, 21, 14, 0, 0, }, /* 470 */
- { 9, 2, 2, 0, 0, }, /* 471 */
- { 9, 9, 12, 0, 0, }, /* 472 */
- { 9, 5, 12, 0, 0, }, /* 473 */
- { 19, 9, 12, 96, -7517, }, /* 474 */
- { 33, 9, 12, 100, -8383, }, /* 475 */
- { 33, 9, 12, 104, -8262, }, /* 476 */
- { 33, 9, 12, 0, 28, }, /* 477 */
- { 9, 5, 14, 0, 0, }, /* 478 */
- { 33, 5, 12, 0, -28, }, /* 479 */
- { 33, 14, 12, 0, 16, }, /* 480 */
- { 33, 14, 12, 0, -16, }, /* 481 */
- { 33, 14, 12, 0, 0, }, /* 482 */
- { 9, 25, 14, 0, 0, }, /* 483 */
- { 9, 26, 12, 0, 26, }, /* 484 */
- { 9, 26, 14, 0, 26, }, /* 485 */
- { 9, 26, 12, 0, -26, }, /* 486 */
- { 4, 26, 12, 0, 0, }, /* 487 */
- { 17, 9, 12, 0, 48, }, /* 488 */
- { 17, 5, 12, 0, -48, }, /* 489 */
- { 33, 9, 12, 0, -10743, }, /* 490 */
- { 33, 9, 12, 0, -3814, }, /* 491 */
- { 33, 9, 12, 0, -10727, }, /* 492 */
- { 33, 5, 12, 0, -10795, }, /* 493 */
- { 33, 5, 12, 0, -10792, }, /* 494 */
- { 33, 9, 12, 0, -10780, }, /* 495 */
- { 33, 9, 12, 0, -10749, }, /* 496 */
- { 33, 9, 12, 0, -10783, }, /* 497 */
- { 33, 9, 12, 0, -10782, }, /* 498 */
- { 33, 9, 12, 0, -10815, }, /* 499 */
- { 10, 5, 12, 0, 0, }, /* 500 */
- { 10, 26, 12, 0, 0, }, /* 501 */
- { 10, 12, 3, 0, 0, }, /* 502 */
- { 10, 21, 12, 0, 0, }, /* 503 */
- { 10, 15, 12, 0, 0, }, /* 504 */
- { 16, 5, 12, 0, -7264, }, /* 505 */
- { 58, 7, 12, 0, 0, }, /* 506 */
- { 58, 6, 12, 0, 0, }, /* 507 */
- { 58, 21, 12, 0, 0, }, /* 508 */
- { 58, 12, 3, 0, 0, }, /* 509 */
- { 22, 26, 12, 0, 0, }, /* 510 */
- { 22, 6, 12, 0, 0, }, /* 511 */
- { 22, 14, 12, 0, 0, }, /* 512 */
- { 23, 10, 3, 0, 0, }, /* 513 */
- { 9, 17, 14, 0, 0, }, /* 514 */
- { 26, 7, 12, 0, 0, }, /* 515 */
- { 26, 6, 12, 0, 0, }, /* 516 */
- { 29, 7, 12, 0, 0, }, /* 517 */
- { 29, 6, 12, 0, 0, }, /* 518 */
- { 3, 7, 12, 0, 0, }, /* 519 */
- { 23, 7, 12, 0, 0, }, /* 520 */
- { 23, 26, 12, 0, 0, }, /* 521 */
- { 29, 26, 12, 0, 0, }, /* 522 */
- { 22, 7, 12, 0, 0, }, /* 523 */
- { 60, 7, 12, 0, 0, }, /* 524 */
- { 60, 6, 12, 0, 0, }, /* 525 */
- { 60, 26, 12, 0, 0, }, /* 526 */
- { 85, 7, 12, 0, 0, }, /* 527 */
- { 85, 6, 12, 0, 0, }, /* 528 */
- { 85, 21, 12, 0, 0, }, /* 529 */
- { 76, 7, 12, 0, 0, }, /* 530 */
- { 76, 6, 12, 0, 0, }, /* 531 */
- { 76, 21, 12, 0, 0, }, /* 532 */
- { 76, 13, 12, 0, 0, }, /* 533 */
- { 12, 9, 12, 108, 1, }, /* 534 */
- { 12, 5, 12, 108, -35267, }, /* 535 */
- { 12, 7, 12, 0, 0, }, /* 536 */
- { 12, 21, 12, 0, 0, }, /* 537 */
- { 78, 7, 12, 0, 0, }, /* 538 */
- { 78, 14, 12, 0, 0, }, /* 539 */
- { 78, 12, 3, 0, 0, }, /* 540 */
- { 78, 21, 12, 0, 0, }, /* 541 */
- { 33, 9, 12, 0, -35332, }, /* 542 */
- { 33, 9, 12, 0, -42280, }, /* 543 */
- { 33, 9, 12, 0, -42308, }, /* 544 */
- { 33, 9, 12, 0, -42319, }, /* 545 */
- { 33, 9, 12, 0, -42315, }, /* 546 */
- { 33, 9, 12, 0, -42305, }, /* 547 */
- { 33, 9, 12, 0, -42258, }, /* 548 */
- { 33, 9, 12, 0, -42282, }, /* 549 */
- { 33, 9, 12, 0, -42261, }, /* 550 */
- { 33, 9, 12, 0, 928, }, /* 551 */
- { 48, 7, 12, 0, 0, }, /* 552 */
- { 48, 12, 3, 0, 0, }, /* 553 */
- { 48, 10, 5, 0, 0, }, /* 554 */
- { 48, 26, 12, 0, 0, }, /* 555 */
- { 64, 7, 12, 0, 0, }, /* 556 */
- { 64, 21, 12, 0, 0, }, /* 557 */
- { 74, 10, 5, 0, 0, }, /* 558 */
- { 74, 7, 12, 0, 0, }, /* 559 */
- { 74, 12, 3, 0, 0, }, /* 560 */
- { 74, 21, 12, 0, 0, }, /* 561 */
- { 74, 13, 12, 0, 0, }, /* 562 */
- { 68, 13, 12, 0, 0, }, /* 563 */
- { 68, 7, 12, 0, 0, }, /* 564 */
- { 68, 12, 3, 0, 0, }, /* 565 */
- { 68, 21, 12, 0, 0, }, /* 566 */
- { 73, 7, 12, 0, 0, }, /* 567 */
- { 73, 12, 3, 0, 0, }, /* 568 */
- { 73, 10, 5, 0, 0, }, /* 569 */
- { 73, 21, 12, 0, 0, }, /* 570 */
- { 83, 12, 3, 0, 0, }, /* 571 */
- { 83, 10, 5, 0, 0, }, /* 572 */
- { 83, 7, 12, 0, 0, }, /* 573 */
- { 83, 21, 12, 0, 0, }, /* 574 */
- { 83, 13, 12, 0, 0, }, /* 575 */
- { 38, 6, 12, 0, 0, }, /* 576 */
- { 67, 7, 12, 0, 0, }, /* 577 */
- { 67, 12, 3, 0, 0, }, /* 578 */
- { 67, 10, 5, 0, 0, }, /* 579 */
- { 67, 13, 12, 0, 0, }, /* 580 */
- { 67, 21, 12, 0, 0, }, /* 581 */
- { 91, 7, 12, 0, 0, }, /* 582 */
- { 91, 12, 3, 0, 0, }, /* 583 */
- { 91, 6, 12, 0, 0, }, /* 584 */
- { 91, 21, 12, 0, 0, }, /* 585 */
- { 86, 7, 12, 0, 0, }, /* 586 */
- { 86, 10, 5, 0, 0, }, /* 587 */
- { 86, 12, 3, 0, 0, }, /* 588 */
- { 86, 21, 12, 0, 0, }, /* 589 */
- { 86, 6, 12, 0, 0, }, /* 590 */
- { 33, 5, 12, 0, -928, }, /* 591 */
- { 8, 5, 12, 0, -38864, }, /* 592 */
- { 86, 13, 12, 0, 0, }, /* 593 */
- { 23, 7, 9, 0, 0, }, /* 594 */
- { 23, 7, 10, 0, 0, }, /* 595 */
- { 9, 4, 2, 0, 0, }, /* 596 */
- { 9, 3, 12, 0, 0, }, /* 597 */
- { 25, 25, 12, 0, 0, }, /* 598 */
- { 0, 24, 12, 0, 0, }, /* 599 */
- { 9, 6, 3, 0, 0, }, /* 600 */
- { 35, 7, 12, 0, 0, }, /* 601 */
- { 19, 14, 12, 0, 0, }, /* 602 */
- { 19, 15, 12, 0, 0, }, /* 603 */
- { 19, 26, 12, 0, 0, }, /* 604 */
- { 70, 7, 12, 0, 0, }, /* 605 */
- { 66, 7, 12, 0, 0, }, /* 606 */
- { 41, 7, 12, 0, 0, }, /* 607 */
- { 41, 15, 12, 0, 0, }, /* 608 */
- { 18, 7, 12, 0, 0, }, /* 609 */
- { 18, 14, 12, 0, 0, }, /* 610 */
- { 117, 7, 12, 0, 0, }, /* 611 */
- { 117, 12, 3, 0, 0, }, /* 612 */
- { 59, 7, 12, 0, 0, }, /* 613 */
- { 59, 21, 12, 0, 0, }, /* 614 */
- { 42, 7, 12, 0, 0, }, /* 615 */
- { 42, 21, 12, 0, 0, }, /* 616 */
- { 42, 14, 12, 0, 0, }, /* 617 */
- { 13, 9, 12, 0, 40, }, /* 618 */
- { 13, 5, 12, 0, -40, }, /* 619 */
- { 46, 7, 12, 0, 0, }, /* 620 */
- { 44, 7, 12, 0, 0, }, /* 621 */
- { 44, 13, 12, 0, 0, }, /* 622 */
- { 135, 9, 12, 0, 40, }, /* 623 */
- { 135, 5, 12, 0, -40, }, /* 624 */
- { 105, 7, 12, 0, 0, }, /* 625 */
- { 103, 7, 12, 0, 0, }, /* 626 */
- { 103, 21, 12, 0, 0, }, /* 627 */
- { 109, 7, 12, 0, 0, }, /* 628 */
- { 11, 7, 12, 0, 0, }, /* 629 */
- { 80, 7, 12, 0, 0, }, /* 630 */
- { 80, 21, 12, 0, 0, }, /* 631 */
- { 80, 15, 12, 0, 0, }, /* 632 */
- { 119, 7, 12, 0, 0, }, /* 633 */
- { 119, 26, 12, 0, 0, }, /* 634 */
- { 119, 15, 12, 0, 0, }, /* 635 */
- { 115, 7, 12, 0, 0, }, /* 636 */
- { 115, 15, 12, 0, 0, }, /* 637 */
- { 127, 7, 12, 0, 0, }, /* 638 */
- { 127, 15, 12, 0, 0, }, /* 639 */
- { 65, 7, 12, 0, 0, }, /* 640 */
- { 65, 15, 12, 0, 0, }, /* 641 */
- { 65, 21, 12, 0, 0, }, /* 642 */
- { 71, 7, 12, 0, 0, }, /* 643 */
- { 71, 21, 12, 0, 0, }, /* 644 */
- { 97, 7, 12, 0, 0, }, /* 645 */
- { 96, 7, 12, 0, 0, }, /* 646 */
- { 96, 15, 12, 0, 0, }, /* 647 */
- { 30, 7, 12, 0, 0, }, /* 648 */
- { 30, 12, 3, 0, 0, }, /* 649 */
- { 30, 15, 12, 0, 0, }, /* 650 */
- { 30, 21, 12, 0, 0, }, /* 651 */
- { 87, 7, 12, 0, 0, }, /* 652 */
- { 87, 15, 12, 0, 0, }, /* 653 */
- { 87, 21, 12, 0, 0, }, /* 654 */
- { 116, 7, 12, 0, 0, }, /* 655 */
- { 116, 15, 12, 0, 0, }, /* 656 */
- { 111, 7, 12, 0, 0, }, /* 657 */
- { 111, 26, 12, 0, 0, }, /* 658 */
- { 111, 12, 3, 0, 0, }, /* 659 */
- { 111, 15, 12, 0, 0, }, /* 660 */
- { 111, 21, 12, 0, 0, }, /* 661 */
- { 77, 7, 12, 0, 0, }, /* 662 */
- { 77, 21, 12, 0, 0, }, /* 663 */
- { 82, 7, 12, 0, 0, }, /* 664 */
- { 82, 15, 12, 0, 0, }, /* 665 */
- { 81, 7, 12, 0, 0, }, /* 666 */
- { 81, 15, 12, 0, 0, }, /* 667 */
- { 120, 7, 12, 0, 0, }, /* 668 */
- { 120, 21, 12, 0, 0, }, /* 669 */
- { 120, 15, 12, 0, 0, }, /* 670 */
- { 88, 7, 12, 0, 0, }, /* 671 */
- { 129, 9, 12, 0, 64, }, /* 672 */
- { 129, 5, 12, 0, -64, }, /* 673 */
- { 129, 15, 12, 0, 0, }, /* 674 */
- { 143, 7, 12, 0, 0, }, /* 675 */
- { 143, 12, 3, 0, 0, }, /* 676 */
- { 143, 13, 12, 0, 0, }, /* 677 */
- { 0, 15, 12, 0, 0, }, /* 678 */
- { 146, 7, 12, 0, 0, }, /* 679 */
- { 146, 15, 12, 0, 0, }, /* 680 */
- { 147, 7, 12, 0, 0, }, /* 681 */
- { 147, 12, 3, 0, 0, }, /* 682 */
- { 147, 15, 12, 0, 0, }, /* 683 */
- { 147, 21, 12, 0, 0, }, /* 684 */
- { 93, 10, 5, 0, 0, }, /* 685 */
- { 93, 12, 3, 0, 0, }, /* 686 */
- { 93, 7, 12, 0, 0, }, /* 687 */
- { 93, 21, 12, 0, 0, }, /* 688 */
- { 93, 15, 12, 0, 0, }, /* 689 */
- { 93, 13, 12, 0, 0, }, /* 690 */
- { 84, 12, 3, 0, 0, }, /* 691 */
- { 84, 10, 5, 0, 0, }, /* 692 */
- { 84, 7, 12, 0, 0, }, /* 693 */
- { 84, 21, 12, 0, 0, }, /* 694 */
- { 84, 1, 4, 0, 0, }, /* 695 */
- { 100, 7, 12, 0, 0, }, /* 696 */
- { 100, 13, 12, 0, 0, }, /* 697 */
- { 95, 12, 3, 0, 0, }, /* 698 */
- { 95, 7, 12, 0, 0, }, /* 699 */
- { 95, 10, 5, 0, 0, }, /* 700 */
- { 95, 13, 12, 0, 0, }, /* 701 */
- { 95, 21, 12, 0, 0, }, /* 702 */
- { 110, 7, 12, 0, 0, }, /* 703 */
- { 110, 12, 3, 0, 0, }, /* 704 */
- { 110, 21, 12, 0, 0, }, /* 705 */
- { 99, 12, 3, 0, 0, }, /* 706 */
- { 99, 10, 5, 0, 0, }, /* 707 */
- { 99, 7, 12, 0, 0, }, /* 708 */
- { 99, 7, 4, 0, 0, }, /* 709 */
- { 99, 21, 12, 0, 0, }, /* 710 */
- { 99, 13, 12, 0, 0, }, /* 711 */
- { 47, 15, 12, 0, 0, }, /* 712 */
- { 107, 7, 12, 0, 0, }, /* 713 */
- { 107, 10, 5, 0, 0, }, /* 714 */
- { 107, 12, 3, 0, 0, }, /* 715 */
- { 107, 21, 12, 0, 0, }, /* 716 */
- { 128, 7, 12, 0, 0, }, /* 717 */
- { 128, 21, 12, 0, 0, }, /* 718 */
- { 108, 7, 12, 0, 0, }, /* 719 */
- { 108, 12, 3, 0, 0, }, /* 720 */
- { 108, 10, 5, 0, 0, }, /* 721 */
- { 108, 13, 12, 0, 0, }, /* 722 */
- { 106, 12, 3, 0, 0, }, /* 723 */
- { 106, 10, 5, 0, 0, }, /* 724 */
- { 106, 7, 12, 0, 0, }, /* 725 */
- { 106, 10, 3, 0, 0, }, /* 726 */
- { 134, 7, 12, 0, 0, }, /* 727 */
- { 134, 10, 5, 0, 0, }, /* 728 */
- { 134, 12, 3, 0, 0, }, /* 729 */
- { 134, 21, 12, 0, 0, }, /* 730 */
- { 134, 13, 12, 0, 0, }, /* 731 */
- { 123, 7, 12, 0, 0, }, /* 732 */
- { 123, 10, 3, 0, 0, }, /* 733 */
- { 123, 10, 5, 0, 0, }, /* 734 */
- { 123, 12, 3, 0, 0, }, /* 735 */
- { 123, 21, 12, 0, 0, }, /* 736 */
- { 123, 13, 12, 0, 0, }, /* 737 */
- { 122, 7, 12, 0, 0, }, /* 738 */
- { 122, 10, 3, 0, 0, }, /* 739 */
- { 122, 10, 5, 0, 0, }, /* 740 */
- { 122, 12, 3, 0, 0, }, /* 741 */
- { 122, 21, 12, 0, 0, }, /* 742 */
- { 113, 7, 12, 0, 0, }, /* 743 */
- { 113, 10, 5, 0, 0, }, /* 744 */
- { 113, 12, 3, 0, 0, }, /* 745 */
- { 113, 21, 12, 0, 0, }, /* 746 */
- { 113, 13, 12, 0, 0, }, /* 747 */
- { 101, 7, 12, 0, 0, }, /* 748 */
- { 101, 12, 3, 0, 0, }, /* 749 */
- { 101, 10, 5, 0, 0, }, /* 750 */
- { 101, 13, 12, 0, 0, }, /* 751 */
- { 125, 7, 12, 0, 0, }, /* 752 */
- { 125, 12, 3, 0, 0, }, /* 753 */
- { 125, 10, 5, 0, 0, }, /* 754 */
- { 125, 13, 12, 0, 0, }, /* 755 */
- { 125, 15, 12, 0, 0, }, /* 756 */
- { 125, 21, 12, 0, 0, }, /* 757 */
- { 125, 26, 12, 0, 0, }, /* 758 */
- { 141, 7, 12, 0, 0, }, /* 759 */
- { 141, 10, 5, 0, 0, }, /* 760 */
- { 141, 12, 3, 0, 0, }, /* 761 */
- { 141, 21, 12, 0, 0, }, /* 762 */
- { 124, 9, 12, 0, 32, }, /* 763 */
- { 124, 5, 12, 0, -32, }, /* 764 */
- { 124, 13, 12, 0, 0, }, /* 765 */
- { 124, 15, 12, 0, 0, }, /* 766 */
- { 124, 7, 12, 0, 0, }, /* 767 */
- { 140, 7, 12, 0, 0, }, /* 768 */
- { 140, 12, 3, 0, 0, }, /* 769 */
- { 140, 10, 5, 0, 0, }, /* 770 */
- { 140, 7, 4, 0, 0, }, /* 771 */
- { 140, 21, 12, 0, 0, }, /* 772 */
- { 139, 7, 12, 0, 0, }, /* 773 */
- { 139, 12, 3, 0, 0, }, /* 774 */
- { 139, 10, 5, 0, 0, }, /* 775 */
- { 139, 7, 4, 0, 0, }, /* 776 */
- { 139, 21, 12, 0, 0, }, /* 777 */
- { 121, 7, 12, 0, 0, }, /* 778 */
- { 132, 7, 12, 0, 0, }, /* 779 */
- { 132, 10, 5, 0, 0, }, /* 780 */
- { 132, 12, 3, 0, 0, }, /* 781 */
- { 132, 21, 12, 0, 0, }, /* 782 */
- { 132, 13, 12, 0, 0, }, /* 783 */
- { 132, 15, 12, 0, 0, }, /* 784 */
- { 133, 21, 12, 0, 0, }, /* 785 */
- { 133, 7, 12, 0, 0, }, /* 786 */
- { 133, 12, 3, 0, 0, }, /* 787 */
- { 133, 10, 5, 0, 0, }, /* 788 */
- { 137, 7, 12, 0, 0, }, /* 789 */
- { 137, 12, 3, 0, 0, }, /* 790 */
- { 137, 7, 4, 0, 0, }, /* 791 */
- { 137, 13, 12, 0, 0, }, /* 792 */
- { 142, 7, 12, 0, 0, }, /* 793 */
- { 142, 10, 5, 0, 0, }, /* 794 */
- { 142, 12, 3, 0, 0, }, /* 795 */
- { 142, 13, 12, 0, 0, }, /* 796 */
- { 144, 7, 12, 0, 0, }, /* 797 */
- { 144, 12, 3, 0, 0, }, /* 798 */
- { 144, 10, 5, 0, 0, }, /* 799 */
- { 144, 21, 12, 0, 0, }, /* 800 */
- { 62, 7, 12, 0, 0, }, /* 801 */
- { 62, 14, 12, 0, 0, }, /* 802 */
- { 62, 21, 12, 0, 0, }, /* 803 */
- { 79, 7, 12, 0, 0, }, /* 804 */
- { 126, 7, 12, 0, 0, }, /* 805 */
- { 114, 7, 12, 0, 0, }, /* 806 */
- { 114, 13, 12, 0, 0, }, /* 807 */
- { 114, 21, 12, 0, 0, }, /* 808 */
- { 102, 7, 12, 0, 0, }, /* 809 */
- { 102, 12, 3, 0, 0, }, /* 810 */
- { 102, 21, 12, 0, 0, }, /* 811 */
- { 118, 7, 12, 0, 0, }, /* 812 */
- { 118, 12, 3, 0, 0, }, /* 813 */
- { 118, 21, 12, 0, 0, }, /* 814 */
- { 118, 26, 12, 0, 0, }, /* 815 */
- { 118, 6, 12, 0, 0, }, /* 816 */
- { 118, 13, 12, 0, 0, }, /* 817 */
- { 118, 15, 12, 0, 0, }, /* 818 */
- { 145, 9, 12, 0, 32, }, /* 819 */
- { 145, 5, 12, 0, -32, }, /* 820 */
- { 145, 15, 12, 0, 0, }, /* 821 */
- { 145, 21, 12, 0, 0, }, /* 822 */
- { 98, 7, 12, 0, 0, }, /* 823 */
- { 98, 10, 5, 0, 0, }, /* 824 */
- { 98, 12, 3, 0, 0, }, /* 825 */
- { 98, 6, 12, 0, 0, }, /* 826 */
- { 136, 6, 12, 0, 0, }, /* 827 */
- { 138, 6, 12, 0, 0, }, /* 828 */
- { 136, 7, 12, 0, 0, }, /* 829 */
- { 138, 7, 12, 0, 0, }, /* 830 */
- { 104, 7, 12, 0, 0, }, /* 831 */
- { 104, 26, 12, 0, 0, }, /* 832 */
- { 104, 12, 3, 0, 0, }, /* 833 */
- { 104, 21, 12, 0, 0, }, /* 834 */
- { 9, 10, 3, 0, 0, }, /* 835 */
- { 19, 12, 3, 0, 0, }, /* 836 */
- { 130, 26, 12, 0, 0, }, /* 837 */
- { 130, 12, 3, 0, 0, }, /* 838 */
- { 130, 21, 12, 0, 0, }, /* 839 */
- { 17, 12, 3, 0, 0, }, /* 840 */
- { 112, 7, 12, 0, 0, }, /* 841 */
- { 112, 15, 12, 0, 0, }, /* 842 */
- { 112, 12, 3, 0, 0, }, /* 843 */
- { 131, 9, 12, 0, 34, }, /* 844 */
- { 131, 5, 12, 0, -34, }, /* 845 */
- { 131, 12, 3, 0, 0, }, /* 846 */
- { 131, 13, 12, 0, 0, }, /* 847 */
- { 131, 21, 12, 0, 0, }, /* 848 */
- { 9, 2, 14, 0, 0, }, /* 849 */
- { 9, 26, 11, 0, 0, }, /* 850 */
- { 26, 26, 12, 0, 0, }, /* 851 */
- { 9, 24, 3, 0, 0, }, /* 852 */
- { 9, 1, 3, 0, 0, }, /* 853 */
+/* This table lists the code points for the '9' characters in each
+set of decimal digits. It is used to ensure that all the digits in
+a script run come from the same set. */
+
+const uint32_t PRIV(ucd_digit_sets)[] = {
+ 61, /* Number of subsequent values */
+ 0x00039, 0x00669, 0x006f9, 0x007c9, 0x0096f, 0x009ef, 0x00a6f, 0x00aef,
+ 0x00b6f, 0x00bef, 0x00c6f, 0x00cef, 0x00d6f, 0x00def, 0x00e59, 0x00ed9,
+ 0x00f29, 0x01049, 0x01099, 0x017e9, 0x01819, 0x0194f, 0x019d9, 0x01a89,
+ 0x01a99, 0x01b59, 0x01bb9, 0x01c49, 0x01c59, 0x0a629, 0x0a8d9, 0x0a909,
+ 0x0a9d9, 0x0a9f9, 0x0aa59, 0x0abf9, 0x0ff19, 0x104a9, 0x10d39, 0x1106f,
+ 0x110f9, 0x1113f, 0x111d9, 0x112f9, 0x11459, 0x114d9, 0x11659, 0x116c9,
+ 0x11739, 0x118e9, 0x11c59, 0x11d59, 0x11da9, 0x16a69, 0x16b59, 0x1d7d7,
+ 0x1d7e1, 0x1d7eb, 0x1d7f5, 0x1d7ff, 0x1e959,
+};
+
+/* This vector is a list of lists of scripts for the Script Extension
+property. Each sublist is zero-terminated. */
+
+const uint8_t PRIV(ucd_script_sets)[] = {
+ /* 0 */ 0,
+ /* 1 */ 1, 11, 0,
+ /* 4 */ 1, 144, 0,
+ /* 7 */ 1, 50, 0,
+ /* 10 */ 1, 56, 0,
+ /* 13 */ 2, 17, 0,
+ /* 16 */ 3, 15, 0,
+ /* 19 */ 4, 23, 0,
+ /* 22 */ 6, 84, 0,
+ /* 25 */ 12, 36, 0,
+ /* 28 */ 13, 18, 0,
+ /* 31 */ 13, 34, 0,
+ /* 34 */ 13, 118, 0,
+ /* 37 */ 15, 107, 0,
+ /* 40 */ 15, 100, 0,
+ /* 43 */ 15, 54, 0,
+ /* 46 */ 17, 34, 0,
+ /* 49 */ 107, 54, 0,
+ /* 52 */ 21, 108, 0,
+ /* 55 */ 22, 129, 0,
+ /* 58 */ 27, 30, 0,
+ /* 61 */ 38, 65, 0,
+ /* 64 */ 1, 50, 56, 0,
+ /* 68 */ 3, 96, 49, 0,
+ /* 72 */ 96, 39, 53, 0,
+ /* 76 */ 12, 110, 36, 0,
+ /* 80 */ 15, 107, 29, 0,
+ /* 84 */ 15, 107, 34, 0,
+ /* 88 */ 23, 27, 30, 0,
+ /* 92 */ 69, 34, 39, 0,
+ /* 96 */ 1, 144, 50, 56, 0,
+ /* 101 */ 3, 15, 107, 29, 0,
+ /* 106 */ 7, 25, 52, 51, 0,
+ /* 111 */ 15, 142, 85, 111, 0,
+ /* 116 */ 4, 24, 23, 27, 30, 0,
+ /* 122 */ 4, 24, 23, 27, 30, 61, 0,
+ /* 129 */ 15, 29, 37, 44, 54, 55, 0,
+ /* 136 */ 132, 1, 95, 112, 121, 144, 148, 50, 0,
+ /* 145 */ 15, 142, 21, 22, 108, 85, 111, 114, 109, 102, 124, 0,
+ /* 157 */ 3, 15, 107, 21, 22, 29, 34, 37, 44, 54, 55, 124, 0,
+ /* 170 */ 15, 142, 21, 22, 108, 29, 85, 111, 114, 109, 102, 124, 0,
+ /* 183 */ 3, 15, 107, 21, 22, 29, 34, 37, 44, 100, 54, 55, 124, 0,
+ /* 197 */ 15, 142, 21, 22, 108, 29, 85, 111, 37, 114, 109, 102, 124, 0,
+ /* 211 */ 3, 15, 142, 143, 107, 21, 22, 29, 111, 37, 44, 109, 48, 49, 102, 54, 55, 124, 0,
+ /* 230 */ 3, 15, 142, 143, 107, 21, 22, 29, 35, 111, 37, 44, 109, 48, 49, 102, 54, 55, 124, 0,
+ /* 250 */
+};
+
+/* These are the main two-stage UCD tables. The fields in each record are:
+script (8 bits), character type (8 bits), grapheme break property (8 bits),
+offset to multichar other cases or zero (8 bits), offset to other case
+or zero (32 bits, signed), script extension (16 bits, signed), and a dummy
+16-bit field to make the whole thing a multiple of 4 bytes. */
+
+const ucd_record PRIV(ucd_records)[] = { /* 11136 bytes, record size 12 */
+ { 10, 0, 2, 0, 0, 10, 256, }, /* 0 */
+ { 10, 0, 2, 0, 0, 10, 0, }, /* 1 */
+ { 10, 0, 1, 0, 0, 10, 0, }, /* 2 */
+ { 10, 0, 0, 0, 0, 10, 0, }, /* 3 */
+ { 10, 29, 12, 0, 0, 10, 0, }, /* 4 */
+ { 10, 21, 12, 0, 0, 10, 0, }, /* 5 */
+ { 10, 23, 12, 0, 0, 10, 0, }, /* 6 */
+ { 10, 22, 12, 0, 0, 10, 0, }, /* 7 */
+ { 10, 18, 12, 0, 0, 10, 0, }, /* 8 */
+ { 10, 25, 12, 0, 0, 10, 0, }, /* 9 */
+ { 10, 17, 12, 0, 0, 10, 0, }, /* 10 */
+ { 10, 13, 12, 0, 0, 10, 0, }, /* 11 */
+ { 34, 9, 12, 0, 32, 34, 0, }, /* 12 */
+ { 34, 9, 12, 100, 32, 34, 0, }, /* 13 */
+ { 34, 9, 12, 1, 32, 34, 0, }, /* 14 */
+ { 10, 24, 12, 0, 0, 10, 0, }, /* 15 */
+ { 10, 16, 12, 0, 0, 10, 0, }, /* 16 */
+ { 34, 5, 12, 0, -32, 34, 0, }, /* 17 */
+ { 34, 5, 12, 100, -32, 34, 0, }, /* 18 */
+ { 34, 5, 12, 1, -32, 34, 0, }, /* 19 */
+ { 10, 26, 12, 0, 0, 10, 0, }, /* 20 */
+ { 10, 26, 14, 0, 0, 10, 0, }, /* 21 */
+ { 34, 7, 12, 0, 0, 34, 0, }, /* 22 */
+ { 10, 20, 12, 0, 0, 10, 0, }, /* 23 */
+ { 10, 1, 2, 0, 0, 10, 0, }, /* 24 */
+ { 10, 15, 12, 0, 0, 10, 0, }, /* 25 */
+ { 10, 5, 12, 26, 775, 10, 0, }, /* 26 */
+ { 10, 19, 12, 0, 0, 10, 0, }, /* 27 */
+ { 34, 9, 12, 104, 32, 34, 0, }, /* 28 */
+ { 34, 5, 12, 0, 7615, 34, 0, }, /* 29 */
+ { 34, 5, 12, 104, -32, 34, 0, }, /* 30 */
+ { 34, 5, 12, 0, 121, 34, 0, }, /* 31 */
+ { 34, 9, 12, 0, 1, 34, 0, }, /* 32 */
+ { 34, 5, 12, 0, -1, 34, 0, }, /* 33 */
+ { 34, 9, 12, 0, 0, 34, 0, }, /* 34 */
+ { 34, 5, 12, 0, 0, 34, 0, }, /* 35 */
+ { 34, 9, 12, 0, -121, 34, 0, }, /* 36 */
+ { 34, 5, 12, 1, -268, 34, 0, }, /* 37 */
+ { 34, 5, 12, 0, 195, 34, 0, }, /* 38 */
+ { 34, 9, 12, 0, 210, 34, 0, }, /* 39 */
+ { 34, 9, 12, 0, 206, 34, 0, }, /* 40 */
+ { 34, 9, 12, 0, 205, 34, 0, }, /* 41 */
+ { 34, 9, 12, 0, 79, 34, 0, }, /* 42 */
+ { 34, 9, 12, 0, 202, 34, 0, }, /* 43 */
+ { 34, 9, 12, 0, 203, 34, 0, }, /* 44 */
+ { 34, 9, 12, 0, 207, 34, 0, }, /* 45 */
+ { 34, 5, 12, 0, 97, 34, 0, }, /* 46 */
+ { 34, 9, 12, 0, 211, 34, 0, }, /* 47 */
+ { 34, 9, 12, 0, 209, 34, 0, }, /* 48 */
+ { 34, 5, 12, 0, 163, 34, 0, }, /* 49 */
+ { 34, 9, 12, 0, 213, 34, 0, }, /* 50 */
+ { 34, 5, 12, 0, 130, 34, 0, }, /* 51 */
+ { 34, 9, 12, 0, 214, 34, 0, }, /* 52 */
+ { 34, 9, 12, 0, 218, 34, 0, }, /* 53 */
+ { 34, 9, 12, 0, 217, 34, 0, }, /* 54 */
+ { 34, 9, 12, 0, 219, 34, 0, }, /* 55 */
+ { 34, 5, 12, 0, 56, 34, 0, }, /* 56 */
+ { 34, 9, 12, 5, 2, 34, 0, }, /* 57 */
+ { 34, 8, 12, 5, 1, 34, 0, }, /* 58 */
+ { 34, 5, 12, 5, -2, 34, 0, }, /* 59 */
+ { 34, 9, 12, 9, 2, 34, 0, }, /* 60 */
+ { 34, 8, 12, 9, 1, 34, 0, }, /* 61 */
+ { 34, 5, 12, 9, -2, 34, 0, }, /* 62 */
+ { 34, 9, 12, 13, 2, 34, 0, }, /* 63 */
+ { 34, 8, 12, 13, 1, 34, 0, }, /* 64 */
+ { 34, 5, 12, 13, -2, 34, 0, }, /* 65 */
+ { 34, 5, 12, 0, -79, 34, 0, }, /* 66 */
+ { 34, 9, 12, 17, 2, 34, 0, }, /* 67 */
+ { 34, 8, 12, 17, 1, 34, 0, }, /* 68 */
+ { 34, 5, 12, 17, -2, 34, 0, }, /* 69 */
+ { 34, 9, 12, 0, -97, 34, 0, }, /* 70 */
+ { 34, 9, 12, 0, -56, 34, 0, }, /* 71 */
+ { 34, 9, 12, 0, -130, 34, 0, }, /* 72 */
+ { 34, 9, 12, 0, 10795, 34, 0, }, /* 73 */
+ { 34, 9, 12, 0, -163, 34, 0, }, /* 74 */
+ { 34, 9, 12, 0, 10792, 34, 0, }, /* 75 */
+ { 34, 5, 12, 0, 10815, 34, 0, }, /* 76 */
+ { 34, 9, 12, 0, -195, 34, 0, }, /* 77 */
+ { 34, 9, 12, 0, 69, 34, 0, }, /* 78 */
+ { 34, 9, 12, 0, 71, 34, 0, }, /* 79 */
+ { 34, 5, 12, 0, 10783, 34, 0, }, /* 80 */
+ { 34, 5, 12, 0, 10780, 34, 0, }, /* 81 */
+ { 34, 5, 12, 0, 10782, 34, 0, }, /* 82 */
+ { 34, 5, 12, 0, -210, 34, 0, }, /* 83 */
+ { 34, 5, 12, 0, -206, 34, 0, }, /* 84 */
+ { 34, 5, 12, 0, -205, 34, 0, }, /* 85 */
+ { 34, 5, 12, 0, -202, 34, 0, }, /* 86 */
+ { 34, 5, 12, 0, -203, 34, 0, }, /* 87 */
+ { 34, 5, 12, 0, 42319, 34, 0, }, /* 88 */
+ { 34, 5, 12, 0, 42315, 34, 0, }, /* 89 */
+ { 34, 5, 12, 0, -207, 34, 0, }, /* 90 */
+ { 34, 5, 12, 0, 42280, 34, 0, }, /* 91 */
+ { 34, 5, 12, 0, 42308, 34, 0, }, /* 92 */
+ { 34, 5, 12, 0, -209, 34, 0, }, /* 93 */
+ { 34, 5, 12, 0, -211, 34, 0, }, /* 94 */
+ { 34, 5, 12, 0, 10743, 34, 0, }, /* 95 */
+ { 34, 5, 12, 0, 42305, 34, 0, }, /* 96 */
+ { 34, 5, 12, 0, 10749, 34, 0, }, /* 97 */
+ { 34, 5, 12, 0, -213, 34, 0, }, /* 98 */
+ { 34, 5, 12, 0, -214, 34, 0, }, /* 99 */
+ { 34, 5, 12, 0, 10727, 34, 0, }, /* 100 */
+ { 34, 5, 12, 0, -218, 34, 0, }, /* 101 */
+ { 34, 5, 12, 0, 42282, 34, 0, }, /* 102 */
+ { 34, 5, 12, 0, -69, 34, 0, }, /* 103 */
+ { 34, 5, 12, 0, -217, 34, 0, }, /* 104 */
+ { 34, 5, 12, 0, -71, 34, 0, }, /* 105 */
+ { 34, 5, 12, 0, -219, 34, 0, }, /* 106 */
+ { 34, 5, 12, 0, 42261, 34, 0, }, /* 107 */
+ { 34, 5, 12, 0, 42258, 34, 0, }, /* 108 */
+ { 34, 6, 12, 0, 0, 34, 0, }, /* 109 */
+ { 10, 6, 12, 0, 0, 10, 0, }, /* 110 */
+ { 4, 24, 12, 0, 0, 4, 0, }, /* 111 */
+ { 28, 12, 3, 0, 0, 28, 0, }, /* 112 */
+ { 28, 12, 3, 0, 0, 20, 0, }, /* 113 */
+ { 28, 12, 3, 21, 116, 20, 0, }, /* 114 */
+ { 28, 12, 3, 0, 0, 34, 0, }, /* 115 */
+ { 20, 9, 12, 0, 1, 20, 0, }, /* 116 */
+ { 20, 5, 12, 0, -1, 20, 0, }, /* 117 */
+ { 20, 24, 12, 0, 0, 20, 0, }, /* 118 */
+ { 0, 2, 12, 0, 0, 0, 0, }, /* 119 */
+ { 20, 6, 12, 0, 0, 20, 0, }, /* 120 */
+ { 20, 5, 12, 0, 130, 20, 0, }, /* 121 */
+ { 20, 9, 12, 0, 116, 20, 0, }, /* 122 */
+ { 20, 9, 12, 0, 38, 20, 0, }, /* 123 */
+ { 20, 9, 12, 0, 37, 20, 0, }, /* 124 */
+ { 20, 9, 12, 0, 64, 20, 0, }, /* 125 */
+ { 20, 9, 12, 0, 63, 20, 0, }, /* 126 */
+ { 20, 5, 12, 0, 0, 20, 0, }, /* 127 */
+ { 20, 9, 12, 0, 32, 20, 0, }, /* 128 */
+ { 20, 9, 12, 34, 32, 20, 0, }, /* 129 */
+ { 20, 9, 12, 59, 32, 20, 0, }, /* 130 */
+ { 20, 9, 12, 38, 32, 20, 0, }, /* 131 */
+ { 20, 9, 12, 21, 32, 20, 0, }, /* 132 */
+ { 20, 9, 12, 51, 32, 20, 0, }, /* 133 */
+ { 20, 9, 12, 26, 32, 20, 0, }, /* 134 */
+ { 20, 9, 12, 47, 32, 20, 0, }, /* 135 */
+ { 20, 9, 12, 55, 32, 20, 0, }, /* 136 */
+ { 20, 9, 12, 30, 32, 20, 0, }, /* 137 */
+ { 20, 9, 12, 43, 32, 20, 0, }, /* 138 */
+ { 20, 9, 12, 96, 32, 20, 0, }, /* 139 */
+ { 20, 5, 12, 0, -38, 20, 0, }, /* 140 */
+ { 20, 5, 12, 0, -37, 20, 0, }, /* 141 */
+ { 20, 5, 12, 0, -32, 20, 0, }, /* 142 */
+ { 20, 5, 12, 34, -32, 20, 0, }, /* 143 */
+ { 20, 5, 12, 59, -32, 20, 0, }, /* 144 */
+ { 20, 5, 12, 38, -32, 20, 0, }, /* 145 */
+ { 20, 5, 12, 21, -116, 20, 0, }, /* 146 */
+ { 20, 5, 12, 51, -32, 20, 0, }, /* 147 */
+ { 20, 5, 12, 26, -775, 20, 0, }, /* 148 */
+ { 20, 5, 12, 47, -32, 20, 0, }, /* 149 */
+ { 20, 5, 12, 55, -32, 20, 0, }, /* 150 */
+ { 20, 5, 12, 30, 1, 20, 0, }, /* 151 */
+ { 20, 5, 12, 30, -32, 20, 0, }, /* 152 */
+ { 20, 5, 12, 43, -32, 20, 0, }, /* 153 */
+ { 20, 5, 12, 96, -32, 20, 0, }, /* 154 */
+ { 20, 5, 12, 0, -64, 20, 0, }, /* 155 */
+ { 20, 5, 12, 0, -63, 20, 0, }, /* 156 */
+ { 20, 9, 12, 0, 8, 20, 0, }, /* 157 */
+ { 20, 5, 12, 34, -30, 20, 0, }, /* 158 */
+ { 20, 5, 12, 38, -25, 20, 0, }, /* 159 */
+ { 20, 9, 12, 0, 0, 20, 0, }, /* 160 */
+ { 20, 5, 12, 43, -15, 20, 0, }, /* 161 */
+ { 20, 5, 12, 47, -22, 20, 0, }, /* 162 */
+ { 20, 5, 12, 0, -8, 20, 0, }, /* 163 */
+ { 11, 9, 12, 0, 1, 11, 0, }, /* 164 */
+ { 11, 5, 12, 0, -1, 11, 0, }, /* 165 */
+ { 20, 5, 12, 51, -54, 20, 0, }, /* 166 */
+ { 20, 5, 12, 55, -48, 20, 0, }, /* 167 */
+ { 20, 5, 12, 0, 7, 20, 0, }, /* 168 */
+ { 20, 5, 12, 0, -116, 20, 0, }, /* 169 */
+ { 20, 9, 12, 38, -60, 20, 0, }, /* 170 */
+ { 20, 5, 12, 59, -64, 20, 0, }, /* 171 */
+ { 20, 25, 12, 0, 0, 20, 0, }, /* 172 */
+ { 20, 9, 12, 0, -7, 20, 0, }, /* 173 */
+ { 20, 9, 12, 0, -130, 20, 0, }, /* 174 */
+ { 13, 9, 12, 0, 80, 13, 0, }, /* 175 */
+ { 13, 9, 12, 0, 32, 13, 0, }, /* 176 */
+ { 13, 9, 12, 63, 32, 13, 0, }, /* 177 */
+ { 13, 9, 12, 67, 32, 13, 0, }, /* 178 */
+ { 13, 9, 12, 71, 32, 13, 0, }, /* 179 */
+ { 13, 9, 12, 75, 32, 13, 0, }, /* 180 */
+ { 13, 9, 12, 79, 32, 13, 0, }, /* 181 */
+ { 13, 9, 12, 84, 32, 13, 0, }, /* 182 */
+ { 13, 5, 12, 0, -32, 13, 0, }, /* 183 */
+ { 13, 5, 12, 63, -32, 13, 0, }, /* 184 */
+ { 13, 5, 12, 67, -32, 13, 0, }, /* 185 */
+ { 13, 5, 12, 71, -32, 13, 0, }, /* 186 */
+ { 13, 5, 12, 75, -32, 13, 0, }, /* 187 */
+ { 13, 5, 12, 79, -32, 13, 0, }, /* 188 */
+ { 13, 5, 12, 84, -32, 13, 0, }, /* 189 */
+ { 13, 5, 12, 0, -80, 13, 0, }, /* 190 */
+ { 13, 9, 12, 0, 1, 13, 0, }, /* 191 */
+ { 13, 5, 12, 0, -1, 13, 0, }, /* 192 */
+ { 13, 9, 12, 88, 1, 13, 0, }, /* 193 */
+ { 13, 5, 12, 88, -1, 13, 0, }, /* 194 */
+ { 13, 26, 12, 0, 0, 13, 0, }, /* 195 */
+ { 13, 12, 3, 0, 0, -34, 0, }, /* 196 */
+ { 13, 12, 3, 0, 0, -28, 0, }, /* 197 */
+ { 28, 12, 3, 0, 0, -31, 0, }, /* 198 */
+ { 13, 11, 3, 0, 0, 13, 0, }, /* 199 */
+ { 13, 9, 12, 0, 15, 13, 0, }, /* 200 */
+ { 13, 5, 12, 0, -15, 13, 0, }, /* 201 */
+ { 2, 9, 12, 0, 48, 2, 0, }, /* 202 */
+ { 2, 6, 12, 0, 0, 2, 0, }, /* 203 */
+ { 2, 21, 12, 0, 0, 2, 0, }, /* 204 */
+ { 2, 5, 12, 0, 0, 2, 0, }, /* 205 */
+ { 2, 5, 12, 0, -48, 2, 0, }, /* 206 */
+ { 10, 21, 12, 0, 0, -13, 0, }, /* 207 */
+ { 2, 17, 12, 0, 0, 2, 0, }, /* 208 */
+ { 2, 26, 12, 0, 0, 2, 0, }, /* 209 */
+ { 2, 23, 12, 0, 0, 2, 0, }, /* 210 */
+ { 26, 12, 3, 0, 0, 26, 0, }, /* 211 */
+ { 26, 17, 12, 0, 0, 26, 0, }, /* 212 */
+ { 26, 21, 12, 0, 0, 26, 0, }, /* 213 */
+ { 26, 7, 12, 0, 0, 26, 0, }, /* 214 */
+ { 1, 1, 4, 0, 0, 1, 0, }, /* 215 */
+ { 10, 1, 4, 0, 0, 10, 0, }, /* 216 */
+ { 1, 25, 12, 0, 0, 1, 0, }, /* 217 */
+ { 1, 21, 12, 0, 0, 1, 0, }, /* 218 */
+ { 1, 23, 12, 0, 0, 1, 0, }, /* 219 */
+ { 10, 21, 12, 0, 0, -96, 0, }, /* 220 */
+ { 1, 26, 12, 0, 0, 1, 0, }, /* 221 */
+ { 1, 12, 3, 0, 0, 1, 0, }, /* 222 */
+ { 1, 1, 2, 0, 0, -64, 0, }, /* 223 */
+ { 1, 7, 12, 0, 0, 1, 0, }, /* 224 */
+ { 10, 6, 12, 0, 0, -136, 0, }, /* 225 */
+ { 28, 12, 3, 0, 0, -7, 0, }, /* 226 */
+ { 1, 13, 12, 0, 0, -10, 0, }, /* 227 */
+ { 1, 21, 12, 0, 0, -4, 0, }, /* 228 */
+ { 1, 6, 12, 0, 0, 1, 0, }, /* 229 */
+ { 1, 13, 12, 0, 0, 1, 0, }, /* 230 */
+ { 50, 21, 12, 0, 0, 50, 0, }, /* 231 */
+ { 50, 1, 4, 0, 0, 50, 0, }, /* 232 */
+ { 50, 7, 12, 0, 0, 50, 0, }, /* 233 */
+ { 50, 12, 3, 0, 0, 50, 0, }, /* 234 */
+ { 56, 7, 12, 0, 0, 56, 0, }, /* 235 */
+ { 56, 12, 3, 0, 0, 56, 0, }, /* 236 */
+ { 64, 13, 12, 0, 0, 64, 0, }, /* 237 */
+ { 64, 7, 12, 0, 0, 64, 0, }, /* 238 */
+ { 64, 12, 3, 0, 0, 64, 0, }, /* 239 */
+ { 64, 6, 12, 0, 0, 64, 0, }, /* 240 */
+ { 64, 26, 12, 0, 0, 64, 0, }, /* 241 */
+ { 64, 21, 12, 0, 0, 64, 0, }, /* 242 */
+ { 64, 23, 12, 0, 0, 64, 0, }, /* 243 */
+ { 90, 7, 12, 0, 0, 90, 0, }, /* 244 */
+ { 90, 12, 3, 0, 0, 90, 0, }, /* 245 */
+ { 90, 6, 12, 0, 0, 90, 0, }, /* 246 */
+ { 90, 21, 12, 0, 0, 90, 0, }, /* 247 */
+ { 95, 7, 12, 0, 0, 95, 0, }, /* 248 */
+ { 95, 12, 3, 0, 0, 95, 0, }, /* 249 */
+ { 95, 21, 12, 0, 0, 95, 0, }, /* 250 */
+ { 15, 12, 3, 0, 0, 15, 0, }, /* 251 */
+ { 15, 10, 5, 0, 0, 15, 0, }, /* 252 */
+ { 15, 7, 12, 0, 0, 15, 0, }, /* 253 */
+ { 28, 12, 3, 0, 0, -183, 0, }, /* 254 */
+ { 28, 12, 3, 0, 0, -157, 0, }, /* 255 */
+ { 10, 21, 12, 0, 0, -211, 0, }, /* 256 */
+ { 10, 21, 12, 0, 0, -230, 0, }, /* 257 */
+ { 15, 13, 12, 0, 0, -111, 0, }, /* 258 */
+ { 15, 21, 12, 0, 0, 15, 0, }, /* 259 */
+ { 15, 6, 12, 0, 0, 15, 0, }, /* 260 */
+ { 3, 7, 12, 0, 0, 3, 0, }, /* 261 */
+ { 3, 12, 3, 0, 0, 3, 0, }, /* 262 */
+ { 3, 10, 5, 0, 0, 3, 0, }, /* 263 */
+ { 3, 10, 3, 0, 0, 3, 0, }, /* 264 */
+ { 3, 13, 12, 0, 0, -68, 0, }, /* 265 */
+ { 3, 23, 12, 0, 0, 3, 0, }, /* 266 */
+ { 3, 15, 12, 0, 0, 3, 0, }, /* 267 */
+ { 3, 26, 12, 0, 0, 3, 0, }, /* 268 */
+ { 3, 21, 12, 0, 0, 3, 0, }, /* 269 */
+ { 22, 12, 3, 0, 0, 22, 0, }, /* 270 */
+ { 22, 10, 5, 0, 0, 22, 0, }, /* 271 */
+ { 22, 7, 12, 0, 0, 22, 0, }, /* 272 */
+ { 22, 13, 12, 0, 0, -55, 0, }, /* 273 */
+ { 22, 21, 12, 0, 0, 22, 0, }, /* 274 */
+ { 21, 12, 3, 0, 0, 21, 0, }, /* 275 */
+ { 21, 10, 5, 0, 0, 21, 0, }, /* 276 */
+ { 21, 7, 12, 0, 0, 21, 0, }, /* 277 */
+ { 21, 13, 12, 0, 0, -52, 0, }, /* 278 */
+ { 21, 21, 12, 0, 0, 21, 0, }, /* 279 */
+ { 21, 23, 12, 0, 0, 21, 0, }, /* 280 */
+ { 44, 12, 3, 0, 0, 44, 0, }, /* 281 */
+ { 44, 10, 5, 0, 0, 44, 0, }, /* 282 */
+ { 44, 7, 12, 0, 0, 44, 0, }, /* 283 */
+ { 44, 10, 3, 0, 0, 44, 0, }, /* 284 */
+ { 44, 13, 12, 0, 0, 44, 0, }, /* 285 */
+ { 44, 26, 12, 0, 0, 44, 0, }, /* 286 */
+ { 44, 15, 12, 0, 0, 44, 0, }, /* 287 */
+ { 54, 12, 3, 0, 0, 54, 0, }, /* 288 */
+ { 54, 7, 12, 0, 0, 54, 0, }, /* 289 */
+ { 54, 10, 3, 0, 0, 54, 0, }, /* 290 */
+ { 54, 10, 5, 0, 0, 54, 0, }, /* 291 */
+ { 54, 13, 12, 0, 0, -49, 0, }, /* 292 */
+ { 54, 15, 12, 0, 0, -49, 0, }, /* 293 */
+ { 54, 26, 12, 0, 0, -49, 0, }, /* 294 */
+ { 54, 26, 12, 0, 0, 54, 0, }, /* 295 */
+ { 54, 23, 12, 0, 0, 54, 0, }, /* 296 */
+ { 55, 12, 3, 0, 0, 55, 0, }, /* 297 */
+ { 55, 10, 5, 0, 0, 55, 0, }, /* 298 */
+ { 55, 7, 12, 0, 0, 55, 0, }, /* 299 */
+ { 55, 13, 12, 0, 0, 55, 0, }, /* 300 */
+ { 55, 15, 12, 0, 0, 55, 0, }, /* 301 */
+ { 55, 26, 12, 0, 0, 55, 0, }, /* 302 */
+ { 29, 7, 12, 0, 0, 29, 0, }, /* 303 */
+ { 29, 12, 3, 0, 0, 29, 0, }, /* 304 */
+ { 29, 10, 5, 0, 0, 29, 0, }, /* 305 */
+ { 29, 21, 12, 0, 0, 29, 0, }, /* 306 */
+ { 29, 10, 3, 0, 0, 29, 0, }, /* 307 */
+ { 29, 13, 12, 0, 0, 29, 0, }, /* 308 */
+ { 37, 12, 3, 0, 0, 37, 0, }, /* 309 */
+ { 37, 10, 5, 0, 0, 37, 0, }, /* 310 */
+ { 37, 7, 12, 0, 0, 37, 0, }, /* 311 */
+ { 37, 10, 3, 0, 0, 37, 0, }, /* 312 */
+ { 37, 7, 4, 0, 0, 37, 0, }, /* 313 */
+ { 37, 26, 12, 0, 0, 37, 0, }, /* 314 */
+ { 37, 15, 12, 0, 0, 37, 0, }, /* 315 */
+ { 37, 13, 12, 0, 0, 37, 0, }, /* 316 */
+ { 48, 10, 5, 0, 0, 48, 0, }, /* 317 */
+ { 48, 7, 12, 0, 0, 48, 0, }, /* 318 */
+ { 48, 12, 3, 0, 0, 48, 0, }, /* 319 */
+ { 48, 10, 3, 0, 0, 48, 0, }, /* 320 */
+ { 48, 13, 12, 0, 0, 48, 0, }, /* 321 */
+ { 48, 21, 12, 0, 0, 48, 0, }, /* 322 */
+ { 57, 7, 12, 0, 0, 57, 0, }, /* 323 */
+ { 57, 12, 3, 0, 0, 57, 0, }, /* 324 */
+ { 57, 7, 5, 0, 0, 57, 0, }, /* 325 */
+ { 57, 6, 12, 0, 0, 57, 0, }, /* 326 */
+ { 57, 21, 12, 0, 0, 57, 0, }, /* 327 */
+ { 57, 13, 12, 0, 0, 57, 0, }, /* 328 */
+ { 33, 7, 12, 0, 0, 33, 0, }, /* 329 */
+ { 33, 12, 3, 0, 0, 33, 0, }, /* 330 */
+ { 33, 7, 5, 0, 0, 33, 0, }, /* 331 */
+ { 33, 6, 12, 0, 0, 33, 0, }, /* 332 */
+ { 33, 13, 12, 0, 0, 33, 0, }, /* 333 */
+ { 58, 7, 12, 0, 0, 58, 0, }, /* 334 */
+ { 58, 26, 12, 0, 0, 58, 0, }, /* 335 */
+ { 58, 21, 12, 0, 0, 58, 0, }, /* 336 */
+ { 58, 12, 3, 0, 0, 58, 0, }, /* 337 */
+ { 58, 13, 12, 0, 0, 58, 0, }, /* 338 */
+ { 58, 15, 12, 0, 0, 58, 0, }, /* 339 */
+ { 58, 22, 12, 0, 0, 58, 0, }, /* 340 */
+ { 58, 18, 12, 0, 0, 58, 0, }, /* 341 */
+ { 58, 10, 5, 0, 0, 58, 0, }, /* 342 */
+ { 39, 7, 12, 0, 0, 39, 0, }, /* 343 */
+ { 39, 10, 12, 0, 0, 39, 0, }, /* 344 */
+ { 39, 12, 3, 0, 0, 39, 0, }, /* 345 */
+ { 39, 10, 5, 0, 0, 39, 0, }, /* 346 */
+ { 39, 13, 12, 0, 0, -72, 0, }, /* 347 */
+ { 39, 21, 12, 0, 0, 39, 0, }, /* 348 */
+ { 39, 13, 12, 0, 0, 39, 0, }, /* 349 */
+ { 39, 26, 12, 0, 0, 39, 0, }, /* 350 */
+ { 17, 9, 12, 0, 7264, 17, 0, }, /* 351 */
+ { 17, 5, 12, 0, 3008, 17, 0, }, /* 352 */
+ { 10, 21, 12, 0, 0, -46, 0, }, /* 353 */
+ { 17, 6, 12, 0, 0, 17, 0, }, /* 354 */
+ { 24, 7, 6, 0, 0, 24, 0, }, /* 355 */
+ { 24, 7, 7, 0, 0, 24, 0, }, /* 356 */
+ { 24, 7, 8, 0, 0, 24, 0, }, /* 357 */
+ { 16, 7, 12, 0, 0, 16, 0, }, /* 358 */
+ { 16, 12, 3, 0, 0, 16, 0, }, /* 359 */
+ { 16, 21, 12, 0, 0, 16, 0, }, /* 360 */
+ { 16, 15, 12, 0, 0, 16, 0, }, /* 361 */
+ { 16, 26, 12, 0, 0, 16, 0, }, /* 362 */
+ { 9, 9, 12, 0, 38864, 9, 0, }, /* 363 */
+ { 9, 9, 12, 0, 8, 9, 0, }, /* 364 */
+ { 9, 5, 12, 0, -8, 9, 0, }, /* 365 */
+ { 8, 17, 12, 0, 0, 8, 0, }, /* 366 */
+ { 8, 7, 12, 0, 0, 8, 0, }, /* 367 */
+ { 8, 21, 12, 0, 0, 8, 0, }, /* 368 */
+ { 41, 29, 12, 0, 0, 41, 0, }, /* 369 */
+ { 41, 7, 12, 0, 0, 41, 0, }, /* 370 */
+ { 41, 22, 12, 0, 0, 41, 0, }, /* 371 */
+ { 41, 18, 12, 0, 0, 41, 0, }, /* 372 */
+ { 46, 7, 12, 0, 0, 46, 0, }, /* 373 */
+ { 46, 14, 12, 0, 0, 46, 0, }, /* 374 */
+ { 51, 7, 12, 0, 0, 51, 0, }, /* 375 */
+ { 51, 12, 3, 0, 0, 51, 0, }, /* 376 */
+ { 25, 7, 12, 0, 0, 25, 0, }, /* 377 */
+ { 25, 12, 3, 0, 0, 25, 0, }, /* 378 */
+ { 10, 21, 12, 0, 0, -106, 0, }, /* 379 */
+ { 7, 7, 12, 0, 0, 7, 0, }, /* 380 */
+ { 7, 12, 3, 0, 0, 7, 0, }, /* 381 */
+ { 52, 7, 12, 0, 0, 52, 0, }, /* 382 */
+ { 52, 12, 3, 0, 0, 52, 0, }, /* 383 */
+ { 32, 7, 12, 0, 0, 32, 0, }, /* 384 */
+ { 32, 12, 3, 0, 0, 32, 0, }, /* 385 */
+ { 32, 10, 5, 0, 0, 32, 0, }, /* 386 */
+ { 32, 21, 12, 0, 0, 32, 0, }, /* 387 */
+ { 32, 6, 12, 0, 0, 32, 0, }, /* 388 */
+ { 32, 23, 12, 0, 0, 32, 0, }, /* 389 */
+ { 32, 13, 12, 0, 0, 32, 0, }, /* 390 */
+ { 32, 15, 12, 0, 0, 32, 0, }, /* 391 */
+ { 38, 21, 12, 0, 0, 38, 0, }, /* 392 */
+ { 10, 21, 12, 0, 0, -61, 0, }, /* 393 */
+ { 38, 17, 12, 0, 0, 38, 0, }, /* 394 */
+ { 38, 12, 3, 0, 0, 38, 0, }, /* 395 */
+ { 38, 1, 2, 0, 0, 38, 0, }, /* 396 */
+ { 38, 13, 12, 0, 0, 38, 0, }, /* 397 */
+ { 38, 7, 12, 0, 0, 38, 0, }, /* 398 */
+ { 38, 6, 12, 0, 0, 38, 0, }, /* 399 */
+ { 35, 7, 12, 0, 0, 35, 0, }, /* 400 */
+ { 35, 12, 3, 0, 0, 35, 0, }, /* 401 */
+ { 35, 10, 5, 0, 0, 35, 0, }, /* 402 */
+ { 35, 26, 12, 0, 0, 35, 0, }, /* 403 */
+ { 35, 21, 12, 0, 0, 35, 0, }, /* 404 */
+ { 35, 13, 12, 0, 0, 35, 0, }, /* 405 */
+ { 53, 7, 12, 0, 0, 53, 0, }, /* 406 */
+ { 40, 7, 12, 0, 0, 40, 0, }, /* 407 */
+ { 40, 13, 12, 0, 0, 40, 0, }, /* 408 */
+ { 40, 15, 12, 0, 0, 40, 0, }, /* 409 */
+ { 40, 26, 12, 0, 0, 40, 0, }, /* 410 */
+ { 32, 26, 12, 0, 0, 32, 0, }, /* 411 */
+ { 6, 7, 12, 0, 0, 6, 0, }, /* 412 */
+ { 6, 12, 3, 0, 0, 6, 0, }, /* 413 */
+ { 6, 10, 5, 0, 0, 6, 0, }, /* 414 */
+ { 6, 21, 12, 0, 0, 6, 0, }, /* 415 */
+ { 91, 7, 12, 0, 0, 91, 0, }, /* 416 */
+ { 91, 10, 5, 0, 0, 91, 0, }, /* 417 */
+ { 91, 12, 3, 0, 0, 91, 0, }, /* 418 */
+ { 91, 10, 12, 0, 0, 91, 0, }, /* 419 */
+ { 91, 13, 12, 0, 0, 91, 0, }, /* 420 */
+ { 91, 21, 12, 0, 0, 91, 0, }, /* 421 */
+ { 91, 6, 12, 0, 0, 91, 0, }, /* 422 */
+ { 28, 11, 3, 0, 0, 28, 0, }, /* 423 */
+ { 62, 12, 3, 0, 0, 62, 0, }, /* 424 */
+ { 62, 10, 5, 0, 0, 62, 0, }, /* 425 */
+ { 62, 7, 12, 0, 0, 62, 0, }, /* 426 */
+ { 62, 13, 12, 0, 0, 62, 0, }, /* 427 */
+ { 62, 21, 12, 0, 0, 62, 0, }, /* 428 */
+ { 62, 26, 12, 0, 0, 62, 0, }, /* 429 */
+ { 76, 12, 3, 0, 0, 76, 0, }, /* 430 */
+ { 76, 10, 5, 0, 0, 76, 0, }, /* 431 */
+ { 76, 7, 12, 0, 0, 76, 0, }, /* 432 */
+ { 76, 13, 12, 0, 0, 76, 0, }, /* 433 */
+ { 93, 7, 12, 0, 0, 93, 0, }, /* 434 */
+ { 93, 12, 3, 0, 0, 93, 0, }, /* 435 */
+ { 93, 10, 5, 0, 0, 93, 0, }, /* 436 */
+ { 93, 21, 12, 0, 0, 93, 0, }, /* 437 */
+ { 70, 7, 12, 0, 0, 70, 0, }, /* 438 */
+ { 70, 10, 5, 0, 0, 70, 0, }, /* 439 */
+ { 70, 12, 3, 0, 0, 70, 0, }, /* 440 */
+ { 70, 21, 12, 0, 0, 70, 0, }, /* 441 */
+ { 70, 13, 12, 0, 0, 70, 0, }, /* 442 */
+ { 73, 13, 12, 0, 0, 73, 0, }, /* 443 */
+ { 73, 7, 12, 0, 0, 73, 0, }, /* 444 */
+ { 73, 6, 12, 0, 0, 73, 0, }, /* 445 */
+ { 73, 21, 12, 0, 0, 73, 0, }, /* 446 */
+ { 13, 5, 12, 63, -6222, 13, 0, }, /* 447 */
+ { 13, 5, 12, 67, -6221, 13, 0, }, /* 448 */
+ { 13, 5, 12, 71, -6212, 13, 0, }, /* 449 */
+ { 13, 5, 12, 75, -6210, 13, 0, }, /* 450 */
+ { 13, 5, 12, 79, -6210, 13, 0, }, /* 451 */
+ { 13, 5, 12, 79, -6211, 13, 0, }, /* 452 */
+ { 13, 5, 12, 84, -6204, 13, 0, }, /* 453 */
+ { 13, 5, 12, 88, -6180, 13, 0, }, /* 454 */
+ { 13, 5, 12, 108, 35267, 13, 0, }, /* 455 */
+ { 17, 9, 12, 0, -3008, 17, 0, }, /* 456 */
+ { 76, 21, 12, 0, 0, 76, 0, }, /* 457 */
+ { 28, 12, 3, 0, 0, -101, 0, }, /* 458 */
+ { 28, 12, 3, 0, 0, 15, 0, }, /* 459 */
+ { 10, 21, 12, 0, 0, -37, 0, }, /* 460 */
+ { 28, 12, 3, 0, 0, -16, 0, }, /* 461 */
+ { 28, 12, 3, 0, 0, -40, 0, }, /* 462 */
+ { 28, 12, 3, 0, 0, -129, 0, }, /* 463 */
+ { 10, 10, 5, 0, 0, -16, 0, }, /* 464 */
+ { 10, 7, 12, 0, 0, 15, 0, }, /* 465 */
+ { 10, 7, 12, 0, 0, -16, 0, }, /* 466 */
+ { 10, 10, 5, 0, 0, -37, 0, }, /* 467 */
+ { 28, 12, 3, 0, 0, -80, 0, }, /* 468 */
+ { 10, 10, 5, 0, 0, 3, 0, }, /* 469 */
+ { 28, 12, 3, 0, 0, -37, 0, }, /* 470 */
+ { 13, 5, 12, 0, 0, 13, 0, }, /* 471 */
+ { 13, 6, 12, 0, 0, 13, 0, }, /* 472 */
+ { 34, 5, 12, 0, 35332, 34, 0, }, /* 473 */
+ { 34, 5, 12, 0, 3814, 34, 0, }, /* 474 */
+ { 34, 9, 12, 92, 1, 34, 0, }, /* 475 */
+ { 34, 5, 12, 92, -1, 34, 0, }, /* 476 */
+ { 34, 5, 12, 92, -58, 34, 0, }, /* 477 */
+ { 34, 9, 12, 0, -7615, 34, 0, }, /* 478 */
+ { 20, 5, 12, 0, 8, 20, 0, }, /* 479 */
+ { 20, 9, 12, 0, -8, 20, 0, }, /* 480 */
+ { 20, 5, 12, 0, 74, 20, 0, }, /* 481 */
+ { 20, 5, 12, 0, 86, 20, 0, }, /* 482 */
+ { 20, 5, 12, 0, 100, 20, 0, }, /* 483 */
+ { 20, 5, 12, 0, 128, 20, 0, }, /* 484 */
+ { 20, 5, 12, 0, 112, 20, 0, }, /* 485 */
+ { 20, 5, 12, 0, 126, 20, 0, }, /* 486 */
+ { 20, 8, 12, 0, -8, 20, 0, }, /* 487 */
+ { 20, 5, 12, 0, 9, 20, 0, }, /* 488 */
+ { 20, 9, 12, 0, -74, 20, 0, }, /* 489 */
+ { 20, 8, 12, 0, -9, 20, 0, }, /* 490 */
+ { 20, 5, 12, 21, -7173, 20, 0, }, /* 491 */
+ { 20, 9, 12, 0, -86, 20, 0, }, /* 492 */
+ { 20, 9, 12, 0, -100, 20, 0, }, /* 493 */
+ { 20, 9, 12, 0, -112, 20, 0, }, /* 494 */
+ { 20, 9, 12, 0, -128, 20, 0, }, /* 495 */
+ { 20, 9, 12, 0, -126, 20, 0, }, /* 496 */
+ { 28, 1, 3, 0, 0, 28, 0, }, /* 497 */
+ { 28, 1, 13, 0, 0, 28, 0, }, /* 498 */
+ { 10, 27, 2, 0, 0, 10, 0, }, /* 499 */
+ { 10, 28, 2, 0, 0, 10, 0, }, /* 500 */
+ { 10, 21, 14, 0, 0, 10, 0, }, /* 501 */
+ { 0, 2, 2, 0, 0, 0, 0, }, /* 502 */
+ { 28, 12, 3, 0, 0, -84, 0, }, /* 503 */
+ { 10, 9, 12, 0, 0, 10, 0, }, /* 504 */
+ { 10, 5, 12, 0, 0, 10, 0, }, /* 505 */
+ { 20, 9, 12, 96, -7517, 20, 0, }, /* 506 */
+ { 34, 9, 12, 100, -8383, 34, 0, }, /* 507 */
+ { 34, 9, 12, 104, -8262, 34, 0, }, /* 508 */
+ { 34, 9, 12, 0, 28, 34, 0, }, /* 509 */
+ { 10, 7, 12, 0, 0, 10, 0, }, /* 510 */
+ { 10, 5, 14, 0, 0, 10, 0, }, /* 511 */
+ { 34, 5, 12, 0, -28, 34, 0, }, /* 512 */
+ { 34, 14, 12, 0, 16, 34, 0, }, /* 513 */
+ { 34, 14, 12, 0, -16, 34, 0, }, /* 514 */
+ { 34, 14, 12, 0, 0, 34, 0, }, /* 515 */
+ { 10, 25, 14, 0, 0, 10, 0, }, /* 516 */
+ { 10, 26, 12, 0, 26, 10, 0, }, /* 517 */
+ { 10, 26, 14, 0, 26, 10, 0, }, /* 518 */
+ { 10, 26, 12, 0, -26, 10, 0, }, /* 519 */
+ { 5, 26, 12, 0, 0, 5, 0, }, /* 520 */
+ { 18, 9, 12, 0, 48, 18, 0, }, /* 521 */
+ { 18, 5, 12, 0, -48, 18, 0, }, /* 522 */
+ { 34, 9, 12, 0, -10743, 34, 0, }, /* 523 */
+ { 34, 9, 12, 0, -3814, 34, 0, }, /* 524 */
+ { 34, 9, 12, 0, -10727, 34, 0, }, /* 525 */
+ { 34, 5, 12, 0, -10795, 34, 0, }, /* 526 */
+ { 34, 5, 12, 0, -10792, 34, 0, }, /* 527 */
+ { 34, 9, 12, 0, -10780, 34, 0, }, /* 528 */
+ { 34, 9, 12, 0, -10749, 34, 0, }, /* 529 */
+ { 34, 9, 12, 0, -10783, 34, 0, }, /* 530 */
+ { 34, 9, 12, 0, -10782, 34, 0, }, /* 531 */
+ { 34, 9, 12, 0, -10815, 34, 0, }, /* 532 */
+ { 11, 5, 12, 0, 0, 11, 0, }, /* 533 */
+ { 11, 26, 12, 0, 0, 11, 0, }, /* 534 */
+ { 11, 12, 3, 0, 0, 11, 0, }, /* 535 */
+ { 11, 21, 12, 0, 0, 11, 0, }, /* 536 */
+ { 11, 15, 12, 0, 0, 11, 0, }, /* 537 */
+ { 17, 5, 12, 0, -7264, 17, 0, }, /* 538 */
+ { 59, 7, 12, 0, 0, 59, 0, }, /* 539 */
+ { 59, 6, 12, 0, 0, 59, 0, }, /* 540 */
+ { 59, 21, 12, 0, 0, 59, 0, }, /* 541 */
+ { 59, 12, 3, 0, 0, 59, 0, }, /* 542 */
+ { 13, 12, 3, 0, 0, 13, 0, }, /* 543 */
+ { 10, 21, 12, 0, 0, -28, 0, }, /* 544 */
+ { 23, 26, 12, 0, 0, 23, 0, }, /* 545 */
+ { 10, 21, 12, 0, 0, -122, 0, }, /* 546 */
+ { 10, 21, 12, 0, 0, -116, 0, }, /* 547 */
+ { 23, 6, 12, 0, 0, 23, 0, }, /* 548 */
+ { 10, 7, 12, 0, 0, 23, 0, }, /* 549 */
+ { 23, 14, 12, 0, 0, 23, 0, }, /* 550 */
+ { 10, 22, 12, 0, 0, -122, 0, }, /* 551 */
+ { 10, 18, 12, 0, 0, -122, 0, }, /* 552 */
+ { 10, 26, 12, 0, 0, -116, 0, }, /* 553 */
+ { 10, 17, 12, 0, 0, -116, 0, }, /* 554 */
+ { 10, 22, 12, 0, 0, -116, 0, }, /* 555 */
+ { 10, 18, 12, 0, 0, -116, 0, }, /* 556 */
+ { 28, 12, 3, 0, 0, -19, 0, }, /* 557 */
+ { 24, 10, 3, 0, 0, 24, 0, }, /* 558 */
+ { 10, 17, 14, 0, 0, -116, 0, }, /* 559 */
+ { 10, 6, 12, 0, 0, -58, 0, }, /* 560 */
+ { 10, 7, 12, 0, 0, -88, 0, }, /* 561 */
+ { 10, 21, 14, 0, 0, -88, 0, }, /* 562 */
+ { 10, 26, 12, 0, 0, 23, 0, }, /* 563 */
+ { 27, 7, 12, 0, 0, 27, 0, }, /* 564 */
+ { 28, 12, 3, 0, 0, -58, 0, }, /* 565 */
+ { 10, 24, 12, 0, 0, -58, 0, }, /* 566 */
+ { 27, 6, 12, 0, 0, 27, 0, }, /* 567 */
+ { 10, 17, 12, 0, 0, -58, 0, }, /* 568 */
+ { 30, 7, 12, 0, 0, 30, 0, }, /* 569 */
+ { 30, 6, 12, 0, 0, 30, 0, }, /* 570 */
+ { 4, 7, 12, 0, 0, 4, 0, }, /* 571 */
+ { 24, 7, 12, 0, 0, 24, 0, }, /* 572 */
+ { 10, 15, 12, 0, 0, 23, 0, }, /* 573 */
+ { 24, 26, 12, 0, 0, 24, 0, }, /* 574 */
+ { 10, 26, 14, 0, 0, 23, 0, }, /* 575 */
+ { 30, 26, 12, 0, 0, 30, 0, }, /* 576 */
+ { 23, 7, 12, 0, 0, 23, 0, }, /* 577 */
+ { 61, 7, 12, 0, 0, 61, 0, }, /* 578 */
+ { 61, 6, 12, 0, 0, 61, 0, }, /* 579 */
+ { 61, 26, 12, 0, 0, 61, 0, }, /* 580 */
+ { 86, 7, 12, 0, 0, 86, 0, }, /* 581 */
+ { 86, 6, 12, 0, 0, 86, 0, }, /* 582 */
+ { 86, 21, 12, 0, 0, 86, 0, }, /* 583 */
+ { 77, 7, 12, 0, 0, 77, 0, }, /* 584 */
+ { 77, 6, 12, 0, 0, 77, 0, }, /* 585 */
+ { 77, 21, 12, 0, 0, 77, 0, }, /* 586 */
+ { 77, 13, 12, 0, 0, 77, 0, }, /* 587 */
+ { 13, 9, 12, 108, 1, 13, 0, }, /* 588 */
+ { 13, 5, 12, 108, -35267, 13, 0, }, /* 589 */
+ { 13, 7, 12, 0, 0, 13, 0, }, /* 590 */
+ { 13, 21, 12, 0, 0, 13, 0, }, /* 591 */
+ { 79, 7, 12, 0, 0, 79, 0, }, /* 592 */
+ { 79, 14, 12, 0, 0, 79, 0, }, /* 593 */
+ { 79, 12, 3, 0, 0, 79, 0, }, /* 594 */
+ { 79, 21, 12, 0, 0, 79, 0, }, /* 595 */
+ { 34, 9, 12, 0, -35332, 34, 0, }, /* 596 */
+ { 34, 9, 12, 0, -42280, 34, 0, }, /* 597 */
+ { 34, 9, 12, 0, -42308, 34, 0, }, /* 598 */
+ { 34, 9, 12, 0, -42319, 34, 0, }, /* 599 */
+ { 34, 9, 12, 0, -42315, 34, 0, }, /* 600 */
+ { 34, 9, 12, 0, -42305, 34, 0, }, /* 601 */
+ { 34, 9, 12, 0, -42258, 34, 0, }, /* 602 */
+ { 34, 9, 12, 0, -42282, 34, 0, }, /* 603 */
+ { 34, 9, 12, 0, -42261, 34, 0, }, /* 604 */
+ { 34, 9, 12, 0, 928, 34, 0, }, /* 605 */
+ { 49, 7, 12, 0, 0, 49, 0, }, /* 606 */
+ { 49, 12, 3, 0, 0, 49, 0, }, /* 607 */
+ { 49, 10, 5, 0, 0, 49, 0, }, /* 608 */
+ { 49, 26, 12, 0, 0, 49, 0, }, /* 609 */
+ { 10, 15, 12, 0, 0, -197, 0, }, /* 610 */
+ { 10, 15, 12, 0, 0, -170, 0, }, /* 611 */
+ { 10, 26, 12, 0, 0, -145, 0, }, /* 612 */
+ { 10, 23, 12, 0, 0, -145, 0, }, /* 613 */
+ { 65, 7, 12, 0, 0, 65, 0, }, /* 614 */
+ { 65, 21, 12, 0, 0, 65, 0, }, /* 615 */
+ { 75, 10, 5, 0, 0, 75, 0, }, /* 616 */
+ { 75, 7, 12, 0, 0, 75, 0, }, /* 617 */
+ { 75, 12, 3, 0, 0, 75, 0, }, /* 618 */
+ { 75, 21, 12, 0, 0, 75, 0, }, /* 619 */
+ { 75, 13, 12, 0, 0, 75, 0, }, /* 620 */
+ { 15, 12, 3, 0, 0, -16, 0, }, /* 621 */
+ { 15, 7, 12, 0, 0, -43, 0, }, /* 622 */
+ { 69, 13, 12, 0, 0, 69, 0, }, /* 623 */
+ { 69, 7, 12, 0, 0, 69, 0, }, /* 624 */
+ { 69, 12, 3, 0, 0, 69, 0, }, /* 625 */
+ { 10, 21, 12, 0, 0, -92, 0, }, /* 626 */
+ { 69, 21, 12, 0, 0, 69, 0, }, /* 627 */
+ { 74, 7, 12, 0, 0, 74, 0, }, /* 628 */
+ { 74, 12, 3, 0, 0, 74, 0, }, /* 629 */
+ { 74, 10, 5, 0, 0, 74, 0, }, /* 630 */
+ { 74, 21, 12, 0, 0, 74, 0, }, /* 631 */
+ { 84, 12, 3, 0, 0, 84, 0, }, /* 632 */
+ { 84, 10, 5, 0, 0, 84, 0, }, /* 633 */
+ { 84, 7, 12, 0, 0, 84, 0, }, /* 634 */
+ { 84, 21, 12, 0, 0, 84, 0, }, /* 635 */
+ { 10, 6, 12, 0, 0, -22, 0, }, /* 636 */
+ { 84, 13, 12, 0, 0, 84, 0, }, /* 637 */
+ { 39, 6, 12, 0, 0, 39, 0, }, /* 638 */
+ { 68, 7, 12, 0, 0, 68, 0, }, /* 639 */
+ { 68, 12, 3, 0, 0, 68, 0, }, /* 640 */
+ { 68, 10, 5, 0, 0, 68, 0, }, /* 641 */
+ { 68, 13, 12, 0, 0, 68, 0, }, /* 642 */
+ { 68, 21, 12, 0, 0, 68, 0, }, /* 643 */
+ { 92, 7, 12, 0, 0, 92, 0, }, /* 644 */
+ { 92, 12, 3, 0, 0, 92, 0, }, /* 645 */
+ { 92, 6, 12, 0, 0, 92, 0, }, /* 646 */
+ { 92, 21, 12, 0, 0, 92, 0, }, /* 647 */
+ { 87, 7, 12, 0, 0, 87, 0, }, /* 648 */
+ { 87, 10, 5, 0, 0, 87, 0, }, /* 649 */
+ { 87, 12, 3, 0, 0, 87, 0, }, /* 650 */
+ { 87, 21, 12, 0, 0, 87, 0, }, /* 651 */
+ { 87, 6, 12, 0, 0, 87, 0, }, /* 652 */
+ { 34, 5, 12, 0, -928, 34, 0, }, /* 653 */
+ { 9, 5, 12, 0, -38864, 9, 0, }, /* 654 */
+ { 87, 13, 12, 0, 0, 87, 0, }, /* 655 */
+ { 24, 7, 9, 0, 0, 24, 0, }, /* 656 */
+ { 24, 7, 10, 0, 0, 24, 0, }, /* 657 */
+ { 0, 4, 2, 0, 0, 0, 0, }, /* 658 */
+ { 0, 3, 12, 0, 0, 0, 0, }, /* 659 */
+ { 26, 25, 12, 0, 0, 26, 0, }, /* 660 */
+ { 1, 24, 12, 0, 0, 1, 0, }, /* 661 */
+ { 1, 7, 12, 0, 0, -10, 0, }, /* 662 */
+ { 1, 26, 12, 0, 0, -10, 0, }, /* 663 */
+ { 10, 6, 3, 0, 0, -58, 0, }, /* 664 */
+ { 36, 7, 12, 0, 0, 36, 0, }, /* 665 */
+ { 10, 21, 12, 0, 0, -25, 0, }, /* 666 */
+ { 10, 15, 12, 0, 0, -76, 0, }, /* 667 */
+ { 10, 26, 12, 0, 0, -25, 0, }, /* 668 */
+ { 20, 14, 12, 0, 0, 20, 0, }, /* 669 */
+ { 20, 15, 12, 0, 0, 20, 0, }, /* 670 */
+ { 20, 26, 12, 0, 0, 20, 0, }, /* 671 */
+ { 71, 7, 12, 0, 0, 71, 0, }, /* 672 */
+ { 67, 7, 12, 0, 0, 67, 0, }, /* 673 */
+ { 28, 12, 3, 0, 0, -1, 0, }, /* 674 */
+ { 10, 15, 12, 0, 0, -1, 0, }, /* 675 */
+ { 42, 7, 12, 0, 0, 42, 0, }, /* 676 */
+ { 42, 15, 12, 0, 0, 42, 0, }, /* 677 */
+ { 19, 7, 12, 0, 0, 19, 0, }, /* 678 */
+ { 19, 14, 12, 0, 0, 19, 0, }, /* 679 */
+ { 118, 7, 12, 0, 0, 118, 0, }, /* 680 */
+ { 118, 12, 3, 0, 0, 118, 0, }, /* 681 */
+ { 60, 7, 12, 0, 0, 60, 0, }, /* 682 */
+ { 60, 21, 12, 0, 0, 60, 0, }, /* 683 */
+ { 43, 7, 12, 0, 0, 43, 0, }, /* 684 */
+ { 43, 21, 12, 0, 0, 43, 0, }, /* 685 */
+ { 43, 14, 12, 0, 0, 43, 0, }, /* 686 */
+ { 14, 9, 12, 0, 40, 14, 0, }, /* 687 */
+ { 14, 5, 12, 0, -40, 14, 0, }, /* 688 */
+ { 47, 7, 12, 0, 0, 47, 0, }, /* 689 */
+ { 45, 7, 12, 0, 0, 45, 0, }, /* 690 */
+ { 45, 13, 12, 0, 0, 45, 0, }, /* 691 */
+ { 136, 9, 12, 0, 40, 136, 0, }, /* 692 */
+ { 136, 5, 12, 0, -40, 136, 0, }, /* 693 */
+ { 106, 7, 12, 0, 0, 106, 0, }, /* 694 */
+ { 104, 7, 12, 0, 0, 104, 0, }, /* 695 */
+ { 104, 21, 12, 0, 0, 104, 0, }, /* 696 */
+ { 110, 7, 12, 0, 0, 110, 0, }, /* 697 */
+ { 12, 7, 12, 0, 0, 12, 0, }, /* 698 */
+ { 81, 7, 12, 0, 0, 81, 0, }, /* 699 */
+ { 81, 21, 12, 0, 0, 81, 0, }, /* 700 */
+ { 81, 15, 12, 0, 0, 81, 0, }, /* 701 */
+ { 120, 7, 12, 0, 0, 120, 0, }, /* 702 */
+ { 120, 26, 12, 0, 0, 120, 0, }, /* 703 */
+ { 120, 15, 12, 0, 0, 120, 0, }, /* 704 */
+ { 116, 7, 12, 0, 0, 116, 0, }, /* 705 */
+ { 116, 15, 12, 0, 0, 116, 0, }, /* 706 */
+ { 128, 7, 12, 0, 0, 128, 0, }, /* 707 */
+ { 128, 15, 12, 0, 0, 128, 0, }, /* 708 */
+ { 66, 7, 12, 0, 0, 66, 0, }, /* 709 */
+ { 66, 15, 12, 0, 0, 66, 0, }, /* 710 */
+ { 66, 21, 12, 0, 0, 66, 0, }, /* 711 */
+ { 72, 7, 12, 0, 0, 72, 0, }, /* 712 */
+ { 72, 21, 12, 0, 0, 72, 0, }, /* 713 */
+ { 98, 7, 12, 0, 0, 98, 0, }, /* 714 */
+ { 97, 7, 12, 0, 0, 97, 0, }, /* 715 */
+ { 97, 15, 12, 0, 0, 97, 0, }, /* 716 */
+ { 31, 7, 12, 0, 0, 31, 0, }, /* 717 */
+ { 31, 12, 3, 0, 0, 31, 0, }, /* 718 */
+ { 31, 15, 12, 0, 0, 31, 0, }, /* 719 */
+ { 31, 21, 12, 0, 0, 31, 0, }, /* 720 */
+ { 88, 7, 12, 0, 0, 88, 0, }, /* 721 */
+ { 88, 15, 12, 0, 0, 88, 0, }, /* 722 */
+ { 88, 21, 12, 0, 0, 88, 0, }, /* 723 */
+ { 117, 7, 12, 0, 0, 117, 0, }, /* 724 */
+ { 117, 15, 12, 0, 0, 117, 0, }, /* 725 */
+ { 112, 7, 12, 0, 0, 112, 0, }, /* 726 */
+ { 112, 26, 12, 0, 0, 112, 0, }, /* 727 */
+ { 112, 12, 3, 0, 0, 112, 0, }, /* 728 */
+ { 112, 15, 12, 0, 0, 112, 0, }, /* 729 */
+ { 112, 21, 12, 0, 0, 112, 0, }, /* 730 */
+ { 78, 7, 12, 0, 0, 78, 0, }, /* 731 */
+ { 78, 21, 12, 0, 0, 78, 0, }, /* 732 */
+ { 83, 7, 12, 0, 0, 83, 0, }, /* 733 */
+ { 83, 15, 12, 0, 0, 83, 0, }, /* 734 */
+ { 82, 7, 12, 0, 0, 82, 0, }, /* 735 */
+ { 82, 15, 12, 0, 0, 82, 0, }, /* 736 */
+ { 121, 7, 12, 0, 0, 121, 0, }, /* 737 */
+ { 121, 21, 12, 0, 0, 121, 0, }, /* 738 */
+ { 121, 15, 12, 0, 0, 121, 0, }, /* 739 */
+ { 89, 7, 12, 0, 0, 89, 0, }, /* 740 */
+ { 130, 9, 12, 0, 64, 130, 0, }, /* 741 */
+ { 130, 5, 12, 0, -64, 130, 0, }, /* 742 */
+ { 130, 15, 12, 0, 0, 130, 0, }, /* 743 */
+ { 144, 7, 12, 0, 0, 144, 0, }, /* 744 */
+ { 144, 12, 3, 0, 0, 144, 0, }, /* 745 */
+ { 144, 13, 12, 0, 0, 144, 0, }, /* 746 */
+ { 1, 15, 12, 0, 0, 1, 0, }, /* 747 */
+ { 147, 7, 12, 0, 0, 147, 0, }, /* 748 */
+ { 147, 15, 12, 0, 0, 147, 0, }, /* 749 */
+ { 148, 7, 12, 0, 0, 148, 0, }, /* 750 */
+ { 148, 12, 3, 0, 0, 148, 0, }, /* 751 */
+ { 148, 15, 12, 0, 0, 148, 0, }, /* 752 */
+ { 148, 21, 12, 0, 0, 148, 0, }, /* 753 */
+ { 94, 10, 5, 0, 0, 94, 0, }, /* 754 */
+ { 94, 12, 3, 0, 0, 94, 0, }, /* 755 */
+ { 94, 7, 12, 0, 0, 94, 0, }, /* 756 */
+ { 94, 21, 12, 0, 0, 94, 0, }, /* 757 */
+ { 94, 15, 12, 0, 0, 94, 0, }, /* 758 */
+ { 94, 13, 12, 0, 0, 94, 0, }, /* 759 */
+ { 85, 12, 3, 0, 0, 85, 0, }, /* 760 */
+ { 85, 10, 5, 0, 0, 85, 0, }, /* 761 */
+ { 85, 7, 12, 0, 0, 85, 0, }, /* 762 */
+ { 85, 21, 12, 0, 0, 85, 0, }, /* 763 */
+ { 85, 1, 4, 0, 0, 85, 0, }, /* 764 */
+ { 101, 7, 12, 0, 0, 101, 0, }, /* 765 */
+ { 101, 13, 12, 0, 0, 101, 0, }, /* 766 */
+ { 96, 12, 3, 0, 0, 96, 0, }, /* 767 */
+ { 96, 7, 12, 0, 0, 96, 0, }, /* 768 */
+ { 96, 10, 5, 0, 0, 96, 0, }, /* 769 */
+ { 96, 13, 12, 0, 0, 96, 0, }, /* 770 */
+ { 96, 21, 12, 0, 0, 96, 0, }, /* 771 */
+ { 111, 7, 12, 0, 0, 111, 0, }, /* 772 */
+ { 111, 12, 3, 0, 0, 111, 0, }, /* 773 */
+ { 111, 21, 12, 0, 0, 111, 0, }, /* 774 */
+ { 100, 12, 3, 0, 0, 100, 0, }, /* 775 */
+ { 100, 10, 5, 0, 0, 100, 0, }, /* 776 */
+ { 100, 7, 12, 0, 0, 100, 0, }, /* 777 */
+ { 100, 7, 4, 0, 0, 100, 0, }, /* 778 */
+ { 100, 21, 12, 0, 0, 100, 0, }, /* 779 */
+ { 100, 13, 12, 0, 0, 100, 0, }, /* 780 */
+ { 48, 15, 12, 0, 0, 48, 0, }, /* 781 */
+ { 108, 7, 12, 0, 0, 108, 0, }, /* 782 */
+ { 108, 10, 5, 0, 0, 108, 0, }, /* 783 */
+ { 108, 12, 3, 0, 0, 108, 0, }, /* 784 */
+ { 108, 21, 12, 0, 0, 108, 0, }, /* 785 */
+ { 129, 7, 12, 0, 0, 129, 0, }, /* 786 */
+ { 129, 21, 12, 0, 0, 129, 0, }, /* 787 */
+ { 109, 7, 12, 0, 0, 109, 0, }, /* 788 */
+ { 109, 12, 3, 0, 0, 109, 0, }, /* 789 */
+ { 109, 10, 5, 0, 0, 109, 0, }, /* 790 */
+ { 109, 13, 12, 0, 0, 109, 0, }, /* 791 */
+ { 107, 12, 3, 0, 0, 107, 0, }, /* 792 */
+ { 107, 12, 3, 0, 0, -49, 0, }, /* 793 */
+ { 107, 10, 5, 0, 0, 107, 0, }, /* 794 */
+ { 107, 10, 5, 0, 0, -49, 0, }, /* 795 */
+ { 107, 7, 12, 0, 0, 107, 0, }, /* 796 */
+ { 28, 12, 3, 0, 0, -49, 0, }, /* 797 */
+ { 107, 10, 3, 0, 0, 107, 0, }, /* 798 */
+ { 135, 7, 12, 0, 0, 135, 0, }, /* 799 */
+ { 135, 10, 5, 0, 0, 135, 0, }, /* 800 */
+ { 135, 12, 3, 0, 0, 135, 0, }, /* 801 */
+ { 135, 21, 12, 0, 0, 135, 0, }, /* 802 */
+ { 135, 13, 12, 0, 0, 135, 0, }, /* 803 */
+ { 124, 7, 12, 0, 0, 124, 0, }, /* 804 */
+ { 124, 10, 3, 0, 0, 124, 0, }, /* 805 */
+ { 124, 10, 5, 0, 0, 124, 0, }, /* 806 */
+ { 124, 12, 3, 0, 0, 124, 0, }, /* 807 */
+ { 124, 21, 12, 0, 0, 124, 0, }, /* 808 */
+ { 124, 13, 12, 0, 0, 124, 0, }, /* 809 */
+ { 123, 7, 12, 0, 0, 123, 0, }, /* 810 */
+ { 123, 10, 3, 0, 0, 123, 0, }, /* 811 */
+ { 123, 10, 5, 0, 0, 123, 0, }, /* 812 */
+ { 123, 12, 3, 0, 0, 123, 0, }, /* 813 */
+ { 123, 21, 12, 0, 0, 123, 0, }, /* 814 */
+ { 114, 7, 12, 0, 0, 114, 0, }, /* 815 */
+ { 114, 10, 5, 0, 0, 114, 0, }, /* 816 */
+ { 114, 12, 3, 0, 0, 114, 0, }, /* 817 */
+ { 114, 21, 12, 0, 0, 114, 0, }, /* 818 */
+ { 114, 13, 12, 0, 0, 114, 0, }, /* 819 */
+ { 102, 7, 12, 0, 0, 102, 0, }, /* 820 */
+ { 102, 12, 3, 0, 0, 102, 0, }, /* 821 */
+ { 102, 10, 5, 0, 0, 102, 0, }, /* 822 */
+ { 102, 13, 12, 0, 0, 102, 0, }, /* 823 */
+ { 126, 7, 12, 0, 0, 126, 0, }, /* 824 */
+ { 126, 12, 3, 0, 0, 126, 0, }, /* 825 */
+ { 126, 10, 5, 0, 0, 126, 0, }, /* 826 */
+ { 126, 13, 12, 0, 0, 126, 0, }, /* 827 */
+ { 126, 15, 12, 0, 0, 126, 0, }, /* 828 */
+ { 126, 21, 12, 0, 0, 126, 0, }, /* 829 */
+ { 126, 26, 12, 0, 0, 126, 0, }, /* 830 */
+ { 142, 7, 12, 0, 0, 142, 0, }, /* 831 */
+ { 142, 10, 5, 0, 0, 142, 0, }, /* 832 */
+ { 142, 12, 3, 0, 0, 142, 0, }, /* 833 */
+ { 142, 21, 12, 0, 0, 142, 0, }, /* 834 */
+ { 125, 9, 12, 0, 32, 125, 0, }, /* 835 */
+ { 125, 5, 12, 0, -32, 125, 0, }, /* 836 */
+ { 125, 13, 12, 0, 0, 125, 0, }, /* 837 */
+ { 125, 15, 12, 0, 0, 125, 0, }, /* 838 */
+ { 125, 7, 12, 0, 0, 125, 0, }, /* 839 */
+ { 141, 7, 12, 0, 0, 141, 0, }, /* 840 */
+ { 141, 12, 3, 0, 0, 141, 0, }, /* 841 */
+ { 141, 10, 5, 0, 0, 141, 0, }, /* 842 */
+ { 141, 7, 4, 0, 0, 141, 0, }, /* 843 */
+ { 141, 21, 12, 0, 0, 141, 0, }, /* 844 */
+ { 140, 7, 12, 0, 0, 140, 0, }, /* 845 */
+ { 140, 12, 3, 0, 0, 140, 0, }, /* 846 */
+ { 140, 10, 5, 0, 0, 140, 0, }, /* 847 */
+ { 140, 7, 4, 0, 0, 140, 0, }, /* 848 */
+ { 140, 21, 12, 0, 0, 140, 0, }, /* 849 */
+ { 122, 7, 12, 0, 0, 122, 0, }, /* 850 */
+ { 133, 7, 12, 0, 0, 133, 0, }, /* 851 */
+ { 133, 10, 5, 0, 0, 133, 0, }, /* 852 */
+ { 133, 12, 3, 0, 0, 133, 0, }, /* 853 */
+ { 133, 21, 12, 0, 0, 133, 0, }, /* 854 */
+ { 133, 13, 12, 0, 0, 133, 0, }, /* 855 */
+ { 133, 15, 12, 0, 0, 133, 0, }, /* 856 */
+ { 134, 21, 12, 0, 0, 134, 0, }, /* 857 */
+ { 134, 7, 12, 0, 0, 134, 0, }, /* 858 */
+ { 134, 12, 3, 0, 0, 134, 0, }, /* 859 */
+ { 134, 10, 5, 0, 0, 134, 0, }, /* 860 */
+ { 138, 7, 12, 0, 0, 138, 0, }, /* 861 */
+ { 138, 12, 3, 0, 0, 138, 0, }, /* 862 */
+ { 138, 7, 4, 0, 0, 138, 0, }, /* 863 */
+ { 138, 13, 12, 0, 0, 138, 0, }, /* 864 */
+ { 143, 7, 12, 0, 0, 143, 0, }, /* 865 */
+ { 143, 10, 5, 0, 0, 143, 0, }, /* 866 */
+ { 143, 12, 3, 0, 0, 143, 0, }, /* 867 */
+ { 143, 13, 12, 0, 0, 143, 0, }, /* 868 */
+ { 145, 7, 12, 0, 0, 145, 0, }, /* 869 */
+ { 145, 12, 3, 0, 0, 145, 0, }, /* 870 */
+ { 145, 10, 5, 0, 0, 145, 0, }, /* 871 */
+ { 145, 21, 12, 0, 0, 145, 0, }, /* 872 */
+ { 63, 7, 12, 0, 0, 63, 0, }, /* 873 */
+ { 63, 14, 12, 0, 0, 63, 0, }, /* 874 */
+ { 63, 21, 12, 0, 0, 63, 0, }, /* 875 */
+ { 80, 7, 12, 0, 0, 80, 0, }, /* 876 */
+ { 127, 7, 12, 0, 0, 127, 0, }, /* 877 */
+ { 115, 7, 12, 0, 0, 115, 0, }, /* 878 */
+ { 115, 13, 12, 0, 0, 115, 0, }, /* 879 */
+ { 115, 21, 12, 0, 0, 115, 0, }, /* 880 */
+ { 103, 7, 12, 0, 0, 103, 0, }, /* 881 */
+ { 103, 12, 3, 0, 0, 103, 0, }, /* 882 */
+ { 103, 21, 12, 0, 0, 103, 0, }, /* 883 */
+ { 119, 7, 12, 0, 0, 119, 0, }, /* 884 */
+ { 119, 12, 3, 0, 0, 119, 0, }, /* 885 */
+ { 119, 21, 12, 0, 0, 119, 0, }, /* 886 */
+ { 119, 26, 12, 0, 0, 119, 0, }, /* 887 */
+ { 119, 6, 12, 0, 0, 119, 0, }, /* 888 */
+ { 119, 13, 12, 0, 0, 119, 0, }, /* 889 */
+ { 119, 15, 12, 0, 0, 119, 0, }, /* 890 */
+ { 146, 9, 12, 0, 32, 146, 0, }, /* 891 */
+ { 146, 5, 12, 0, -32, 146, 0, }, /* 892 */
+ { 146, 15, 12, 0, 0, 146, 0, }, /* 893 */
+ { 146, 21, 12, 0, 0, 146, 0, }, /* 894 */
+ { 99, 7, 12, 0, 0, 99, 0, }, /* 895 */
+ { 99, 10, 5, 0, 0, 99, 0, }, /* 896 */
+ { 99, 12, 3, 0, 0, 99, 0, }, /* 897 */
+ { 99, 6, 12, 0, 0, 99, 0, }, /* 898 */
+ { 137, 6, 12, 0, 0, 137, 0, }, /* 899 */
+ { 139, 6, 12, 0, 0, 139, 0, }, /* 900 */
+ { 137, 7, 12, 0, 0, 137, 0, }, /* 901 */
+ { 139, 7, 12, 0, 0, 139, 0, }, /* 902 */
+ { 105, 7, 12, 0, 0, 105, 0, }, /* 903 */
+ { 105, 26, 12, 0, 0, 105, 0, }, /* 904 */
+ { 105, 12, 3, 0, 0, 105, 0, }, /* 905 */
+ { 105, 21, 12, 0, 0, 105, 0, }, /* 906 */
+ { 10, 1, 2, 0, 0, 105, 0, }, /* 907 */
+ { 10, 10, 3, 0, 0, 10, 0, }, /* 908 */
+ { 10, 10, 5, 0, 0, 10, 0, }, /* 909 */
+ { 20, 12, 3, 0, 0, 20, 0, }, /* 910 */
+ { 131, 26, 12, 0, 0, 131, 0, }, /* 911 */
+ { 131, 12, 3, 0, 0, 131, 0, }, /* 912 */
+ { 131, 21, 12, 0, 0, 131, 0, }, /* 913 */
+ { 18, 12, 3, 0, 0, 18, 0, }, /* 914 */
+ { 113, 7, 12, 0, 0, 113, 0, }, /* 915 */
+ { 113, 15, 12, 0, 0, 113, 0, }, /* 916 */
+ { 113, 12, 3, 0, 0, 113, 0, }, /* 917 */
+ { 132, 9, 12, 0, 34, 132, 0, }, /* 918 */
+ { 132, 5, 12, 0, -34, 132, 0, }, /* 919 */
+ { 132, 12, 3, 0, 0, 132, 0, }, /* 920 */
+ { 132, 13, 12, 0, 0, 132, 0, }, /* 921 */
+ { 132, 21, 12, 0, 0, 132, 0, }, /* 922 */
+ { 0, 2, 14, 0, 0, 0, 0, }, /* 923 */
+ { 10, 26, 11, 0, 0, 10, 0, }, /* 924 */
+ { 27, 26, 12, 0, 0, 27, 0, }, /* 925 */
+ { 10, 24, 3, 0, 0, 10, 0, }, /* 926 */
+ { 10, 1, 3, 0, 0, 10, 0, }, /* 927 */
};
const uint16_t PRIV(ucd_stage1)[] = { /* 17408 bytes */
@@ -968,3216 +1123,3226 @@ const uint16_t PRIV(ucd_stage1)[] = { /* 17408 bytes */
46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, /* U+1800 */
62, 63, 64, 65, 66, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, /* U+2000 */
77, 77, 78, 79, 66, 66, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, /* U+2800 */
- 90, 91, 92, 93, 94, 95, 96, 71, 97, 97, 97, 97, 97, 97, 97, 97, /* U+3000 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+3800 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+4000 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 98, 97, 97, 97, 97, /* U+4800 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+5000 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+5800 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+6000 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+6800 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+7000 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+7800 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+8000 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+8800 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+9000 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 99, /* U+9800 */
-100,101,101,101,101,101,101,101,101,102,103,103,104,105,106,107, /* U+A000 */
-108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,116, /* U+A800 */
-117,118,119,120,121,122,116,117,118,119,120,121,122,116,117,118, /* U+B000 */
-119,120,121,122,116,117,118,119,120,121,122,116,117,118,119,120, /* U+B800 */
-121,122,116,117,118,119,120,121,122,116,117,118,119,120,121,122, /* U+C000 */
-116,117,118,119,120,121,122,116,117,118,119,120,121,122,116,117, /* U+C800 */
-118,119,120,121,122,116,117,118,119,120,121,122,116,117,118,123, /* U+D000 */
-124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124, /* U+D800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+E000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+E800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+F000 */
-125,125, 97, 97,126,127,128,129,130,130,131,132,133,134,135,136, /* U+F800 */
-137,138,139,140,141,142,143,144,145,146,147,141,148,148,149,141, /* U+10000 */
-150,151,152,153,154,155,156,157,158,159,160,141,161,141,162,141, /* U+10800 */
-163,164,165,166,167,168,169,141,170,171,141,172,173,174,175,141, /* U+11000 */
-176,177,141,141,178,179,141,141,180,181,182,183,141,184,141,141, /* U+11800 */
-185,185,185,185,185,185,185,186,187,185,188,141,141,141,141,141, /* U+12000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+12800 */
-189,189,189,189,189,189,189,189,190,141,141,141,141,141,141,141, /* U+13000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+13800 */
-141,141,141,141,141,141,141,141,191,191,191,191,192,141,141,141, /* U+14000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+14800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+15000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+15800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+16000 */
-193,193,193,193,194,195,196,197,141,141,141,141,198,199,200,201, /* U+16800 */
-202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,202, /* U+17000 */
-202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,202, /* U+17800 */
-202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,203, /* U+18000 */
-202,202,202,202,202,204,141,141,141,141,141,141,141,141,141,141, /* U+18800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+19000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+19800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+1A000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+1A800 */
-205,206,207,208,208,209,141,141,141,141,141,141,141,141,141,141, /* U+1B000 */
-141,141,141,141,141,141,141,141,210,211,141,141,141,141,141,141, /* U+1B800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+1C000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+1C800 */
- 71,212,213,214,215,216,217,141,218,219,220,221,222,223,224,225, /* U+1D000 */
-226,226,226,226,227,228,141,141,141,141,141,141,141,141,141,141, /* U+1D800 */
-229,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+1E000 */
-230,231,232,141,141,141,141,141,233,234,141,141,235,236,141,141, /* U+1E800 */
-237,238,239,240,241,242,243,244,243,243,245,243,246,247,248,249, /* U+1F000 */
-250,251,252,253,254,242,242,242,242,242,242,242,242,242,242,255, /* U+1F800 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+20000 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+20800 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+21000 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+21800 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+22000 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+22800 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+23000 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+23800 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+24000 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+24800 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+25000 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+25800 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+26000 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+26800 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+27000 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+27800 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+28000 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+28800 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+29000 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+29800 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97,256, 97, 97, /* U+2A000 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+2A800 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97,257, 97, /* U+2B000 */
-258, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+2B800 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+2C000 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97,259, 97, 97, /* U+2C800 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+2D000 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+2D800 */
- 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, /* U+2E000 */
- 97, 97, 97, 97, 97, 97, 97,260,141,141,141,141,141,141,141,141, /* U+2E800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+2F000 */
- 97, 97, 97, 97,261,141,141,141,141,141,141,141,141,141,141,141, /* U+2F800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+30000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+30800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+31000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+31800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+32000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+32800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+33000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+33800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+34000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+34800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+35000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+35800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+36000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+36800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+37000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+37800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+38000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+38800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+39000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+39800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+3A000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+3A800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+3B000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+3B800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+3C000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+3C800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+3D000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+3D800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+3E000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+3E800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+3F000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+3F800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+40000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+40800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+41000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+41800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+42000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+42800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+43000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+43800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+44000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+44800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+45000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+45800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+46000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+46800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+47000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+47800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+48000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+48800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+49000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+49800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+4A000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+4A800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+4B000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+4B800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+4C000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+4C800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+4D000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+4D800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+4E000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+4E800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+4F000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+4F800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+50000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+50800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+51000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+51800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+52000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+52800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+53000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+53800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+54000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+54800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+55000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+55800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+56000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+56800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+57000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+57800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+58000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+58800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+59000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+59800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+5A000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+5A800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+5B000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+5B800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+5C000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+5C800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+5D000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+5D800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+5E000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+5E800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+5F000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+5F800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+60000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+60800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+61000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+61800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+62000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+62800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+63000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+63800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+64000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+64800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+65000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+65800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+66000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+66800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+67000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+67800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+68000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+68800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+69000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+69800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+6A000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+6A800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+6B000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+6B800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+6C000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+6C800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+6D000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+6D800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+6E000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+6E800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+6F000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+6F800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+70000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+70800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+71000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+71800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+72000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+72800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+73000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+73800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+74000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+74800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+75000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+75800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+76000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+76800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+77000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+77800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+78000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+78800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+79000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+79800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+7A000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+7A800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+7B000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+7B800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+7C000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+7C800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+7D000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+7D800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+7E000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+7E800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+7F000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+7F800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+80000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+80800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+81000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+81800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+82000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+82800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+83000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+83800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+84000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+84800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+85000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+85800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+86000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+86800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+87000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+87800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+88000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+88800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+89000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+89800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+8A000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+8A800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+8B000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+8B800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+8C000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+8C800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+8D000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+8D800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+8E000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+8E800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+8F000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+8F800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+90000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+90800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+91000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+91800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+92000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+92800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+93000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+93800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+94000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+94800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+95000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+95800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+96000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+96800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+97000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+97800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+98000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+98800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+99000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+99800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+9A000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+9A800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+9B000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+9B800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+9C000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+9C800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+9D000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+9D800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+9E000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+9E800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+9F000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+9F800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+A0000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+A0800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+A1000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+A1800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+A2000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+A2800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+A3000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+A3800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+A4000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+A4800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+A5000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+A5800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+A6000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+A6800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+A7000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+A7800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+A8000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+A8800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+A9000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+A9800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+AA000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+AA800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+AB000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+AB800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+AC000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+AC800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+AD000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+AD800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+AE000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+AE800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+AF000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+AF800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+B0000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+B0800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+B1000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+B1800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+B2000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+B2800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+B3000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+B3800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+B4000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+B4800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+B5000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+B5800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+B6000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+B6800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+B7000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+B7800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+B8000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+B8800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+B9000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+B9800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+BA000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+BA800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+BB000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+BB800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+BC000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+BC800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+BD000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+BD800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+BE000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+BE800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+BF000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+BF800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+C0000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+C0800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+C1000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+C1800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+C2000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+C2800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+C3000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+C3800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+C4000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+C4800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+C5000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+C5800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+C6000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+C6800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+C7000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+C7800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+C8000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+C8800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+C9000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+C9800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+CA000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+CA800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+CB000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+CB800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+CC000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+CC800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+CD000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+CD800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+CE000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+CE800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+CF000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+CF800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+D0000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+D0800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+D1000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+D1800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+D2000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+D2800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+D3000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+D3800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+D4000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+D4800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+D5000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+D5800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+D6000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+D6800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+D7000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+D7800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+D8000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+D8800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+D9000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+D9800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+DA000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+DA800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+DB000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+DB800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+DC000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+DC800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+DD000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+DD800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+DE000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+DE800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+DF000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+DF800 */
-262,263,264,265,263,263,263,263,263,263,263,263,263,263,263,263, /* U+E0000 */
-263,263,263,263,263,263,263,263,263,263,263,263,263,263,263,263, /* U+E0800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+E1000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+E1800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+E2000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+E2800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+E3000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+E3800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+E4000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+E4800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+E5000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+E5800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+E6000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+E6800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+E7000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+E7800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+E8000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+E8800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+E9000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+E9800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+EA000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+EA800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+EB000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+EB800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+EC000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+EC800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+ED000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+ED800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+EE000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+EE800 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+EF000 */
-141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, /* U+EF800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+F0000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+F0800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+F1000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+F1800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+F2000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+F2800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+F3000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+F3800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+F4000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+F4800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+F5000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+F5800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+F6000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+F6800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+F7000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+F7800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+F8000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+F8800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+F9000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+F9800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+FA000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+FA800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+FB000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+FB800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+FC000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+FC800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+FD000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+FD800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+FE000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+FE800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+FF000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,266, /* U+FF800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+100000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+100800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+101000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+101800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+102000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+102800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+103000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+103800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+104000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+104800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+105000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+105800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+106000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+106800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+107000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+107800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+108000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+108800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+109000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+109800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+10A000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+10A800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+10B000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+10B800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+10C000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+10C800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+10D000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+10D800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+10E000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+10E800 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+10F000 */
-125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,266, /* U+10F800 */
+ 90, 91, 92, 93, 94, 95, 96, 97, 98, 98, 98, 98, 98, 98, 98, 98, /* U+3000 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+3800 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+4000 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 99, 98, 98, 98, 98, /* U+4800 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+5000 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+5800 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+6000 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+6800 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+7000 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+7800 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+8000 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+8800 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+9000 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,100, /* U+9800 */
+101,102,102,102,102,102,102,102,102,103,104,104,105,106,107,108, /* U+A000 */
+109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,117, /* U+A800 */
+118,119,120,121,122,123,117,118,119,120,121,122,123,117,118,119, /* U+B000 */
+120,121,122,123,117,118,119,120,121,122,123,117,118,119,120,121, /* U+B800 */
+122,123,117,118,119,120,121,122,123,117,118,119,120,121,122,123, /* U+C000 */
+117,118,119,120,121,122,123,117,118,119,120,121,122,123,117,118, /* U+C800 */
+119,120,121,122,123,117,118,119,120,121,122,123,117,118,119,124, /* U+D000 */
+125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125, /* U+D800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+E000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+E800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+F000 */
+126,126, 98, 98,127,128,129,130,131,131,132,133,134,135,136,137, /* U+F800 */
+138,139,140,141,142,143,144,145,146,147,148,142,149,149,150,142, /* U+10000 */
+151,152,153,154,155,156,157,158,159,160,161,142,162,142,163,142, /* U+10800 */
+164,165,166,167,168,169,170,142,171,172,142,173,174,175,176,142, /* U+11000 */
+177,178,142,142,179,180,142,142,181,182,183,184,142,185,142,142, /* U+11800 */
+186,186,186,186,186,186,186,187,188,186,189,142,142,142,142,142, /* U+12000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+12800 */
+190,190,190,190,190,190,190,190,191,142,142,142,142,142,142,142, /* U+13000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+13800 */
+142,142,142,142,142,142,142,142,192,192,192,192,193,142,142,142, /* U+14000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+14800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+15000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+15800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+16000 */
+194,194,194,194,195,196,197,198,142,142,142,142,199,200,201,202, /* U+16800 */
+203,203,203,203,203,203,203,203,203,203,203,203,203,203,203,203, /* U+17000 */
+203,203,203,203,203,203,203,203,203,203,203,203,203,203,203,203, /* U+17800 */
+203,203,203,203,203,203,203,203,203,203,203,203,203,203,203,204, /* U+18000 */
+203,203,203,203,203,205,142,142,142,142,142,142,142,142,142,142, /* U+18800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+19000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+19800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+1A000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+1A800 */
+206,207,208,209,209,210,142,142,142,142,142,142,142,142,142,142, /* U+1B000 */
+142,142,142,142,142,142,142,142,211,212,142,142,142,142,142,142, /* U+1B800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+1C000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+1C800 */
+ 71,213,214,215,216,217,218,142,219,220,221,222,223,224,225,226, /* U+1D000 */
+227,227,227,227,228,229,142,142,142,142,142,142,142,142,142,142, /* U+1D800 */
+230,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+1E000 */
+231,232,233,142,142,142,142,142,234,235,142,142,236,237,142,142, /* U+1E800 */
+238,239,240,241,242,243,244,245,244,244,246,244,247,248,249,250, /* U+1F000 */
+251,252,253,254,255,243,243,243,243,243,243,243,243,243,243,256, /* U+1F800 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+20000 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+20800 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+21000 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+21800 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+22000 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+22800 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+23000 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+23800 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+24000 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+24800 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+25000 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+25800 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+26000 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+26800 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+27000 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+27800 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+28000 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+28800 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+29000 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+29800 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,257, 98, 98, /* U+2A000 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+2A800 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,258, 98, /* U+2B000 */
+259, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+2B800 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+2C000 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,260, 98, 98, /* U+2C800 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+2D000 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+2D800 */
+ 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, /* U+2E000 */
+ 98, 98, 98, 98, 98, 98, 98,261,142,142,142,142,142,142,142,142, /* U+2E800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+2F000 */
+ 98, 98, 98, 98,262,142,142,142,142,142,142,142,142,142,142,142, /* U+2F800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+30000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+30800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+31000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+31800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+32000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+32800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+33000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+33800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+34000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+34800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+35000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+35800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+36000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+36800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+37000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+37800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+38000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+38800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+39000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+39800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+3A000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+3A800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+3B000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+3B800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+3C000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+3C800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+3D000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+3D800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+3E000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+3E800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+3F000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+3F800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+40000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+40800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+41000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+41800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+42000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+42800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+43000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+43800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+44000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+44800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+45000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+45800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+46000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+46800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+47000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+47800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+48000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+48800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+49000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+49800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+4A000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+4A800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+4B000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+4B800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+4C000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+4C800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+4D000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+4D800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+4E000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+4E800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+4F000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+4F800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+50000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+50800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+51000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+51800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+52000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+52800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+53000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+53800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+54000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+54800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+55000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+55800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+56000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+56800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+57000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+57800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+58000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+58800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+59000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+59800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+5A000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+5A800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+5B000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+5B800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+5C000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+5C800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+5D000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+5D800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+5E000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+5E800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+5F000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+5F800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+60000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+60800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+61000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+61800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+62000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+62800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+63000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+63800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+64000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+64800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+65000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+65800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+66000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+66800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+67000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+67800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+68000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+68800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+69000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+69800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+6A000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+6A800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+6B000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+6B800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+6C000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+6C800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+6D000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+6D800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+6E000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+6E800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+6F000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+6F800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+70000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+70800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+71000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+71800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+72000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+72800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+73000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+73800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+74000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+74800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+75000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+75800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+76000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+76800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+77000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+77800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+78000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+78800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+79000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+79800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+7A000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+7A800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+7B000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+7B800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+7C000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+7C800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+7D000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+7D800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+7E000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+7E800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+7F000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+7F800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+80000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+80800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+81000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+81800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+82000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+82800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+83000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+83800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+84000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+84800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+85000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+85800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+86000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+86800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+87000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+87800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+88000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+88800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+89000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+89800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+8A000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+8A800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+8B000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+8B800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+8C000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+8C800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+8D000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+8D800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+8E000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+8E800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+8F000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+8F800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+90000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+90800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+91000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+91800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+92000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+92800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+93000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+93800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+94000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+94800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+95000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+95800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+96000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+96800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+97000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+97800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+98000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+98800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+99000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+99800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+9A000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+9A800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+9B000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+9B800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+9C000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+9C800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+9D000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+9D800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+9E000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+9E800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+9F000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+9F800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+A0000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+A0800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+A1000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+A1800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+A2000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+A2800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+A3000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+A3800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+A4000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+A4800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+A5000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+A5800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+A6000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+A6800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+A7000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+A7800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+A8000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+A8800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+A9000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+A9800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+AA000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+AA800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+AB000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+AB800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+AC000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+AC800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+AD000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+AD800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+AE000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+AE800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+AF000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+AF800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+B0000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+B0800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+B1000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+B1800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+B2000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+B2800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+B3000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+B3800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+B4000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+B4800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+B5000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+B5800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+B6000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+B6800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+B7000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+B7800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+B8000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+B8800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+B9000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+B9800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+BA000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+BA800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+BB000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+BB800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+BC000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+BC800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+BD000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+BD800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+BE000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+BE800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+BF000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+BF800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+C0000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+C0800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+C1000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+C1800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+C2000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+C2800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+C3000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+C3800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+C4000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+C4800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+C5000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+C5800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+C6000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+C6800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+C7000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+C7800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+C8000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+C8800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+C9000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+C9800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+CA000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+CA800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+CB000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+CB800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+CC000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+CC800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+CD000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+CD800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+CE000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+CE800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+CF000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+CF800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+D0000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+D0800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+D1000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+D1800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+D2000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+D2800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+D3000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+D3800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+D4000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+D4800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+D5000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+D5800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+D6000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+D6800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+D7000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+D7800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+D8000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+D8800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+D9000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+D9800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+DA000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+DA800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+DB000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+DB800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+DC000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+DC800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+DD000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+DD800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+DE000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+DE800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+DF000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+DF800 */
+263,264,265,266,264,264,264,264,264,264,264,264,264,264,264,264, /* U+E0000 */
+264,264,264,264,264,264,264,264,264,264,264,264,264,264,264,264, /* U+E0800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+E1000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+E1800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+E2000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+E2800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+E3000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+E3800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+E4000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+E4800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+E5000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+E5800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+E6000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+E6800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+E7000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+E7800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+E8000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+E8800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+E9000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+E9800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+EA000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+EA800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+EB000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+EB800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+EC000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+EC800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+ED000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+ED800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+EE000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+EE800 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+EF000 */
+142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, /* U+EF800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+F0000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+F0800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+F1000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+F1800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+F2000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+F2800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+F3000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+F3800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+F4000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+F4800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+F5000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+F5800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+F6000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+F6800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+F7000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+F7800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+F8000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+F8800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+F9000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+F9800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+FA000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+FA800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+FB000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+FB800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+FC000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+FC800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+FD000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+FD800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+FE000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+FE800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+FF000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,267, /* U+FF800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+100000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+100800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+101000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+101800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+102000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+102800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+103000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+103800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+104000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+104800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+105000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+105800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+106000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+106800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+107000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+107800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+108000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+108800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+109000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+109800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+10A000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+10A800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+10B000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+10B800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+10C000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+10C800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+10D000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+10D800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+10E000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+10E800 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, /* U+10F000 */
+126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,267, /* U+10F800 */
};
-const uint16_t PRIV(ucd_stage2)[] = { /* 68352 bytes, block = 128 */
+const uint16_t PRIV(ucd_stage2)[] = { /* 68608 bytes, block = 128 */
/* block 0 */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 3, 4, 4, 4, 5, 4, 4, 4, 6, 7, 4, 8, 4, 9, 4, 4,
- 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 4, 4, 8, 8, 8, 4,
- 4, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 11, 11, 11, 11,
- 11, 11, 11, 13, 11, 11, 11, 11, 11, 11, 11, 6, 4, 7, 14, 15,
- 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 16, 16, 16, 16,
- 16, 16, 16, 18, 16, 16, 16, 16, 16, 16, 16, 6, 8, 7, 8, 0,
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 3, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 4, 5, 5, 5, 6, 5, 5, 5, 7, 8, 5, 9, 5, 10, 5, 5,
+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 5, 5, 9, 9, 9, 5,
+ 5, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 12, 12, 12, 12,
+ 12, 12, 12, 14, 12, 12, 12, 12, 12, 12, 12, 7, 5, 8, 15, 16,
+ 15, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 17, 17, 17, 17,
+ 17, 17, 17, 19, 17, 17, 17, 17, 17, 17, 17, 7, 9, 8, 9, 1,
/* block 1 */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 3, 4, 5, 5, 5, 5, 19, 4, 14, 20, 21, 22, 8, 23, 20, 14,
- 19, 8, 24, 24, 14, 25, 4, 4, 14, 24, 21, 26, 24, 24, 24, 4,
- 11, 11, 11, 11, 11, 27, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
- 11, 11, 11, 11, 11, 11, 11, 8, 11, 11, 11, 11, 11, 11, 11, 28,
- 16, 16, 16, 16, 16, 29, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 8, 16, 16, 16, 16, 16, 16, 16, 30,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 4, 5, 6, 6, 6, 6, 20, 5, 15, 21, 22, 23, 9, 24, 21, 15,
+ 20, 9, 25, 25, 15, 26, 5, 5, 15, 25, 22, 27, 25, 25, 25, 5,
+ 12, 12, 12, 12, 12, 28, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+ 12, 12, 12, 12, 12, 12, 12, 9, 12, 12, 12, 12, 12, 12, 12, 29,
+ 17, 17, 17, 17, 17, 30, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
+ 17, 17, 17, 17, 17, 17, 17, 9, 17, 17, 17, 17, 17, 17, 17, 31,
/* block 2 */
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 33, 34, 31, 32, 31, 32, 31, 32, 34, 31, 32, 31, 32, 31, 32, 31,
- 32, 31, 32, 31, 32, 31, 32, 31, 32, 34, 31, 32, 31, 32, 31, 32,
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 31, 32, 31, 32, 31, 32, 31, 32, 35, 31, 32, 31, 32, 31, 32, 36,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 34, 35, 32, 33, 32, 33, 32, 33, 35, 32, 33, 32, 33, 32, 33, 32,
+ 33, 32, 33, 32, 33, 32, 33, 32, 33, 35, 32, 33, 32, 33, 32, 33,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 32, 33, 32, 33, 32, 33, 32, 33, 36, 32, 33, 32, 33, 32, 33, 37,
/* block 3 */
- 37, 38, 31, 32, 31, 32, 39, 31, 32, 40, 40, 31, 32, 34, 41, 42,
- 43, 31, 32, 40, 44, 45, 46, 47, 31, 32, 48, 34, 46, 49, 50, 51,
- 31, 32, 31, 32, 31, 32, 52, 31, 32, 52, 34, 34, 31, 32, 52, 31,
- 32, 53, 53, 31, 32, 31, 32, 54, 31, 32, 34, 21, 31, 32, 34, 55,
- 21, 21, 21, 21, 56, 57, 58, 59, 60, 61, 62, 63, 64, 31, 32, 31,
- 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 65, 31, 32,
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 34, 66, 67, 68, 31, 32, 69, 70, 31, 32, 31, 32, 31, 32, 31, 32,
+ 38, 39, 32, 33, 32, 33, 40, 32, 33, 41, 41, 32, 33, 35, 42, 43,
+ 44, 32, 33, 41, 45, 46, 47, 48, 32, 33, 49, 35, 47, 50, 51, 52,
+ 32, 33, 32, 33, 32, 33, 53, 32, 33, 53, 35, 35, 32, 33, 53, 32,
+ 33, 54, 54, 32, 33, 32, 33, 55, 32, 33, 35, 22, 32, 33, 35, 56,
+ 22, 22, 22, 22, 57, 58, 59, 60, 61, 62, 63, 64, 65, 32, 33, 32,
+ 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 66, 32, 33,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 35, 67, 68, 69, 32, 33, 70, 71, 32, 33, 32, 33, 32, 33, 32, 33,
/* block 4 */
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 71, 34, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 31, 32, 31, 32, 34, 34, 34, 34, 34, 34, 72, 31, 32, 73, 74, 75,
- 75, 31, 32, 76, 77, 78, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 79, 80, 81, 82, 83, 34, 84, 84, 34, 85, 34, 86, 87, 34, 34, 34,
- 84, 88, 34, 89, 34, 90, 91, 34, 92, 93, 91, 94, 95, 34, 34, 93,
- 34, 96, 97, 34, 34, 98, 34, 34, 34, 34, 34, 34, 34, 99, 34, 34,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 72, 35, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 32, 33, 32, 33, 35, 35, 35, 35, 35, 35, 73, 32, 33, 74, 75, 76,
+ 76, 32, 33, 77, 78, 79, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 80, 81, 82, 83, 84, 35, 85, 85, 35, 86, 35, 87, 88, 35, 35, 35,
+ 85, 89, 35, 90, 35, 91, 92, 35, 93, 94, 92, 95, 96, 35, 35, 94,
+ 35, 97, 98, 35, 35, 99, 35, 35, 35, 35, 35, 35, 35,100, 35, 35,
/* block 5 */
-100, 34, 34,100, 34, 34, 34,101,100,102,103,103,104, 34, 34, 34,
- 34, 34,105, 34, 21, 34, 34, 34, 34, 34, 34, 34, 34,106,107, 34,
- 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
-108,108,108,108,108,108,108,108,108,109,109,109,109,109,109,109,
-109,109, 14, 14, 14, 14,109,109,109,109,109,109,109,109,109,109,
-109,109, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
-108,108,108,108,108, 14, 14, 14, 14, 14,110,110,109, 14,109, 14,
- 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+101, 35, 35,101, 35, 35, 35,102,101,103,104,104,105, 35, 35, 35,
+ 35, 35,106, 35, 22, 35, 35, 35, 35, 35, 35, 35, 35,107,108, 35,
+ 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
+109,109,109,109,109,109,109,109,109,110,110,110,110,110,110,110,
+110,110, 15, 15, 15, 15,110,110,110,110,110,110,110,110,110,110,
+110,110, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+109,109,109,109,109, 15, 15, 15, 15, 15,111,111,110, 15,110, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
/* block 6 */
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
-111,111,111,111,111,112,111,111,111,111,111,111,111,111,111,111,
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
-113,114,113,114,109,115,113,114,116,116,117,118,118,118, 4,119,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,
+112,112,113,112,112,114,112,112,112,112,112,112,112,112,112,112,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,
+112,112,112,115,115,115,115,115,115,115,115,115,115,115,115,115,
+116,117,116,117,110,118,116,117,119,119,120,121,121,121, 5,122,
/* block 7 */
-116,116,116,116,115, 14,120, 4,121,121,121,116,122,116,123,123,
-124,125,126,125,125,127,125,125,128,129,130,125,131,125,125,125,
-132,133,116,134,125,125,135,125,125,136,125,125,137,138,138,138,
-124,139,140,139,139,141,139,139,142,143,144,139,145,139,139,139,
-146,147,148,149,139,139,150,139,139,151,139,139,152,153,153,154,
-155,156,157,157,157,158,159,160,113,114,113,114,113,114,113,114,
-113,114,161,162,161,162,161,162,161,162,161,162,161,162,161,162,
-163,164,165,166,167,168,169,113,114,170,113,114,124,171,171,171,
+119,119,119,119,118, 15,123, 5,124,124,124,119,125,119,126,126,
+127,128,129,128,128,130,128,128,131,132,133,128,134,128,128,128,
+135,136,119,137,128,128,138,128,128,139,128,128,140,141,141,141,
+127,142,143,142,142,144,142,142,145,146,147,142,148,142,142,142,
+149,150,151,152,142,142,153,142,142,154,142,142,155,156,156,157,
+158,159,160,160,160,161,162,163,116,117,116,117,116,117,116,117,
+116,117,164,165,164,165,164,165,164,165,164,165,164,165,164,165,
+166,167,168,169,170,171,172,116,117,173,116,117,127,174,174,174,
/* block 8 */
-172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,
-173,173,174,173,175,173,173,173,173,173,173,173,173,173,176,173,
-173,177,178,173,173,173,173,173,173,173,179,173,173,173,173,173,
-180,180,181,180,182,180,180,180,180,180,180,180,180,180,183,180,
-180,184,185,180,180,180,180,180,180,180,186,180,180,180,180,180,
-187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,
-188,189,190,191,188,189,188,189,188,189,188,189,188,189,188,189,
-188,189,188,189,188,189,188,189,188,189,188,189,188,189,188,189,
+175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,
+176,176,177,176,178,176,176,176,176,176,176,176,176,176,179,176,
+176,180,181,176,176,176,176,176,176,176,182,176,176,176,176,176,
+183,183,184,183,185,183,183,183,183,183,183,183,183,183,186,183,
+183,187,188,183,183,183,183,183,183,183,189,183,183,183,183,183,
+190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,
+191,192,193,194,191,192,191,192,191,192,191,192,191,192,191,192,
+191,192,191,192,191,192,191,192,191,192,191,192,191,192,191,192,
/* block 9 */
-188,189,192,193,193,111,111,193,194,194,188,189,188,189,188,189,
-188,189,188,189,188,189,188,189,188,189,188,189,188,189,188,189,
-188,189,188,189,188,189,188,189,188,189,188,189,188,189,188,189,
-188,189,188,189,188,189,188,189,188,189,188,189,188,189,188,189,
-195,188,189,188,189,188,189,188,189,188,189,188,189,188,189,196,
-188,189,188,189,188,189,188,189,188,189,188,189,188,189,188,189,
-188,189,188,189,188,189,188,189,188,189,188,189,188,189,188,189,
-188,189,188,189,188,189,188,189,188,189,188,189,188,189,188,189,
+191,192,195,196,197,198,198,197,199,199,191,192,191,192,191,192,
+191,192,191,192,191,192,191,192,191,192,191,192,191,192,191,192,
+191,192,191,192,191,192,191,192,191,192,191,192,191,192,191,192,
+191,192,191,192,191,192,191,192,191,192,191,192,191,192,191,192,
+200,191,192,191,192,191,192,191,192,191,192,191,192,191,192,201,
+191,192,191,192,191,192,191,192,191,192,191,192,191,192,191,192,
+191,192,191,192,191,192,191,192,191,192,191,192,191,192,191,192,
+191,192,191,192,191,192,191,192,191,192,191,192,191,192,191,192,
/* block 10 */
-188,189,188,189,188,189,188,189,188,189,188,189,188,189,188,189,
-188,189,188,189,188,189,188,189,188,189,188,189,188,189,188,189,
-188,189,188,189,188,189,188,189,188,189,188,189,188,189,188,189,
-116,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,
-197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,
-197,197,197,197,197,197,197,116,116,198,199,199,199,199,199,199,
-200,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,
-201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,
+191,192,191,192,191,192,191,192,191,192,191,192,191,192,191,192,
+191,192,191,192,191,192,191,192,191,192,191,192,191,192,191,192,
+191,192,191,192,191,192,191,192,191,192,191,192,191,192,191,192,
+119,202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,
+202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,
+202,202,202,202,202,202,202,119,119,203,204,204,204,204,204,204,
+205,206,206,206,206,206,206,206,206,206,206,206,206,206,206,206,
+206,206,206,206,206,206,206,206,206,206,206,206,206,206,206,206,
/* block 11 */
-201,201,201,201,201,201,201,200,200, 4,202,116,116,203,203,204,
-116,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,
-205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,
-205,205,205,205,205,205,205,205,205,205,205,205,205,205,206,205,
-207,205,205,207,205,205,207,205,116,116,116,116,116,116,116,116,
-208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,
-208,208,208,208,208,208,208,208,208,208,208,116,116,116,116,208,
-208,208,208,207,207,116,116,116,116,116,116,116,116,116,116,116,
+206,206,206,206,206,206,206,205,205,207,208,119,119,209,209,210,
+119,211,211,211,211,211,211,211,211,211,211,211,211,211,211,211,
+211,211,211,211,211,211,211,211,211,211,211,211,211,211,211,211,
+211,211,211,211,211,211,211,211,211,211,211,211,211,211,212,211,
+213,211,211,213,211,211,213,211,119,119,119,119,119,119,119,119,
+214,214,214,214,214,214,214,214,214,214,214,214,214,214,214,214,
+214,214,214,214,214,214,214,214,214,214,214,119,119,119,119,214,
+214,214,214,213,213,119,119,119,119,119,119,119,119,119,119,119,
/* block 12 */
-209,209,209,209,209,210,211,211,211,212,212,213, 4,212,214,214,
-215,215,215,215,215,215,215,215,215,215,215, 4,216,116,212, 4,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-109,217,217,217,217,217,217,217,217,217,217,111,111,111,111,111,
-111,111,111,111,111,111,215,215,215,215,215,215,215,215,215,215,
-218,218,218,218,218,218,218,218,218,218,212,212,212,212,217,217,
-111,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
+215,215,215,215,215,216,217,217,217,218,218,219,220,218,221,221,
+222,222,222,222,222,222,222,222,222,222,222,220,223,119,218,220,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+225,224,224,224,224,224,224,224,224,224,224,226,226,226,226,226,
+226,226,226,226,226,226,222,222,222,222,222,222,222,222,222,222,
+227,227,227,227,227,227,227,227,227,227,218,218,218,218,224,224,
+226,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
/* block 13 */
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,212,217,215,215,215,215,215,215,215,210,214,215,
-215,215,215,215,215,219,219,215,215,214,215,215,215,215,217,217,
-218,218,218,218,218,218,218,218,218,218,217,217,217,214,214,217,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,228,224,222,222,222,222,222,222,222,216,221,222,
+222,222,222,222,222,229,229,222,222,221,222,222,222,222,224,224,
+230,230,230,230,230,230,230,230,230,230,224,224,224,221,221,224,
/* block 14 */
-220,220,220,220,220,220,220,220,220,220,220,220,220,220,116,221,
-222,223,222,222,222,222,222,222,222,222,222,222,222,222,222,222,
-222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,
-223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,
-223,223,223,223,223,223,223,223,223,223,223,116,116,222,222,222,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-
-/* block 15 */
+231,231,231,231,231,231,231,231,231,231,231,231,231,231,119,232,
+233,234,233,233,233,233,233,233,233,233,233,233,233,233,233,233,
+233,233,233,233,233,233,233,233,233,233,233,233,233,233,233,233,
+234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,
+234,234,234,234,234,234,234,234,234,234,234,119,119,233,233,233,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
-224,224,224,224,224,224,225,225,225,225,225,225,225,225,225,225,
-225,224,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-226,226,226,226,226,226,226,226,226,226,227,227,227,227,227,227,
-227,227,227,227,227,227,227,227,227,227,227,227,227,227,227,227,
-227,227,227,227,227,227,227,227,227,227,227,228,228,228,228,228,
-228,228,228,228,229,229,230,231,231,231,229,116,116,228,232,232,
+
+/* block 15 */
+235,235,235,235,235,235,235,235,235,235,235,235,235,235,235,235,
+235,235,235,235,235,235,235,235,235,235,235,235,235,235,235,235,
+235,235,235,235,235,235,236,236,236,236,236,236,236,236,236,236,
+236,235,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+237,237,237,237,237,237,237,237,237,237,238,238,238,238,238,238,
+238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,
+238,238,238,238,238,238,238,238,238,238,238,239,239,239,239,239,
+239,239,239,239,240,240,241,242,242,242,240,119,119,239,243,243,
/* block 16 */
-233,233,233,233,233,233,233,233,233,233,233,233,233,233,233,233,
-233,233,233,233,233,233,234,234,234,234,235,234,234,234,234,234,
-234,234,234,234,235,234,234,234,235,234,234,234,234,234,116,116,
-236,236,236,236,236,236,236,236,236,236,236,236,236,236,236,116,
-237,237,237,237,237,237,237,237,237,237,237,237,237,237,237,237,
-237,237,237,237,237,237,237,237,237,238,238,238,116,116,239,116,
-222,222,222,222,222,222,222,222,222,222,222,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+244,244,244,244,244,244,244,244,244,244,244,244,244,244,244,244,
+244,244,244,244,244,244,245,245,245,245,246,245,245,245,245,245,
+245,245,245,245,246,245,245,245,246,245,245,245,245,245,119,119,
+247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,119,
+248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,
+248,248,248,248,248,248,248,248,248,249,249,249,119,119,250,119,
+233,233,233,233,233,233,233,233,233,233,233,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 17 */
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,116,217,217,217,217,217,217,217,217,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,215,215,215,215,215,215,215,215,215,215,215,215,215,
-215,215,210,215,215,215,215,215,215,215,215,215,215,215,215,215,
-215,215,215,215,215,215,215,215,215,215,215,215,215,215,215,215,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,119,224,224,224,224,224,224,224,224,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,222,222,222,222,222,222,222,222,222,222,222,222,222,
+222,222,216,222,222,222,222,222,222,222,222,222,222,222,222,222,
+222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,
/* block 18 */
-240,240,240,241,242,242,242,242,242,242,242,242,242,242,242,242,
-242,242,242,242,242,242,242,242,242,242,242,242,242,242,242,242,
-242,242,242,242,242,242,242,242,242,242,242,242,242,242,242,242,
-242,242,242,242,242,242,242,242,242,242,240,241,240,242,241,241,
-241,240,240,240,240,240,240,240,240,241,241,241,241,240,241,241,
-242,111,111,240,240,240,240,240,242,242,242,242,242,242,242,242,
-242,242,240,240, 4, 4,243,243,243,243,243,243,243,243,243,243,
-244,245,242,242,242,242,242,242,242,242,242,242,242,242,242,242,
+251,251,251,252,253,253,253,253,253,253,253,253,253,253,253,253,
+253,253,253,253,253,253,253,253,253,253,253,253,253,253,253,253,
+253,253,253,253,253,253,253,253,253,253,253,253,253,253,253,253,
+253,253,253,253,253,253,253,253,253,253,251,252,251,253,252,252,
+252,251,251,251,251,251,251,251,251,252,252,252,252,251,252,252,
+253,254,255,251,251,251,251,251,253,253,253,253,253,253,253,253,
+253,253,251,251,256,257,258,258,258,258,258,258,258,258,258,258,
+259,260,253,253,253,253,253,253,253,253,253,253,253,253,253,253,
/* block 19 */
-246,247,248,248,116,246,246,246,246,246,246,246,246,116,116,246,
-246,116,116,246,246,246,246,246,246,246,246,246,246,246,246,246,
-246,246,246,246,246,246,246,246,246,116,246,246,246,246,246,246,
-246,116,246,116,116,116,246,246,246,246,116,116,247,246,249,248,
-248,247,247,247,247,116,116,248,248,116,116,248,248,247,246,116,
-116,116,116,116,116,116,116,249,116,116,116,116,246,246,116,246,
-246,246,247,247,116,116,250,250,250,250,250,250,250,250,250,250,
-246,246,251,251,252,252,252,252,252,252,253,251,246,254,247,116,
+261,262,263,263,119,261,261,261,261,261,261,261,261,119,119,261,
+261,119,119,261,261,261,261,261,261,261,261,261,261,261,261,261,
+261,261,261,261,261,261,261,261,261,119,261,261,261,261,261,261,
+261,119,261,119,119,119,261,261,261,261,119,119,262,261,264,263,
+263,262,262,262,262,119,119,263,263,119,119,263,263,262,261,119,
+119,119,119,119,119,119,119,264,119,119,119,119,261,261,119,261,
+261,261,262,262,119,119,265,265,265,265,265,265,265,265,265,265,
+261,261,266,266,267,267,267,267,267,267,268,266,261,269,262,119,
/* block 20 */
-116,255,255,256,116,257,257,257,257,257,257,116,116,116,116,257,
-257,116,116,257,257,257,257,257,257,257,257,257,257,257,257,257,
-257,257,257,257,257,257,257,257,257,116,257,257,257,257,257,257,
-257,116,257,257,116,257,257,116,257,257,116,116,255,116,256,256,
-256,255,255,116,116,116,116,255,255,116,116,255,255,255,116,116,
-116,255,116,116,116,116,116,116,116,257,257,257,257,116,257,116,
-116,116,116,116,116,116,258,258,258,258,258,258,258,258,258,258,
-255,255,257,257,257,255,259,116,116,116,116,116,116,116,116,116,
+119,270,270,271,119,272,272,272,272,272,272,119,119,119,119,272,
+272,119,119,272,272,272,272,272,272,272,272,272,272,272,272,272,
+272,272,272,272,272,272,272,272,272,119,272,272,272,272,272,272,
+272,119,272,272,119,272,272,119,272,272,119,119,270,119,271,271,
+271,270,270,119,119,119,119,270,270,119,119,270,270,270,119,119,
+119,270,119,119,119,119,119,119,119,272,272,272,272,119,272,119,
+119,119,119,119,119,119,273,273,273,273,273,273,273,273,273,273,
+270,270,272,272,272,270,274,119,119,119,119,119,119,119,119,119,
/* block 21 */
-116,260,260,261,116,262,262,262,262,262,262,262,262,262,116,262,
-262,262,116,262,262,262,262,262,262,262,262,262,262,262,262,262,
-262,262,262,262,262,262,262,262,262,116,262,262,262,262,262,262,
-262,116,262,262,116,262,262,262,262,262,116,116,260,262,261,261,
-261,260,260,260,260,260,116,260,260,261,116,261,261,260,116,116,
-262,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-262,262,260,260,116,116,263,263,263,263,263,263,263,263,263,263,
-264,265,116,116,116,116,116,116,116,262,260,260,260,260,260,260,
+119,275,275,276,119,277,277,277,277,277,277,277,277,277,119,277,
+277,277,119,277,277,277,277,277,277,277,277,277,277,277,277,277,
+277,277,277,277,277,277,277,277,277,119,277,277,277,277,277,277,
+277,119,277,277,119,277,277,277,277,277,119,119,275,277,276,276,
+276,275,275,275,275,275,119,275,275,276,119,276,276,275,119,119,
+277,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+277,277,275,275,119,119,278,278,278,278,278,278,278,278,278,278,
+279,280,119,119,119,119,119,119,119,277,275,275,275,275,275,275,
/* block 22 */
-116,266,267,267,116,268,268,268,268,268,268,268,268,116,116,268,
-268,116,116,268,268,268,268,268,268,268,268,268,268,268,268,268,
-268,268,268,268,268,268,268,268,268,116,268,268,268,268,268,268,
-268,116,268,268,116,268,268,268,268,268,116,116,266,268,269,266,
-267,266,266,266,266,116,116,267,267,116,116,267,267,266,116,116,
-116,116,116,116,116,116,266,269,116,116,116,116,268,268,116,268,
-268,268,266,266,116,116,270,270,270,270,270,270,270,270,270,270,
-271,268,272,272,272,272,272,272,116,116,116,116,116,116,116,116,
+119,281,282,282,119,283,283,283,283,283,283,283,283,119,119,283,
+283,119,119,283,283,283,283,283,283,283,283,283,283,283,283,283,
+283,283,283,283,283,283,283,283,283,119,283,283,283,283,283,283,
+283,119,283,283,119,283,283,283,283,283,119,119,281,283,284,281,
+282,281,281,281,281,119,119,282,282,119,119,282,282,281,119,119,
+119,119,119,119,119,119,281,284,119,119,119,119,283,283,119,283,
+283,283,281,281,119,119,285,285,285,285,285,285,285,285,285,285,
+286,283,287,287,287,287,287,287,119,119,119,119,119,119,119,119,
/* block 23 */
-116,116,273,274,116,274,274,274,274,274,274,116,116,116,274,274,
-274,116,274,274,274,274,116,116,116,274,274,116,274,116,274,274,
-116,116,116,274,274,116,116,116,274,274,274,116,116,116,274,274,
-274,274,274,274,274,274,274,274,274,274,116,116,116,116,275,276,
-273,276,276,116,116,116,276,276,276,116,276,276,276,273,116,116,
-274,116,116,116,116,116,116,275,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,277,277,277,277,277,277,277,277,277,277,
-278,278,278,279,279,279,279,279,279,280,279,116,116,116,116,116,
+119,119,288,289,119,289,289,289,289,289,289,119,119,119,289,289,
+289,119,289,289,289,289,119,119,119,289,289,119,289,119,289,289,
+119,119,119,289,289,119,119,119,289,289,289,119,119,119,289,289,
+289,289,289,289,289,289,289,289,289,289,119,119,119,119,290,291,
+288,291,291,119,119,119,291,291,291,119,291,291,291,288,119,119,
+289,119,119,119,119,119,119,290,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,292,292,292,292,292,292,292,292,292,292,
+293,293,293,294,295,295,295,295,295,296,295,119,119,119,119,119,
/* block 24 */
-281,282,282,282,281,283,283,283,283,283,283,283,283,116,283,283,
-283,116,283,283,283,283,283,283,283,283,283,283,283,283,283,283,
-283,283,283,283,283,283,283,283,283,116,283,283,283,283,283,283,
-283,283,283,283,283,283,283,283,283,283,116,116,116,283,281,281,
-281,282,282,282,282,116,281,281,281,116,281,281,281,281,116,116,
-116,116,116,116,116,281,281,116,283,283,283,116,116,116,116,116,
-283,283,281,281,116,116,284,284,284,284,284,284,284,284,284,284,
-116,116,116,116,116,116,116,116,285,285,285,285,285,285,285,286,
+297,298,298,298,297,299,299,299,299,299,299,299,299,119,299,299,
+299,119,299,299,299,299,299,299,299,299,299,299,299,299,299,299,
+299,299,299,299,299,299,299,299,299,119,299,299,299,299,299,299,
+299,299,299,299,299,299,299,299,299,299,119,119,119,299,297,297,
+297,298,298,298,298,119,297,297,297,119,297,297,297,297,119,119,
+119,119,119,119,119,297,297,119,299,299,299,119,119,119,119,119,
+299,299,297,297,119,119,300,300,300,300,300,300,300,300,300,300,
+119,119,119,119,119,119,119,119,301,301,301,301,301,301,301,302,
/* block 25 */
-287,288,289,289,290,287,287,287,287,287,287,287,287,116,287,287,
-287,116,287,287,287,287,287,287,287,287,287,287,287,287,287,287,
-287,287,287,287,287,287,287,287,287,116,287,287,287,287,287,287,
-287,287,287,287,116,287,287,287,287,287,116,116,288,287,289,288,
-289,289,291,289,289,116,288,289,289,116,289,289,288,288,116,116,
-116,116,116,116,116,291,291,116,116,116,116,116,116,116,287,116,
-287,287,288,288,116,116,292,292,292,292,292,292,292,292,292,292,
-116,287,287,116,116,116,116,116,116,116,116,116,116,116,116,116,
+303,304,305,305,306,303,303,303,303,303,303,303,303,119,303,303,
+303,119,303,303,303,303,303,303,303,303,303,303,303,303,303,303,
+303,303,303,303,303,303,303,303,303,119,303,303,303,303,303,303,
+303,303,303,303,119,303,303,303,303,303,119,119,304,303,305,304,
+305,305,307,305,305,119,304,305,305,119,305,305,304,304,119,119,
+119,119,119,119,119,307,307,119,119,119,119,119,119,119,303,119,
+303,303,304,304,119,119,308,308,308,308,308,308,308,308,308,308,
+119,303,303,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 26 */
-293,293,294,294,116,295,295,295,295,295,295,295,295,116,295,295,
-295,116,295,295,295,295,295,295,295,295,295,295,295,295,295,295,
-295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,
-295,295,295,295,295,295,295,295,295,295,295,293,293,295,296,294,
-294,293,293,293,293,116,294,294,294,116,294,294,294,293,297,298,
-116,116,116,116,295,295,295,296,299,299,299,299,299,299,299,295,
-295,295,293,293,116,116,300,300,300,300,300,300,300,300,300,300,
-299,299,299,299,299,299,299,299,299,298,295,295,295,295,295,295,
+309,309,310,310,119,311,311,311,311,311,311,311,311,119,311,311,
+311,119,311,311,311,311,311,311,311,311,311,311,311,311,311,311,
+311,311,311,311,311,311,311,311,311,311,311,311,311,311,311,311,
+311,311,311,311,311,311,311,311,311,311,311,309,309,311,312,310,
+310,309,309,309,309,119,310,310,310,119,310,310,310,309,313,314,
+119,119,119,119,311,311,311,312,315,315,315,315,315,315,315,311,
+311,311,309,309,119,119,316,316,316,316,316,316,316,316,316,316,
+315,315,315,315,315,315,315,315,315,314,311,311,311,311,311,311,
/* block 27 */
-116,116,301,301,116,302,302,302,302,302,302,302,302,302,302,302,
-302,302,302,302,302,302,302,116,116,116,302,302,302,302,302,302,
-302,302,302,302,302,302,302,302,302,302,302,302,302,302,302,302,
-302,302,116,302,302,302,302,302,302,302,302,302,116,302,116,116,
-302,302,302,302,302,302,302,116,116,116,303,116,116,116,116,304,
-301,301,303,303,303,116,303,116,301,301,301,301,301,301,301,304,
-116,116,116,116,116,116,305,305,305,305,305,305,305,305,305,305,
-116,116,301,301,306,116,116,116,116,116,116,116,116,116,116,116,
+119,119,317,317,119,318,318,318,318,318,318,318,318,318,318,318,
+318,318,318,318,318,318,318,119,119,119,318,318,318,318,318,318,
+318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,
+318,318,119,318,318,318,318,318,318,318,318,318,119,318,119,119,
+318,318,318,318,318,318,318,119,119,119,319,119,119,119,119,320,
+317,317,319,319,319,119,319,119,317,317,317,317,317,317,317,320,
+119,119,119,119,119,119,321,321,321,321,321,321,321,321,321,321,
+119,119,317,317,322,119,119,119,119,119,119,119,119,119,119,119,
/* block 28 */
-116,307,307,307,307,307,307,307,307,307,307,307,307,307,307,307,
-307,307,307,307,307,307,307,307,307,307,307,307,307,307,307,307,
-307,307,307,307,307,307,307,307,307,307,307,307,307,307,307,307,
-307,308,307,309,308,308,308,308,308,308,308,116,116,116,116, 5,
-307,307,307,307,307,307,310,308,308,308,308,308,308,308,308,311,
-312,312,312,312,312,312,312,312,312,312,311,311,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+119,323,323,323,323,323,323,323,323,323,323,323,323,323,323,323,
+323,323,323,323,323,323,323,323,323,323,323,323,323,323,323,323,
+323,323,323,323,323,323,323,323,323,323,323,323,323,323,323,323,
+323,324,323,325,324,324,324,324,324,324,324,119,119,119,119, 6,
+323,323,323,323,323,323,326,324,324,324,324,324,324,324,324,327,
+328,328,328,328,328,328,328,328,328,328,327,327,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 29 */
-116,313,313,116,313,116,116,313,313,116,313,116,116,313,116,116,
-116,116,116,116,313,313,313,313,116,313,313,313,313,313,313,313,
-116,313,313,313,116,313,116,313,116,116,313,313,116,313,313,313,
-313,314,313,315,314,314,314,314,314,314,116,314,314,313,116,116,
-313,313,313,313,313,116,316,116,314,314,314,314,314,314,116,116,
-317,317,317,317,317,317,317,317,317,317,116,116,313,313,313,313,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+119,329,329,119,329,119,119,329,329,119,329,119,119,329,119,119,
+119,119,119,119,329,329,329,329,119,329,329,329,329,329,329,329,
+119,329,329,329,119,329,119,329,119,119,329,329,119,329,329,329,
+329,330,329,331,330,330,330,330,330,330,119,330,330,329,119,119,
+329,329,329,329,329,119,332,119,330,330,330,330,330,330,119,119,
+333,333,333,333,333,333,333,333,333,333,119,119,329,329,329,329,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 30 */
-318,319,319,319,320,320,320,320,320,320,320,320,320,320,320,320,
-320,320,320,319,320,319,319,319,321,321,319,319,319,319,319,319,
-322,322,322,322,322,322,322,322,322,322,323,323,323,323,323,323,
-323,323,323,323,319,321,319,321,319,321,324,325,324,325,326,326,
-318,318,318,318,318,318,318,318,116,318,318,318,318,318,318,318,
-318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,
-318,318,318,318,318,318,318,318,318,318,318,318,318,116,116,116,
-116,321,321,321,321,321,321,321,321,321,321,321,321,321,321,326,
+334,335,335,335,336,336,336,336,336,336,336,336,336,336,336,336,
+336,336,336,335,336,335,335,335,337,337,335,335,335,335,335,335,
+338,338,338,338,338,338,338,338,338,338,339,339,339,339,339,339,
+339,339,339,339,335,337,335,337,335,337,340,341,340,341,342,342,
+334,334,334,334,334,334,334,334,119,334,334,334,334,334,334,334,
+334,334,334,334,334,334,334,334,334,334,334,334,334,334,334,334,
+334,334,334,334,334,334,334,334,334,334,334,334,334,119,119,119,
+119,337,337,337,337,337,337,337,337,337,337,337,337,337,337,342,
/* block 31 */
-321,321,321,321,321,320,321,321,318,318,318,318,318,321,321,321,
-321,321,321,321,321,321,321,321,116,321,321,321,321,321,321,321,
-321,321,321,321,321,321,321,321,321,321,321,321,321,321,321,321,
-321,321,321,321,321,321,321,321,321,321,321,321,321,116,319,319,
-319,319,319,319,319,319,321,319,319,319,319,319,319,116,319,319,
-320,320,320,320,320, 19, 19, 19, 19,320,320,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+337,337,337,337,337,336,337,337,334,334,334,334,334,337,337,337,
+337,337,337,337,337,337,337,337,119,337,337,337,337,337,337,337,
+337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,
+337,337,337,337,337,337,337,337,337,337,337,337,337,119,335,335,
+335,335,335,335,335,335,337,335,335,335,335,335,335,119,335,335,
+336,336,336,336,336, 20, 20, 20, 20,336,336,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 32 */
-327,327,327,327,327,327,327,327,327,327,327,327,327,327,327,327,
-327,327,327,327,327,327,327,327,327,327,327,327,327,327,327,327,
-327,327,327,327,327,327,327,327,327,327,327,328,328,329,329,329,
-329,330,329,329,329,329,329,329,328,329,329,330,330,329,329,327,
-331,331,331,331,331,331,331,331,331,331,332,332,332,332,332,332,
-327,327,327,327,327,327,330,330,329,329,327,327,327,327,329,329,
-329,327,328,328,328,327,327,328,328,328,328,328,328,328,327,327,
-327,329,329,329,329,327,327,327,327,327,327,327,327,327,327,327,
+343,343,343,343,343,343,343,343,343,343,343,343,343,343,343,343,
+343,343,343,343,343,343,343,343,343,343,343,343,343,343,343,343,
+343,343,343,343,343,343,343,343,343,343,343,344,344,345,345,345,
+345,346,345,345,345,345,345,345,344,345,345,346,346,345,345,343,
+347,347,347,347,347,347,347,347,347,347,348,348,348,348,348,348,
+343,343,343,343,343,343,346,346,345,345,343,343,343,343,345,345,
+345,343,344,344,344,343,343,344,344,344,344,344,344,344,343,343,
+343,345,345,345,345,343,343,343,343,343,343,343,343,343,343,343,
/* block 33 */
-327,327,329,328,330,329,329,328,328,328,328,328,328,329,327,328,
-331,331,331,331,331,331,331,331,331,331,328,328,328,329,333,333,
-334,334,334,334,334,334,334,334,334,334,334,334,334,334,334,334,
-334,334,334,334,334,334,334,334,334,334,334,334,334,334,334,334,
-334,334,334,334,334,334,116,334,116,116,116,116,116,334,116,116,
-335,335,335,335,335,335,335,335,335,335,335,335,335,335,335,335,
-335,335,335,335,335,335,335,335,335,335,335,335,335,335,335,335,
-335,335,335,335,335,335,335,335,335,335,335, 4,336,335,335,335,
+343,343,345,344,346,345,345,344,344,344,344,344,344,345,343,344,
+349,349,349,349,349,349,349,349,349,349,344,344,344,345,350,350,
+351,351,351,351,351,351,351,351,351,351,351,351,351,351,351,351,
+351,351,351,351,351,351,351,351,351,351,351,351,351,351,351,351,
+351,351,351,351,351,351,119,351,119,119,119,119,119,351,119,119,
+352,352,352,352,352,352,352,352,352,352,352,352,352,352,352,352,
+352,352,352,352,352,352,352,352,352,352,352,352,352,352,352,352,
+352,352,352,352,352,352,352,352,352,352,352,353,354,352,352,352,
/* block 34 */
-337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,
-337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,
-337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,
-337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,
-337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,
-337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,
-338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,
-338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,
+355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,
+355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,
+355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,
+355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,
+355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,
+355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,
+356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,
+356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,
/* block 35 */
-338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,
-338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,
-338,338,338,338,338,338,338,338,339,339,339,339,339,339,339,339,
-339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,
-339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,
-339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,
-339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,
-339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,
+356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,
+356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,
+356,356,356,356,356,356,356,356,357,357,357,357,357,357,357,357,
+357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,
+357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,
+357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,
+357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,
+357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,
/* block 36 */
-340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,
-340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,
-340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,
-340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,
-340,340,340,340,340,340,340,340,340,116,340,340,340,340,116,116,
-340,340,340,340,340,340,340,116,340,116,340,340,340,340,116,116,
-340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,
-340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,
+358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,
+358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,
+358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,
+358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,
+358,358,358,358,358,358,358,358,358,119,358,358,358,358,119,119,
+358,358,358,358,358,358,358,119,358,119,358,358,358,358,119,119,
+358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,
+358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,
/* block 37 */
-340,340,340,340,340,340,340,340,340,116,340,340,340,340,116,116,
-340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,
-340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,
-340,116,340,340,340,340,116,116,340,340,340,340,340,340,340,116,
-340,116,340,340,340,340,116,116,340,340,340,340,340,340,340,340,
-340,340,340,340,340,340,340,116,340,340,340,340,340,340,340,340,
-340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,
-340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,
+358,358,358,358,358,358,358,358,358,119,358,358,358,358,119,119,
+358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,
+358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,
+358,119,358,358,358,358,119,119,358,358,358,358,358,358,358,119,
+358,119,358,358,358,358,119,119,358,358,358,358,358,358,358,358,
+358,358,358,358,358,358,358,119,358,358,358,358,358,358,358,358,
+358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,
+358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,
/* block 38 */
-340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,
-340,116,340,340,340,340,116,116,340,340,340,340,340,340,340,340,
-340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,
-340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,
-340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,
-340,340,340,340,340,340,340,340,340,340,340,116,116,341,341,341,
-342,342,342,342,342,342,342,342,342,343,343,343,343,343,343,343,
-343,343,343,343,343,343,343,343,343,343,343,343,343,116,116,116,
+358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,
+358,119,358,358,358,358,119,119,358,358,358,358,358,358,358,358,
+358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,
+358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,
+358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,
+358,358,358,358,358,358,358,358,358,358,358,119,119,359,359,359,
+360,360,360,360,360,360,360,360,360,361,361,361,361,361,361,361,
+361,361,361,361,361,361,361,361,361,361,361,361,361,119,119,119,
/* block 39 */
-340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,
-344,344,344,344,344,344,344,344,344,344,116,116,116,116,116,116,
-345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,
-345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,
-345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,
-345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,
-345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,
-346,346,346,346,346,346,116,116,347,347,347,347,347,347,116,116,
+358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,
+362,362,362,362,362,362,362,362,362,362,119,119,119,119,119,119,
+363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,
+363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,
+363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,
+363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,
+363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,
+364,364,364,364,364,364,119,119,365,365,365,365,365,365,119,119,
/* block 40 */
-348,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
+366,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
/* block 41 */
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
/* block 42 */
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
-349,349,349,349,349,349,349,349,349,349,349,349,349,350,350,349,
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
+367,367,367,367,367,367,367,367,367,367,367,367,367,368,368,367,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
/* block 43 */
-351,352,352,352,352,352,352,352,352,352,352,352,352,352,352,352,
-352,352,352,352,352,352,352,352,352,352,352,353,354,116,116,116,
-355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,
-355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,
-355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,
-355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,
-355,355,355,355,355,355,355,355,355,355,355, 4, 4, 4,356,356,
-356,355,355,355,355,355,355,355,355,116,116,116,116,116,116,116,
+369,370,370,370,370,370,370,370,370,370,370,370,370,370,370,370,
+370,370,370,370,370,370,370,370,370,370,370,371,372,119,119,119,
+373,373,373,373,373,373,373,373,373,373,373,373,373,373,373,373,
+373,373,373,373,373,373,373,373,373,373,373,373,373,373,373,373,
+373,373,373,373,373,373,373,373,373,373,373,373,373,373,373,373,
+373,373,373,373,373,373,373,373,373,373,373,373,373,373,373,373,
+373,373,373,373,373,373,373,373,373,373,373, 5, 5, 5,374,374,
+374,373,373,373,373,373,373,373,373,119,119,119,119,119,119,119,
/* block 44 */
-357,357,357,357,357,357,357,357,357,357,357,357,357,116,357,357,
-357,357,358,358,358,116,116,116,116,116,116,116,116,116,116,116,
-359,359,359,359,359,359,359,359,359,359,359,359,359,359,359,359,
-359,359,360,360,360, 4, 4,116,116,116,116,116,116,116,116,116,
-361,361,361,361,361,361,361,361,361,361,361,361,361,361,361,361,
-361,361,362,362,116,116,116,116,116,116,116,116,116,116,116,116,
-363,363,363,363,363,363,363,363,363,363,363,363,363,116,363,363,
-363,116,364,364,116,116,116,116,116,116,116,116,116,116,116,116,
+375,375,375,375,375,375,375,375,375,375,375,375,375,119,375,375,
+375,375,376,376,376,119,119,119,119,119,119,119,119,119,119,119,
+377,377,377,377,377,377,377,377,377,377,377,377,377,377,377,377,
+377,377,378,378,378,379,379,119,119,119,119,119,119,119,119,119,
+380,380,380,380,380,380,380,380,380,380,380,380,380,380,380,380,
+380,380,381,381,119,119,119,119,119,119,119,119,119,119,119,119,
+382,382,382,382,382,382,382,382,382,382,382,382,382,119,382,382,
+382,119,383,383,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 45 */
-365,365,365,365,365,365,365,365,365,365,365,365,365,365,365,365,
-365,365,365,365,365,365,365,365,365,365,365,365,365,365,365,365,
-365,365,365,365,365,365,365,365,365,365,365,365,365,365,365,365,
-365,365,365,365,366,366,367,366,366,366,366,366,366,366,367,367,
-367,367,367,367,367,367,366,367,367,366,366,366,366,366,366,366,
-366,366,366,366,368,368,368,369,368,368,368,370,365,366,116,116,
-371,371,371,371,371,371,371,371,371,371,116,116,116,116,116,116,
-372,372,372,372,372,372,372,372,372,372,116,116,116,116,116,116,
+384,384,384,384,384,384,384,384,384,384,384,384,384,384,384,384,
+384,384,384,384,384,384,384,384,384,384,384,384,384,384,384,384,
+384,384,384,384,384,384,384,384,384,384,384,384,384,384,384,384,
+384,384,384,384,385,385,386,385,385,385,385,385,385,385,386,386,
+386,386,386,386,386,386,385,386,386,385,385,385,385,385,385,385,
+385,385,385,385,387,387,387,388,387,387,387,389,384,385,119,119,
+390,390,390,390,390,390,390,390,390,390,119,119,119,119,119,119,
+391,391,391,391,391,391,391,391,391,391,119,119,119,119,119,119,
/* block 46 */
-373,373, 4, 4,373, 4,374,373,373,373,373,375,375,375,376,116,
-377,377,377,377,377,377,377,377,377,377,116,116,116,116,116,116,
-378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,
-378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,
-378,378,378,379,378,378,378,378,378,378,378,378,378,378,378,378,
-378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,
-378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,
-378,378,378,378,378,378,378,378,378,116,116,116,116,116,116,116,
+392,392,393,393,392,393,394,392,392,392,392,395,395,395,396,119,
+397,397,397,397,397,397,397,397,397,397,119,119,119,119,119,119,
+398,398,398,398,398,398,398,398,398,398,398,398,398,398,398,398,
+398,398,398,398,398,398,398,398,398,398,398,398,398,398,398,398,
+398,398,398,399,398,398,398,398,398,398,398,398,398,398,398,398,
+398,398,398,398,398,398,398,398,398,398,398,398,398,398,398,398,
+398,398,398,398,398,398,398,398,398,398,398,398,398,398,398,398,
+398,398,398,398,398,398,398,398,398,119,119,119,119,119,119,119,
/* block 47 */
-378,378,378,378,378,375,375,378,378,378,378,378,378,378,378,378,
-378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,
-378,378,378,378,378,378,378,378,378,375,378,116,116,116,116,116,
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
-349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,
-349,349,349,349,349,349,116,116,116,116,116,116,116,116,116,116,
+398,398,398,398,398,395,395,398,398,398,398,398,398,398,398,398,
+398,398,398,398,398,398,398,398,398,398,398,398,398,398,398,398,
+398,398,398,398,398,398,398,398,398,395,398,119,119,119,119,119,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
+367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
+367,367,367,367,367,367,119,119,119,119,119,119,119,119,119,119,
/* block 48 */
-380,380,380,380,380,380,380,380,380,380,380,380,380,380,380,380,
-380,380,380,380,380,380,380,380,380,380,380,380,380,380,380,116,
-381,381,381,382,382,382,382,381,381,382,382,382,116,116,116,116,
-382,382,381,382,382,382,382,382,382,381,381,381,116,116,116,116,
-383,116,116,116,384,384,385,385,385,385,385,385,385,385,385,385,
-386,386,386,386,386,386,386,386,386,386,386,386,386,386,386,386,
-386,386,386,386,386,386,386,386,386,386,386,386,386,386,116,116,
-386,386,386,386,386,116,116,116,116,116,116,116,116,116,116,116,
+400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,
+400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,119,
+401,401,401,402,402,402,402,401,401,402,402,402,119,119,119,119,
+402,402,401,402,402,402,402,402,402,401,401,401,119,119,119,119,
+403,119,119,119,404,404,405,405,405,405,405,405,405,405,405,405,
+406,406,406,406,406,406,406,406,406,406,406,406,406,406,406,406,
+406,406,406,406,406,406,406,406,406,406,406,406,406,406,119,119,
+406,406,406,406,406,119,119,119,119,119,119,119,119,119,119,119,
/* block 49 */
-387,387,387,387,387,387,387,387,387,387,387,387,387,387,387,387,
-387,387,387,387,387,387,387,387,387,387,387,387,387,387,387,387,
-387,387,387,387,387,387,387,387,387,387,387,387,116,116,116,116,
-387,387,387,387,387,387,387,387,387,387,387,387,387,387,387,387,
-387,387,387,387,387,387,387,387,387,387,116,116,116,116,116,116,
-388,388,388,388,388,388,388,388,388,388,389,116,116,116,390,390,
-391,391,391,391,391,391,391,391,391,391,391,391,391,391,391,391,
-391,391,391,391,391,391,391,391,391,391,391,391,391,391,391,391,
+407,407,407,407,407,407,407,407,407,407,407,407,407,407,407,407,
+407,407,407,407,407,407,407,407,407,407,407,407,407,407,407,407,
+407,407,407,407,407,407,407,407,407,407,407,407,119,119,119,119,
+407,407,407,407,407,407,407,407,407,407,407,407,407,407,407,407,
+407,407,407,407,407,407,407,407,407,407,119,119,119,119,119,119,
+408,408,408,408,408,408,408,408,408,408,409,119,119,119,410,410,
+411,411,411,411,411,411,411,411,411,411,411,411,411,411,411,411,
+411,411,411,411,411,411,411,411,411,411,411,411,411,411,411,411,
/* block 50 */
-392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,
-392,392,392,392,392,392,392,393,393,394,394,393,116,116,395,395,
-396,396,396,396,396,396,396,396,396,396,396,396,396,396,396,396,
-396,396,396,396,396,396,396,396,396,396,396,396,396,396,396,396,
-396,396,396,396,396,396,396,396,396,396,396,396,396,396,396,396,
-396,396,396,396,396,397,398,397,398,398,398,398,398,398,398,116,
-398,399,398,399,399,398,398,398,398,398,398,398,398,397,397,397,
-397,397,397,398,398,398,398,398,398,398,398,398,398,116,116,398,
+412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,
+412,412,412,412,412,412,412,413,413,414,414,413,119,119,415,415,
+416,416,416,416,416,416,416,416,416,416,416,416,416,416,416,416,
+416,416,416,416,416,416,416,416,416,416,416,416,416,416,416,416,
+416,416,416,416,416,416,416,416,416,416,416,416,416,416,416,416,
+416,416,416,416,416,417,418,417,418,418,418,418,418,418,418,119,
+418,419,418,419,419,418,418,418,418,418,418,418,418,417,417,417,
+417,417,417,418,418,418,418,418,418,418,418,418,418,119,119,418,
/* block 51 */
-400,400,400,400,400,400,400,400,400,400,116,116,116,116,116,116,
-400,400,400,400,400,400,400,400,400,400,116,116,116,116,116,116,
-401,401,401,401,401,401,401,402,401,401,401,401,401,401,116,116,
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,403,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+420,420,420,420,420,420,420,420,420,420,119,119,119,119,119,119,
+420,420,420,420,420,420,420,420,420,420,119,119,119,119,119,119,
+421,421,421,421,421,421,421,422,421,421,421,421,421,421,119,119,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,423,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 52 */
-404,404,404,404,405,406,406,406,406,406,406,406,406,406,406,406,
-406,406,406,406,406,406,406,406,406,406,406,406,406,406,406,406,
-406,406,406,406,406,406,406,406,406,406,406,406,406,406,406,406,
-406,406,406,406,404,405,404,404,404,404,404,405,404,405,405,405,
-405,405,404,405,405,406,406,406,406,406,406,406,116,116,116,116,
-407,407,407,407,407,407,407,407,407,407,408,408,408,408,408,408,
-408,409,409,409,409,409,409,409,409,409,409,404,404,404,404,404,
-404,404,404,404,409,409,409,409,409,409,409,409,409,116,116,116,
+424,424,424,424,425,426,426,426,426,426,426,426,426,426,426,426,
+426,426,426,426,426,426,426,426,426,426,426,426,426,426,426,426,
+426,426,426,426,426,426,426,426,426,426,426,426,426,426,426,426,
+426,426,426,426,424,425,424,424,424,424,424,425,424,425,425,425,
+425,425,424,425,425,426,426,426,426,426,426,426,119,119,119,119,
+427,427,427,427,427,427,427,427,427,427,428,428,428,428,428,428,
+428,429,429,429,429,429,429,429,429,429,429,424,424,424,424,424,
+424,424,424,424,429,429,429,429,429,429,429,429,429,119,119,119,
/* block 53 */
-410,410,411,412,412,412,412,412,412,412,412,412,412,412,412,412,
-412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,
-412,411,410,410,410,410,411,411,410,410,411,410,410,410,412,412,
-413,413,413,413,413,413,413,413,413,413,412,412,412,412,412,412,
-414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,
-414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,
-414,414,414,414,414,414,415,416,415,415,416,416,416,415,416,415,
-415,415,416,416,116,116,116,116,116,116,116,116,417,417,417,417,
+430,430,431,432,432,432,432,432,432,432,432,432,432,432,432,432,
+432,432,432,432,432,432,432,432,432,432,432,432,432,432,432,432,
+432,431,430,430,430,430,431,431,430,430,431,430,430,430,432,432,
+433,433,433,433,433,433,433,433,433,433,432,432,432,432,432,432,
+434,434,434,434,434,434,434,434,434,434,434,434,434,434,434,434,
+434,434,434,434,434,434,434,434,434,434,434,434,434,434,434,434,
+434,434,434,434,434,434,435,436,435,435,436,436,436,435,436,435,
+435,435,436,436,119,119,119,119,119,119,119,119,437,437,437,437,
/* block 54 */
-418,418,418,418,418,418,418,418,418,418,418,418,418,418,418,418,
-418,418,418,418,418,418,418,418,418,418,418,418,418,418,418,418,
-418,418,418,418,419,419,419,419,419,419,419,419,420,420,420,420,
-420,420,420,420,419,419,420,420,116,116,116,421,421,421,421,421,
-422,422,422,422,422,422,422,422,422,422,116,116,116,418,418,418,
-423,423,423,423,423,423,423,423,423,423,424,424,424,424,424,424,
-424,424,424,424,424,424,424,424,424,424,424,424,424,424,424,424,
-424,424,424,424,424,424,424,424,425,425,425,425,425,425,426,426,
+438,438,438,438,438,438,438,438,438,438,438,438,438,438,438,438,
+438,438,438,438,438,438,438,438,438,438,438,438,438,438,438,438,
+438,438,438,438,439,439,439,439,439,439,439,439,440,440,440,440,
+440,440,440,440,439,439,440,440,119,119,119,441,441,441,441,441,
+442,442,442,442,442,442,442,442,442,442,119,119,119,438,438,438,
+443,443,443,443,443,443,443,443,443,443,444,444,444,444,444,444,
+444,444,444,444,444,444,444,444,444,444,444,444,444,444,444,444,
+444,444,444,444,444,444,444,444,445,445,445,445,445,445,446,446,
/* block 55 */
-427,428,429,430,431,432,433,434,435,116,116,116,116,116,116,116,
-436,436,436,436,436,436,436,436,436,436,436,436,436,436,436,436,
-436,436,436,436,436,436,436,436,436,436,436,436,436,436,436,436,
-436,436,436,436,436,436,436,436,436,436,436,116,116,436,436,436,
-437,437,437,437,437,437,437,437,116,116,116,116,116,116,116,116,
-111,111,111, 4,111,111,111,111,111,111,111,111,111,111,111,111,
-111,438,111,111,111,111,111,111,111,439,439,439,439,111,439,439,
-439,439,438,438,111,439,439,438,111,111,116,116,116,116,116,116,
+447,448,449,450,451,452,453,454,455,119,119,119,119,119,119,119,
+456,456,456,456,456,456,456,456,456,456,456,456,456,456,456,456,
+456,456,456,456,456,456,456,456,456,456,456,456,456,456,456,456,
+456,456,456,456,456,456,456,456,456,456,456,119,119,456,456,456,
+457,457,457,457,457,457,457,457,119,119,119,119,119,119,119,119,
+458,459,458,460,459,461,461,462,461,462,463,459,462,462,459,459,
+462,464,459,459,459,459,459,459,459,465,466,465,465,461,465,465,
+465,465,467,467,468,466,466,469,470,470,119,119,119,119,119,119,
/* block 56 */
- 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
- 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
- 34, 34, 34, 34, 34, 34,124,124,124,124,124,440,108,108,108,108,
-108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,
-108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,
-108,108,108,108,108,108,108,108,108,108,108,108,108,117,117,117,
-117,117,108,108,108,108,117,117,117,117,117, 34, 34, 34, 34, 34,
- 34, 34, 34, 34, 34, 34, 34, 34,441,442, 34, 34, 34,443, 34, 34,
+ 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
+ 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
+ 35, 35, 35, 35, 35, 35,127,127,127,127,127,471,109,109,109,109,
+109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,
+109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,
+109,109,109,109,109,109,109,109,109,109,109,109,109,120,120,120,
+120,120,109,109,109,109,120,120,120,120,120, 35, 35, 35, 35, 35,
+ 35, 35, 35, 35, 35, 35, 35, 35,472,473, 35, 35, 35,474, 35, 35,
/* block 57 */
- 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
- 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,108,108,108,108,108,
-108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,
-108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,117,
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
-111,111,111,111,111,111,111,111,111,111,116,111,111,111,111,111,
+ 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
+ 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,109,109,109,109,109,
+109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,
+109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,120,
+113,113,112,112,112,112,112,112,112,112,112,112,112,112,112,112,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,
+112,112,112,112,112,112,112,112,112,112,119,112,112,112,112,112,
/* block 58 */
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
-444,445, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+475,476, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
/* block 59 */
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 31, 32, 31, 32, 31, 32, 34, 34, 34, 34, 34,446, 34, 34,447, 34,
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 32, 33, 32, 33, 32, 33, 35, 35, 35, 35, 35,477, 35, 35,478, 35,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
/* block 60 */
-448,448,448,448,448,448,448,448,449,449,449,449,449,449,449,449,
-448,448,448,448,448,448,116,116,449,449,449,449,449,449,116,116,
-448,448,448,448,448,448,448,448,449,449,449,449,449,449,449,449,
-448,448,448,448,448,448,448,448,449,449,449,449,449,449,449,449,
-448,448,448,448,448,448,116,116,449,449,449,449,449,449,116,116,
-124,448,124,448,124,448,124,448,116,449,116,449,116,449,116,449,
-448,448,448,448,448,448,448,448,449,449,449,449,449,449,449,449,
-450,450,451,451,451,451,452,452,453,453,454,454,455,455,116,116,
+479,479,479,479,479,479,479,479,480,480,480,480,480,480,480,480,
+479,479,479,479,479,479,119,119,480,480,480,480,480,480,119,119,
+479,479,479,479,479,479,479,479,480,480,480,480,480,480,480,480,
+479,479,479,479,479,479,479,479,480,480,480,480,480,480,480,480,
+479,479,479,479,479,479,119,119,480,480,480,480,480,480,119,119,
+127,479,127,479,127,479,127,479,119,480,119,480,119,480,119,480,
+479,479,479,479,479,479,479,479,480,480,480,480,480,480,480,480,
+481,481,482,482,482,482,483,483,484,484,485,485,486,486,119,119,
/* block 61 */
-448,448,448,448,448,448,448,448,456,456,456,456,456,456,456,456,
-448,448,448,448,448,448,448,448,456,456,456,456,456,456,456,456,
-448,448,448,448,448,448,448,448,456,456,456,456,456,456,456,456,
-448,448,124,457,124,116,124,124,449,449,458,458,459,115,460,115,
-115,115,124,457,124,116,124,124,461,461,461,461,459,115,115,115,
-448,448,124,124,116,116,124,124,449,449,462,462,116,115,115,115,
-448,448,124,124,124,165,124,124,449,449,463,463,170,115,115,115,
-116,116,124,457,124,116,124,124,464,464,465,465,459,115,115,116,
+479,479,479,479,479,479,479,479,487,487,487,487,487,487,487,487,
+479,479,479,479,479,479,479,479,487,487,487,487,487,487,487,487,
+479,479,479,479,479,479,479,479,487,487,487,487,487,487,487,487,
+479,479,127,488,127,119,127,127,480,480,489,489,490,118,491,118,
+118,118,127,488,127,119,127,127,492,492,492,492,490,118,118,118,
+479,479,127,127,119,119,127,127,480,480,493,493,119,118,118,118,
+479,479,127,127,127,168,127,127,480,480,494,494,173,118,118,118,
+119,119,127,488,127,119,127,127,495,495,496,496,490,118,118,119,
/* block 62 */
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 23,466,467, 23, 23,
- 9, 9, 9, 9, 9, 9, 4, 4, 22, 26, 6, 22, 22, 26, 6, 22,
- 4, 4, 4, 4, 4, 4, 4, 4,468,469, 23, 23, 23, 23, 23, 3,
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 22, 26, 4,470, 4, 4, 15,
- 15, 4, 4, 4, 8, 6, 7, 4, 4,470, 4, 4, 4, 4, 4, 4,
- 4, 4, 8, 4, 15, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3,
- 23, 23, 23, 23, 23,471, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
- 24,108,116,116, 24, 24, 24, 24, 24, 24, 8, 8, 8, 6, 7,108,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 24,497,498, 24, 24,
+ 10, 10, 10, 10, 10, 10, 5, 5, 23, 27, 7, 23, 23, 27, 7, 23,
+ 5, 5, 5, 5, 5, 5, 5, 5,499,500, 24, 24, 24, 24, 24, 4,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 23, 27, 5,501, 5, 5, 16,
+ 16, 5, 5, 5, 9, 7, 8, 5, 5,501, 5, 5, 5, 5, 5, 5,
+ 5, 5, 9, 5, 16, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4,
+ 24, 24, 24, 24, 24,502, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 25,109,119,119, 25, 25, 25, 25, 25, 25, 9, 9, 9, 7, 8,109,
/* block 63 */
- 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 8, 8, 8, 6, 7,116,
-108,108,108,108,108,108,108,108,108,108,108,108,108,116,116,116,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-111,111,111,111,111,111,111,111,111,111,111,111,111,403,403,403,
-403,111,403,403,403,111,111,111,111,111,111,111,111,111,111,111,
-111,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 9, 9, 9, 7, 8,119,
+109,109,109,109,109,109,109,109,109,109,109,109,109,119,119,119,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+112,112,112,112,112,112,112,112,112,112,112,112,112,423,423,423,
+423,112,423,423,423,112,112,112,112,112,112,112,112,112,112,112,
+503,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 64 */
- 19, 19,472, 19, 19, 19, 19,472, 19, 19,473,472,472,472,473,473,
-472,472,472,473, 19,472, 19, 19, 8,472,472,472,472,472, 19, 19,
- 19, 19, 20, 19,472, 19,474, 19,472, 19,475,476,472,472, 19,473,
-472,472,477,472,473,439,439,439,439,478, 19, 19,473,473,472,472,
- 8, 8, 8, 8, 8,472,473,473,473,473, 19, 8, 19, 19,479, 19,
- 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-480,480,480,480,480,480,480,480,480,480,480,480,480,480,480,480,
-481,481,481,481,481,481,481,481,481,481,481,481,481,481,481,481,
+ 20, 20,504, 20, 20, 20, 20,504, 20, 20,505,504,504,504,505,505,
+504,504,504,505, 20,504, 20, 20, 9,504,504,504,504,504, 20, 20,
+ 20, 20, 21, 20,504, 20,506, 20,504, 20,507,508,504,504, 20,505,
+504,504,509,504,505,510,510,510,510,511, 20, 20,505,505,504,504,
+ 9, 9, 9, 9, 9,504,505,505,505,505, 20, 9, 20, 20,512, 20,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+513,513,513,513,513,513,513,513,513,513,513,513,513,513,513,513,
+514,514,514,514,514,514,514,514,514,514,514,514,514,514,514,514,
/* block 65 */
-482,482,482, 31, 32,482,482,482,482, 24, 19, 19,116,116,116,116,
- 8, 8, 8, 8,483, 20, 20, 20, 20, 20, 8, 8, 19, 19, 19, 19,
- 8, 19, 19, 8, 19, 19, 8, 19, 19, 20, 20, 19, 19, 19, 8, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 8, 8,
- 19, 19, 8, 19, 8, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+515,515,515, 32, 33,515,515,515,515, 25, 20, 20,119,119,119,119,
+ 9, 9, 9, 9,516, 21, 21, 21, 21, 21, 9, 9, 20, 20, 20, 20,
+ 9, 20, 20, 9, 20, 20, 9, 20, 20, 21, 21, 20, 20, 20, 9, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 9, 9,
+ 20, 20, 9, 20, 9, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
/* block 66 */
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
/* block 67 */
- 19, 19, 19, 19, 19, 19, 19, 19, 6, 7, 6, 7, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 19, 19, 19, 19,
- 8, 8, 19, 19, 19, 19, 19, 19, 20, 6, 7, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 8, 19, 19, 19,
+ 20, 20, 20, 20, 20, 20, 20, 20, 7, 8, 7, 8, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 20, 20, 20, 20,
+ 9, 9, 20, 20, 20, 20, 20, 20, 21, 7, 8, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 9, 20, 20, 20,
/* block 68 */
- 19, 19, 19, 19, 19, 19, 19, 19, 20, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 8, 8, 8, 8,
- 8, 8, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 19, 19, 19, 19, 20, 20, 20, 19, 19, 19, 19, 19,
+ 20, 20, 20, 20, 20, 20, 20, 20, 21, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 9, 9, 9, 9,
+ 9, 9, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 20, 20, 20, 20, 21, 21, 21, 20, 20, 20, 20, 20,
/* block 69 */
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
- 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
- 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
/* block 70 */
- 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
- 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19,484,484,484,484,484,484,484,484,484,484,
-484,484,485,484,484,484,484,484,484,484,484,484,484,484,484,484,
-486,486,486,486,486,486,486,486,486,486,486,486,486,486,486,486,
-486,486,486,486,486,486,486,486,486,486, 24, 24, 24, 24, 24, 24,
- 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20,517,517,517,517,517,517,517,517,517,517,
+517,517,518,517,517,517,517,517,517,517,517,517,517,517,517,517,
+519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,
+519,519,519,519,519,519,519,519,519,519, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
/* block 71 */
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
-
-/* block 72 */
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 20, 8, 19, 19, 19, 19, 19, 19, 19, 19,
- 20, 8, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 8, 8, 8,483,483,483,483, 8,
-
-/* block 73 */
- 20, 20, 20, 20, 20, 20, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,483,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
-
-/* block 74 */
- 20, 20, 20, 20, 20, 20, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+
+/* block 72 */
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 21, 9, 20, 20, 20, 20, 20, 20, 20, 20,
+ 21, 9, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 9, 9, 9,516,516,516,516, 9,
+
+/* block 73 */
+ 21, 21, 21, 21, 21, 21, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,516,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+
+/* block 74 */
+ 21, 21, 21, 21, 21, 21, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
/* block 75 */
- 20, 20, 20, 20, 20, 20, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 19, 20, 19, 20, 19, 19, 19, 19, 19, 19, 20, 19, 19,
- 19, 20, 19, 19, 19, 19, 19, 19, 20, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 20, 20, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 20, 19, 19, 20, 19, 19, 19, 19, 20, 19, 20, 19,
- 19, 19, 19, 20, 20, 20, 19, 20, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 20, 20, 20, 20, 20, 6, 7, 6, 7, 6, 7, 6, 7,
- 6, 7, 6, 7, 6, 7, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 21, 21, 21, 21, 21, 21, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 20, 21, 20, 21, 20, 20, 20, 20, 20, 20, 21, 20, 20,
+ 20, 21, 20, 20, 20, 20, 20, 20, 21, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 21, 21, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 21, 20, 20, 21, 20, 20, 20, 20, 21, 20, 21, 20,
+ 20, 20, 20, 21, 21, 21, 20, 21, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 21, 21, 21, 21, 21, 7, 8, 7, 8, 7, 8, 7, 8,
+ 7, 8, 7, 8, 7, 8, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
/* block 76 */
- 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
- 24, 24, 24, 24, 19, 20, 20, 20, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 20, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 20, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20,
- 8, 8, 8, 8, 8, 6, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 20, 21, 21, 21, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 21, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 21, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21,
+ 9, 9, 9, 9, 9, 7, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
/* block 77 */
-487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,
-487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,
-487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,
-487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,
-487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,
-487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,
-487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,
-487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,
+520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,
+520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,
+520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,
+520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,
+520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,
+520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,
+520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,
+520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,
/* block 78 */
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8,483,483, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9,516,516, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
/* block 79 */
- 8, 8, 8, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6,
- 7, 6, 7, 6, 7, 6, 7, 6, 7, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 6, 7, 6, 7, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 6, 7, 8, 8,
+ 9, 9, 9, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7,
+ 8, 7, 8, 7, 8, 7, 8, 7, 8, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 7, 8, 7, 8, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8, 9, 9,
/* block 80 */
- 19, 19, 19, 19, 19, 20, 20, 20, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 19, 19, 8, 8, 8, 8, 8, 8, 19, 19, 19,
- 20, 19, 19, 19, 19, 20, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19,116,116, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 20, 20, 20, 20, 20, 21, 21, 21, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 20, 20, 9, 9, 9, 9, 9, 9, 20, 20, 20,
+ 21, 20, 20, 20, 20, 21, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20,119,119, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
/* block 81 */
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19,116,116, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19,116, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,116,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20,119,119, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20,119, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,119,
/* block 82 */
-488,488,488,488,488,488,488,488,488,488,488,488,488,488,488,488,
-488,488,488,488,488,488,488,488,488,488,488,488,488,488,488,488,
-488,488,488,488,488,488,488,488,488,488,488,488,488,488,488,116,
-489,489,489,489,489,489,489,489,489,489,489,489,489,489,489,489,
-489,489,489,489,489,489,489,489,489,489,489,489,489,489,489,489,
-489,489,489,489,489,489,489,489,489,489,489,489,489,489,489,116,
- 31, 32,490,491,492,493,494, 31, 32, 31, 32, 31, 32,495,496,497,
-498, 34, 31, 32, 34, 31, 32, 34, 34, 34, 34, 34,108,108,499,499,
+521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,
+521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,
+521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,119,
+522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,
+522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,
+522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,119,
+ 32, 33,523,524,525,526,527, 32, 33, 32, 33, 32, 33,528,529,530,
+531, 35, 32, 33, 35, 32, 33, 35, 35, 35, 35, 35,109,109,532,532,
/* block 83 */
-161,162,161,162,161,162,161,162,161,162,161,162,161,162,161,162,
-161,162,161,162,161,162,161,162,161,162,161,162,161,162,161,162,
-161,162,161,162,161,162,161,162,161,162,161,162,161,162,161,162,
-161,162,161,162,161,162,161,162,161,162,161,162,161,162,161,162,
-161,162,161,162,161,162,161,162,161,162,161,162,161,162,161,162,
-161,162,161,162,161,162,161,162,161,162,161,162,161,162,161,162,
-161,162,161,162,500,501,501,501,501,501,501,161,162,161,162,502,
-502,502,161,162,116,116,116,116,116,503,503,503,503,504,503,503,
+164,165,164,165,164,165,164,165,164,165,164,165,164,165,164,165,
+164,165,164,165,164,165,164,165,164,165,164,165,164,165,164,165,
+164,165,164,165,164,165,164,165,164,165,164,165,164,165,164,165,
+164,165,164,165,164,165,164,165,164,165,164,165,164,165,164,165,
+164,165,164,165,164,165,164,165,164,165,164,165,164,165,164,165,
+164,165,164,165,164,165,164,165,164,165,164,165,164,165,164,165,
+164,165,164,165,533,534,534,534,534,534,534,164,165,164,165,535,
+535,535,164,165,119,119,119,119,119,536,536,536,536,537,536,536,
/* block 84 */
-505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,
-505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,
-505,505,505,505,505,505,116,505,116,116,116,116,116,505,116,116,
-506,506,506,506,506,506,506,506,506,506,506,506,506,506,506,506,
-506,506,506,506,506,506,506,506,506,506,506,506,506,506,506,506,
-506,506,506,506,506,506,506,506,506,506,506,506,506,506,506,506,
-506,506,506,506,506,506,506,506,116,116,116,116,116,116,116,507,
-508,116,116,116,116,116,116,116,116,116,116,116,116,116,116,509,
+538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,
+538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,
+538,538,538,538,538,538,119,538,119,119,119,119,119,538,119,119,
+539,539,539,539,539,539,539,539,539,539,539,539,539,539,539,539,
+539,539,539,539,539,539,539,539,539,539,539,539,539,539,539,539,
+539,539,539,539,539,539,539,539,539,539,539,539,539,539,539,539,
+539,539,539,539,539,539,539,539,119,119,119,119,119,119,119,540,
+541,119,119,119,119,119,119,119,119,119,119,119,119,119,119,542,
/* block 85 */
-340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,
-340,340,340,340,340,340,340,116,116,116,116,116,116,116,116,116,
-340,340,340,340,340,340,340,116,340,340,340,340,340,340,340,116,
-340,340,340,340,340,340,340,116,340,340,340,340,340,340,340,116,
-340,340,340,340,340,340,340,116,340,340,340,340,340,340,340,116,
-340,340,340,340,340,340,340,116,340,340,340,340,340,340,340,116,
-193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,
-193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,
+358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,
+358,358,358,358,358,358,358,119,119,119,119,119,119,119,119,119,
+358,358,358,358,358,358,358,119,358,358,358,358,358,358,358,119,
+358,358,358,358,358,358,358,119,358,358,358,358,358,358,358,119,
+358,358,358,358,358,358,358,119,358,358,358,358,358,358,358,119,
+358,358,358,358,358,358,358,119,358,358,358,358,358,358,358,119,
+543,543,543,543,543,543,543,543,543,543,543,543,543,543,543,543,
+543,543,543,543,543,543,543,543,543,543,543,543,543,543,543,543,
/* block 86 */
- 4, 4, 22, 26, 22, 26, 4, 4, 4, 22, 26, 4, 22, 26, 4, 4,
- 4, 4, 4, 4, 4, 4, 4, 9, 4, 4, 9, 4, 22, 26, 4, 4,
- 22, 26, 6, 7, 6, 7, 6, 7, 6, 7, 4, 4, 4, 4, 4,109,
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 9, 9, 4, 4, 4, 4,
- 9, 4, 6, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+ 5, 5, 23, 27, 23, 27, 5, 5, 5, 23, 27, 5, 23, 27, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 10, 5, 5, 10, 5, 23, 27, 5, 5,
+ 23, 27, 7, 8, 7, 8, 7, 8, 7, 8, 5, 5, 5, 5, 5,110,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 10, 10, 5, 5, 5, 5,
+ 10, 5, 7,544, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 87 */
-510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,
-510,510,510,510,510,510,510,510,510,510,116,510,510,510,510,510,
-510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,
-510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,
-510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,
-510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,
-510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,
-510,510,510,510,116,116,116,116,116,116,116,116,116,116,116,116,
+545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,
+545,545,545,545,545,545,545,545,545,545,119,545,545,545,545,545,
+545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,
+545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,
+545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,
+545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,
+545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,
+545,545,545,545,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 88 */
-510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,
-510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,
-510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,
-510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,
-510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,
-510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,
-510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,
-510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,
+545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,
+545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,
+545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,
+545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,
+545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,
+545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,
+545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,
+545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,
/* block 89 */
-510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,
-510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,
-510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,
-510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,
-510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,
-510,510,510,510,510,510,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,116,116,116,116,
+545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,
+545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,
+545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,
+545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,
+545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,
+545,545,545,545,545,545,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,119,119,119,119,
/* block 90 */
- 3, 4, 4, 4, 19,511,439,512, 6, 7, 6, 7, 6, 7, 6, 7,
- 6, 7, 19, 19, 6, 7, 6, 7, 6, 7, 6, 7, 9, 6, 7, 7,
- 19,512,512,512,512,512,512,512,512,512,111,111,111,111,513,513,
-514,109,109,109,109,109, 19, 19,512,512,512,511,439,470, 19, 19,
-116,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,
-515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,
-515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,
-515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,
+ 4,546,546,547, 20,548,549,550,551,552,551,552,551,552,551,552,
+551,552, 20,553,551,552,551,552,551,552,551,552,554,555,556,556,
+ 20,550,550,550,550,550,550,550,550,550,557,557,557,557,558,558,
+559,560,560,560,560,560, 20,553,550,550,550,548,561,562,563,563,
+119,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,
+564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,
+564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,
+564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,
/* block 91 */
-515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,
-515,515,515,515,515,515,515,116,116,111,111, 14, 14,516,516,515,
- 9,517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,
-517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,
-517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,
-517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,
-517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,
-517,517,517,517,517,517,517,517,517,517,517, 4,109,518,518,517,
+564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,
+564,564,564,564,564,564,564,119,119,565,565,566,566,567,567,564,
+568,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,
+569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,
+569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,
+569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,
+569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,
+569,569,569,569,569,569,569,569,569,569,569,546,560,570,570,569,
/* block 92 */
-116,116,116,116,116,519,519,519,519,519,519,519,519,519,519,519,
-519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,
-519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,
-116,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,
-520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,
-520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,
-520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,
-520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,
+119,119,119,119,119,571,571,571,571,571,571,571,571,571,571,571,
+571,571,571,571,571,571,571,571,571,571,571,571,571,571,571,571,
+571,571,571,571,571,571,571,571,571,571,571,571,571,571,571,571,
+119,572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,
+572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,
+572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,
+572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,
+572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,
/* block 93 */
-520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,116,
- 19, 19, 24, 24, 24, 24, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
-519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,
-519,519,519,519,519,519,519,519,519,519,519,116,116,116,116,116,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19,116,116,116,116,116,116,116,116,116,116,116,116,
-517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,
+572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,119,
+563,563,573,573,573,573,563,563,563,563,563,563,563,563,563,563,
+571,571,571,571,571,571,571,571,571,571,571,571,571,571,571,571,
+571,571,571,571,571,571,571,571,571,571,571,119,119,119,119,119,
+563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,
+563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,
+563,563,563,563,119,119,119,119,119,119,119,119,119,119,119,119,
+569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,
/* block 94 */
-521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,
-521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,116,
- 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 24, 24, 24, 24, 24, 24, 24, 24,
- 19, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,
-521,521,521,521,521,521,521,521,521,521,521,521,521,521,521, 19,
+574,574,574,574,574,574,574,574,574,574,574,574,574,574,574,574,
+574,574,574,574,574,574,574,574,574,574,574,574,574,574,574,119,
+573,573,573,573,573,573,573,573,573,573,563,563,563,563,563,563,
+563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,
+563,563,563,563,563,563,563,563, 25, 25, 25, 25, 25, 25, 25, 25,
+ 20, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+574,574,574,574,574,574,574,574,574,574,574,574,574,574,574,574,
+574,574,574,574,574,574,574,574,574,574,574,574,574,574,574, 20,
/* block 95 */
- 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 20, 19, 20, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
-522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,
-522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,
-522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,116,
+573,573,573,573,573,573,573,573,573,573,563,563,563,563,563,563,
+563,563,563,563,563,563,563,575,563,575,563,563,563,563,563,563,
+563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,
+563, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+563,563,563,563,563,563,563,563,563,563,563,563, 20, 20, 20, 20,
+576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,
+576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,
+576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,119,
/* block 96 */
-522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,
-522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,
-522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,
-522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,
-522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,
-522,522,522,522,522,522,522,522, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,
+576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,
+576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,
+576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,
+576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,
+576,576,576,576,576,576,576,576,563,563,563,563,563,563,563,563,
+563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,
+563, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,563,563,563,563,563,
/* block 97 */
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,
+563,563,563,563,563,563,563,563,563,563,563,563,563,563,563, 20,
/* block 98 */
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,116,116,116,116,116,116,116,116,116,116,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
/* block 99 */
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,119,119,119,119,119,119,119,119,119,119,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
/* block 100 */
-524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,
-524,524,524,524,524,525,524,524,524,524,524,524,524,524,524,524,
-524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,
-524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,
-524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,
-524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,
-524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,
-524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 101 */
-524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,
-524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,
-524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,
-524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,
-524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,
-524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,
-524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,
-524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,
+578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,
+578,578,578,578,578,579,578,578,578,578,578,578,578,578,578,578,
+578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,
+578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,
+578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,
+578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,
+578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,
+578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,
/* block 102 */
-524,524,524,524,524,524,524,524,524,524,524,524,524,116,116,116,
-526,526,526,526,526,526,526,526,526,526,526,526,526,526,526,526,
-526,526,526,526,526,526,526,526,526,526,526,526,526,526,526,526,
-526,526,526,526,526,526,526,526,526,526,526,526,526,526,526,526,
-526,526,526,526,526,526,526,116,116,116,116,116,116,116,116,116,
-527,527,527,527,527,527,527,527,527,527,527,527,527,527,527,527,
-527,527,527,527,527,527,527,527,527,527,527,527,527,527,527,527,
-527,527,527,527,527,527,527,527,528,528,528,528,528,528,529,529,
+578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,
+578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,
+578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,
+578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,
+578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,
+578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,
+578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,
+578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,
/* block 103 */
-530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,
-530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,
-530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,
-530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,
-530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,
-530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,
-530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,
-530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,
+578,578,578,578,578,578,578,578,578,578,578,578,578,119,119,119,
+580,580,580,580,580,580,580,580,580,580,580,580,580,580,580,580,
+580,580,580,580,580,580,580,580,580,580,580,580,580,580,580,580,
+580,580,580,580,580,580,580,580,580,580,580,580,580,580,580,580,
+580,580,580,580,580,580,580,119,119,119,119,119,119,119,119,119,
+581,581,581,581,581,581,581,581,581,581,581,581,581,581,581,581,
+581,581,581,581,581,581,581,581,581,581,581,581,581,581,581,581,
+581,581,581,581,581,581,581,581,582,582,582,582,582,582,583,583,
/* block 104 */
-530,530,530,530,530,530,530,530,530,530,530,530,531,532,532,532,
-530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,
-533,533,533,533,533,533,533,533,533,533,530,530,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-188,189,188,189,188,189,188,189,188,189,534,535,188,189,188,189,
-188,189,188,189,188,189,188,189,188,189,188,189,188,189,188,189,
-188,189,188,189,188,189,188,189,188,189,188,189,188,189,536,193,
-194,194,194,537,193,193,193,193,193,193,193,193,193,193,537,441,
+584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,
+584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,
+584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,
+584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,
+584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,
+584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,
+584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,
+584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,
/* block 105 */
-188,189,188,189,188,189,188,189,188,189,188,189,188,189,188,189,
-188,189,188,189,188,189,188,189,188,189,188,189,441,441,193,193,
-538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,
-538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,
-538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,
-538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,
-538,538,538,538,538,538,539,539,539,539,539,539,539,539,539,539,
-540,540,541,541,541,541,541,541,116,116,116,116,116,116,116,116,
+584,584,584,584,584,584,584,584,584,584,584,584,585,586,586,586,
+584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,
+587,587,587,587,587,587,587,587,587,587,584,584,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+191,192,191,192,191,192,191,192,191,192,588,589,191,192,191,192,
+191,192,191,192,191,192,191,192,191,192,191,192,191,192,191,192,
+191,192,191,192,191,192,191,192,191,192,191,192,191,192,590,197,
+199,199,199,591,543,543,543,543,543,543,543,543,543,543,591,472,
/* block 106 */
- 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14,109,109,109,109,109,109,109,109,109,
- 14, 14, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 34, 34, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
-108, 34, 34, 34, 34, 34, 34, 34, 34, 31, 32, 31, 32,542, 31, 32,
+191,192,191,192,191,192,191,192,191,192,191,192,191,192,191,192,
+191,192,191,192,191,192,191,192,191,192,191,192,472,472,543,543,
+592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,
+592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,
+592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,
+592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,
+592,592,592,592,592,592,593,593,593,593,593,593,593,593,593,593,
+594,594,595,595,595,595,595,595,119,119,119,119,119,119,119,119,
/* block 107 */
- 31, 32, 31, 32, 31, 32, 31, 32,109, 14, 14, 31, 32,543, 34, 21,
- 31, 32, 31, 32, 34, 34, 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,
- 31, 32, 31, 32, 31, 32, 31, 32, 31, 32,544,545,546,547,544, 34,
-548,549,550,551, 31, 32, 31, 32, 31, 32,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116, 21,108,108, 34, 21, 21, 21, 21, 21,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15,110,110,110,110,110,110,110,110,110,
+ 15, 15, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 35, 35, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+109, 35, 35, 35, 35, 35, 35, 35, 35, 32, 33, 32, 33,596, 32, 33,
/* block 108 */
-552,552,553,552,552,552,553,552,552,552,552,553,552,552,552,552,
-552,552,552,552,552,552,552,552,552,552,552,552,552,552,552,552,
-552,552,552,554,554,553,553,554,555,555,555,555,116,116,116,116,
- 24, 24, 24, 24, 24, 24, 19, 19, 5, 19,116,116,116,116,116,116,
-556,556,556,556,556,556,556,556,556,556,556,556,556,556,556,556,
-556,556,556,556,556,556,556,556,556,556,556,556,556,556,556,556,
-556,556,556,556,556,556,556,556,556,556,556,556,556,556,556,556,
-556,556,556,556,557,557,557,557,116,116,116,116,116,116,116,116,
+ 32, 33, 32, 33, 32, 33, 32, 33,110, 15, 15, 32, 33,597, 35, 22,
+ 32, 33, 32, 33, 35, 35, 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,
+ 32, 33, 32, 33, 32, 33, 32, 33, 32, 33,598,599,600,601,598, 35,
+602,603,604,605, 32, 33, 32, 33, 32, 33,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119, 22,109,109, 35, 22, 22, 22, 22, 22,
/* block 109 */
-558,558,559,559,559,559,559,559,559,559,559,559,559,559,559,559,
-559,559,559,559,559,559,559,559,559,559,559,559,559,559,559,559,
-559,559,559,559,559,559,559,559,559,559,559,559,559,559,559,559,
-559,559,559,559,558,558,558,558,558,558,558,558,558,558,558,558,
-558,558,558,558,560,560,116,116,116,116,116,116,116,116,561,561,
-562,562,562,562,562,562,562,562,562,562,116,116,116,116,116,116,
-240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,
-240,240,242,242,242,242,242,242,244,244,244,242,244,242,242,240,
+606,606,607,606,606,606,607,606,606,606,606,607,606,606,606,606,
+606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,
+606,606,606,608,608,607,607,608,609,609,609,609,119,119,119,119,
+610,610,610,611,611,611,612,612,613,612,119,119,119,119,119,119,
+614,614,614,614,614,614,614,614,614,614,614,614,614,614,614,614,
+614,614,614,614,614,614,614,614,614,614,614,614,614,614,614,614,
+614,614,614,614,614,614,614,614,614,614,614,614,614,614,614,614,
+614,614,614,614,615,615,615,615,119,119,119,119,119,119,119,119,
/* block 110 */
-563,563,563,563,563,563,563,563,563,563,564,564,564,564,564,564,
-564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,
-564,564,564,564,564,564,565,565,565,565,565,565,565,565, 4,566,
-567,567,567,567,567,567,567,567,567,567,567,567,567,567,567,567,
-567,567,567,567,567,567,567,568,568,568,568,568,568,568,568,568,
-568,568,569,569,116,116,116,116,116,116,116,116,116,116,116,570,
-337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,
-337,337,337,337,337,337,337,337,337,337,337,337,337,116,116,116,
+616,616,617,617,617,617,617,617,617,617,617,617,617,617,617,617,
+617,617,617,617,617,617,617,617,617,617,617,617,617,617,617,617,
+617,617,617,617,617,617,617,617,617,617,617,617,617,617,617,617,
+617,617,617,617,616,616,616,616,616,616,616,616,616,616,616,616,
+616,616,616,616,618,618,119,119,119,119,119,119,119,119,619,619,
+620,620,620,620,620,620,620,620,620,620,119,119,119,119,119,119,
+251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,
+251,621,253,622,253,253,253,253,259,259,259,253,259,253,253,251,
/* block 111 */
-571,571,571,572,573,573,573,573,573,573,573,573,573,573,573,573,
-573,573,573,573,573,573,573,573,573,573,573,573,573,573,573,573,
-573,573,573,573,573,573,573,573,573,573,573,573,573,573,573,573,
-573,573,573,571,572,572,571,571,571,571,572,572,571,572,572,572,
-572,574,574,574,574,574,574,574,574,574,574,574,574,574,116,109,
-575,575,575,575,575,575,575,575,575,575,116,116,116,116,574,574,
-327,327,327,327,327,329,576,327,327,327,327,327,327,327,327,327,
-331,331,331,331,331,331,331,331,331,331,327,327,327,327,327,116,
+623,623,623,623,623,623,623,623,623,623,624,624,624,624,624,624,
+624,624,624,624,624,624,624,624,624,624,624,624,624,624,624,624,
+624,624,624,624,624,624,625,625,625,625,625,625,625,625,626,627,
+628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,
+628,628,628,628,628,628,628,629,629,629,629,629,629,629,629,629,
+629,629,630,630,119,119,119,119,119,119,119,119,119,119,119,631,
+355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,
+355,355,355,355,355,355,355,355,355,355,355,355,355,119,119,119,
/* block 112 */
-577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
-577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
-577,577,577,577,577,577,577,577,577,578,578,578,578,578,578,579,
-579,578,578,579,579,578,578,116,116,116,116,116,116,116,116,116,
-577,577,577,578,577,577,577,577,577,577,577,577,578,579,116,116,
-580,580,580,580,580,580,580,580,580,580,116,116,581,581,581,581,
-327,327,327,327,327,327,327,327,327,327,327,327,327,327,327,327,
-576,327,327,327,327,327,327,333,333,333,327,328,329,328,327,327,
+632,632,632,633,634,634,634,634,634,634,634,634,634,634,634,634,
+634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,
+634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,
+634,634,634,632,633,633,632,632,632,632,633,633,632,633,633,633,
+633,635,635,635,635,635,635,635,635,635,635,635,635,635,119,636,
+637,637,637,637,637,637,637,637,637,637,119,119,119,119,635,635,
+343,343,343,343,343,345,638,343,343,343,343,343,343,343,343,343,
+349,349,349,349,349,349,349,349,349,349,343,343,343,343,343,119,
/* block 113 */
-582,582,582,582,582,582,582,582,582,582,582,582,582,582,582,582,
-582,582,582,582,582,582,582,582,582,582,582,582,582,582,582,582,
-582,582,582,582,582,582,582,582,582,582,582,582,582,582,582,582,
-583,582,583,583,583,582,582,583,583,582,582,582,582,582,583,583,
-582,583,582,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,582,582,584,585,585,
-586,586,586,586,586,586,586,586,586,586,586,587,588,588,587,587,
-589,589,586,590,590,587,588,116,116,116,116,116,116,116,116,116,
+639,639,639,639,639,639,639,639,639,639,639,639,639,639,639,639,
+639,639,639,639,639,639,639,639,639,639,639,639,639,639,639,639,
+639,639,639,639,639,639,639,639,639,640,640,640,640,640,640,641,
+641,640,640,641,641,640,640,119,119,119,119,119,119,119,119,119,
+639,639,639,640,639,639,639,639,639,639,639,639,640,641,119,119,
+642,642,642,642,642,642,642,642,642,642,119,119,643,643,643,643,
+343,343,343,343,343,343,343,343,343,343,343,343,343,343,343,343,
+638,343,343,343,343,343,343,350,350,350,343,344,345,344,343,343,
/* block 114 */
-116,340,340,340,340,340,340,116,116,340,340,340,340,340,340,116,
-116,340,340,340,340,340,340,116,116,116,116,116,116,116,116,116,
-340,340,340,340,340,340,340,116,340,340,340,340,340,340,340,116,
- 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
- 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
- 34, 34, 34,591, 34, 34, 34, 34, 34, 34, 34, 14,108,108,108,108,
- 34, 34, 34, 34, 34,124,116,116,116,116,116,116,116,116,116,116,
-592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,
+644,644,644,644,644,644,644,644,644,644,644,644,644,644,644,644,
+644,644,644,644,644,644,644,644,644,644,644,644,644,644,644,644,
+644,644,644,644,644,644,644,644,644,644,644,644,644,644,644,644,
+645,644,645,645,645,644,644,645,645,644,644,644,644,644,645,645,
+644,645,644,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,644,644,646,647,647,
+648,648,648,648,648,648,648,648,648,648,648,649,650,650,649,649,
+651,651,648,652,652,649,650,119,119,119,119,119,119,119,119,119,
/* block 115 */
-592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,
-592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,
-592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,
-592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,
-586,586,586,586,586,586,586,586,586,586,586,586,586,586,586,586,
-586,586,586,586,586,586,586,586,586,586,586,586,586,586,586,586,
-586,586,586,587,587,588,587,587,588,587,587,589,587,588,116,116,
-593,593,593,593,593,593,593,593,593,593,116,116,116,116,116,116,
+119,358,358,358,358,358,358,119,119,358,358,358,358,358,358,119,
+119,358,358,358,358,358,358,119,119,119,119,119,119,119,119,119,
+358,358,358,358,358,358,358,119,358,358,358,358,358,358,358,119,
+ 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
+ 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
+ 35, 35, 35,653, 35, 35, 35, 35, 35, 35, 35, 15,109,109,109,109,
+ 35, 35, 35, 35, 35,127,119,119,119,119,119,119,119,119,119,119,
+654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,
/* block 116 */
-594,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,594,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,594,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,594,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-594,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
+654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,
+654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,
+654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,
+654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,
+648,648,648,648,648,648,648,648,648,648,648,648,648,648,648,648,
+648,648,648,648,648,648,648,648,648,648,648,648,648,648,648,648,
+648,648,648,649,649,650,649,649,650,649,649,651,649,650,119,119,
+655,655,655,655,655,655,655,655,655,655,119,119,119,119,119,119,
/* block 117 */
-595,595,595,595,595,595,595,595,595,595,595,595,594,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,594,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,594,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-594,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,594,595,595,595,
+656,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,656,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,656,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,656,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+656,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
/* block 118 */
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,594,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,594,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-594,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,594,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
+657,657,657,657,657,657,657,657,657,657,657,657,656,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,656,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,656,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+656,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,656,657,657,657,
/* block 119 */
-595,595,595,595,595,595,595,595,594,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,594,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-594,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,594,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,594,595,595,595,595,595,595,595,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,656,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,656,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+656,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,656,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
/* block 120 */
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,594,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-594,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,594,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,594,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
+657,657,657,657,657,657,657,657,656,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,656,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+656,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,656,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,656,657,657,657,657,657,657,657,
/* block 121 */
-595,595,595,595,594,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-594,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,594,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,594,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,594,595,595,595,595,595,595,595,595,595,595,595,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,656,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+656,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,656,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,656,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
/* block 122 */
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-594,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,594,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,594,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,594,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
+657,657,657,657,656,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+656,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,656,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,656,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,656,657,657,657,657,657,657,657,657,657,657,657,
/* block 123 */
-595,595,595,595,595,595,595,595,594,595,595,595,595,595,595,595,
-595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
-595,595,595,595,116,116,116,116,116,116,116,116,116,116,116,116,
-338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,
-338,338,338,338,338,338,338,116,116,116,116,339,339,339,339,339,
-339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,
-339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,
-339,339,339,339,339,339,339,339,339,339,339,339,116,116,116,116,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+656,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,656,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,656,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,656,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
/* block 124 */
-596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,
-596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,
-596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,
-596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,
-596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,
-596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,
-596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,
-596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,
+657,657,657,657,657,657,657,657,656,657,657,657,657,657,657,657,
+657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
+657,657,657,657,119,119,119,119,119,119,119,119,119,119,119,119,
+356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,
+356,356,356,356,356,356,356,119,119,119,119,357,357,357,357,357,
+357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,
+357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,
+357,357,357,357,357,357,357,357,357,357,357,357,119,119,119,119,
/* block 125 */
-597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,
-597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,
-597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,
-597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,
-597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,
-597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,
-597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,
-597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,
+658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,
+658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,
+658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,
+658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,
+658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,
+658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,
+658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,
+658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,
/* block 126 */
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,116,116,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
+659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,
+659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,
+659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,
+659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,
+659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,
+659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,
+659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,
+659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,
/* block 127 */
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,119,119,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
/* block 128 */
- 34, 34, 34, 34, 34, 34, 34,116,116,116,116,116,116,116,116,116,
-116,116,116,200,200,200,200,200,116,116,116,116,116,208,205,208,
-208,208,208,208,208,208,208,208,208,598,208,208,208,208,208,208,
-208,208,208,208,208,208,208,116,208,208,208,208,208,116,208,116,
-208,208,116,208,208,116,208,208,208,208,208,208,208,208,208,208,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 129 */
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,599,599,599,599,599,599,599,599,599,599,599,599,599,599,
-599,599,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
+ 35, 35, 35, 35, 35, 35, 35,119,119,119,119,119,119,119,119,119,
+119,119,119,205,205,205,205,205,119,119,119,119,119,214,211,214,
+214,214,214,214,214,214,214,214,214,660,214,214,214,214,214,214,
+214,214,214,214,214,214,214,119,214,214,214,214,214,119,214,119,
+214,214,119,214,214,119,214,214,214,214,214,214,214,214,214,214,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
/* block 130 */
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,661,661,661,661,661,661,661,661,661,661,661,661,661,661,
+661,661,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
/* block 131 */
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217, 7, 6,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
/* block 132 */
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-116,116,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-217,217,217,217,217,217,217,217,217,217,217,217,213,214,116,116,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224, 8, 7,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
/* block 133 */
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
- 4, 4, 4, 4, 4, 4, 4, 6, 7, 4,116,116,116,116,116,116,
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,193,193,
- 4, 9, 9, 15, 15, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6,
- 7, 6, 7, 6, 7, 4, 4, 6, 7, 4, 4, 4, 4, 15, 15, 15,
- 4, 4, 4,116, 4, 4, 4, 4, 9, 6, 7, 6, 7, 6, 7, 4,
- 4, 4, 8, 9, 8, 8, 8,116, 4, 5, 4, 4,116,116,116,116,
-217,217,217,217,217,116,217,217,217,217,217,217,217,217,217,217,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+119,119,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+224,224,662,224,224,224,224,224,224,224,224,224,219,663,119,119,
/* block 134 */
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,116,116, 23,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,
+ 5, 5, 5, 5, 5, 5, 5, 7, 8, 5,119,119,119,119,119,119,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,543,543,
+ 5, 10, 10, 16, 16, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7,
+ 8, 7, 8, 7, 8,547,547, 7, 8, 5, 5, 5, 5, 16, 16, 16,
+ 5, 5, 5,119, 5, 5, 5, 5, 10, 7, 8, 7, 8, 7, 8, 5,
+ 5, 5, 9, 10, 9, 9, 9,119, 5, 6, 5, 5,119,119,119,119,
+224,224,224,224,224,119,224,224,224,224,224,224,224,224,224,224,
/* block 135 */
-116, 4, 4, 4, 5, 4, 4, 4, 6, 7, 4, 8, 4, 9, 4, 4,
- 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 4, 4, 8, 8, 8, 4,
- 4, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
- 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 6, 4, 7, 14, 15,
- 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 6, 8, 7, 8, 6,
- 7, 4, 6, 7, 4, 4,517,517,517,517,517,517,517,517,517,517,
-109,517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,119,119, 24,
/* block 136 */
-517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,
-517,517,517,517,517,517,517,517,517,517,517,517,517,517,600,600,
-520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,
-520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,116,
-116,116,520,520,520,520,520,520,116,116,520,520,520,520,520,520,
-116,116,520,520,520,520,520,520,116,116,520,520,520,116,116,116,
- 5, 5, 8, 14, 19, 5, 5,116, 19, 8, 8, 8, 8, 19, 19,116,
-471,471,471,471,471,471,471,471,471, 23, 23, 23, 19, 19,116,116,
+119, 5, 5, 5, 6, 5, 5, 5, 7, 8, 5, 9, 5, 10, 5, 5,
+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 5, 5, 9, 9, 9, 5,
+ 5, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 7, 5, 8, 15, 16,
+ 15, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
+ 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 7, 9, 8, 9, 7,
+ 8,546,551,552,546,546,569,569,569,569,569,569,569,569,569,569,
+560,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,
/* block 137 */
-601,601,601,601,601,601,601,601,601,601,601,601,116,601,601,601,
-601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,
-601,601,601,601,601,601,601,116,601,601,601,601,601,601,601,601,
-601,601,601,601,601,601,601,601,601,601,601,116,601,601,116,601,
-601,601,601,601,601,601,601,601,601,601,601,601,601,601,116,116,
-601,601,601,601,601,601,601,601,601,601,601,601,601,601,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,
+569,569,569,569,569,569,569,569,569,569,569,569,569,569,664,664,
+572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,
+572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,119,
+119,119,572,572,572,572,572,572,119,119,572,572,572,572,572,572,
+119,119,572,572,572,572,572,572,119,119,572,572,572,119,119,119,
+ 6, 6, 9, 15, 20, 6, 6,119, 20, 9, 9, 9, 9, 20, 20,119,
+502,502,502,502,502,502,502,502,502, 24, 24, 24, 20, 20,119,119,
/* block 138 */
-601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,
-601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,
-601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,
-601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,
-601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,
-601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,
-601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,
-601,601,601,601,601,601,601,601,601,601,601,116,116,116,116,116,
+665,665,665,665,665,665,665,665,665,665,665,665,119,665,665,665,
+665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,
+665,665,665,665,665,665,665,119,665,665,665,665,665,665,665,665,
+665,665,665,665,665,665,665,665,665,665,665,119,665,665,119,665,
+665,665,665,665,665,665,665,665,665,665,665,665,665,665,119,119,
+665,665,665,665,665,665,665,665,665,665,665,665,665,665,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 139 */
- 4, 4, 4,116,116,116,116, 24, 24, 24, 24, 24, 24, 24, 24, 24,
- 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
- 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
- 24, 24, 24, 24,116,116,116, 19, 19, 19, 19, 19, 19, 19, 19, 19,
-602,602,602,602,602,602,602,602,602,602,602,602,602,602,602,602,
-602,602,602,602,602,602,602,602,602,602,602,602,602,602,602,602,
-602,602,602,602,602,602,602,602,602,602,602,602,602,602,602,602,
-602,602,602,602,602,603,603,603,603,604,604,604,604,604,604,604,
+665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,
+665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,
+665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,
+665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,
+665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,
+665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,
+665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,
+665,665,665,665,665,665,665,665,665,665,665,119,119,119,119,119,
/* block 140 */
-604,604,604,604,604,604,604,604,604,604,603,603,604,604,604,116,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,116,116,116,116,
-604,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,111,116,116,
+666,666,666,119,119,119,119,667,667,667,667,667,667,667,667,667,
+667,667,667,667,667,667,667,667,667,667,667,667,667,667,667,667,
+667,667,667,667,667,667,667,667,667,667,667,667,667,667,667,667,
+667,667,667,667,119,119,119,668,668,668,668,668,668,668,668,668,
+669,669,669,669,669,669,669,669,669,669,669,669,669,669,669,669,
+669,669,669,669,669,669,669,669,669,669,669,669,669,669,669,669,
+669,669,669,669,669,669,669,669,669,669,669,669,669,669,669,669,
+669,669,669,669,669,670,670,670,670,671,671,671,671,671,671,671,
/* block 141 */
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+671,671,671,671,671,671,671,671,671,671,670,670,671,671,671,119,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,119,119,119,119,
+671,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,112,119,119,
/* block 142 */
-605,605,605,605,605,605,605,605,605,605,605,605,605,605,605,605,
-605,605,605,605,605,605,605,605,605,605,605,605,605,116,116,116,
-606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,
-606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,
-606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,
-606,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-111, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
- 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,116,116,116,116,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 143 */
-607,607,607,607,607,607,607,607,607,607,607,607,607,607,607,607,
-607,607,607,607,607,607,607,607,607,607,607,607,607,607,607,607,
-608,608,608,608,116,116,116,116,116,116,116,116,116,607,607,607,
-609,609,609,609,609,609,609,609,609,609,609,609,609,609,609,609,
-609,610,609,609,609,609,609,609,609,609,610,116,116,116,116,116,
-611,611,611,611,611,611,611,611,611,611,611,611,611,611,611,611,
-611,611,611,611,611,611,611,611,611,611,611,611,611,611,611,611,
-611,611,611,611,611,611,612,612,612,612,612,116,116,116,116,116,
+672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,
+672,672,672,672,672,672,672,672,672,672,672,672,672,119,119,119,
+673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,
+673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,
+673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,
+673,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+674,675,675,675,675,675,675,675,675,675,675,675,675,675,675,675,
+675,675,675,675,675,675,675,675,675,675,675,675,119,119,119,119,
/* block 144 */
-613,613,613,613,613,613,613,613,613,613,613,613,613,613,613,613,
-613,613,613,613,613,613,613,613,613,613,613,613,613,613,116,614,
-615,615,615,615,615,615,615,615,615,615,615,615,615,615,615,615,
-615,615,615,615,615,615,615,615,615,615,615,615,615,615,615,615,
-615,615,615,615,116,116,116,116,615,615,615,615,615,615,615,615,
-616,617,617,617,617,617,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+676,676,676,676,676,676,676,676,676,676,676,676,676,676,676,676,
+676,676,676,676,676,676,676,676,676,676,676,676,676,676,676,676,
+677,677,677,677,119,119,119,119,119,119,119,119,119,676,676,676,
+678,678,678,678,678,678,678,678,678,678,678,678,678,678,678,678,
+678,679,678,678,678,678,678,678,678,678,679,119,119,119,119,119,
+680,680,680,680,680,680,680,680,680,680,680,680,680,680,680,680,
+680,680,680,680,680,680,680,680,680,680,680,680,680,680,680,680,
+680,680,680,680,680,680,681,681,681,681,681,119,119,119,119,119,
/* block 145 */
-618,618,618,618,618,618,618,618,618,618,618,618,618,618,618,618,
-618,618,618,618,618,618,618,618,618,618,618,618,618,618,618,618,
-618,618,618,618,618,618,618,618,619,619,619,619,619,619,619,619,
-619,619,619,619,619,619,619,619,619,619,619,619,619,619,619,619,
-619,619,619,619,619,619,619,619,619,619,619,619,619,619,619,619,
-620,620,620,620,620,620,620,620,620,620,620,620,620,620,620,620,
-620,620,620,620,620,620,620,620,620,620,620,620,620,620,620,620,
-620,620,620,620,620,620,620,620,620,620,620,620,620,620,620,620,
+682,682,682,682,682,682,682,682,682,682,682,682,682,682,682,682,
+682,682,682,682,682,682,682,682,682,682,682,682,682,682,119,683,
+684,684,684,684,684,684,684,684,684,684,684,684,684,684,684,684,
+684,684,684,684,684,684,684,684,684,684,684,684,684,684,684,684,
+684,684,684,684,119,119,119,119,684,684,684,684,684,684,684,684,
+685,686,686,686,686,686,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 146 */
-621,621,621,621,621,621,621,621,621,621,621,621,621,621,621,621,
-621,621,621,621,621,621,621,621,621,621,621,621,621,621,116,116,
-622,622,622,622,622,622,622,622,622,622,116,116,116,116,116,116,
-623,623,623,623,623,623,623,623,623,623,623,623,623,623,623,623,
-623,623,623,623,623,623,623,623,623,623,623,623,623,623,623,623,
-623,623,623,623,116,116,116,116,624,624,624,624,624,624,624,624,
-624,624,624,624,624,624,624,624,624,624,624,624,624,624,624,624,
-624,624,624,624,624,624,624,624,624,624,624,624,116,116,116,116,
+687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,
+687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,
+687,687,687,687,687,687,687,687,688,688,688,688,688,688,688,688,
+688,688,688,688,688,688,688,688,688,688,688,688,688,688,688,688,
+688,688,688,688,688,688,688,688,688,688,688,688,688,688,688,688,
+689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,
+689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,
+689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,
/* block 147 */
-625,625,625,625,625,625,625,625,625,625,625,625,625,625,625,625,
-625,625,625,625,625,625,625,625,625,625,625,625,625,625,625,625,
-625,625,625,625,625,625,625,625,116,116,116,116,116,116,116,116,
-626,626,626,626,626,626,626,626,626,626,626,626,626,626,626,626,
-626,626,626,626,626,626,626,626,626,626,626,626,626,626,626,626,
-626,626,626,626,626,626,626,626,626,626,626,626,626,626,626,626,
-626,626,626,626,116,116,116,116,116,116,116,116,116,116,116,627,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+690,690,690,690,690,690,690,690,690,690,690,690,690,690,690,690,
+690,690,690,690,690,690,690,690,690,690,690,690,690,690,119,119,
+691,691,691,691,691,691,691,691,691,691,119,119,119,119,119,119,
+692,692,692,692,692,692,692,692,692,692,692,692,692,692,692,692,
+692,692,692,692,692,692,692,692,692,692,692,692,692,692,692,692,
+692,692,692,692,119,119,119,119,693,693,693,693,693,693,693,693,
+693,693,693,693,693,693,693,693,693,693,693,693,693,693,693,693,
+693,693,693,693,693,693,693,693,693,693,693,693,119,119,119,119,
/* block 148 */
-628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,
-628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,
-628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,
-628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,
-628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,
-628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,
-628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,
-628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,
+694,694,694,694,694,694,694,694,694,694,694,694,694,694,694,694,
+694,694,694,694,694,694,694,694,694,694,694,694,694,694,694,694,
+694,694,694,694,694,694,694,694,119,119,119,119,119,119,119,119,
+695,695,695,695,695,695,695,695,695,695,695,695,695,695,695,695,
+695,695,695,695,695,695,695,695,695,695,695,695,695,695,695,695,
+695,695,695,695,695,695,695,695,695,695,695,695,695,695,695,695,
+695,695,695,695,119,119,119,119,119,119,119,119,119,119,119,696,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 149 */
-628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,
-628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,
-628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,
-628,628,628,628,628,628,628,116,116,116,116,116,116,116,116,116,
-628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,
-628,628,628,628,628,628,116,116,116,116,116,116,116,116,116,116,
-628,628,628,628,628,628,628,628,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,
+697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,
+697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,
+697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,
+697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,
+697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,
+697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,
+697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,
/* block 150 */
-629,629,629,629,629,629,116,116,629,116,629,629,629,629,629,629,
-629,629,629,629,629,629,629,629,629,629,629,629,629,629,629,629,
-629,629,629,629,629,629,629,629,629,629,629,629,629,629,629,629,
-629,629,629,629,629,629,116,629,629,116,116,116,629,116,116,629,
-630,630,630,630,630,630,630,630,630,630,630,630,630,630,630,630,
-630,630,630,630,630,630,116,631,632,632,632,632,632,632,632,632,
-633,633,633,633,633,633,633,633,633,633,633,633,633,633,633,633,
-633,633,633,633,633,633,633,634,634,635,635,635,635,635,635,635,
+697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,
+697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,
+697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,
+697,697,697,697,697,697,697,119,119,119,119,119,119,119,119,119,
+697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,
+697,697,697,697,697,697,119,119,119,119,119,119,119,119,119,119,
+697,697,697,697,697,697,697,697,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 151 */
-636,636,636,636,636,636,636,636,636,636,636,636,636,636,636,636,
-636,636,636,636,636,636,636,636,636,636,636,636,636,636,636,116,
-116,116,116,116,116,116,116,637,637,637,637,637,637,637,637,637,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-638,638,638,638,638,638,638,638,638,638,638,638,638,638,638,638,
-638,638,638,116,638,638,116,116,116,116,116,639,639,639,639,639,
+698,698,698,698,698,698,119,119,698,119,698,698,698,698,698,698,
+698,698,698,698,698,698,698,698,698,698,698,698,698,698,698,698,
+698,698,698,698,698,698,698,698,698,698,698,698,698,698,698,698,
+698,698,698,698,698,698,119,698,698,119,119,119,698,119,119,698,
+699,699,699,699,699,699,699,699,699,699,699,699,699,699,699,699,
+699,699,699,699,699,699,119,700,701,701,701,701,701,701,701,701,
+702,702,702,702,702,702,702,702,702,702,702,702,702,702,702,702,
+702,702,702,702,702,702,702,703,703,704,704,704,704,704,704,704,
/* block 152 */
-640,640,640,640,640,640,640,640,640,640,640,640,640,640,640,640,
-640,640,640,640,640,640,641,641,641,641,641,641,116,116,116,642,
-643,643,643,643,643,643,643,643,643,643,643,643,643,643,643,643,
-643,643,643,643,643,643,643,643,643,643,116,116,116,116,116,644,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+705,705,705,705,705,705,705,705,705,705,705,705,705,705,705,705,
+705,705,705,705,705,705,705,705,705,705,705,705,705,705,705,119,
+119,119,119,119,119,119,119,706,706,706,706,706,706,706,706,706,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+707,707,707,707,707,707,707,707,707,707,707,707,707,707,707,707,
+707,707,707,119,707,707,119,119,119,119,119,708,708,708,708,708,
/* block 153 */
-645,645,645,645,645,645,645,645,645,645,645,645,645,645,645,645,
-645,645,645,645,645,645,645,645,645,645,645,645,645,645,645,645,
-646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,
-646,646,646,646,646,646,646,646,116,116,116,116,647,647,646,646,
-647,647,647,647,647,647,647,647,647,647,647,647,647,647,647,647,
-116,116,647,647,647,647,647,647,647,647,647,647,647,647,647,647,
-647,647,647,647,647,647,647,647,647,647,647,647,647,647,647,647,
-647,647,647,647,647,647,647,647,647,647,647,647,647,647,647,647,
+709,709,709,709,709,709,709,709,709,709,709,709,709,709,709,709,
+709,709,709,709,709,709,710,710,710,710,710,710,119,119,119,711,
+712,712,712,712,712,712,712,712,712,712,712,712,712,712,712,712,
+712,712,712,712,712,712,712,712,712,712,119,119,119,119,119,713,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 154 */
-648,649,649,649,116,649,649,116,116,116,116,116,649,649,649,649,
-648,648,648,648,116,648,648,648,116,648,648,648,648,648,648,648,
-648,648,648,648,648,648,648,648,648,648,648,648,648,648,648,648,
-648,648,648,648,648,648,116,116,649,649,649,116,116,116,116,649,
-650,650,650,650,650,650,650,650,650,116,116,116,116,116,116,116,
-651,651,651,651,651,651,651,651,651,116,116,116,116,116,116,116,
-652,652,652,652,652,652,652,652,652,652,652,652,652,652,652,652,
-652,652,652,652,652,652,652,652,652,652,652,652,652,653,653,654,
+714,714,714,714,714,714,714,714,714,714,714,714,714,714,714,714,
+714,714,714,714,714,714,714,714,714,714,714,714,714,714,714,714,
+715,715,715,715,715,715,715,715,715,715,715,715,715,715,715,715,
+715,715,715,715,715,715,715,715,119,119,119,119,716,716,715,715,
+716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,
+119,119,716,716,716,716,716,716,716,716,716,716,716,716,716,716,
+716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,
+716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,
/* block 155 */
-655,655,655,655,655,655,655,655,655,655,655,655,655,655,655,655,
-655,655,655,655,655,655,655,655,655,655,655,655,655,656,656,656,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-657,657,657,657,657,657,657,657,658,657,657,657,657,657,657,657,
-657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
-657,657,657,657,657,659,659,116,116,116,116,660,660,660,660,660,
-661,661,661,661,661,661,661,116,116,116,116,116,116,116,116,116,
+717,718,718,718,119,718,718,119,119,119,119,119,718,718,718,718,
+717,717,717,717,119,717,717,717,119,717,717,717,717,717,717,717,
+717,717,717,717,717,717,717,717,717,717,717,717,717,717,717,717,
+717,717,717,717,717,717,119,119,718,718,718,119,119,119,119,718,
+719,719,719,719,719,719,719,719,719,119,119,119,119,119,119,119,
+720,720,720,720,720,720,720,720,720,119,119,119,119,119,119,119,
+721,721,721,721,721,721,721,721,721,721,721,721,721,721,721,721,
+721,721,721,721,721,721,721,721,721,721,721,721,721,722,722,723,
/* block 156 */
-662,662,662,662,662,662,662,662,662,662,662,662,662,662,662,662,
-662,662,662,662,662,662,662,662,662,662,662,662,662,662,662,662,
-662,662,662,662,662,662,662,662,662,662,662,662,662,662,662,662,
-662,662,662,662,662,662,116,116,116,663,663,663,663,663,663,663,
-664,664,664,664,664,664,664,664,664,664,664,664,664,664,664,664,
-664,664,664,664,664,664,116,116,665,665,665,665,665,665,665,665,
-666,666,666,666,666,666,666,666,666,666,666,666,666,666,666,666,
-666,666,666,116,116,116,116,116,667,667,667,667,667,667,667,667,
+724,724,724,724,724,724,724,724,724,724,724,724,724,724,724,724,
+724,724,724,724,724,724,724,724,724,724,724,724,724,725,725,725,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+726,726,726,726,726,726,726,726,727,726,726,726,726,726,726,726,
+726,726,726,726,726,726,726,726,726,726,726,726,726,726,726,726,
+726,726,726,726,726,728,728,119,119,119,119,729,729,729,729,729,
+730,730,730,730,730,730,730,119,119,119,119,119,119,119,119,119,
/* block 157 */
-668,668,668,668,668,668,668,668,668,668,668,668,668,668,668,668,
-668,668,116,116,116,116,116,116,116,669,669,669,669,116,116,116,
-116,116,116,116,116,116,116,116,116,670,670,670,670,670,670,670,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,
+731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,
+731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,
+731,731,731,731,731,731,119,119,119,732,732,732,732,732,732,732,
+733,733,733,733,733,733,733,733,733,733,733,733,733,733,733,733,
+733,733,733,733,733,733,119,119,734,734,734,734,734,734,734,734,
+735,735,735,735,735,735,735,735,735,735,735,735,735,735,735,735,
+735,735,735,119,119,119,119,119,736,736,736,736,736,736,736,736,
/* block 158 */
-671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,
-671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,
-671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,
-671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,
-671,671,671,671,671,671,671,671,671,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+737,737,737,737,737,737,737,737,737,737,737,737,737,737,737,737,
+737,737,119,119,119,119,119,119,119,738,738,738,738,119,119,119,
+119,119,119,119,119,119,119,119,119,739,739,739,739,739,739,739,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 159 */
-672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,
-672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,
-672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,
-672,672,672,116,116,116,116,116,116,116,116,116,116,116,116,116,
-673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,
-673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,
-673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,
-673,673,673,116,116,116,116,116,116,116,674,674,674,674,674,674,
+740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,
+740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,
+740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,
+740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,
+740,740,740,740,740,740,740,740,740,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 160 */
-675,675,675,675,675,675,675,675,675,675,675,675,675,675,675,675,
-675,675,675,675,675,675,675,675,675,675,675,675,675,675,675,675,
-675,675,675,675,676,676,676,676,116,116,116,116,116,116,116,116,
-677,677,677,677,677,677,677,677,677,677,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+741,741,741,741,741,741,741,741,741,741,741,741,741,741,741,741,
+741,741,741,741,741,741,741,741,741,741,741,741,741,741,741,741,
+741,741,741,741,741,741,741,741,741,741,741,741,741,741,741,741,
+741,741,741,119,119,119,119,119,119,119,119,119,119,119,119,119,
+742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,
+742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,
+742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,
+742,742,742,119,119,119,119,119,119,119,743,743,743,743,743,743,
/* block 161 */
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-678,678,678,678,678,678,678,678,678,678,678,678,678,678,678,678,
-678,678,678,678,678,678,678,678,678,678,678,678,678,678,678,116,
+744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,
+744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,
+744,744,744,744,745,745,745,745,119,119,119,119,119,119,119,119,
+746,746,746,746,746,746,746,746,746,746,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 162 */
-679,679,679,679,679,679,679,679,679,679,679,679,679,679,679,679,
-679,679,679,679,679,679,679,679,679,679,679,679,679,680,680,680,
-680,680,680,680,680,680,680,679,116,116,116,116,116,116,116,116,
-681,681,681,681,681,681,681,681,681,681,681,681,681,681,681,681,
-681,681,681,681,681,681,682,682,682,682,682,682,682,682,682,682,
-682,683,683,683,683,684,684,684,684,684,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+747,747,747,747,747,747,747,747,747,747,747,747,747,747,747,747,
+747,747,747,747,747,747,747,747,747,747,747,747,747,747,747,119,
/* block 163 */
-685,686,685,687,687,687,687,687,687,687,687,687,687,687,687,687,
-687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,
-687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,
-687,687,687,687,687,687,687,687,686,686,686,686,686,686,686,686,
-686,686,686,686,686,686,686,688,688,688,688,688,688,688,116,116,
-116,116,689,689,689,689,689,689,689,689,689,689,689,689,689,689,
-689,689,689,689,689,689,690,690,690,690,690,690,690,690,690,690,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,686,
+748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,
+748,748,748,748,748,748,748,748,748,748,748,748,748,749,749,749,
+749,749,749,749,749,749,749,748,119,119,119,119,119,119,119,119,
+750,750,750,750,750,750,750,750,750,750,750,750,750,750,750,750,
+750,750,750,750,750,750,751,751,751,751,751,751,751,751,751,751,
+751,752,752,752,752,753,753,753,753,753,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 164 */
-691,691,692,693,693,693,693,693,693,693,693,693,693,693,693,693,
-693,693,693,693,693,693,693,693,693,693,693,693,693,693,693,693,
-693,693,693,693,693,693,693,693,693,693,693,693,693,693,693,693,
-692,692,692,691,691,691,691,692,692,691,691,694,694,695,694,694,
-694,694,116,116,116,116,116,116,116,116,116,116,116,695,116,116,
-696,696,696,696,696,696,696,696,696,696,696,696,696,696,696,696,
-696,696,696,696,696,696,696,696,696,116,116,116,116,116,116,116,
-697,697,697,697,697,697,697,697,697,697,116,116,116,116,116,116,
+754,755,754,756,756,756,756,756,756,756,756,756,756,756,756,756,
+756,756,756,756,756,756,756,756,756,756,756,756,756,756,756,756,
+756,756,756,756,756,756,756,756,756,756,756,756,756,756,756,756,
+756,756,756,756,756,756,756,756,755,755,755,755,755,755,755,755,
+755,755,755,755,755,755,755,757,757,757,757,757,757,757,119,119,
+119,119,758,758,758,758,758,758,758,758,758,758,758,758,758,758,
+758,758,758,758,758,758,759,759,759,759,759,759,759,759,759,759,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,755,
/* block 165 */
-698,698,698,699,699,699,699,699,699,699,699,699,699,699,699,699,
-699,699,699,699,699,699,699,699,699,699,699,699,699,699,699,699,
-699,699,699,699,699,699,699,698,698,698,698,698,700,698,698,698,
-698,698,698,698,698,116,701,701,701,701,701,701,701,701,701,701,
-702,702,702,702,699,700,700,116,116,116,116,116,116,116,116,116,
-703,703,703,703,703,703,703,703,703,703,703,703,703,703,703,703,
-703,703,703,703,703,703,703,703,703,703,703,703,703,703,703,703,
-703,703,703,704,705,705,703,116,116,116,116,116,116,116,116,116,
+760,760,761,762,762,762,762,762,762,762,762,762,762,762,762,762,
+762,762,762,762,762,762,762,762,762,762,762,762,762,762,762,762,
+762,762,762,762,762,762,762,762,762,762,762,762,762,762,762,762,
+761,761,761,760,760,760,760,761,761,760,760,763,763,764,763,763,
+763,763,119,119,119,119,119,119,119,119,119,119,119,764,119,119,
+765,765,765,765,765,765,765,765,765,765,765,765,765,765,765,765,
+765,765,765,765,765,765,765,765,765,119,119,119,119,119,119,119,
+766,766,766,766,766,766,766,766,766,766,119,119,119,119,119,119,
/* block 166 */
-706,706,707,708,708,708,708,708,708,708,708,708,708,708,708,708,
-708,708,708,708,708,708,708,708,708,708,708,708,708,708,708,708,
-708,708,708,708,708,708,708,708,708,708,708,708,708,708,708,708,
-708,708,708,707,707,707,706,706,706,706,706,706,706,706,706,707,
-707,708,709,709,708,710,710,710,710,706,706,706,706,710,116,116,
-711,711,711,711,711,711,711,711,711,711,708,710,708,710,710,710,
-116,712,712,712,712,712,712,712,712,712,712,712,712,712,712,712,
-712,712,712,712,712,116,116,116,116,116,116,116,116,116,116,116,
+767,767,767,768,768,768,768,768,768,768,768,768,768,768,768,768,
+768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,
+768,768,768,768,768,768,768,767,767,767,767,767,769,767,767,767,
+767,767,767,767,767,119,770,770,770,770,770,770,770,770,770,770,
+771,771,771,771,768,769,769,119,119,119,119,119,119,119,119,119,
+772,772,772,772,772,772,772,772,772,772,772,772,772,772,772,772,
+772,772,772,772,772,772,772,772,772,772,772,772,772,772,772,772,
+772,772,772,773,774,774,772,119,119,119,119,119,119,119,119,119,
/* block 167 */
-713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,
-713,713,116,713,713,713,713,713,713,713,713,713,713,713,713,713,
-713,713,713,713,713,713,713,713,713,713,713,713,714,714,714,715,
-715,715,714,714,715,714,715,715,716,716,716,716,716,716,715,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+775,775,776,777,777,777,777,777,777,777,777,777,777,777,777,777,
+777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,
+777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,
+777,777,777,776,776,776,775,775,775,775,775,775,775,775,775,776,
+776,777,778,778,777,779,779,779,779,775,775,775,775,779,119,119,
+780,780,780,780,780,780,780,780,780,780,777,779,777,779,779,779,
+119,781,781,781,781,781,781,781,781,781,781,781,781,781,781,781,
+781,781,781,781,781,119,119,119,119,119,119,119,119,119,119,119,
/* block 168 */
-717,717,717,717,717,717,717,116,717,116,717,717,717,717,116,717,
-717,717,717,717,717,717,717,717,717,717,717,717,717,717,116,717,
-717,717,717,717,717,717,717,717,717,718,116,116,116,116,116,116,
-719,719,719,719,719,719,719,719,719,719,719,719,719,719,719,719,
-719,719,719,719,719,719,719,719,719,719,719,719,719,719,719,719,
-719,719,719,719,719,719,719,719,719,719,719,719,719,719,719,720,
-721,721,721,720,720,720,720,720,720,720,720,116,116,116,116,116,
-722,722,722,722,722,722,722,722,722,722,116,116,116,116,116,116,
+782,782,782,782,782,782,782,782,782,782,782,782,782,782,782,782,
+782,782,119,782,782,782,782,782,782,782,782,782,782,782,782,782,
+782,782,782,782,782,782,782,782,782,782,782,782,783,783,783,784,
+784,784,783,783,784,783,784,784,785,785,785,785,785,785,784,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 169 */
-723,723,724,724,116,725,725,725,725,725,725,725,725,116,116,725,
-725,116,116,725,725,725,725,725,725,725,725,725,725,725,725,725,
-725,725,725,725,725,725,725,725,725,116,725,725,725,725,725,725,
-725,116,725,725,116,725,725,725,725,725,116,111,723,725,726,724,
-723,724,724,724,724,116,116,724,724,116,116,724,724,724,116,116,
-725,116,116,116,116,116,116,726,116,116,116,116,116,725,725,725,
-725,725,724,724,116,116,723,723,723,723,723,723,723,116,116,116,
-723,723,723,723,723,116,116,116,116,116,116,116,116,116,116,116,
+786,786,786,786,786,786,786,119,786,119,786,786,786,786,119,786,
+786,786,786,786,786,786,786,786,786,786,786,786,786,786,119,786,
+786,786,786,786,786,786,786,786,786,787,119,119,119,119,119,119,
+788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,
+788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,
+788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,789,
+790,790,790,789,789,789,789,789,789,789,789,119,119,119,119,119,
+791,791,791,791,791,791,791,791,791,791,119,119,119,119,119,119,
/* block 170 */
-727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,
-727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,
-727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,
-727,727,727,727,727,728,728,728,729,729,729,729,729,729,729,729,
-728,728,729,729,729,728,729,727,727,727,727,730,730,730,730,730,
-731,731,731,731,731,731,731,731,731,731,116,730,116,730,729,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+792,793,794,795,119,796,796,796,796,796,796,796,796,119,119,796,
+796,119,119,796,796,796,796,796,796,796,796,796,796,796,796,796,
+796,796,796,796,796,796,796,796,796,119,796,796,796,796,796,796,
+796,119,796,796,119,796,796,796,796,796,119,797,793,796,798,794,
+792,794,794,794,794,119,119,794,794,119,119,794,794,794,119,119,
+796,119,119,119,119,119,119,798,119,119,119,119,119,796,796,796,
+796,796,794,794,119,119,792,792,792,792,792,792,792,119,119,119,
+792,792,792,792,792,119,119,119,119,119,119,119,119,119,119,119,
/* block 171 */
-732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,
-732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,
-732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,
-733,734,734,735,735,735,735,735,735,734,735,734,734,733,734,735,
-735,734,735,735,732,732,736,732,116,116,116,116,116,116,116,116,
-737,737,737,737,737,737,737,737,737,737,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,
+799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,
+799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,
+799,799,799,799,799,800,800,800,801,801,801,801,801,801,801,801,
+800,800,801,801,801,800,801,799,799,799,799,802,802,802,802,802,
+803,803,803,803,803,803,803,803,803,803,119,802,119,802,801,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 172 */
-738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,
-738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,
-738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,739,
-740,740,741,741,741,741,116,116,740,740,740,740,741,741,740,741,
-741,742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,
-742,742,742,742,742,742,742,742,738,738,738,738,741,741,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,
+804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,
+804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,
+805,806,806,807,807,807,807,807,807,806,807,806,806,805,806,807,
+807,806,807,807,804,804,808,804,119,119,119,119,119,119,119,119,
+809,809,809,809,809,809,809,809,809,809,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 173 */
-743,743,743,743,743,743,743,743,743,743,743,743,743,743,743,743,
-743,743,743,743,743,743,743,743,743,743,743,743,743,743,743,743,
-743,743,743,743,743,743,743,743,743,743,743,743,743,743,743,743,
-744,744,744,745,745,745,745,745,745,745,745,744,744,745,744,745,
-745,746,746,746,743,116,116,116,116,116,116,116,116,116,116,116,
-747,747,747,747,747,747,747,747,747,747,116,116,116,116,116,116,
-373,373,373,373,373,373,373,373,373,373,373,373,373,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,
+810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,
+810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,811,
+812,812,813,813,813,813,119,119,812,812,812,812,813,813,812,813,
+813,814,814,814,814,814,814,814,814,814,814,814,814,814,814,814,
+814,814,814,814,814,814,814,814,810,810,810,810,813,813,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 174 */
-748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,
-748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,
-748,748,748,748,748,748,748,748,748,748,748,749,750,749,750,750,
-749,749,749,749,749,749,750,749,116,116,116,116,116,116,116,116,
-751,751,751,751,751,751,751,751,751,751,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,
+815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,
+815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,
+816,816,816,817,817,817,817,817,817,817,817,816,816,817,816,817,
+817,818,818,818,815,119,119,119,119,119,119,119,119,119,119,119,
+819,819,819,819,819,819,819,819,819,819,119,119,119,119,119,119,
+392,392,392,392,392,392,392,392,392,392,392,392,392,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 175 */
-752,752,752,752,752,752,752,752,752,752,752,752,752,752,752,752,
-752,752,752,752,752,752,752,752,752,752,752,116,116,753,753,753,
-754,754,753,753,753,753,754,753,753,753,753,753,116,116,116,116,
-755,755,755,755,755,755,755,755,755,755,756,756,757,757,757,758,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,
+820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,
+820,820,820,820,820,820,820,820,820,820,820,821,822,821,822,822,
+821,821,821,821,821,821,822,821,119,119,119,119,119,119,119,119,
+823,823,823,823,823,823,823,823,823,823,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 176 */
-759,759,759,759,759,759,759,759,759,759,759,759,759,759,759,759,
-759,759,759,759,759,759,759,759,759,759,759,759,759,759,759,759,
-759,759,759,759,759,759,759,759,759,759,759,759,760,760,760,761,
-761,761,761,761,761,761,761,761,760,761,761,762,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,
+824,824,824,824,824,824,824,824,824,824,824,119,119,825,825,825,
+826,826,825,825,825,825,826,825,825,825,825,825,119,119,119,119,
+827,827,827,827,827,827,827,827,827,827,828,828,829,829,829,830,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 177 */
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-763,763,763,763,763,763,763,763,763,763,763,763,763,763,763,763,
-763,763,763,763,763,763,763,763,763,763,763,763,763,763,763,763,
-764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,
-764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,
-765,765,765,765,765,765,765,765,765,765,766,766,766,766,766,766,
-766,766,766,116,116,116,116,116,116,116,116,116,116,116,116,767,
+831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,
+831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,
+831,831,831,831,831,831,831,831,831,831,831,831,832,832,832,833,
+833,833,833,833,833,833,833,833,832,833,833,834,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 178 */
-768,769,769,769,769,769,769,769,769,769,769,768,768,768,768,768,
-768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,
-768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,
-768,768,768,769,769,769,769,769,769,770,771,769,769,769,769,772,
-772,772,772,772,772,772,772,769,116,116,116,116,116,116,116,116,
-773,774,774,774,774,774,774,775,775,774,774,774,773,773,773,773,
-773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,
-773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,
+835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,
+836,836,836,836,836,836,836,836,836,836,836,836,836,836,836,836,
+836,836,836,836,836,836,836,836,836,836,836,836,836,836,836,836,
+837,837,837,837,837,837,837,837,837,837,838,838,838,838,838,838,
+838,838,838,119,119,119,119,119,119,119,119,119,119,119,119,839,
/* block 179 */
-773,773,773,773,116,116,776,776,776,776,774,774,774,774,774,774,
-774,774,774,774,774,774,774,775,774,774,777,777,777,773,777,777,
-777,777,777,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-778,778,778,778,778,778,778,778,778,778,778,778,778,778,778,778,
-778,778,778,778,778,778,778,778,778,778,778,778,778,778,778,778,
-778,778,778,778,778,778,778,778,778,778,778,778,778,778,778,778,
-778,778,778,778,778,778,778,778,778,116,116,116,116,116,116,116,
+840,841,841,841,841,841,841,841,841,841,841,840,840,840,840,840,
+840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,
+840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,
+840,840,840,841,841,841,841,841,841,842,843,841,841,841,841,844,
+844,844,844,844,844,844,844,841,119,119,119,119,119,119,119,119,
+845,846,846,846,846,846,846,847,847,846,846,846,845,845,845,845,
+845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,
+845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,
/* block 180 */
-779,779,779,779,779,779,779,779,779,116,779,779,779,779,779,779,
-779,779,779,779,779,779,779,779,779,779,779,779,779,779,779,779,
-779,779,779,779,779,779,779,779,779,779,779,779,779,779,779,780,
-781,781,781,781,781,781,781,116,781,781,781,781,781,781,780,781,
-779,782,782,782,782,782,116,116,116,116,116,116,116,116,116,116,
-783,783,783,783,783,783,783,783,783,783,784,784,784,784,784,784,
-784,784,784,784,784,784,784,784,784,784,784,784,784,116,116,116,
-785,785,786,786,786,786,786,786,786,786,786,786,786,786,786,786,
+845,845,845,845,119,119,848,848,848,848,846,846,846,846,846,846,
+846,846,846,846,846,846,846,847,846,846,849,849,849,845,849,849,
+849,849,849,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,
+850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,
+850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,
+850,850,850,850,850,850,850,850,850,119,119,119,119,119,119,119,
/* block 181 */
-786,786,786,786,786,786,786,786,786,786,786,786,786,786,786,786,
-116,116,787,787,787,787,787,787,787,787,787,787,787,787,787,787,
-787,787,787,787,787,787,787,787,116,788,787,787,787,787,787,787,
-787,788,787,787,788,787,787,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+851,851,851,851,851,851,851,851,851,119,851,851,851,851,851,851,
+851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,
+851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,852,
+853,853,853,853,853,853,853,119,853,853,853,853,853,853,852,853,
+851,854,854,854,854,854,119,119,119,119,119,119,119,119,119,119,
+855,855,855,855,855,855,855,855,855,855,856,856,856,856,856,856,
+856,856,856,856,856,856,856,856,856,856,856,856,856,119,119,119,
+857,857,858,858,858,858,858,858,858,858,858,858,858,858,858,858,
/* block 182 */
-789,789,789,789,789,789,789,116,789,789,116,789,789,789,789,789,
-789,789,789,789,789,789,789,789,789,789,789,789,789,789,789,789,
-789,789,789,789,789,789,789,789,789,789,789,789,789,789,789,789,
-789,790,790,790,790,790,790,116,116,116,790,116,790,790,116,790,
-790,790,790,790,790,790,791,790,116,116,116,116,116,116,116,116,
-792,792,792,792,792,792,792,792,792,792,116,116,116,116,116,116,
-793,793,793,793,793,793,116,793,793,116,793,793,793,793,793,793,
-793,793,793,793,793,793,793,793,793,793,793,793,793,793,793,793,
+858,858,858,858,858,858,858,858,858,858,858,858,858,858,858,858,
+119,119,859,859,859,859,859,859,859,859,859,859,859,859,859,859,
+859,859,859,859,859,859,859,859,119,860,859,859,859,859,859,859,
+859,860,859,859,860,859,859,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 183 */
-793,793,793,793,793,793,793,793,793,793,794,794,794,794,794,116,
-795,795,116,794,794,795,794,795,793,116,116,116,116,116,116,116,
-796,796,796,796,796,796,796,796,796,796,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+861,861,861,861,861,861,861,119,861,861,119,861,861,861,861,861,
+861,861,861,861,861,861,861,861,861,861,861,861,861,861,861,861,
+861,861,861,861,861,861,861,861,861,861,861,861,861,861,861,861,
+861,862,862,862,862,862,862,119,119,119,862,119,862,862,119,862,
+862,862,862,862,862,862,863,862,119,119,119,119,119,119,119,119,
+864,864,864,864,864,864,864,864,864,864,119,119,119,119,119,119,
+865,865,865,865,865,865,119,865,865,119,865,865,865,865,865,865,
+865,865,865,865,865,865,865,865,865,865,865,865,865,865,865,865,
/* block 184 */
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-797,797,797,797,797,797,797,797,797,797,797,797,797,797,797,797,
-797,797,797,798,798,799,799,800,800,116,116,116,116,116,116,116,
+865,865,865,865,865,865,865,865,865,865,866,866,866,866,866,119,
+867,867,119,866,866,867,866,867,865,119,119,119,119,119,119,119,
+868,868,868,868,868,868,868,868,868,868,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 185 */
-801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,
-801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,
-801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,
-801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,
-801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,
-801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,
-801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,
-801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+869,869,869,869,869,869,869,869,869,869,869,869,869,869,869,869,
+869,869,869,870,870,871,871,872,872,119,119,119,119,119,119,119,
/* block 186 */
-801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,
-801,801,801,801,801,801,801,801,801,801,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,
+873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,
+873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,
+873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,
+873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,
+873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,
+873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,
+873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,
/* block 187 */
-802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,
-802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,
-802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,
-802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,
-802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,
-802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,
-802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,116,
-803,803,803,803,803,116,116,116,116,116,116,116,116,116,116,116,
+873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,
+873,873,873,873,873,873,873,873,873,873,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 188 */
-801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,
-801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,
-801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,
-801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,
-801,801,801,801,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+874,874,874,874,874,874,874,874,874,874,874,874,874,874,874,874,
+874,874,874,874,874,874,874,874,874,874,874,874,874,874,874,874,
+874,874,874,874,874,874,874,874,874,874,874,874,874,874,874,874,
+874,874,874,874,874,874,874,874,874,874,874,874,874,874,874,874,
+874,874,874,874,874,874,874,874,874,874,874,874,874,874,874,874,
+874,874,874,874,874,874,874,874,874,874,874,874,874,874,874,874,
+874,874,874,874,874,874,874,874,874,874,874,874,874,874,874,119,
+875,875,875,875,875,119,119,119,119,119,119,119,119,119,119,119,
/* block 189 */
-804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,
-804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,
-804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,
-804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,
-804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,
-804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,
-804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,
-804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,
+873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,
+873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,
+873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,
+873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,873,
+873,873,873,873,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 190 */
-804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,
-804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,
-804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+876,876,876,876,876,876,876,876,876,876,876,876,876,876,876,876,
+876,876,876,876,876,876,876,876,876,876,876,876,876,876,876,876,
+876,876,876,876,876,876,876,876,876,876,876,876,876,876,876,876,
+876,876,876,876,876,876,876,876,876,876,876,876,876,876,876,876,
+876,876,876,876,876,876,876,876,876,876,876,876,876,876,876,876,
+876,876,876,876,876,876,876,876,876,876,876,876,876,876,876,876,
+876,876,876,876,876,876,876,876,876,876,876,876,876,876,876,876,
+876,876,876,876,876,876,876,876,876,876,876,876,876,876,876,876,
/* block 191 */
-805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,
-805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,
-805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,
-805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,
-805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,
-805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,
-805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,
-805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,
+876,876,876,876,876,876,876,876,876,876,876,876,876,876,876,876,
+876,876,876,876,876,876,876,876,876,876,876,876,876,876,876,876,
+876,876,876,876,876,876,876,876,876,876,876,876,876,876,876,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 192 */
-805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,
-805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,
-805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,
-805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,
-805,805,805,805,805,805,805,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+877,877,877,877,877,877,877,877,877,877,877,877,877,877,877,877,
+877,877,877,877,877,877,877,877,877,877,877,877,877,877,877,877,
+877,877,877,877,877,877,877,877,877,877,877,877,877,877,877,877,
+877,877,877,877,877,877,877,877,877,877,877,877,877,877,877,877,
+877,877,877,877,877,877,877,877,877,877,877,877,877,877,877,877,
+877,877,877,877,877,877,877,877,877,877,877,877,877,877,877,877,
+877,877,877,877,877,877,877,877,877,877,877,877,877,877,877,877,
+877,877,877,877,877,877,877,877,877,877,877,877,877,877,877,877,
/* block 193 */
-538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,
-538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,
-538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,
-538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,
-538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,
-538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,
-538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,
-538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,
+877,877,877,877,877,877,877,877,877,877,877,877,877,877,877,877,
+877,877,877,877,877,877,877,877,877,877,877,877,877,877,877,877,
+877,877,877,877,877,877,877,877,877,877,877,877,877,877,877,877,
+877,877,877,877,877,877,877,877,877,877,877,877,877,877,877,877,
+877,877,877,877,877,877,877,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 194 */
-538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,
-538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,
-538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,
-538,538,538,538,538,538,538,538,538,116,116,116,116,116,116,116,
-806,806,806,806,806,806,806,806,806,806,806,806,806,806,806,806,
-806,806,806,806,806,806,806,806,806,806,806,806,806,806,806,116,
-807,807,807,807,807,807,807,807,807,807,116,116,116,116,808,808,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,
+592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,
+592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,
+592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,
+592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,
+592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,
+592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,
+592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,
/* block 195 */
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-809,809,809,809,809,809,809,809,809,809,809,809,809,809,809,809,
-809,809,809,809,809,809,809,809,809,809,809,809,809,809,116,116,
-810,810,810,810,810,811,116,116,116,116,116,116,116,116,116,116,
+592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,
+592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,
+592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,
+592,592,592,592,592,592,592,592,592,119,119,119,119,119,119,119,
+878,878,878,878,878,878,878,878,878,878,878,878,878,878,878,878,
+878,878,878,878,878,878,878,878,878,878,878,878,878,878,878,119,
+879,879,879,879,879,879,879,879,879,879,119,119,119,119,880,880,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 196 */
-812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,
-812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,
-812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,
-813,813,813,813,813,813,813,814,814,814,814,814,815,815,815,815,
-816,816,816,816,814,815,116,116,116,116,116,116,116,116,116,116,
-817,817,817,817,817,817,817,817,817,817,116,818,818,818,818,818,
-818,818,116,812,812,812,812,812,812,812,812,812,812,812,812,812,
-812,812,812,812,812,812,812,812,116,116,116,116,116,812,812,812,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+881,881,881,881,881,881,881,881,881,881,881,881,881,881,881,881,
+881,881,881,881,881,881,881,881,881,881,881,881,881,881,119,119,
+882,882,882,882,882,883,119,119,119,119,119,119,119,119,119,119,
/* block 197 */
-812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+884,884,884,884,884,884,884,884,884,884,884,884,884,884,884,884,
+884,884,884,884,884,884,884,884,884,884,884,884,884,884,884,884,
+884,884,884,884,884,884,884,884,884,884,884,884,884,884,884,884,
+885,885,885,885,885,885,885,886,886,886,886,886,887,887,887,887,
+888,888,888,888,886,887,119,119,119,119,119,119,119,119,119,119,
+889,889,889,889,889,889,889,889,889,889,119,890,890,890,890,890,
+890,890,119,884,884,884,884,884,884,884,884,884,884,884,884,884,
+884,884,884,884,884,884,884,884,119,119,119,119,119,884,884,884,
/* block 198 */
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,
-819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,
-820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,
-820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,
+884,884,884,884,884,884,884,884,884,884,884,884,884,884,884,884,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 199 */
-821,821,821,821,821,821,821,821,821,821,821,821,821,821,821,821,
-821,821,821,821,821,821,821,822,822,822,822,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+891,891,891,891,891,891,891,891,891,891,891,891,891,891,891,891,
+891,891,891,891,891,891,891,891,891,891,891,891,891,891,891,891,
+892,892,892,892,892,892,892,892,892,892,892,892,892,892,892,892,
+892,892,892,892,892,892,892,892,892,892,892,892,892,892,892,892,
/* block 200 */
-823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,
-823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,
-823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,
-823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,
-823,823,823,823,823,116,116,116,116,116,116,116,116,116,116,116,
-823,824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,
-824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,
-824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,116,
+893,893,893,893,893,893,893,893,893,893,893,893,893,893,893,893,
+893,893,893,893,893,893,893,894,894,894,894,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 201 */
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,825,
-825,825,825,826,826,826,826,826,826,826,826,826,826,826,826,826,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-827,828,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+895,895,895,895,895,895,895,895,895,895,895,895,895,895,895,895,
+895,895,895,895,895,895,895,895,895,895,895,895,895,895,895,895,
+895,895,895,895,895,895,895,895,895,895,895,895,895,895,895,895,
+895,895,895,895,895,895,895,895,895,895,895,895,895,895,895,895,
+895,895,895,895,895,119,119,119,119,119,119,119,119,119,119,119,
+895,896,896,896,896,896,896,896,896,896,896,896,896,896,896,896,
+896,896,896,896,896,896,896,896,896,896,896,896,896,896,896,896,
+896,896,896,896,896,896,896,896,896,896,896,896,896,896,896,119,
/* block 202 */
-829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,
-829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,
-829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,
-829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,
-829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,
-829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,
-829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,
-829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,897,
+897,897,897,898,898,898,898,898,898,898,898,898,898,898,898,898,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+899,900,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 203 */
-829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,
-829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,
-829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,
-829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,
-829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,
-829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,
-829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,
-829,829,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,
+901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,
+901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,
+901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,
+901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,
+901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,
+901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,
+901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,
/* block 204 */
-829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,
-829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,
-829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,
-829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,
-829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,
-829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,
-829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,
-829,829,829,116,116,116,116,116,116,116,116,116,116,116,116,116,
+901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,
+901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,
+901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,
+901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,
+901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,
+901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,
+901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,
+901,901,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 205 */
-517,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,
-515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,
-515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,
-515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,
-515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,
-515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,
-515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,
-515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,
+901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,
+901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,
+901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,
+901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,
+901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,
+901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,
+901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,901,
+901,901,901,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 206 */
-515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,
-515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,
-515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,
-515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,
-515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,
-515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,
-515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,
-515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,
+569,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,
+564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,
+564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,
+564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,
+564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,
+564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,
+564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,
+564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,
/* block 207 */
-515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,
-515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,
+564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,
+564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,
+564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,
+564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,
+564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,
+564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,
+564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,
+564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,
/* block 208 */
-830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,
-830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,
-830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,
-830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,
-830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,
-830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,
-830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,
-830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,
+564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,
+564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,
/* block 209 */
-830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,
-830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,
-830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,
-830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,
-830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,
-830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,
-830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,
-830,830,830,830,830,830,830,830,830,830,830,830,116,116,116,116,
+902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,
+902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,
+902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,
+902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,
+902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,
+902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,
+902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,
+902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,
/* block 210 */
-831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,
-831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,
-831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,
-831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,
-831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,
-831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,
-831,831,831,831,831,831,831,831,831,831,831,116,116,116,116,116,
-831,831,831,831,831,831,831,831,831,831,831,831,831,116,116,116,
+902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,
+902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,
+902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,
+902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,
+902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,
+902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,
+902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,902,
+902,902,902,902,902,902,902,902,902,902,902,902,119,119,119,119,
/* block 211 */
-831,831,831,831,831,831,831,831,831,116,116,116,116,116,116,116,
-831,831,831,831,831,831,831,831,831,831,116,116,832,833,833,834,
- 23, 23, 23, 23,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+903,903,903,903,903,903,903,903,903,903,903,903,903,903,903,903,
+903,903,903,903,903,903,903,903,903,903,903,903,903,903,903,903,
+903,903,903,903,903,903,903,903,903,903,903,903,903,903,903,903,
+903,903,903,903,903,903,903,903,903,903,903,903,903,903,903,903,
+903,903,903,903,903,903,903,903,903,903,903,903,903,903,903,903,
+903,903,903,903,903,903,903,903,903,903,903,903,903,903,903,903,
+903,903,903,903,903,903,903,903,903,903,903,119,119,119,119,119,
+903,903,903,903,903,903,903,903,903,903,903,903,903,119,119,119,
/* block 212 */
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19,116,116,116,116,116,116,116,116,116,116,
+903,903,903,903,903,903,903,903,903,119,119,119,119,119,119,119,
+903,903,903,903,903,903,903,903,903,903,119,119,904,905,905,906,
+907,907,907,907,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 213 */
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19,116,116, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19,835,438,111,111,111, 19, 19, 19,438,835,835,
-835,835,835, 23, 23, 23, 23, 23, 23, 23, 23,111,111,111,111,111,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20,119,119,119,119,119,119,119,119,119,119,
/* block 214 */
-111,111,111, 19, 19,111,111,111,111,111,111,111, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,111,111,111,111, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20,119,119, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20,908,909,112,112,112, 20, 20, 20,909,908,908,
+908,908,908, 24, 24, 24, 24, 24, 24, 24, 24,112,112,112,112,112,
/* block 215 */
-604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,
-604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,
-604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,
-604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,
-604,604,836,836,836,604,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+112,112,112, 20, 20,112,112,112,112,112,112,112, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,112,112,112,112, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 216 */
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
- 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
- 24, 24, 24, 24,116,116,116,116,116,116,116,116,116,116,116,116,
+671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,
+671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,
+671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,
+671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,
+671,671,910,910,910,671,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 217 */
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19,116,116,116,116,116,116,116,116,116,
- 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
- 24, 24, 24, 24, 24, 24, 24, 24, 24,116,116,116,116,116,116,116,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 218 */
-472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,
-472,472,472,472,472,472,472,472,472,472,473,473,473,473,473,473,
-473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,
-473,473,473,473,472,472,472,472,472,472,472,472,472,472,472,472,
-472,472,472,472,472,472,472,472,472,472,472,472,472,472,473,473,
-473,473,473,473,473,116,473,473,473,473,473,473,473,473,473,473,
-473,473,473,473,473,473,473,473,472,472,472,472,472,472,472,472,
-472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20,119,119,119,119,119,119,119,119,119,
+573,573,573,573,573,573,573,573,573,573,573,573,573,573,573,573,
+573,573, 25, 25, 25, 25, 25, 25, 25,119,119,119,119,119,119,119,
/* block 219 */
-472,472,473,473,473,473,473,473,473,473,473,473,473,473,473,473,
-473,473,473,473,473,473,473,473,473,473,473,473,472,116,472,472,
-116,116,472,116,116,472,472,116,116,472,472,472,472,116,472,472,
-472,472,472,472,472,472,473,473,473,473,116,473,116,473,473,473,
-473,473,473,473,116,473,473,473,473,473,473,473,473,473,473,473,
-472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,
-472,472,472,472,472,472,472,472,472,472,473,473,473,473,473,473,
-473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,
+504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,
+504,504,504,504,504,504,504,504,504,504,505,505,505,505,505,505,
+505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,
+505,505,505,505,504,504,504,504,504,504,504,504,504,504,504,504,
+504,504,504,504,504,504,504,504,504,504,504,504,504,504,505,505,
+505,505,505,505,505,119,505,505,505,505,505,505,505,505,505,505,
+505,505,505,505,505,505,505,505,504,504,504,504,504,504,504,504,
+504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,
/* block 220 */
-473,473,473,473,472,472,116,472,472,472,472,116,116,472,472,472,
-472,472,472,472,472,116,472,472,472,472,472,472,472,116,473,473,
-473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,
-473,473,473,473,473,473,473,473,472,472,116,472,472,472,472,116,
-472,472,472,472,472,116,472,116,116,116,472,472,472,472,472,472,
-472,116,473,473,473,473,473,473,473,473,473,473,473,473,473,473,
-473,473,473,473,473,473,473,473,473,473,473,473,472,472,472,472,
-472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,
+504,504,505,505,505,505,505,505,505,505,505,505,505,505,505,505,
+505,505,505,505,505,505,505,505,505,505,505,505,504,119,504,504,
+119,119,504,119,119,504,504,119,119,504,504,504,504,119,504,504,
+504,504,504,504,504,504,505,505,505,505,119,505,119,505,505,505,
+505,505,505,505,119,505,505,505,505,505,505,505,505,505,505,505,
+504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,
+504,504,504,504,504,504,504,504,504,504,505,505,505,505,505,505,
+505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,
/* block 221 */
-472,472,472,472,472,472,473,473,473,473,473,473,473,473,473,473,
-473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,
-472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,
-472,472,472,472,472,472,472,472,472,472,473,473,473,473,473,473,
-473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,
-473,473,473,473,472,472,472,472,472,472,472,472,472,472,472,472,
-472,472,472,472,472,472,472,472,472,472,472,472,472,472,473,473,
-473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,
+505,505,505,505,504,504,119,504,504,504,504,119,119,504,504,504,
+504,504,504,504,504,119,504,504,504,504,504,504,504,119,505,505,
+505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,
+505,505,505,505,505,505,505,505,504,504,119,504,504,504,504,119,
+504,504,504,504,504,119,504,119,119,119,504,504,504,504,504,504,
+504,119,505,505,505,505,505,505,505,505,505,505,505,505,505,505,
+505,505,505,505,505,505,505,505,505,505,505,505,504,504,504,504,
+504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,
/* block 222 */
-473,473,473,473,473,473,473,473,472,472,472,472,472,472,472,472,
-472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,
-472,472,473,473,473,473,473,473,473,473,473,473,473,473,473,473,
-473,473,473,473,473,473,473,473,473,473,473,473,472,472,472,472,
-472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,
-472,472,472,472,472,472,473,473,473,473,473,473,473,473,473,473,
-473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,
-472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,
+504,504,504,504,504,504,505,505,505,505,505,505,505,505,505,505,
+505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,
+504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,
+504,504,504,504,504,504,504,504,504,504,505,505,505,505,505,505,
+505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,
+505,505,505,505,504,504,504,504,504,504,504,504,504,504,504,504,
+504,504,504,504,504,504,504,504,504,504,504,504,504,504,505,505,
+505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,
/* block 223 */
-472,472,472,472,472,472,472,472,472,472,473,473,473,473,473,473,
-473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,
-473,473,473,473,473,473,116,116,472,472,472,472,472,472,472,472,
-472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,
-472, 8,473,473,473,473,473,473,473,473,473,473,473,473,473,473,
-473,473,473,473,473,473,473,473,473,473,473, 8,473,473,473,473,
-473,473,472,472,472,472,472,472,472,472,472,472,472,472,472,472,
-472,472,472,472,472,472,472,472,472,472,472, 8,473,473,473,473,
+505,505,505,505,505,505,505,505,504,504,504,504,504,504,504,504,
+504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,
+504,504,505,505,505,505,505,505,505,505,505,505,505,505,505,505,
+505,505,505,505,505,505,505,505,505,505,505,505,504,504,504,504,
+504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,
+504,504,504,504,504,504,505,505,505,505,505,505,505,505,505,505,
+505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,
+504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,
/* block 224 */
-473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,
-473,473,473,473,473, 8,473,473,473,473,473,473,472,472,472,472,
-472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,
-472,472,472,472,472, 8,473,473,473,473,473,473,473,473,473,473,
-473,473,473,473,473,473,473,473,473,473,473,473,473,473,473, 8,
-473,473,473,473,473,473,472,472,472,472,472,472,472,472,472,472,
-472,472,472,472,472,472,472,472,472,472,472,472,472,472,472, 8,
-473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,
+504,504,504,504,504,504,504,504,504,504,505,505,505,505,505,505,
+505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,
+505,505,505,505,505,505,119,119,504,504,504,504,504,504,504,504,
+504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,
+504, 9,505,505,505,505,505,505,505,505,505,505,505,505,505,505,
+505,505,505,505,505,505,505,505,505,505,505, 9,505,505,505,505,
+505,505,504,504,504,504,504,504,504,504,504,504,504,504,504,504,
+504,504,504,504,504,504,504,504,504,504,504, 9,505,505,505,505,
/* block 225 */
-473,473,473,473,473,473,473,473,473, 8,473,473,473,473,473,473,
-472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,
-472,472,472,472,472,472,472,472,472, 8,473,473,473,473,473,473,
-473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,
-473,473,473, 8,473,473,473,473,473,473,472,473,116,116, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,
+505,505,505,505,505, 9,505,505,505,505,505,505,504,504,504,504,
+504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,
+504,504,504,504,504, 9,505,505,505,505,505,505,505,505,505,505,
+505,505,505,505,505,505,505,505,505,505,505,505,505,505,505, 9,
+505,505,505,505,505,505,504,504,504,504,504,504,504,504,504,504,
+504,504,504,504,504,504,504,504,504,504,504,504,504,504,504, 9,
+505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,
/* block 226 */
-837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,
-837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,
-837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,
-837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,
-837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,
-837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,
-837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,
-837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,
+505,505,505,505,505,505,505,505,505, 9,505,505,505,505,505,505,
+504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,
+504,504,504,504,504,504,504,504,504, 9,505,505,505,505,505,505,
+505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,
+505,505,505, 9,505,505,505,505,505,505,504,505,119,119, 11, 11,
+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
/* block 227 */
-838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,
-838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,
-838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,
-838,838,838,838,838,838,838,837,837,837,837,838,838,838,838,838,
-838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,
-838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,
-838,838,838,838,838,838,838,838,838,838,838,838,838,837,837,837,
-837,837,837,837,837,838,837,837,837,837,837,837,837,837,837,837,
+911,911,911,911,911,911,911,911,911,911,911,911,911,911,911,911,
+911,911,911,911,911,911,911,911,911,911,911,911,911,911,911,911,
+911,911,911,911,911,911,911,911,911,911,911,911,911,911,911,911,
+911,911,911,911,911,911,911,911,911,911,911,911,911,911,911,911,
+911,911,911,911,911,911,911,911,911,911,911,911,911,911,911,911,
+911,911,911,911,911,911,911,911,911,911,911,911,911,911,911,911,
+911,911,911,911,911,911,911,911,911,911,911,911,911,911,911,911,
+911,911,911,911,911,911,911,911,911,911,911,911,911,911,911,911,
/* block 228 */
-837,837,837,837,838,837,837,839,839,839,839,839,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,838,838,838,838,838,
-116,838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+912,912,912,912,912,912,912,912,912,912,912,912,912,912,912,912,
+912,912,912,912,912,912,912,912,912,912,912,912,912,912,912,912,
+912,912,912,912,912,912,912,912,912,912,912,912,912,912,912,912,
+912,912,912,912,912,912,912,911,911,911,911,912,912,912,912,912,
+912,912,912,912,912,912,912,912,912,912,912,912,912,912,912,912,
+912,912,912,912,912,912,912,912,912,912,912,912,912,912,912,912,
+912,912,912,912,912,912,912,912,912,912,912,912,912,911,911,911,
+911,911,911,911,911,912,911,911,911,911,911,911,911,911,911,911,
/* block 229 */
-840,840,840,840,840,840,840,116,840,840,840,840,840,840,840,840,
-840,840,840,840,840,840,840,840,840,116,116,840,840,840,840,840,
-840,840,116,840,840,116,840,840,840,840,840,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+911,911,911,911,912,911,911,913,913,913,913,913,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,912,912,912,912,912,
+119,912,912,912,912,912,912,912,912,912,912,912,912,912,912,912,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 230 */
-841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,
-841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,
-841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,
-841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,
-841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,
-841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,
-841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,
-841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,
+914,914,914,914,914,914,914,119,914,914,914,914,914,914,914,914,
+914,914,914,914,914,914,914,914,914,119,119,914,914,914,914,914,
+914,914,119,914,914,119,914,914,914,914,914,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 231 */
-841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,
-841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,
-841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,
-841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,
-841,841,841,841,841,116,116,842,842,842,842,842,842,842,842,842,
-843,843,843,843,843,843,843,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+915,915,915,915,915,915,915,915,915,915,915,915,915,915,915,915,
+915,915,915,915,915,915,915,915,915,915,915,915,915,915,915,915,
+915,915,915,915,915,915,915,915,915,915,915,915,915,915,915,915,
+915,915,915,915,915,915,915,915,915,915,915,915,915,915,915,915,
+915,915,915,915,915,915,915,915,915,915,915,915,915,915,915,915,
+915,915,915,915,915,915,915,915,915,915,915,915,915,915,915,915,
+915,915,915,915,915,915,915,915,915,915,915,915,915,915,915,915,
+915,915,915,915,915,915,915,915,915,915,915,915,915,915,915,915,
/* block 232 */
-844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,
-844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,
-844,844,845,845,845,845,845,845,845,845,845,845,845,845,845,845,
-845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,
-845,845,845,845,846,846,846,846,846,846,846,116,116,116,116,116,
-847,847,847,847,847,847,847,847,847,847,116,116,116,116,848,848,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+915,915,915,915,915,915,915,915,915,915,915,915,915,915,915,915,
+915,915,915,915,915,915,915,915,915,915,915,915,915,915,915,915,
+915,915,915,915,915,915,915,915,915,915,915,915,915,915,915,915,
+915,915,915,915,915,915,915,915,915,915,915,915,915,915,915,915,
+915,915,915,915,915,119,119,916,916,916,916,916,916,916,916,916,
+917,917,917,917,917,917,917,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 233 */
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+918,918,918,918,918,918,918,918,918,918,918,918,918,918,918,918,
+918,918,918,918,918,918,918,918,918,918,918,918,918,918,918,918,
+918,918,919,919,919,919,919,919,919,919,919,919,919,919,919,919,
+919,919,919,919,919,919,919,919,919,919,919,919,919,919,919,919,
+919,919,919,919,920,920,920,920,920,920,920,119,119,119,119,119,
+921,921,921,921,921,921,921,921,921,921,119,119,119,119,922,922,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 234 */
- 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
- 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
- 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 19, 24, 24, 24,
- 5, 24, 24, 24, 24,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
/* block 235 */
-217,217,217,217,116,217,217,217,217,217,217,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,
-116,217,217,116,217,116,116,217,116,217,217,217,217,217,217,217,
-217,217,217,116,217,217,217,217,116,217,116,217,116,116,116,116,
-116,116,217,116,116,116,116,217,116,217,116,217,116,217,217,217,
-116,217,217,116,217,116,116,217,116,217,116,217,116,217,116,217,
-116,217,217,116,217,116,116,217,217,217,217,116,217,217,217,217,
-217,217,217,116,217,217,217,217,116,217,217,217,217,116,217,116,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 20, 25, 25, 25,
+ 6, 25, 25, 25, 25,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 236 */
-217,217,217,217,217,217,217,217,217,217,116,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,116,116,116,116,
-116,217,217,217,116,217,217,217,217,217,116,217,217,217,217,217,
-217,217,217,217,217,217,217,217,217,217,217,217,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-211,211,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+224,224,224,224,119,224,224,224,224,224,224,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,
+119,224,224,119,224,119,119,224,119,224,224,224,224,224,224,224,
+224,224,224,119,224,224,224,224,119,224,119,224,119,119,119,119,
+119,119,224,119,119,119,119,224,119,224,119,224,119,224,224,224,
+119,224,224,119,224,119,119,224,119,224,119,224,119,224,119,224,
+119,224,224,119,224,119,119,224,224,224,224,119,224,224,224,224,
+224,224,224,119,224,224,224,224,119,224,224,224,224,119,224,119,
/* block 237 */
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,849,849,849,849,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+224,224,224,224,224,224,224,224,224,224,119,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,119,119,119,119,
+119,224,224,224,119,224,224,224,224,224,119,224,224,224,224,224,
+224,224,224,224,224,224,224,224,224,224,224,224,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+217,217,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 238 */
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20,849,849,849,849,849,849,849,849,849,849,849,849,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,849,
-849, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
-849, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
-849, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20,849,849,849,849,849,849,849,849,849,849,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,923,923,923,923,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
/* block 239 */
- 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,849,849,849,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,849,849,849,849,
- 20, 20, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21,923,923,923,923,923,923,923,923,923,923,923,923,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,923,
+923, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+923, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+923, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21,923,923,923,923,923,923,923,923,923,923,
/* block 240 */
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 19,
- 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,850,850,850,850,850,850,850,850,850,850,
-850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,923,923,923,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,923,923,923,923,
+ 21, 21, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21,
/* block 241 */
-851, 20, 20,849,849,849,849,849,849,849,849,849,849,849,849,849,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20,
- 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 19,849,849,849,849,
- 19, 19, 19, 19, 19, 19, 19, 19, 19,849,849,849,849,849,849,849,
- 20, 20,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
- 20, 20, 20, 20, 20, 20,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, 20,
+ 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,924,924,924,924,924,924,924,924,924,924,
+924,924,924,924,924,924,924,924,924,924,924,924,924,924,924,924,
/* block 242 */
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
+925, 21, 21,923,923,923,923,923,923,923,923,923,923,923,923,923,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21,
+ 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 20,923,923,923,923,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20,923,923,923,923,923,923,923,
+575,575,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+ 21, 21, 21, 21, 21, 21,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
/* block 243 */
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
/* block 244 */
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+
+/* block 245 */
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,926,926,926,926,926,
+
+/* block 246 */
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 20, 20,
+ 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+
+/* block 247 */
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,852,852,852,852,852,
-/* block 245 */
+/* block 248 */
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21,923,923,923,923,923,923,923,923,923,923,923,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,923,923,923,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,923,923,923,923,923,923,
+
+/* block 249 */
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 19, 19,
- 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20,923,923,923,923,923,923,923,923,923,923,923,923,
-/* block 246 */
+/* block 250 */
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 20, 20, 20, 20, 20, 21, 21, 21, 21,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
-/* block 247 */
+/* block 251 */
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,923,923,923,923,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20,923,923,923,923,923,923,923,923,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,923,923,923,923,923,923,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20,849,849,849,849,849,849,849,849,849,849,849,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,849,849,849,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,849,849,849,849,849,849,
-
-/* block 248 */
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19,849,849,849,849,849,849,849,849,849,849,849,849,
-
-/* block 249 */
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 20, 20, 20, 20,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-
-/* block 250 */
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,849,849,849,849,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,849,849,849,849,849,849,849,849,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,849,849,849,849,849,849,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
-
-/* block 251 */
- 19, 19, 19, 19, 19, 19, 19, 19,849,849,849,849,849,849,849,849,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
/* block 252 */
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,849,849,849,849,
+ 20, 20, 20, 20, 20, 20, 20, 20,923,923,923,923,923,923,923,923,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 19, 20, 20, 20,849,
- 20, 20, 20, 20, 20, 20, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20,849,849, 20, 20, 20, 20,849,849,849, 20,849, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
/* block 253 */
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20,849,849,849,849,849,849,849,849,849,849,849,849,849,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,849,849,849,849,849,849,
- 20, 20, 20,849,849,849,849,849,849,849,849,849,849,849,849,849,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,923,923,923,923,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 20, 21, 21, 21,923,
+ 21, 21, 21, 21, 21, 21, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21,923,923, 21, 21, 21, 21,923,923,923, 21,923, 21, 21, 21, 21,
/* block 254 */
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21,923,923,923,923,923,923,923,923,923,923,923,923,923,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,923,923,923,923,923,923,
+ 21, 21, 21,923,923,923,923,923,923,923,923,923,923,923,923,923,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
/* block 255 */
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
-849,849,849,849,849,849,849,849,849,849,849,849,849,849,116,116,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
/* block 256 */
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,923,
+923,923,923,923,923,923,923,923,923,923,923,923,923,923,119,119,
/* block 257 */
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,116,116,116,116,116,116,116,116,116,116,116,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 258 */
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,116,116,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,119,119,119,119,119,119,119,119,119,119,119,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
/* block 259 */
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,119,119,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
/* block 260 */
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
/* block 261 */
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
-523,523,523,523,523,523,523,523,523,523,523,523,523,523,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
-116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 262 */
-471, 23,471,471,471,471,471,471,471,471,471,471,471,471,471,471,
-471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,
-853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,
-853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,
-853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,
-853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,
-853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,
-853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
+577,577,577,577,577,577,577,577,577,577,577,577,577,577,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
+119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,
/* block 263 */
-471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,
-471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,
-471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,
-471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,
-471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,
-471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,
-471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,
-471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,
+502, 24,502,502,502,502,502,502,502,502,502,502,502,502,502,502,
+502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,
+927,927,927,927,927,927,927,927,927,927,927,927,927,927,927,927,
+927,927,927,927,927,927,927,927,927,927,927,927,927,927,927,927,
+927,927,927,927,927,927,927,927,927,927,927,927,927,927,927,927,
+927,927,927,927,927,927,927,927,927,927,927,927,927,927,927,927,
+927,927,927,927,927,927,927,927,927,927,927,927,927,927,927,927,
+927,927,927,927,927,927,927,927,927,927,927,927,927,927,927,927,
/* block 264 */
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
+502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,
+502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,
+502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,
+502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,
+502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,
+502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,
+502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,
+502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,
/* block 265 */
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
-111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
-471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,
/* block 266 */
-597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,
-597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,
-597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,
-597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,
-597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,
-597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,
-597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,
-597,597,597,597,597,597,597,597,597,597,597,597,597,597,116,116,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,
+112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,
+502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,
+
+/* block 267 */
+659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,
+659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,
+659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,
+659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,
+659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,
+659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,
+659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,
+659,659,659,659,659,659,659,659,659,659,659,659,659,659,119,119,
};
diff --git a/thirdparty/pcre2/src/pcre2_ucp.h b/thirdparty/pcre2/src/pcre2_ucp.h
index 0c330edcb2..483abd18fc 100644
--- a/thirdparty/pcre2/src/pcre2_ucp.h
+++ b/thirdparty/pcre2/src/pcre2_ucp.h
@@ -124,6 +124,7 @@ enum {
/* These are the script identifications. */
enum {
+ ucp_Unknown,
ucp_Arabic,
ucp_Armenian,
ucp_Bengali,
diff --git a/thirdparty/pcre2/src/pcre2_xclass.c b/thirdparty/pcre2/src/pcre2_xclass.c
index 407d3f5b87..8b052be66a 100644
--- a/thirdparty/pcre2/src/pcre2_xclass.c
+++ b/thirdparty/pcre2/src/pcre2_xclass.c
@@ -7,7 +7,7 @@ and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
Original API code Copyright (c) 1997-2012 University of Cambridge
- New API code Copyright (c) 2016 University of Cambridge
+ New API code Copyright (c) 2016-2019 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -85,10 +85,10 @@ if (c < 256)
if ((*data & XCL_HASPROP) == 0)
{
if ((*data & XCL_MAP) == 0) return negated;
- return (((uint8_t *)(data + 1))[c/8] & (1 << (c&7))) != 0;
+ return (((uint8_t *)(data + 1))[c/8] & (1u << (c&7))) != 0;
}
if ((*data & XCL_MAP) != 0 &&
- (((uint8_t *)(data + 1))[c/8] & (1 << (c&7))) != 0)
+ (((uint8_t *)(data + 1))[c/8] & (1u << (c&7))) != 0)
return !negated; /* char found */
}
diff --git a/thirdparty/pcre2/src/sljit/sljitConfigInternal.h b/thirdparty/pcre2/src/sljit/sljitConfigInternal.h
index f5703e8e7f..ba60311e45 100644
--- a/thirdparty/pcre2/src/sljit/sljitConfigInternal.h
+++ b/thirdparty/pcre2/src/sljit/sljitConfigInternal.h
@@ -530,7 +530,7 @@ typedef double sljit_f64;
#endif /* !SLJIT_FUNC */
#ifndef SLJIT_INDIRECT_CALL
-#if ((defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) && (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)) \
+#if ((defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) && (!defined _CALL_ELF || _CALL_ELF == 1)) \
|| ((defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) && defined _AIX)
/* It seems certain ppc compilers use an indirect addressing for functions
which makes things complicated. */
diff --git a/thirdparty/pcre2/src/sljit/sljitExecAllocator.c b/thirdparty/pcre2/src/sljit/sljitExecAllocator.c
index 7c18578618..3b37a9751f 100644
--- a/thirdparty/pcre2/src/sljit/sljitExecAllocator.c
+++ b/thirdparty/pcre2/src/sljit/sljitExecAllocator.c
@@ -94,6 +94,46 @@ static SLJIT_INLINE void free_chunk(void *chunk, sljit_uw size)
#else
+#ifdef __APPLE__
+/* Configures TARGET_OS_OSX when appropriate */
+#include <TargetConditionals.h>
+
+#if TARGET_OS_OSX && defined(MAP_JIT)
+#include <sys/utsname.h>
+#endif /* TARGET_OS_OSX && MAP_JIT */
+
+#ifdef MAP_JIT
+
+static SLJIT_INLINE int get_map_jit_flag()
+{
+#if TARGET_OS_OSX
+ /* On macOS systems, returns MAP_JIT if it is defined _and_ we're running on a version
+ of macOS where it's OK to have more than one JIT block. On non-macOS systems, returns
+ MAP_JIT if it is defined. */
+ static int map_jit_flag = -1;
+
+ /* The following code is thread safe because multiple initialization
+ sets map_jit_flag to the same value and the code has no side-effects.
+ Changing the kernel version witout system restart is (very) unlikely. */
+ if (map_jit_flag == -1) {
+ struct utsname name;
+
+ uname(&name);
+
+ /* Kernel version for 10.14.0 (Mojave) */
+ map_jit_flag = (atoi(name.release) >= 18) ? MAP_JIT : 0;
+ }
+
+ return map_jit_flag;
+#else /* !TARGET_OS_OSX */
+ return MAP_JIT;
+#endif /* TARGET_OS_OSX */
+}
+
+#endif /* MAP_JIT */
+
+#endif /* __APPLE__ */
+
static SLJIT_INLINE void* alloc_chunk(sljit_uw size)
{
void *retval;
@@ -103,17 +143,17 @@ static SLJIT_INLINE void* alloc_chunk(sljit_uw size)
int flags = MAP_PRIVATE | MAP_ANON;
#ifdef MAP_JIT
- flags |= MAP_JIT;
+ flags |= get_map_jit_flag();
#endif
retval = mmap(NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, flags, -1, 0);
-#else
+#else /* !MAP_ANON */
if (dev_zero < 0) {
if (open_dev_zero())
return NULL;
}
retval = mmap(NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, dev_zero, 0);
-#endif
+#endif /* MAP_ANON */
return (retval != MAP_FAILED) ? retval : NULL;
}
diff --git a/thirdparty/pcre2/src/sljit/sljitLir.c b/thirdparty/pcre2/src/sljit/sljitLir.c
index 5bdddc10cf..ded9541b31 100644
--- a/thirdparty/pcre2/src/sljit/sljitLir.c
+++ b/thirdparty/pcre2/src/sljit/sljitLir.c
@@ -201,15 +201,16 @@
# define IS_CALL 0x010
# define IS_BIT26_COND 0x020
# define IS_BIT16_COND 0x040
+# define IS_BIT23_COND 0x080
-# define IS_COND (IS_BIT26_COND | IS_BIT16_COND)
+# define IS_COND (IS_BIT26_COND | IS_BIT16_COND | IS_BIT23_COND)
-# define PATCH_B 0x080
-# define PATCH_J 0x100
+# define PATCH_B 0x100
+# define PATCH_J 0x200
#if (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
-# define PATCH_ABS32 0x200
-# define PATCH_ABS48 0x400
+# define PATCH_ABS32 0x400
+# define PATCH_ABS48 0x800
#endif
/* instruction types */
diff --git a/thirdparty/pcre2/src/sljit/sljitNativeARM_64.c b/thirdparty/pcre2/src/sljit/sljitNativeARM_64.c
index 27af741487..b015695c52 100644
--- a/thirdparty/pcre2/src/sljit/sljitNativeARM_64.c
+++ b/thirdparty/pcre2/src/sljit/sljitNativeARM_64.c
@@ -51,7 +51,7 @@ static const sljit_u8 freg_map[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 3] = {
0, 0, 1, 2, 3, 4, 5, 6, 7
};
-#define W_OP (1 << 31)
+#define W_OP (1u << 31)
#define RD(rd) (reg_map[rd])
#define RT(rt) (reg_map[rt])
#define RN(rn) (reg_map[rn] << 5)
@@ -560,7 +560,7 @@ static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, s
/* dst must be register, TMP_REG1
arg1 must be register, TMP_REG1, imm
arg2 must be register, TMP_REG2, imm */
- sljit_ins inv_bits = (flags & INT_OP) ? (1 << 31) : 0;
+ sljit_ins inv_bits = (flags & INT_OP) ? W_OP : 0;
sljit_ins inst_bits;
sljit_s32 op = (flags & 0xffff);
sljit_s32 reg;
@@ -710,7 +710,7 @@ static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, s
return push_inst(compiler, ORR | RD(dst) | RN(TMP_ZERO) | RM(arg2));
case SLJIT_MOV_U8:
SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG1);
- return push_inst(compiler, (UBFM ^ (1 << 31)) | RD(dst) | RN(arg2) | (7 << 10));
+ return push_inst(compiler, (UBFM ^ W_OP) | RD(dst) | RN(arg2) | (7 << 10));
case SLJIT_MOV_S8:
SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG1);
if (!(flags & INT_OP))
@@ -718,7 +718,7 @@ static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, s
return push_inst(compiler, (SBFM ^ inv_bits) | RD(dst) | RN(arg2) | (7 << 10));
case SLJIT_MOV_U16:
SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG1);
- return push_inst(compiler, (UBFM ^ (1 << 31)) | RD(dst) | RN(arg2) | (15 << 10));
+ return push_inst(compiler, (UBFM ^ W_OP) | RD(dst) | RN(arg2) | (15 << 10));
case SLJIT_MOV_S16:
SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG1);
if (!(flags & INT_OP))
@@ -728,7 +728,7 @@ static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, s
SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG1);
if ((flags & INT_OP) && dst == arg2)
return SLJIT_SUCCESS;
- return push_inst(compiler, (ORR ^ (1 << 31)) | RD(dst) | RN(TMP_ZERO) | RM(arg2));
+ return push_inst(compiler, (ORR ^ W_OP) | RD(dst) | RN(TMP_ZERO) | RM(arg2));
case SLJIT_MOV_S32:
SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG1);
if ((flags & INT_OP) && dst == arg2)
@@ -1080,7 +1080,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *comp
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op)
{
- sljit_ins inv_bits = (op & SLJIT_I32_OP) ? (1 << 31) : 0;
+ sljit_ins inv_bits = (op & SLJIT_I32_OP) ? W_OP : 0;
CHECK_ERROR();
CHECK(check_sljit_emit_op0(compiler, op));
@@ -1360,7 +1360,7 @@ static SLJIT_INLINE sljit_s32 sljit_emit_fop1_conv_sw_from_f64(struct sljit_comp
sljit_ins inv_bits = (op & SLJIT_F32_OP) ? (1 << 22) : 0;
if (GET_OPCODE(op) == SLJIT_CONV_S32_FROM_F64)
- inv_bits |= (1 << 31);
+ inv_bits |= W_OP;
if (src & SLJIT_MEM) {
emit_fop_mem(compiler, (op & SLJIT_F32_OP) ? INT_SIZE : WORD_SIZE, TMP_FREG1, src, srcw);
@@ -1382,7 +1382,7 @@ static SLJIT_INLINE sljit_s32 sljit_emit_fop1_conv_f64_from_sw(struct sljit_comp
sljit_ins inv_bits = (op & SLJIT_F32_OP) ? (1 << 22) : 0;
if (GET_OPCODE(op) == SLJIT_CONV_F64_FROM_S32)
- inv_bits |= (1 << 31);
+ inv_bits |= W_OP;
if (src & SLJIT_MEM) {
emit_op_mem(compiler, ((GET_OPCODE(op) == SLJIT_CONV_F64_FROM_S32) ? INT_SIZE : WORD_SIZE), TMP_REG1, src, srcw, TMP_REG1);
@@ -1662,7 +1662,7 @@ static SLJIT_INLINE struct sljit_jump* emit_cmp_to0(struct sljit_compiler *compi
sljit_s32 src, sljit_sw srcw)
{
struct sljit_jump *jump;
- sljit_ins inv_bits = (type & SLJIT_I32_OP) ? (1 << 31) : 0;
+ sljit_ins inv_bits = (type & SLJIT_I32_OP) ? W_OP : 0;
SLJIT_ASSERT((type & 0xff) == SLJIT_EQUAL || (type & 0xff) == SLJIT_NOT_EQUAL);
ADJUST_LOCAL_OFFSET(src, srcw);
@@ -1787,7 +1787,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_cmov(struct sljit_compiler *compil
sljit_s32 dst_reg,
sljit_s32 src, sljit_sw srcw)
{
- sljit_ins inv_bits = (dst_reg & SLJIT_I32_OP) ? (1 << 31) : 0;
+ sljit_ins inv_bits = (dst_reg & SLJIT_I32_OP) ? W_OP : 0;
sljit_ins cc;
CHECK_ERROR();
diff --git a/thirdparty/pcre2/src/sljit/sljitNativeMIPS_32.c b/thirdparty/pcre2/src/sljit/sljitNativeMIPS_32.c
index 094c9923bc..ad970bf25a 100644
--- a/thirdparty/pcre2/src/sljit/sljitNativeMIPS_32.c
+++ b/thirdparty/pcre2/src/sljit/sljitNativeMIPS_32.c
@@ -368,16 +368,21 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl
SLJIT_ASSERT(!(flags & SRC2_IMM));
if (GET_FLAG_TYPE(op) != SLJIT_MUL_OVERFLOW) {
-#if (defined SLJIT_MIPS_R1 && SLJIT_MIPS_R1)
+#if (defined SLJIT_MIPS_R1 && SLJIT_MIPS_R1) || (defined SLJIT_MIPS_R6 && SLJIT_MIPS_R6)
return push_inst(compiler, MUL | S(src1) | T(src2) | D(dst), DR(dst));
-#else
+#else /* !SLJIT_MIPS_R1 && !SLJIT_MIPS_R6 */
FAIL_IF(push_inst(compiler, MULT | S(src1) | T(src2), MOVABLE_INS));
return push_inst(compiler, MFLO | D(dst), DR(dst));
-#endif
+#endif /* SLJIT_MIPS_R1 || SLJIT_MIPS_R6 */
}
+#if (defined SLJIT_MIPS_R6 && SLJIT_MIPS_R6)
+ FAIL_IF(push_inst(compiler, MUL | S(src1) | T(src2) | D(dst), DR(dst)));
+ FAIL_IF(push_inst(compiler, MUH | S(src1) | T(src2) | DA(EQUAL_FLAG), EQUAL_FLAG));
+#else /* !SLJIT_MIPS_R6 */
FAIL_IF(push_inst(compiler, MULT | S(src1) | T(src2), MOVABLE_INS));
FAIL_IF(push_inst(compiler, MFHI | DA(EQUAL_FLAG), EQUAL_FLAG));
FAIL_IF(push_inst(compiler, MFLO | D(dst), DR(dst)));
+#endif /* SLJIT_MIPS_R6 */
FAIL_IF(push_inst(compiler, SRA | T(dst) | DA(OTHER_FLAG) | SH_IMM(31), OTHER_FLAG));
return push_inst(compiler, SUBU | SA(EQUAL_FLAG) | TA(OTHER_FLAG) | DA(OTHER_FLAG), OTHER_FLAG);
diff --git a/thirdparty/pcre2/src/sljit/sljitNativeMIPS_64.c b/thirdparty/pcre2/src/sljit/sljitNativeMIPS_64.c
index f841aef5dd..a6a2bcc0c9 100644
--- a/thirdparty/pcre2/src/sljit/sljitNativeMIPS_64.c
+++ b/thirdparty/pcre2/src/sljit/sljitNativeMIPS_64.c
@@ -459,19 +459,26 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl
SLJIT_ASSERT(!(flags & SRC2_IMM));
if (GET_FLAG_TYPE(op) != SLJIT_MUL_OVERFLOW) {
-#if (defined SLJIT_MIPS_R1 && SLJIT_MIPS_R1)
+#if (defined SLJIT_MIPS_R6 && SLJIT_MIPS_R6)
+ return push_inst(compiler, SELECT_OP(DMUL, MUL) | S(src1) | T(src2) | D(dst), DR(dst));
+#elif (defined SLJIT_MIPS_R1 && SLJIT_MIPS_R1)
if (op & SLJIT_I32_OP)
return push_inst(compiler, MUL | S(src1) | T(src2) | D(dst), DR(dst));
FAIL_IF(push_inst(compiler, DMULT | S(src1) | T(src2), MOVABLE_INS));
return push_inst(compiler, MFLO | D(dst), DR(dst));
-#else
+#else /* !SLJIT_MIPS_R6 && !SLJIT_MIPS_R1 */
FAIL_IF(push_inst(compiler, SELECT_OP(DMULT, MULT) | S(src1) | T(src2), MOVABLE_INS));
return push_inst(compiler, MFLO | D(dst), DR(dst));
-#endif
+#endif /* SLJIT_MIPS_R6 */
}
+#if (defined SLJIT_MIPS_R6 && SLJIT_MIPS_R6)
+ FAIL_IF(push_inst(compiler, SELECT_OP(DMUL, MUL) | S(src1) | T(src2) | D(dst), DR(dst)));
+ FAIL_IF(push_inst(compiler, SELECT_OP(DMUH, MUH) | S(src1) | T(src2) | DA(EQUAL_FLAG), EQUAL_FLAG));
+#else /* !SLJIT_MIPS_R6 */
FAIL_IF(push_inst(compiler, SELECT_OP(DMULT, MULT) | S(src1) | T(src2), MOVABLE_INS));
FAIL_IF(push_inst(compiler, MFHI | DA(EQUAL_FLAG), EQUAL_FLAG));
FAIL_IF(push_inst(compiler, MFLO | D(dst), DR(dst)));
+#endif /* SLJIT_MIPS_R6 */
FAIL_IF(push_inst(compiler, SELECT_OP(DSRA32, SRA) | T(dst) | DA(OTHER_FLAG) | SH_IMM(31), OTHER_FLAG));
return push_inst(compiler, SELECT_OP(DSUBU, SUBU) | SA(EQUAL_FLAG) | TA(OTHER_FLAG) | DA(OTHER_FLAG), OTHER_FLAG);
diff --git a/thirdparty/pcre2/src/sljit/sljitNativeMIPS_common.c b/thirdparty/pcre2/src/sljit/sljitNativeMIPS_common.c
index 894e21304b..e0d6a3f085 100644
--- a/thirdparty/pcre2/src/sljit/sljitNativeMIPS_common.c
+++ b/thirdparty/pcre2/src/sljit/sljitNativeMIPS_common.c
@@ -27,17 +27,31 @@
/* Latest MIPS architecture. */
/* Automatically detect SLJIT_MIPS_R1 */
+#if (defined __mips_isa_rev) && (__mips_isa_rev >= 6)
+#define SLJIT_MIPS_R6 1
+#endif
+
SLJIT_API_FUNC_ATTRIBUTE const char* sljit_get_platform_name(void)
{
-#if (defined SLJIT_MIPS_R1 && SLJIT_MIPS_R1)
+#if (defined SLJIT_MIPS_R6 && SLJIT_MIPS_R6)
+
+#if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
+ return "MIPS32-R6" SLJIT_CPUINFO;
+#else /* !SLJIT_CONFIG_MIPS_32 */
+ return "MIPS64-R6" SLJIT_CPUINFO;
+#endif /* SLJIT_CONFIG_MIPS_32 */
+
+#elif (defined SLJIT_MIPS_R1 && SLJIT_MIPS_R1)
+
#if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
return "MIPS32-R1" SLJIT_CPUINFO;
-#else
+#else /* !SLJIT_CONFIG_MIPS_32 */
return "MIPS64-R1" SLJIT_CPUINFO;
-#endif
+#endif /* SLJIT_CONFIG_MIPS_32 */
+
#else /* SLJIT_MIPS_R1 */
return "MIPS III" SLJIT_CPUINFO;
-#endif
+#endif /* SLJIT_MIPS_R6 */
}
/* Length of an instruction word
@@ -62,6 +76,7 @@ typedef sljit_u32 sljit_ins;
#define TMP_FREG1 (SLJIT_NUMBER_OF_FLOAT_REGISTERS + 1)
#define TMP_FREG2 (SLJIT_NUMBER_OF_FLOAT_REGISTERS + 2)
+#define TMP_FREG3 (SLJIT_NUMBER_OF_FLOAT_REGISTERS + 3)
static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 5] = {
0, 2, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 24, 23, 22, 21, 20, 19, 18, 17, 16, 29, 4, 25, 31
@@ -69,14 +84,14 @@ static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 5] = {
#if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
-static const sljit_u8 freg_map[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 3] = {
- 0, 0, 14, 2, 4, 6, 8, 12, 10
+static const sljit_u8 freg_map[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 4] = {
+ 0, 0, 14, 2, 4, 6, 8, 12, 10, 16
};
#else
-static const sljit_u8 freg_map[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 3] = {
- 0, 0, 13, 14, 15, 16, 17, 12, 18
+static const sljit_u8 freg_map[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 4] = {
+ 0, 0, 13, 14, 15, 16, 17, 12, 18, 10
};
#endif
@@ -102,6 +117,11 @@ static const sljit_u8 freg_map[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 3] = {
#define FR(dr) (freg_map[dr])
#define HI(opcode) ((opcode) << 26)
#define LO(opcode) (opcode)
+#if (defined SLJIT_MIPS_R6 && SLJIT_MIPS_R6)
+/* CMP.cond.fmt */
+/* S = (20 << 21) D = (21 << 21) */
+#define CMP_FMT_S (20 << 21)
+#endif /* SLJIT_MIPS_R6 */
/* S = (16 << 21) D = (17 << 21) */
#define FMT_S (16 << 21)
#define FMT_D (17 << 21)
@@ -114,8 +134,13 @@ static const sljit_u8 freg_map[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 3] = {
#define ANDI (HI(12))
#define B (HI(4))
#define BAL (HI(1) | (17 << 16))
+#if (defined SLJIT_MIPS_R6 && SLJIT_MIPS_R6)
+#define BC1EQZ (HI(17) | (9 << 21) | FT(TMP_FREG3))
+#define BC1NEZ (HI(17) | (13 << 21) | FT(TMP_FREG3))
+#else /* !SLJIT_MIPS_R6 */
#define BC1F (HI(17) | (8 << 21))
#define BC1T (HI(17) | (8 << 21) | (1 << 16))
+#endif /* SLJIT_MIPS_R6 */
#define BEQ (HI(4))
#define BGEZ (HI(1) | (1 << 16))
#define BGTZ (HI(7))
@@ -124,20 +149,42 @@ static const sljit_u8 freg_map[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 3] = {
#define BNE (HI(5))
#define BREAK (HI(0) | LO(13))
#define CFC1 (HI(17) | (2 << 21))
-#define C_UN_S (HI(17) | FMT_S | LO(49))
+#if (defined SLJIT_MIPS_R6 && SLJIT_MIPS_R6)
+#define C_UEQ_S (HI(17) | CMP_FMT_S | LO(3))
+#define C_ULE_S (HI(17) | CMP_FMT_S | LO(7))
+#define C_ULT_S (HI(17) | CMP_FMT_S | LO(5))
+#define C_UN_S (HI(17) | CMP_FMT_S | LO(1))
+#define C_FD (FD(TMP_FREG3))
+#else /* !SLJIT_MIPS_R6 */
#define C_UEQ_S (HI(17) | FMT_S | LO(51))
#define C_ULE_S (HI(17) | FMT_S | LO(55))
#define C_ULT_S (HI(17) | FMT_S | LO(53))
+#define C_UN_S (HI(17) | FMT_S | LO(49))
+#define C_FD (0)
+#endif /* SLJIT_MIPS_R6 */
#define CVT_S_S (HI(17) | FMT_S | LO(32))
#define DADDIU (HI(25))
#define DADDU (HI(0) | LO(45))
+#if (defined SLJIT_MIPS_R6 && SLJIT_MIPS_R6)
+#define DDIV (HI(0) | (2 << 6) | LO(30))
+#define DDIVU (HI(0) | (2 << 6) | LO(31))
+#define DMOD (HI(0) | (3 << 6) | LO(30))
+#define DMODU (HI(0) | (3 << 6) | LO(31))
+#define DIV (HI(0) | (2 << 6) | LO(26))
+#define DIVU (HI(0) | (2 << 6) | LO(27))
+#define DMUH (HI(0) | (3 << 6) | LO(28))
+#define DMUHU (HI(0) | (3 << 6) | LO(29))
+#define DMUL (HI(0) | (2 << 6) | LO(28))
+#define DMULU (HI(0) | (2 << 6) | LO(29))
+#else /* !SLJIT_MIPS_R6 */
#define DDIV (HI(0) | LO(30))
#define DDIVU (HI(0) | LO(31))
#define DIV (HI(0) | LO(26))
#define DIVU (HI(0) | LO(27))
-#define DIV_S (HI(17) | FMT_S | LO(3))
#define DMULT (HI(0) | LO(28))
#define DMULTU (HI(0) | LO(29))
+#endif /* SLJIT_MIPS_R6 */
+#define DIV_S (HI(17) | FMT_S | LO(3))
#define DSLL (HI(0) | LO(56))
#define DSLL32 (HI(0) | LO(60))
#define DSLLV (HI(0) | LO(20))
@@ -151,18 +198,34 @@ static const sljit_u8 freg_map[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 3] = {
#define J (HI(2))
#define JAL (HI(3))
#define JALR (HI(0) | LO(9))
+#if (defined SLJIT_MIPS_R6 && SLJIT_MIPS_R6)
+#define JR (HI(0) | LO(9))
+#else /* !SLJIT_MIPS_R6 */
#define JR (HI(0) | LO(8))
+#endif /* SLJIT_MIPS_R6 */
#define LD (HI(55))
#define LUI (HI(15))
#define LW (HI(35))
#define MFC1 (HI(17))
+#if !(defined SLJIT_MIPS_R6 && SLJIT_MIPS_R6)
#define MFHI (HI(0) | LO(16))
#define MFLO (HI(0) | LO(18))
+#else /* SLJIT_MIPS_R6 */
+#define MOD (HI(0) | (3 << 6) | LO(26))
+#define MODU (HI(0) | (3 << 6) | LO(27))
+#endif /* !SLJIT_MIPS_R6 */
#define MOV_S (HI(17) | FMT_S | LO(6))
#define MTC1 (HI(17) | (4 << 21))
-#define MUL_S (HI(17) | FMT_S | LO(2))
+#if (defined SLJIT_MIPS_R6 && SLJIT_MIPS_R6)
+#define MUH (HI(0) | (3 << 6) | LO(24))
+#define MUHU (HI(0) | (3 << 6) | LO(25))
+#define MUL (HI(0) | (2 << 6) | LO(24))
+#define MULU (HI(0) | (2 << 6) | LO(25))
+#else /* !SLJIT_MIPS_R6 */
#define MULT (HI(0) | LO(24))
#define MULTU (HI(0) | LO(25))
+#endif /* SLJIT_MIPS_R6 */
+#define MUL_S (HI(17) | FMT_S | LO(2))
#define NEG_S (HI(17) | FMT_S | LO(7))
#define NOP (HI(0) | LO(0))
#define NOR (HI(0) | LO(39))
@@ -188,14 +251,18 @@ static const sljit_u8 freg_map[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 3] = {
#define XOR (HI(0) | LO(38))
#define XORI (HI(14))
-#if (defined SLJIT_MIPS_R1 && SLJIT_MIPS_R1)
+#if (defined SLJIT_MIPS_R1 && SLJIT_MIPS_R1) || (defined SLJIT_MIPS_R6 && SLJIT_MIPS_R6)
#define CLZ (HI(28) | LO(32))
+#if (defined SLJIT_MIPS_R6 && SLJIT_MIPS_R6)
+#define DCLZ (LO(18))
+#else /* !SLJIT_MIPS_R6 */
#define DCLZ (HI(28) | LO(36))
#define MOVF (HI(0) | (0 << 16) | LO(1))
#define MOVN (HI(0) | LO(11))
#define MOVT (HI(0) | (1 << 16) | LO(1))
#define MOVZ (HI(0) | LO(10))
#define MUL (HI(28) | LO(2))
+#endif /* SLJIT_MIPS_R6 */
#define PREF (HI(51))
#define PREFX (HI(19) | LO(15))
#define SEB (HI(31) | (16 << 6) | LO(32))
@@ -234,7 +301,13 @@ static sljit_s32 push_inst(struct sljit_compiler *compiler, sljit_ins ins, sljit
static SLJIT_INLINE sljit_ins invert_branch(sljit_s32 flags)
{
- return (flags & IS_BIT26_COND) ? (1 << 26) : (1 << 16);
+ if (flags & IS_BIT26_COND)
+ return (1 << 26);
+#if (defined SLJIT_MIPS_R6 && SLJIT_MIPS_R6)
+ if (flags & IS_BIT23_COND)
+ return (1 << 23);
+#endif /* SLJIT_MIPS_R6 */
+ return (1 << 16);
}
static SLJIT_INLINE sljit_ins* detect_jump_type(struct sljit_jump *jump, sljit_ins *code_ptr, sljit_ins *code, sljit_sw executable_offset)
@@ -1075,34 +1148,62 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op0(struct sljit_compiler *compile
return push_inst(compiler, NOP, UNMOVABLE_INS);
case SLJIT_LMUL_UW:
case SLJIT_LMUL_SW:
+#if (defined SLJIT_MIPS_R6 && SLJIT_MIPS_R6)
+#if (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
+ FAIL_IF(push_inst(compiler, (op == SLJIT_LMUL_UW ? DMULU : DMUL) | S(SLJIT_R0) | T(SLJIT_R1) | D(TMP_REG3), DR(TMP_REG3)));
+ FAIL_IF(push_inst(compiler, (op == SLJIT_LMUL_UW ? DMUHU : DMUH) | S(SLJIT_R0) | T(SLJIT_R1) | D(TMP_REG1), DR(TMP_REG1)));
+#else /* !SLJIT_CONFIG_MIPS_64 */
+ FAIL_IF(push_inst(compiler, (op == SLJIT_LMUL_UW ? MULU : MUL) | S(SLJIT_R0) | T(SLJIT_R1) | D(TMP_REG3), DR(TMP_REG3)));
+ FAIL_IF(push_inst(compiler, (op == SLJIT_LMUL_UW ? MUHU : MUH) | S(SLJIT_R0) | T(SLJIT_R1) | D(TMP_REG1), DR(TMP_REG1)));
+#endif /* SLJIT_CONFIG_MIPS_64 */
+ FAIL_IF(push_inst(compiler, ADDU_W | S(TMP_REG3) | TA(0) | D(SLJIT_R0), DR(SLJIT_R0)));
+ return push_inst(compiler, ADDU_W | S(TMP_REG1) | TA(0) | D(SLJIT_R1), DR(SLJIT_R1));
+#else /* !SLJIT_MIPS_R6 */
#if (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
FAIL_IF(push_inst(compiler, (op == SLJIT_LMUL_UW ? DMULTU : DMULT) | S(SLJIT_R0) | T(SLJIT_R1), MOVABLE_INS));
-#else
+#else /* !SLJIT_CONFIG_MIPS_64 */
FAIL_IF(push_inst(compiler, (op == SLJIT_LMUL_UW ? MULTU : MULT) | S(SLJIT_R0) | T(SLJIT_R1), MOVABLE_INS));
-#endif
+#endif /* SLJIT_CONFIG_MIPS_64 */
FAIL_IF(push_inst(compiler, MFLO | D(SLJIT_R0), DR(SLJIT_R0)));
return push_inst(compiler, MFHI | D(SLJIT_R1), DR(SLJIT_R1));
+#endif /* SLJIT_MIPS_R6 */
case SLJIT_DIVMOD_UW:
case SLJIT_DIVMOD_SW:
case SLJIT_DIV_UW:
case SLJIT_DIV_SW:
SLJIT_COMPILE_ASSERT((SLJIT_DIVMOD_UW & 0x2) == 0 && SLJIT_DIV_UW - 0x2 == SLJIT_DIVMOD_UW, bad_div_opcode_assignments);
+#if (defined SLJIT_MIPS_R6 && SLJIT_MIPS_R6)
+#if (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
+ if (int_op) {
+ FAIL_IF(push_inst(compiler, ((op | 0x2) == SLJIT_DIV_UW ? DIVU : DIV) | S(SLJIT_R0) | T(SLJIT_R1) | D(TMP_REG3), DR(TMP_REG3)));
+ FAIL_IF(push_inst(compiler, ((op | 0x2) == SLJIT_DIV_UW ? MODU : MOD) | S(SLJIT_R0) | T(SLJIT_R1) | D(TMP_REG1), DR(TMP_REG1)));
+ }
+ else {
+ FAIL_IF(push_inst(compiler, ((op | 0x2) == SLJIT_DIV_UW ? DDIVU : DDIV) | S(SLJIT_R0) | T(SLJIT_R1) | D(TMP_REG3), DR(TMP_REG3)));
+ FAIL_IF(push_inst(compiler, ((op | 0x2) == SLJIT_DIV_UW ? DMODU : DMOD) | S(SLJIT_R0) | T(SLJIT_R1) | D(TMP_REG1), DR(TMP_REG1)));
+ }
+#else /* !SLJIT_CONFIG_MIPS_64 */
+ FAIL_IF(push_inst(compiler, ((op | 0x2) == SLJIT_DIV_UW ? DIVU : DIV) | S(SLJIT_R0) | T(SLJIT_R1) | D(TMP_REG3), DR(TMP_REG3)));
+ FAIL_IF(push_inst(compiler, ((op | 0x2) == SLJIT_DIV_UW ? MODU : MOD) | S(SLJIT_R0) | T(SLJIT_R1) | D(TMP_REG1), DR(TMP_REG1)));
+#endif /* SLJIT_CONFIG_MIPS_64 */
+ FAIL_IF(push_inst(compiler, ADDU_W | S(TMP_REG3) | TA(0) | D(SLJIT_R0), DR(SLJIT_R0)));
+ return (op >= SLJIT_DIV_UW) ? SLJIT_SUCCESS : push_inst(compiler, ADDU_W | S(TMP_REG1) | TA(0) | D(SLJIT_R1), DR(SLJIT_R1));
+#else /* !SLJIT_MIPS_R6 */
#if !(defined SLJIT_MIPS_R1 && SLJIT_MIPS_R1)
FAIL_IF(push_inst(compiler, NOP, UNMOVABLE_INS));
FAIL_IF(push_inst(compiler, NOP, UNMOVABLE_INS));
-#endif
-
+#endif /* !SLJIT_MIPS_R1 */
#if (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
if (int_op)
FAIL_IF(push_inst(compiler, ((op | 0x2) == SLJIT_DIV_UW ? DIVU : DIV) | S(SLJIT_R0) | T(SLJIT_R1), MOVABLE_INS));
else
FAIL_IF(push_inst(compiler, ((op | 0x2) == SLJIT_DIV_UW ? DDIVU : DDIV) | S(SLJIT_R0) | T(SLJIT_R1), MOVABLE_INS));
-#else
+#else /* !SLJIT_CONFIG_MIPS_64 */
FAIL_IF(push_inst(compiler, ((op | 0x2) == SLJIT_DIV_UW ? DIVU : DIV) | S(SLJIT_R0) | T(SLJIT_R1), MOVABLE_INS));
-#endif
-
+#endif /* SLJIT_CONFIG_MIPS_64 */
FAIL_IF(push_inst(compiler, MFLO | D(SLJIT_R0), DR(SLJIT_R0)));
return (op >= SLJIT_DIV_UW) ? SLJIT_SUCCESS : push_inst(compiler, MFHI | D(SLJIT_R1), DR(SLJIT_R1));
+#endif /* SLJIT_MIPS_R6 */
}
return SLJIT_SUCCESS;
@@ -1408,8 +1509,7 @@ static SLJIT_INLINE sljit_s32 sljit_emit_fop1_cmp(struct sljit_compiler *compile
inst = C_UN_S;
break;
}
-
- return push_inst(compiler, inst | FMT(op) | FT(src2) | FS(src1), UNMOVABLE_INS);
+ return push_inst(compiler, inst | FMT(op) | FT(src2) | FS(src1) | C_FD, UNMOVABLE_INS);
}
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op,
@@ -1608,16 +1708,30 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compi
flags = IS_BIT26_COND; \
delay_check = src;
+#if (defined SLJIT_MIPS_R6 && SLJIT_MIPS_R6)
+
+#define BR_T() \
+ inst = BC1NEZ; \
+ flags = IS_BIT23_COND; \
+ delay_check = FCSR_FCC;
+#define BR_F() \
+ inst = BC1EQZ; \
+ flags = IS_BIT23_COND; \
+ delay_check = FCSR_FCC;
+
+#else /* !SLJIT_MIPS_R6 */
+
#define BR_T() \
inst = BC1T | JUMP_LENGTH; \
flags = IS_BIT16_COND; \
delay_check = FCSR_FCC;
-
#define BR_F() \
inst = BC1F | JUMP_LENGTH; \
flags = IS_BIT16_COND; \
delay_check = FCSR_FCC;
+#endif /* SLJIT_MIPS_R6 */
+
SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type)
{
struct sljit_jump *jump;
@@ -1927,7 +2041,11 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *co
case SLJIT_GREATER_EQUAL_F64:
case SLJIT_UNORDERED_F64:
case SLJIT_ORDERED_F64:
+#if (defined SLJIT_MIPS_R6 && SLJIT_MIPS_R6)
+ FAIL_IF(push_inst(compiler, MFC1 | TA(dst_ar) | FS(TMP_FREG3), dst_ar));
+#else /* !SLJIT_MIPS_R6 */
FAIL_IF(push_inst(compiler, CFC1 | TA(dst_ar) | DA(FCSR_REG), dst_ar));
+#endif /* SLJIT_MIPS_R6 */
FAIL_IF(push_inst(compiler, SRL | TA(dst_ar) | DA(dst_ar) | SH_IMM(23), dst_ar));
FAIL_IF(push_inst(compiler, ANDI | SA(dst_ar) | TA(dst_ar) | IMM(1), dst_ar));
src_ar = dst_ar;
diff --git a/thirdparty/pcre2/src/sljit/sljitNativePPC_common.c b/thirdparty/pcre2/src/sljit/sljitNativePPC_common.c
index 5ef4ac96c4..b34e3965ed 100644
--- a/thirdparty/pcre2/src/sljit/sljitNativePPC_common.c
+++ b/thirdparty/pcre2/src/sljit/sljitNativePPC_common.c
@@ -42,7 +42,7 @@ typedef sljit_u32 sljit_ins;
#include <sys/cache.h>
#endif
-#if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
+#if (defined _CALL_ELF && _CALL_ELF == 2)
#define SLJIT_PASS_ENTRY_ADDR_TO_CALL 1
#endif
diff --git a/thirdparty/tinyexr/tinyexr.h b/thirdparty/tinyexr/tinyexr.h
index 3c19391850..f22163738f 100644
--- a/thirdparty/tinyexr/tinyexr.h
+++ b/thirdparty/tinyexr/tinyexr.h
@@ -1,5 +1,5 @@
/*
-Copyright (c) 2014 - 2018, Syoyo Fujita and many contributors.
+Copyright (c) 2014 - 2019, Syoyo Fujita and many contributors.
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -276,7 +276,8 @@ extern int LoadEXR(float **out_rgba, int *width, int *height,
// @deprecated { to be removed. }
// Simple wrapper API for ParseEXRHeaderFromFile.
// checking given file is a EXR file(by just look up header)
-// @return TINYEXR_SUCCEES for EXR image, TINYEXR_ERROR_INVALID_HEADER for others
+// @return TINYEXR_SUCCEES for EXR image, TINYEXR_ERROR_INVALID_HEADER for
+// others
extern int IsEXR(const char *filename);
// @deprecated { to be removed. }
@@ -469,9 +470,10 @@ extern int LoadEXRFromMemory(float **out_rgba, int *width, int *height,
#include <cstdio>
#include <cstdlib>
#include <cstring>
-#include <iostream>
#include <sstream>
+//#include <iostream> // debug
+
#include <limits>
#include <string>
#include <vector>
@@ -2537,10 +2539,10 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r,
tinfl_status status = TINFL_STATUS_FAILED;
mz_uint32 num_bits, dist, counter, num_extra;
tinfl_bit_buf_t bit_buf;
- const mz_uint8 *pIn_buf_cur = pIn_buf_next,
- *const pIn_buf_end = pIn_buf_next + *pIn_buf_size;
- mz_uint8 *pOut_buf_cur = pOut_buf_next,
- *const pOut_buf_end = pOut_buf_next + *pOut_buf_size;
+ const mz_uint8 *pIn_buf_cur = pIn_buf_next, *const pIn_buf_end =
+ pIn_buf_next + *pIn_buf_size;
+ mz_uint8 *pOut_buf_cur = pOut_buf_next, *const pOut_buf_end =
+ pOut_buf_next + *pOut_buf_size;
size_t out_buf_size_mask =
(decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)
? (size_t)-1
@@ -2957,8 +2959,9 @@ void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len,
tinfl_status status = tinfl_decompress(
&decomp, (const mz_uint8 *)pSrc_buf + src_buf_ofs, &src_buf_size,
(mz_uint8 *)pBuf, pBuf ? (mz_uint8 *)pBuf + *pOut_len : NULL,
- &dst_buf_size, (flags & ~TINFL_FLAG_HAS_MORE_INPUT) |
- TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
+ &dst_buf_size,
+ (flags & ~TINFL_FLAG_HAS_MORE_INPUT) |
+ TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
if ((status < 0) || (status == TINFL_STATUS_NEEDS_MORE_INPUT)) {
MZ_FREE(pBuf);
*pOut_len = 0;
@@ -3011,9 +3014,8 @@ int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size,
tinfl_status status =
tinfl_decompress(&decomp, (const mz_uint8 *)pIn_buf + in_buf_ofs,
&in_buf_size, pDict, pDict + dict_ofs, &dst_buf_size,
- (flags &
- ~(TINFL_FLAG_HAS_MORE_INPUT |
- TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)));
+ (flags & ~(TINFL_FLAG_HAS_MORE_INPUT |
+ TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)));
in_buf_ofs += in_buf_size;
if ((dst_buf_size) &&
(!(*pPut_buf_func)(pDict + dict_ofs, (int)dst_buf_size, pPut_buf_user)))
@@ -3138,7 +3140,9 @@ static const mz_uint8 s_tdefl_large_dist_extra[128] = {
// Radix sorts tdefl_sym_freq[] array by 16-bit key m_key. Returns ptr to sorted
// values.
-typedef struct { mz_uint16 m_key, m_sym_index; } tdefl_sym_freq;
+typedef struct {
+ mz_uint16 m_key, m_sym_index;
+} tdefl_sym_freq;
static tdefl_sym_freq *tdefl_radix_sort_syms(mz_uint num_syms,
tdefl_sym_freq *pSyms0,
tdefl_sym_freq *pSyms1) {
@@ -5282,9 +5286,10 @@ mz_bool mz_zip_reader_file_stat(mz_zip_archive *pZip, mz_uint file_index,
n = MZ_READ_LE16(p + MZ_ZIP_CDH_COMMENT_LEN_OFS);
n = MZ_MIN(n, MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE - 1);
pStat->m_comment_size = n;
- memcpy(pStat->m_comment, p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE +
- MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS) +
- MZ_READ_LE16(p + MZ_ZIP_CDH_EXTRA_LEN_OFS),
+ memcpy(pStat->m_comment,
+ p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE +
+ MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS) +
+ MZ_READ_LE16(p + MZ_ZIP_CDH_EXTRA_LEN_OFS),
n);
pStat->m_comment[n] = '\0';
@@ -7008,6 +7013,11 @@ static void swap2(unsigned short *val) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-function"
#endif
+
+#ifdef __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+#endif
static void cpy4(int *dst_val, const int *src_val) {
unsigned char *dst = reinterpret_cast<unsigned char *>(dst_val);
const unsigned char *src = reinterpret_cast<const unsigned char *>(src_val);
@@ -7037,11 +7047,14 @@ static void cpy4(float *dst_val, const float *src_val) {
dst[2] = src[2];
dst[3] = src[3];
}
-
#ifdef __clang__
#pragma clang diagnostic pop
#endif
+#ifdef __GNUC__
+#pragma GCC diagnostic pop
+#endif
+
static void swap4(unsigned int *val) {
#ifdef MINIZ_LITTLE_ENDIAN
(void)val;
@@ -7696,7 +7709,8 @@ static int rleUncompress(int inLength, int maxLength, const signed char in[],
int count = -(static_cast<int>(*in++));
inLength -= count + 1;
- if (0 > (maxLength -= count)) return 0;
+ // Fixes #116: Add bounds check to in buffer.
+ if ((0 > (maxLength -= count)) || (inLength < 0)) return 0;
memcpy(out, in, count);
out += count;
@@ -7790,13 +7804,19 @@ static void CompressRle(unsigned char *dst,
}
}
-static void DecompressRle(unsigned char *dst,
+static bool DecompressRle(unsigned char *dst,
const unsigned long uncompressed_size,
const unsigned char *src, unsigned long src_size) {
if (uncompressed_size == src_size) {
// Data is not compressed(Issue 40).
memcpy(dst, src, src_size);
- return;
+ return true;
+ }
+
+ // Workaround for issue #112.
+ // TODO(syoyo): Add more robust out-of-bounds check in `rleUncompress`.
+ if (src_size <= 2) {
+ return false;
}
std::vector<unsigned char> tmpBuf(uncompressed_size);
@@ -7805,8 +7825,9 @@ static void DecompressRle(unsigned char *dst,
static_cast<int>(uncompressed_size),
reinterpret_cast<const signed char *>(src),
reinterpret_cast<char *>(&tmpBuf.at(0)));
- assert(ret == static_cast<int>(uncompressed_size));
- (void)ret;
+ if (ret != static_cast<int>(uncompressed_size)) {
+ return false;
+ }
//
// Apply EXR-specific? postprocess. Grabbed from OpenEXR's
@@ -7845,6 +7866,8 @@ static void DecompressRle(unsigned char *dst,
break;
}
}
+
+ return true;
}
#if TINYEXR_USE_PIZ
@@ -8556,7 +8579,7 @@ static bool hufUnpackEncTable(
int lc = 0;
for (; im <= iM; im++) {
- if (p - *pcode > ni) {
+ if (p - *pcode >= ni) {
return false;
}
@@ -8854,7 +8877,7 @@ static bool getCode(int po, int rlc, long long &c, int &lc, const char *&in,
if (out + cs > oe) return false;
// Bounds check for safety
- // Issue 100.
+ // Issue 100.
if ((out - 1) < ob) return false;
unsigned short s = out[-1];
@@ -9348,6 +9371,10 @@ static bool DecompressPiz(unsigned char *outPtr, const unsigned char *inPtr,
tinyexr::cpy4(&length, reinterpret_cast<const int *>(ptr));
ptr += sizeof(int);
+ if (size_t((ptr - inPtr) + length) > inLen) {
+ return false;
+ }
+
std::vector<unsigned short> tmpBuffer(tmpBufSize);
hufUncompress(reinterpret_cast<const char *>(ptr), length, &tmpBuffer);
@@ -9642,8 +9669,9 @@ static bool DecodePixelData(/* out */ unsigned char **out_images,
reinterpret_cast<unsigned char *>(&outBuf.at(0)), data_ptr, tmpBufLen,
data_len, static_cast<int>(num_channels), channels, width, num_lines);
- assert(ret);
- (void)ret;
+ if (!ret) {
+ return false;
+ }
// For PIZ_COMPRESSION:
// pixel sample data for channel 0 for scanline 0
@@ -9688,16 +9716,18 @@ static bool DecodePixelData(/* out */ unsigned char **out_images,
} else { // HALF -> FLOAT
FP32 f32 = half_to_float(hf);
float *image = reinterpret_cast<float **>(out_images)[c];
+ size_t offset = 0;
if (line_order == 0) {
- image += (static_cast<size_t>(line_no) + v) *
+ offset = (static_cast<size_t>(line_no) + v) *
static_cast<size_t>(x_stride) +
u;
} else {
- image += static_cast<size_t>(
+ offset = static_cast<size_t>(
(height - 1 - (line_no + static_cast<int>(v)))) *
static_cast<size_t>(x_stride) +
u;
}
+ image += offset;
*image = f32.f;
}
}
@@ -9824,16 +9854,19 @@ static bool DecodePixelData(/* out */ unsigned char **out_images,
} else { // HALF -> FLOAT
tinyexr::FP32 f32 = half_to_float(hf);
float *image = reinterpret_cast<float **>(out_images)[c];
+ size_t offset = 0;
if (line_order == 0) {
- image += (static_cast<size_t>(line_no) + v) *
+ offset = (static_cast<size_t>(line_no) + v) *
static_cast<size_t>(x_stride) +
u;
} else {
- image += (static_cast<size_t>(height) - 1U -
+ offset = (static_cast<size_t>(height) - 1U -
(static_cast<size_t>(line_no) + v)) *
static_cast<size_t>(x_stride) +
u;
}
+ image += offset;
+
*image = f32.f;
}
}
@@ -9906,10 +9939,15 @@ static bool DecodePixelData(/* out */ unsigned char **out_images,
pixel_data_size);
unsigned long dstLen = static_cast<unsigned long>(outBuf.size());
- assert(dstLen > 0);
- tinyexr::DecompressRle(reinterpret_cast<unsigned char *>(&outBuf.at(0)),
+ if (dstLen == 0) {
+ return false;
+ }
+
+ if (!tinyexr::DecompressRle(reinterpret_cast<unsigned char *>(&outBuf.at(0)),
dstLen, data_ptr,
- static_cast<unsigned long>(data_len));
+ static_cast<unsigned long>(data_len))) {
+ return false;
+ }
// For RLE_COMPRESSION:
// pixel sample data for channel 0 for scanline 0
@@ -10739,12 +10777,28 @@ static int DecodeChunk(EXRImage *exr_image, const EXRHeader *exr_header,
if ((data_width < 0) || (data_height < 0)) {
if (err) {
std::stringstream ss;
- ss << "Invalid data width or data height: " << data_width << ", " << data_height << std::endl;
+ ss << "Invalid data width or data height: " << data_width << ", "
+ << data_height << std::endl;
(*err) += ss.str();
}
return TINYEXR_ERROR_INVALID_DATA;
}
+ // Do not allow too large data_width and data_height. header invalid?
+ {
+ const int threshold = 1024 * 8192; // heuristics
+ if ((data_width > threshold) || (data_height > threshold)) {
+ if (err) {
+ std::stringstream ss;
+ ss << "data_with or data_height too large. data_width: " << data_width
+ << ", "
+ << "data_height = " << data_height << std::endl;
+ (*err) += ss.str();
+ }
+ return TINYEXR_ERROR_INVALID_DATA;
+ }
+ }
+
size_t num_blocks = offsets.size();
std::vector<size_t> channel_offset_list;
@@ -10762,6 +10816,25 @@ static int DecodeChunk(EXRImage *exr_image, const EXRHeader *exr_header,
bool invalid_data = false; // TODO(LTE): Use atomic lock for MT safety.
if (exr_header->tiled) {
+ // value check
+ if (exr_header->tile_size_x < 0) {
+ if (err) {
+ std::stringstream ss;
+ ss << "Invalid tile size x : " << exr_header->tile_size_x << "\n";
+ (*err) += ss.str();
+ }
+ return TINYEXR_ERROR_INVALID_HEADER;
+ }
+
+ if (exr_header->tile_size_y < 0) {
+ if (err) {
+ std::stringstream ss;
+ ss << "Invalid tile size y : " << exr_header->tile_size_y << "\n";
+ (*err) += ss.str();
+ }
+ return TINYEXR_ERROR_INVALID_HEADER;
+ }
+
size_t num_tiles = offsets.size(); // = # of blocks
exr_image->tiles = static_cast<EXRTile *>(
@@ -10840,12 +10913,17 @@ static int DecodeChunk(EXRImage *exr_image, const EXRHeader *exr_header,
}
} else { // scanline format
- // Don't allow too large image(256GB * pixel_data_size or more). Workaround for #104.
- size_t data_len = size_t(data_width) * size_t(data_height) * size_t(num_channels);
- if ((data_len == 0) || (data_len >= 0x4000000000)) {
+ // Don't allow too large image(256GB * pixel_data_size or more). Workaround
+ // for #104.
+ size_t total_data_len =
+ size_t(data_width) * size_t(data_height) * size_t(num_channels);
+ const bool total_data_len_overflown = sizeof(void*) == 8 ? (total_data_len >= 0x4000000000) : false;
+ if ((total_data_len == 0) || total_data_len_overflown ) {
if (err) {
std::stringstream ss;
- ss << "Image data size is zero or too large: width = " << data_width << ", height = " << data_height << ", channels = " << num_channels << std::endl;
+ ss << "Image data size is zero or too large: width = " << data_width
+ << ", height = " << data_height << ", channels = " << num_channels
+ << std::endl;
(*err) += ss.str();
}
return TINYEXR_ERROR_INVALID_DATA;
@@ -10880,12 +10958,21 @@ static int DecodeChunk(EXRImage *exr_image, const EXRHeader *exr_header,
if (size_t(data_len) > data_size) {
invalid_data = true;
+
+ } else if ((line_no > (2 << 20)) || (line_no < -(2 << 20))) {
+ // Too large value. Assume this is invalid
+ // 2**20 = 1048576 = heuristic value.
+ invalid_data = true;
+ } else if (data_len == 0) {
+ // TODO(syoyo): May be ok to raise the threshold for example `data_len
+ // < 4`
+ invalid_data = true;
} else {
+ // line_no may be negative.
int end_line_no = (std::min)(line_no + num_scanline_blocks,
(exr_header->data_window[3] + 1));
int num_lines = end_line_no - line_no;
- // assert(num_lines > 0);
if (num_lines <= 0) {
invalid_data = true;
@@ -10894,7 +10981,16 @@ static int DecodeChunk(EXRImage *exr_image, const EXRHeader *exr_header,
data_ptr += 8;
// Adjust line_no with data_window.bmin.y
- line_no -= exr_header->data_window[1];
+
+ // overflow check
+ tinyexr_int64 lno = static_cast<tinyexr_int64>(line_no) - static_cast<tinyexr_int64>(exr_header->data_window[1]);
+ if (lno > std::numeric_limits<int>::max()) {
+ line_no = -1; // invalid
+ } else if (lno < -std::numeric_limits<int>::max()) {
+ line_no = -1; // invalid
+ } else {
+ line_no -= exr_header->data_window[1];
+ }
if (line_no < 0) {
invalid_data = true;
@@ -10919,6 +11015,10 @@ static int DecodeChunk(EXRImage *exr_image, const EXRHeader *exr_header,
}
if (invalid_data) {
+ if (err) {
+ std::stringstream ss;
+ (*err) += "Invalid data found when decoding pixels.\n";
+ }
return TINYEXR_ERROR_INVALID_DATA;
}
@@ -10995,7 +11095,7 @@ static int DecodeEXRImage(EXRImage *exr_image, const EXRHeader *exr_header,
int data_width = exr_header->data_window[2] - exr_header->data_window[0];
if (data_width >= std::numeric_limits<int>::max()) {
// Issue 63
- tinyexr::SetErrorMessage("Invalid data window value", err);
+ tinyexr::SetErrorMessage("Invalid data width value", err);
return TINYEXR_ERROR_INVALID_DATA;
}
data_width++;
@@ -11008,10 +11108,23 @@ static int DecodeEXRImage(EXRImage *exr_image, const EXRHeader *exr_header,
data_height++;
if ((data_width < 0) || (data_height < 0)) {
- tinyexr::SetErrorMessage("data window or data height is negative.", err);
+ tinyexr::SetErrorMessage("data width or data height is negative.", err);
return TINYEXR_ERROR_INVALID_DATA;
}
+ // Do not allow too large data_width and data_height. header invalid?
+ {
+ const int threshold = 1024 * 8192; // heuristics
+ if (data_width > threshold) {
+ tinyexr::SetErrorMessage("data width too large.", err);
+ return TINYEXR_ERROR_INVALID_DATA;
+ }
+ if (data_height > threshold) {
+ tinyexr::SetErrorMessage("data height too large.", err);
+ return TINYEXR_ERROR_INVALID_DATA;
+ }
+ }
+
// Read offset tables.
size_t num_blocks = 0;
@@ -11190,7 +11303,6 @@ int LoadEXR(float **out_rgba, int *width, int *height, const char *filename,
static_cast<size_t>(exr_image.height)));
if (exr_header.tiled) {
-
for (int it = 0; it < exr_image.num_tiles; it++) {
for (int j = 0; j < exr_header.tile_size_y; j++) {
for (int i = 0; i < exr_header.tile_size_x; i++) {
@@ -11325,7 +11437,7 @@ int IsEXR(const char *filename) {
if (ret != TINYEXR_SUCCESS) {
return TINYEXR_ERROR_INVALID_HEADER;
}
-
+
return TINYEXR_SUCCESS;
}
@@ -11434,7 +11546,6 @@ int LoadEXRFromMemory(float **out_rgba, int *width, int *height,
static_cast<size_t>(exr_image.height)));
if (exr_header.tiled) {
-
for (int it = 0; it < exr_image.num_tiles; it++) {
for (int j = 0; j < exr_header.tile_size_y; j++) {
for (int i = 0; i < exr_header.tile_size_x; i++) {
@@ -12115,7 +12226,7 @@ size_t SaveEXRImageToMemory(const EXRImage *exr_image,
sizeof(tinyexr::tinyexr_uint64) * static_cast<size_t>(num_blocks));
}
- if ( memory.size() == 0 ) {
+ if (memory.size() == 0) {
tinyexr::SetErrorMessage("Output memory size is zero", err);
return 0;
}
@@ -12286,6 +12397,9 @@ int LoadDeepEXR(DeepImage *deep_image, const char *filename, const char **err) {
size_t marker_size;
if (!tinyexr::ReadAttribute(&attr_name, &attr_type, &data, &marker_size,
marker, size)) {
+ std::stringstream ss;
+ ss << "Failed to parse attribute\n";
+ tinyexr::SetErrorMessage(ss.str(), err);
return TINYEXR_ERROR_INVALID_DATA;
}
marker += marker_size;
diff --git a/thirdparty/xatlas/xatlas.cpp b/thirdparty/xatlas/xatlas.cpp
index 2cc2905eee..1b30305cd4 100644
--- a/thirdparty/xatlas/xatlas.cpp
+++ b/thirdparty/xatlas/xatlas.cpp
@@ -1,128 +1,443 @@
-// This code is in the public domain -- castanyo@yahoo.es
+/*
+MIT License
+
+Copyright (c) 2018-2019 Jonathan Young
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+/*
+thekla_atlas
+https://github.com/Thekla/thekla_atlas
+MIT License
+Copyright (c) 2013 Thekla, Inc
+Copyright NVIDIA Corporation 2006 -- Ignacio Castano <icastano@nvidia.com>
+
+Fast-BVH
+https://github.com/brandonpelfrey/Fast-BVH
+MIT License
+Copyright (c) 2012 Brandon Pelfrey
+*/
#include <algorithm>
-#include <cmath>
-#include <memory>
-#include <unordered_map>
-#include <vector>
+#include <atomic>
+#include <condition_variable>
+#include <mutex>
+#include <thread>
#include <assert.h>
-#include <float.h>
+#include <float.h> // FLT_MAX
+#include <limits.h>
#include <math.h>
-#include <stdarg.h>
+#define __STDC_LIMIT_MACROS
#include <stdint.h>
#include <stdio.h>
#include <string.h>
-#include <time.h>
#include "xatlas.h"
-#undef min
-#undef max
+#ifndef XA_DEBUG
+#ifdef NDEBUG
+#define XA_DEBUG 0
+#else
+#define XA_DEBUG 1
+#endif
+#endif
-#ifndef xaAssert
-#define xaAssert(exp) if (!(exp)) { xaPrint("%s %s %s\n", #exp, __FILE__, __LINE__); }
+#ifndef XA_PROFILE
+#define XA_PROFILE 0
#endif
-#ifndef xaDebugAssert
-#define xaDebugAssert(exp) assert(exp)
+#if XA_PROFILE
+#include <time.h>
#endif
-#ifndef xaPrint
-#define xaPrint(...) if (xatlas::internal::s_print) { xatlas::internal::s_print(__VA_ARGS__); }
+
+#ifndef XA_MULTITHREADED
+#define XA_MULTITHREADED 1
#endif
-#ifdef _MSC_VER
-// Ignore gcc attributes.
-#define __attribute__(X)
+#define XA_STR(x) #x
+#define XA_XSTR(x) XA_STR(x)
+
+#ifndef XA_ASSERT
+#define XA_ASSERT(exp) if (!(exp)) { XA_PRINT_WARNING("\rASSERT: %s %s %d\n", XA_XSTR(exp), __FILE__, __LINE__); }
#endif
-#ifdef _MSC_VER
-#define restrict
-#define NV_FORCEINLINE __forceinline
-#else
-#define restrict __restrict__
-#define NV_FORCEINLINE __attribute__((always_inline)) inline
+#ifndef XA_DEBUG_ASSERT
+#define XA_DEBUG_ASSERT(exp) assert(exp)
#endif
-#define NV_UINT32_MAX 0xffffffff
-#define NV_FLOAT_MAX 3.402823466e+38F
+#ifndef XA_PRINT
+#define XA_PRINT(...) \
+ if (xatlas::internal::s_print && xatlas::internal::s_printVerbose) \
+ xatlas::internal::s_print(__VA_ARGS__);
+#endif
-#ifndef PI
-#define PI float(3.1415926535897932384626433833)
+#ifndef XA_PRINT_WARNING
+#define XA_PRINT_WARNING(...) \
+ if (xatlas::internal::s_print) \
+ xatlas::internal::s_print(__VA_ARGS__);
#endif
-#define NV_EPSILON (0.0001f)
-#define NV_NORMAL_EPSILON (0.001f)
+#define XA_ALLOC(tag, type) (type *)internal::Realloc(nullptr, sizeof(type), tag, __FILE__, __LINE__)
+#define XA_ALLOC_ARRAY(tag, type, num) (type *)internal::Realloc(nullptr, sizeof(type) * num, tag, __FILE__, __LINE__)
+#define XA_REALLOC(tag, ptr, type, num) (type *)internal::Realloc(ptr, sizeof(type) * num, tag, __FILE__, __LINE__)
+#define XA_FREE(ptr) internal::Realloc(ptr, 0, internal::MemTag::Default, __FILE__, __LINE__)
+#define XA_NEW(tag, type, ...) new (XA_ALLOC(tag, type)) type(__VA_ARGS__)
+
+#define XA_UNUSED(a) ((void)(a))
+
+#define XA_GROW_CHARTS_COPLANAR 1
+#define XA_MERGE_CHARTS 1
+#define XA_MERGE_CHARTS_MIN_NORMAL_DEVIATION 0.5f
+#define XA_RECOMPUTE_CHARTS 1
+#define XA_CLOSE_HOLES_CHECK_EDGE_INTERSECTION 0
+
+#define XA_DEBUG_HEAP 0
+#define XA_DEBUG_SINGLE_CHART 0
+#define XA_DEBUG_EXPORT_ATLAS_IMAGES 0
+#define XA_DEBUG_EXPORT_OBJ_SOURCE_MESHES 0
+#define XA_DEBUG_EXPORT_OBJ_CHART_GROUPS 0
+#define XA_DEBUG_EXPORT_OBJ_CHARTS 0
+#define XA_DEBUG_EXPORT_OBJ_BEFORE_FIX_TJUNCTION 0
+#define XA_DEBUG_EXPORT_OBJ_CLOSE_HOLES_ERROR 0
+#define XA_DEBUG_EXPORT_OBJ_NOT_DISK 0
+#define XA_DEBUG_EXPORT_OBJ_CHARTS_AFTER_PARAMETERIZATION 0
+#define XA_DEBUG_EXPORT_OBJ_INVALID_PARAMETERIZATION 0
+#define XA_DEBUG_EXPORT_OBJ_RECOMPUTED_CHARTS 0
+
+#define XA_DEBUG_EXPORT_OBJ (0 \
+ || XA_DEBUG_EXPORT_OBJ_SOURCE_MESHES \
+ || XA_DEBUG_EXPORT_OBJ_CHART_GROUPS \
+ || XA_DEBUG_EXPORT_OBJ_CHARTS \
+ || XA_DEBUG_EXPORT_OBJ_BEFORE_FIX_TJUNCTION \
+ || XA_DEBUG_EXPORT_OBJ_CLOSE_HOLES_ERROR \
+ || XA_DEBUG_EXPORT_OBJ_NOT_DISK \
+ || XA_DEBUG_EXPORT_OBJ_CHARTS_AFTER_PARAMETERIZATION \
+ || XA_DEBUG_EXPORT_OBJ_INVALID_PARAMETERIZATION \
+ || XA_DEBUG_EXPORT_OBJ_RECOMPUTED_CHARTS)
+
+#ifdef _MSC_VER
+#define XA_FOPEN(_file, _filename, _mode) { if (fopen_s(&_file, _filename, _mode) != 0) _file = NULL; }
+#define XA_SPRINTF(_buffer, _size, _format, ...) sprintf_s(_buffer, _size, _format, __VA_ARGS__)
+#else
+#define XA_FOPEN(_file, _filename, _mode) _file = fopen(_filename, _mode)
+#define XA_SPRINTF(_buffer, _size, _format, ...) sprintf(_buffer, _format, __VA_ARGS__)
+#endif
namespace xatlas {
namespace internal {
-static PrintFunc s_print = NULL;
+static ReallocFunc s_realloc = realloc;
+static PrintFunc s_print = printf;
+static bool s_printVerbose = false;
+
+struct MemTag
+{
+ enum
+ {
+ Default,
+ Mesh,
+ MeshBoundaries,
+ MeshColocals,
+ MeshEdgeMap,
+ MeshIndices,
+ MeshNormals,
+ MeshPositions,
+ MeshTexcoords,
+ Count
+ };
+};
+
+#if XA_DEBUG_HEAP
+struct AllocHeader
+{
+ size_t size;
+ const char *file;
+ int line;
+ int tag;
+ AllocHeader *prev, *next;
+ bool free;
+};
+
+static std::mutex s_allocMutex;
+static AllocHeader *s_allocRoot = nullptr;
+static size_t s_allocTotalSize = 0, s_allocPeakSize = 0, s_allocTotalTagSize[MemTag::Count] = { 0 }, s_allocPeakTagSize[MemTag::Count] = { 0 };
+static constexpr uint32_t kAllocRedzone = 0x12345678;
+
+static void *Realloc(void *ptr, size_t size, int tag, const char *file, int line)
+{
+ std::unique_lock<std::mutex> lock(s_allocMutex);
+ if (!size && !ptr)
+ return nullptr;
+ uint8_t *realPtr = nullptr;
+ AllocHeader *header = nullptr;
+ if (ptr) {
+ realPtr = ((uint8_t *)ptr) - sizeof(AllocHeader);
+ header = (AllocHeader *)realPtr;
+ }
+ if (realPtr && size) {
+ s_allocTotalSize -= header->size;
+ s_allocTotalTagSize[header->tag] -= header->size;
+ // realloc, remove.
+ if (header->prev)
+ header->prev->next = header->next;
+ else
+ s_allocRoot = header->next;
+ if (header->next)
+ header->next->prev = header->prev;
+ }
+ if (!size) {
+ s_allocTotalSize -= header->size;
+ s_allocTotalTagSize[header->tag] -= header->size;
+ XA_ASSERT(!header->free); // double free
+ header->free = true;
+ return nullptr;
+ }
+ size += sizeof(AllocHeader) + sizeof(kAllocRedzone);
+ uint8_t *newPtr = (uint8_t *)s_realloc(realPtr, size);
+ if (!newPtr)
+ return nullptr;
+ header = (AllocHeader *)newPtr;
+ header->size = size;
+ header->file = file;
+ header->line = line;
+ header->tag = tag;
+ header->free = false;
+ if (!s_allocRoot) {
+ s_allocRoot = header;
+ header->prev = header->next = 0;
+ } else {
+ header->prev = nullptr;
+ header->next = s_allocRoot;
+ s_allocRoot = header;
+ header->next->prev = header;
+ }
+ s_allocTotalSize += size;
+ if (s_allocTotalSize > s_allocPeakSize)
+ s_allocPeakSize = s_allocTotalSize;
+ s_allocTotalTagSize[tag] += size;
+ if (s_allocTotalTagSize[tag] > s_allocPeakTagSize[tag])
+ s_allocPeakTagSize[tag] = s_allocTotalTagSize[tag];
+ auto redzone = (uint32_t *)(newPtr + size - sizeof(kAllocRedzone));
+ *redzone = kAllocRedzone;
+ return newPtr + sizeof(AllocHeader);
+}
+
+static void ReportLeaks()
+{
+ printf("Checking for memory leaks...\n");
+ bool anyLeaks = false;
+ AllocHeader *header = s_allocRoot;
+ while (header) {
+ if (!header->free) {
+ printf(" Leak: %zu bytes %s %d\n", header->size, header->file, header->line);
+ anyLeaks = true;
+ }
+ auto redzone = (const uint32_t *)((const uint8_t *)header + header->size - sizeof(kAllocRedzone));
+ if (*redzone != kAllocRedzone)
+ printf(" Redzone corrupted: %zu bytes %s %d\n", header->size, header->file, header->line);
+ header = header->next;
+ }
+ if (!anyLeaks)
+ printf(" No memory leaks\n");
+ header = s_allocRoot;
+ while (header) {
+ AllocHeader *destroy = header;
+ header = header->next;
+ s_realloc(destroy, 0);
+ }
+ s_allocRoot = nullptr;
+ s_allocTotalSize = s_allocPeakSize = 0;
+ for (int i = 0; i < MemTag::Count; i++)
+ s_allocTotalTagSize[i] = s_allocPeakTagSize[i] = 0;
+}
+
+static void PrintMemoryUsage()
+{
+ XA_PRINT("Memory usage: %0.2fMB current, %0.2fMB peak\n", internal::s_allocTotalSize / 1024.0f / 1024.0f, internal::s_allocPeakSize / 1024.0f / 1024.0f);
+ static const char *labels[] = { // Sync with MemTag
+ "Default",
+ "Mesh",
+ "MeshBoundaries",
+ "MeshColocals",
+ "MeshEdgeMap",
+ "MeshIndices",
+ "MeshNormals",
+ "MeshPositions",
+ "MeshTexcoords"
+ };
+ for (int i = 0; i < MemTag::Count; i++) {
+ XA_PRINT(" %s: %0.2fMB current, %0.2fMB peak\n", labels[i], internal::s_allocTotalTagSize[i] / 1024.0f / 1024.0f, internal::s_allocPeakTagSize[i] / 1024.0f / 1024.0f);
+ }
+}
+
+#define XA_PRINT_MEM_USAGE internal::PrintMemoryUsage();
+#else
+static void *Realloc(void *ptr, size_t size, int /*tag*/, const char * /*file*/, int /*line*/)
+{
+ void *mem = s_realloc(ptr, size);
+ if (size > 0) {
+ XA_DEBUG_ASSERT(mem);
+ }
+ return mem;
+}
+#define XA_PRINT_MEM_USAGE
+#endif
+
+#if XA_PROFILE
+#define XA_PROFILE_START(var) const clock_t var##Start = clock();
+#define XA_PROFILE_END(var) internal::s_profile.var += clock() - var##Start;
+#define XA_PROFILE_PRINT_AND_RESET(label, var) XA_PRINT("%s%.2f seconds (%g ms)\n", label, internal::clockToSeconds(internal::s_profile.var), internal::clockToMs(internal::s_profile.var)); internal::s_profile.var = 0;
+
+struct ProfileData
+{
+ clock_t addMeshReal;
+ std::atomic<clock_t> addMeshThread;
+ std::atomic<clock_t> addMeshCreateColocals;
+ std::atomic<clock_t> addMeshCreateFaceGroups;
+ std::atomic<clock_t> addMeshCreateBoundaries;
+ std::atomic<clock_t> addMeshCreateChartGroupsReal;
+ std::atomic<clock_t> addMeshCreateChartGroupsThread;
+ clock_t computeChartsReal;
+ std::atomic<clock_t> computeChartsThread;
+ std::atomic<clock_t> atlasBuilder;
+ std::atomic<clock_t> atlasBuilderInit;
+ std::atomic<clock_t> atlasBuilderCreateInitialCharts;
+ std::atomic<clock_t> atlasBuilderGrowCharts;
+ std::atomic<clock_t> atlasBuilderMergeCharts;
+ std::atomic<clock_t> createChartMeshesReal;
+ std::atomic<clock_t> createChartMeshesThread;
+ std::atomic<clock_t> fixChartMeshTJunctions;
+ std::atomic<clock_t> closeChartMeshHoles;
+ clock_t parameterizeChartsReal;
+ std::atomic<clock_t> parameterizeChartsThread;
+ std::atomic<clock_t> parameterizeChartsOrthogonal;
+ std::atomic<clock_t> parameterizeChartsLSCM;
+ std::atomic<clock_t> parameterizeChartsEvaluateQuality;
+ clock_t packCharts;
+ clock_t packChartsRasterize;
+ clock_t packChartsDilate;
+ clock_t packChartsFindLocation;
+ std::atomic<clock_t> packChartsFindLocationThread;
+ clock_t packChartsBlit;
+};
+
+static ProfileData s_profile;
+
+static double clockToMs(clock_t c)
+{
+ return c * 1000.0 / CLOCKS_PER_SEC;
+}
+
+static double clockToSeconds(clock_t c)
+{
+ return c / (double)CLOCKS_PER_SEC;
+}
+#else
+#define XA_PROFILE_START(var)
+#define XA_PROFILE_END(var)
+#define XA_PROFILE_PRINT_AND_RESET(label, var)
+#endif
+
+static constexpr float kPi = 3.14159265358979323846f;
+static constexpr float kPi2 = 6.28318530717958647692f;
+static constexpr float kEpsilon = 0.0001f;
+static constexpr float kAreaEpsilon = FLT_EPSILON;
+static constexpr float kNormalEpsilon = 0.001f;
static int align(int x, int a)
{
return (x + a - 1) & ~(a - 1);
}
-static bool isAligned(int x, int a)
+template <typename T>
+static T max(const T &a, const T &b)
{
- return (x & (a - 1)) == 0;
+ return a > b ? a : b;
+}
+
+template <typename T>
+static T min(const T &a, const T &b)
+{
+ return a < b ? a : b;
}
-/// Return the maximum of the three arguments.
template <typename T>
static T max3(const T &a, const T &b, const T &c)
{
- return std::max(a, std::max(b, c));
+ return max(a, max(b, c));
}
/// Return the maximum of the three arguments.
template <typename T>
static T min3(const T &a, const T &b, const T &c)
{
- return std::min(a, std::min(b, c));
+ return min(a, min(b, c));
}
/// Clamp between two values.
template <typename T>
static T clamp(const T &x, const T &a, const T &b)
{
- return std::min(std::max(x, a), b);
+ return min(max(x, a), b);
}
-static float saturate(float f)
+template <typename T>
+static void swap(T &a, T &b)
{
- return clamp(f, 0.0f, 1.0f);
+ T temp;
+ temp = a;
+ a = b;
+ b = temp;
+ temp = T();
}
-// Robust floating point comparisons:
-// http://realtimecollisiondetection.net/blog/?p=89
-static bool equal(const float f0, const float f1, const float epsilon = NV_EPSILON)
+union FloatUint32
{
- //return fabs(f0-f1) <= epsilon;
- return fabs(f0 - f1) <= epsilon * max3(1.0f, fabsf(f0), fabsf(f1));
-}
+ float f;
+ uint32_t u;
+};
-NV_FORCEINLINE static int ftoi_floor(float val)
+static bool isFinite(float f)
{
- return (int)val;
+ FloatUint32 fu;
+ fu.f = f;
+ return fu.u != 0x7F800000u && fu.u != 0x7F800001u;
}
-NV_FORCEINLINE static int ftoi_ceil(float val)
+static bool isNan(float f)
{
- return (int)ceilf(val);
+ return f != f;
}
-NV_FORCEINLINE static int ftoi_round(float f)
+// Robust floating point comparisons:
+// http://realtimecollisiondetection.net/blog/?p=89
+static bool equal(const float f0, const float f1, const float epsilon)
{
- return int(floorf(f + 0.5f));
+ //return fabs(f0-f1) <= epsilon;
+ return fabs(f0 - f1) <= epsilon * max3(1.0f, fabsf(f0), fabsf(f1));
}
-static bool isZero(const float f, const float epsilon = NV_EPSILON)
+static int ftoi_ceil(float val)
{
- return fabs(f) <= epsilon;
+ return (int)ceilf(val);
}
-static float lerp(float f0, float f1, float t)
+static bool isZero(const float f, const float epsilon)
{
- const float s = 1.0f - t;
- return f0 * s + f1 * t;
+ return fabs(f) <= epsilon;
}
static float square(float f)
@@ -130,11 +445,6 @@ static float square(float f)
return f * f;
}
-static int square(int i)
-{
- return i * i;
-}
-
/** Return the next power of two.
* @see http://graphics.stanford.edu/~seander/bithacks.html
* @warning Behaviour for 0 is undefined.
@@ -143,7 +453,7 @@ static int square(int i)
*/
static uint32_t nextPowerOfTwo(uint32_t x)
{
- xaDebugAssert( x != 0 );
+ XA_DEBUG_ASSERT( x != 0 );
// On modern CPUs this is supposed to be as fast as using the bsr instruction.
x--;
x |= x >> 1;
@@ -154,16 +464,6 @@ static uint32_t nextPowerOfTwo(uint32_t x)
return x + 1;
}
-static uint64_t nextPowerOfTwo(uint64_t x)
-{
- xaDebugAssert(x != 0);
- uint32_t p = 1;
- while (x > p) {
- p += p;
- }
- return p;
-}
-
static uint32_t sdbmHash(const void *data_in, uint32_t size, uint32_t h = 5381)
{
const uint8_t *data = (const uint8_t *) data_in;
@@ -174,31 +474,12 @@ static uint32_t sdbmHash(const void *data_in, uint32_t size, uint32_t h = 5381)
return h;
}
-// Note that this hash does not handle NaN properly.
-static uint32_t sdbmFloatHash(const float *f, uint32_t count, uint32_t h = 5381)
-{
- for (uint32_t i = 0; i < count; i++) {
- union {
- float f;
- uint32_t i;
- } x = { f[i] };
- if (x.i == 0x80000000) x.i = 0;
- h = sdbmHash(&x, 4, h);
- }
- return h;
-}
-
template <typename T>
static uint32_t hash(const T &t, uint32_t h = 5381)
{
return sdbmHash(&t, sizeof(T), h);
}
-static uint32_t hash(const float &f, uint32_t h)
-{
- return sdbmFloatHash(&f, 1, h);
-}
-
// Functors for hash table:
template <typename Key> struct Hash
{
@@ -213,40 +494,22 @@ template <typename Key> struct Equal
class Vector2
{
public:
- typedef Vector2 const &Arg;
-
Vector2() {}
explicit Vector2(float f) : x(f), y(f) {}
Vector2(float x, float y): x(x), y(y) {}
- Vector2(Vector2::Arg v) : x(v.x), y(v.y) {}
-
- const Vector2 &operator=(Vector2::Arg v)
- {
- x = v.x;
- y = v.y;
- return
- *this;
- }
- const float *ptr() const { return &x; }
-
- void set(float _x, float _y)
- {
- x = _x;
- y = _y;
- }
Vector2 operator-() const
{
return Vector2(-x, -y);
}
- void operator+=(Vector2::Arg v)
+ void operator+=(const Vector2 &v)
{
x += v.x;
y += v.y;
}
- void operator-=(Vector2::Arg v)
+ void operator-=(const Vector2 &v)
{
x -= v.x;
y -= v.y;
@@ -258,138 +521,99 @@ public:
y *= s;
}
- void operator*=(Vector2::Arg v)
+ void operator*=(const Vector2 &v)
{
x *= v.x;
y *= v.y;
}
- friend bool operator==(Vector2::Arg a, Vector2::Arg b)
- {
- return a.x == b.x && a.y == b.y;
- }
-
- friend bool operator!=(Vector2::Arg a, Vector2::Arg b)
- {
- return a.x != b.x || a.y != b.y;
- }
-
- union
- {
-#ifdef _MSC_VER
-#pragma warning(push)
-#pragma warning(disable : 4201)
-#endif
- struct
- {
- float x, y;
- };
-#ifdef _MSC_VER
-#pragma warning(pop)
-#endif
-
- float component[2];
- };
+ float x, y;
};
-Vector2 operator+(Vector2::Arg a, Vector2::Arg b)
+static bool operator==(const Vector2 &a, const Vector2 &b)
{
- return Vector2(a.x + b.x, a.y + b.y);
+ return a.x == b.x && a.y == b.y;
}
-Vector2 operator-(Vector2::Arg a, Vector2::Arg b)
+static bool operator!=(const Vector2 &a, const Vector2 &b)
{
- return Vector2(a.x - b.x, a.y - b.y);
+ return a.x != b.x || a.y != b.y;
}
-Vector2 operator*(Vector2::Arg v, float s)
+static Vector2 operator+(const Vector2 &a, const Vector2 &b)
{
- return Vector2(v.x * s, v.y * s);
-}
-
-Vector2 operator*(Vector2::Arg v1, Vector2::Arg v2)
-{
- return Vector2(v1.x * v2.x, v1.y * v2.y);
+ return Vector2(a.x + b.x, a.y + b.y);
}
-Vector2 operator/(Vector2::Arg v, float s)
+static Vector2 operator-(const Vector2 &a, const Vector2 &b)
{
- return Vector2(v.x / s, v.y / s);
+ return Vector2(a.x - b.x, a.y - b.y);
}
-Vector2 lerp(Vector2::Arg v1, Vector2::Arg v2, float t)
+static Vector2 operator*(const Vector2 &v, float s)
{
- const float s = 1.0f - t;
- return Vector2(v1.x * s + t * v2.x, v1.y * s + t * v2.y);
+ return Vector2(v.x * s, v.y * s);
}
-float dot(Vector2::Arg a, Vector2::Arg b)
+static float dot(const Vector2 &a, const Vector2 &b)
{
return a.x * b.x + a.y * b.y;
}
-float lengthSquared(Vector2::Arg v)
+static float lengthSquared(const Vector2 &v)
{
return v.x * v.x + v.y * v.y;
}
-float length(Vector2::Arg v)
+static float length(const Vector2 &v)
{
return sqrtf(lengthSquared(v));
}
-float distance(Vector2::Arg a, Vector2::Arg b)
-{
- return length(a - b);
-}
-
-bool isNormalized(Vector2::Arg v, float epsilon = NV_NORMAL_EPSILON)
+#if XA_DEBUG
+static bool isNormalized(const Vector2 &v, float epsilon = kNormalEpsilon)
{
return equal(length(v), 1, epsilon);
}
+#endif
-Vector2 normalize(Vector2::Arg v, float epsilon = NV_EPSILON)
+static Vector2 normalize(const Vector2 &v, float epsilon)
{
float l = length(v);
- xaDebugAssert(!isZero(l, epsilon));
-#ifdef NDEBUG
- epsilon = 0; // silence unused parameter warning
-#endif
+ XA_DEBUG_ASSERT(!isZero(l, epsilon));
+ XA_UNUSED(epsilon);
Vector2 n = v * (1.0f / l);
- xaDebugAssert(isNormalized(n));
+ XA_DEBUG_ASSERT(isNormalized(n));
return n;
}
-Vector2 normalizeSafe(Vector2::Arg v, Vector2::Arg fallback, float epsilon = NV_EPSILON)
+static bool equal(const Vector2 &v1, const Vector2 &v2, float epsilon)
{
- float l = length(v);
- if (isZero(l, epsilon)) {
- return fallback;
- }
- return v * (1.0f / l);
+ return equal(v1.x, v2.x, epsilon) && equal(v1.y, v2.y, epsilon);
}
-bool equal(Vector2::Arg v1, Vector2::Arg v2, float epsilon = NV_EPSILON)
+static Vector2 min(const Vector2 &a, const Vector2 &b)
{
- return equal(v1.x, v2.x, epsilon) && equal(v1.y, v2.y, epsilon);
+ return Vector2(min(a.x, b.x), min(a.y, b.y));
}
-Vector2 max(Vector2::Arg a, Vector2::Arg b)
+static Vector2 max(const Vector2 &a, const Vector2 &b)
{
- return Vector2(std::max(a.x, b.x), std::max(a.y, b.y));
+ return Vector2(max(a.x, b.x), max(a.y, b.y));
}
-bool isFinite(Vector2::Arg v)
+static bool isFinite(const Vector2 &v)
{
- return std::isfinite(v.x) && std::isfinite(v.y);
+ return isFinite(v.x) && isFinite(v.y);
}
// Note, this is the area scaled by 2!
-float triangleArea(Vector2::Arg v0, Vector2::Arg v1)
+static float triangleArea(const Vector2 &v0, const Vector2 &v1)
{
return (v0.x * v1.y - v0.y * v1.x); // * 0.5f;
}
-float triangleArea(Vector2::Arg a, Vector2::Arg b, Vector2::Arg c)
+
+static float triangleArea(const Vector2 &a, const Vector2 &b, const Vector2 &c)
{
// IC: While it may be appealing to use the following expression:
//return (c.x * a.y + a.x * b.y + b.x * c.y - b.x * a.y - c.x * b.y - a.x * c.y); // * 0.5f;
@@ -402,62 +626,55 @@ float triangleArea(Vector2::Arg a, Vector2::Arg b, Vector2::Arg c)
return triangleArea(a - c, b - c);
}
-float triangleArea2(Vector2::Arg v1, Vector2::Arg v2, Vector2::Arg v3)
+static bool linesIntersect(const Vector2 &a1, const Vector2 &a2, const Vector2 &b1, const Vector2 &b2, float epsilon)
{
- return 0.5f * (v3.x * v1.y + v1.x * v2.y + v2.x * v3.y - v2.x * v1.y - v3.x * v2.y - v1.x * v3.y);
+ const Vector2 v0 = a2 - a1;
+ const Vector2 v1 = b2 - b1;
+ const float denom = -v1.x * v0.y + v0.x * v1.y;
+ if (equal(denom, 0.0f, epsilon))
+ return false;
+ const float s = (-v0.y * (a1.x - b1.x) + v0.x * (a1.y - b1.y)) / denom;
+ if (s > epsilon && s < 1.0f - epsilon) {
+ const float t = ( v1.x * (a1.y - b1.y) - v1.y * (a1.x - b1.x)) / denom;
+ return t > epsilon && t < 1.0f - epsilon;
+ }
+ return false;
}
-static uint32_t hash(const Vector2 &v, uint32_t h)
+struct Vector2i
{
- return sdbmFloatHash(v.component, 2, h);
-}
+ Vector2i() {}
+ Vector2i(int32_t x, int32_t y) : x(x), y(y) {}
+
+ int32_t x, y;
+};
class Vector3
{
public:
- typedef Vector3 const &Arg;
-
Vector3() {}
explicit Vector3(float f) : x(f), y(f), z(f) {}
Vector3(float x, float y, float z) : x(x), y(y), z(z) {}
- Vector3(Vector2::Arg v, float z) : x(v.x), y(v.y), z(z) {}
- Vector3(Vector3::Arg v) : x(v.x), y(v.y), z(v.z) {}
-
- const Vector3 &operator=(Vector3::Arg v)
- {
- x = v.x;
- y = v.y;
- z = v.z;
- return *this;
- }
+ Vector3(const Vector2 &v, float z) : x(v.x), y(v.y), z(z) {}
Vector2 xy() const
{
return Vector2(x, y);
}
- const float *ptr() const { return &x; }
-
- void set(float _x, float _y, float _z)
- {
- x = _x;
- y = _y;
- z = _z;
- }
-
Vector3 operator-() const
{
return Vector3(-x, -y, -z);
}
- void operator+=(Vector3::Arg v)
+ void operator+=(const Vector3 &v)
{
x += v.x;
y += v.y;
z += v.z;
}
- void operator-=(Vector3::Arg v)
+ void operator-=(const Vector3 &v)
{
x -= v.x;
y -= v.y;
@@ -479,159 +696,89 @@ public:
z *= is;
}
- void operator*=(Vector3::Arg v)
+ void operator*=(const Vector3 &v)
{
x *= v.x;
y *= v.y;
z *= v.z;
}
- void operator/=(Vector3::Arg v)
+ void operator/=(const Vector3 &v)
{
x /= v.x;
y /= v.y;
z /= v.z;
}
- friend bool operator==(Vector3::Arg a, Vector3::Arg b)
- {
- return a.x == b.x && a.y == b.y && a.z == b.z;
- }
-
- friend bool operator!=(Vector3::Arg a, Vector3::Arg b)
- {
- return a.x != b.x || a.y != b.y || a.z != b.z;
- }
-
- union
- {
-#ifdef _MSC_VER
-#pragma warning(push)
-#pragma warning(disable : 4201)
-#endif
- struct
- {
- float x, y, z;
- };
-#ifdef _MSC_VER
-#pragma warning(pop)
-#endif
-
- float component[3];
- };
+ float x, y, z;
};
-Vector3 add(Vector3::Arg a, Vector3::Arg b)
+static bool operator!=(const Vector3 &a, const Vector3 &b)
{
- return Vector3(a.x + b.x, a.y + b.y, a.z + b.z);
-}
-Vector3 add(Vector3::Arg a, float b)
-{
- return Vector3(a.x + b, a.y + b, a.z + b);
-}
-Vector3 operator+(Vector3::Arg a, Vector3::Arg b)
-{
- return add(a, b);
-}
-Vector3 operator+(Vector3::Arg a, float b)
-{
- return add(a, b);
-}
-
-Vector3 sub(Vector3::Arg a, Vector3::Arg b)
-{
- return Vector3(a.x - b.x, a.y - b.y, a.z - b.z);
+ return a.x != b.x || a.y != b.y || a.z != b.z;
}
-Vector3 sub(Vector3::Arg a, float b)
+static Vector3 operator+(const Vector3 &a, const Vector3 &b)
{
- return Vector3(a.x - b, a.y - b, a.z - b);
-}
-
-Vector3 operator-(Vector3::Arg a, Vector3::Arg b)
-{
- return sub(a, b);
+ return Vector3(a.x + b.x, a.y + b.y, a.z + b.z);
}
-Vector3 operator-(Vector3::Arg a, float b)
+static Vector3 operator-(const Vector3 &a, const Vector3 &b)
{
- return sub(a, b);
+ return Vector3(a.x - b.x, a.y - b.y, a.z - b.z);
}
-Vector3 cross(Vector3::Arg a, Vector3::Arg b)
+static Vector3 cross(const Vector3 &a, const Vector3 &b)
{
return Vector3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
}
-Vector3 operator*(Vector3::Arg v, float s)
+static Vector3 operator*(const Vector3 &v, float s)
{
return Vector3(v.x * s, v.y * s, v.z * s);
}
-Vector3 operator*(float s, Vector3::Arg v)
+static Vector3 operator*(float s, const Vector3 &v)
{
return Vector3(v.x * s, v.y * s, v.z * s);
}
-Vector3 operator*(Vector3::Arg v, Vector3::Arg s)
-{
- return Vector3(v.x * s.x, v.y * s.y, v.z * s.z);
-}
-
-Vector3 operator/(Vector3::Arg v, float s)
+static Vector3 operator/(const Vector3 &v, float s)
{
return v * (1.0f / s);
}
-Vector3 lerp(Vector3::Arg v1, Vector3::Arg v2, float t)
-{
- const float s = 1.0f - t;
- return Vector3(v1.x * s + t * v2.x, v1.y * s + t * v2.y, v1.z * s + t * v2.z);
-}
-
-float dot(Vector3::Arg a, Vector3::Arg b)
+static float dot(const Vector3 &a, const Vector3 &b)
{
return a.x * b.x + a.y * b.y + a.z * b.z;
}
-float lengthSquared(Vector3::Arg v)
+static float lengthSquared(const Vector3 &v)
{
return v.x * v.x + v.y * v.y + v.z * v.z;
}
-float length(Vector3::Arg v)
+static float length(const Vector3 &v)
{
return sqrtf(lengthSquared(v));
}
-float distance(Vector3::Arg a, Vector3::Arg b)
-{
- return length(a - b);
-}
-
-float distanceSquared(Vector3::Arg a, Vector3::Arg b)
-{
- return lengthSquared(a - b);
-}
-
-bool isNormalized(Vector3::Arg v, float epsilon = NV_NORMAL_EPSILON)
+static bool isNormalized(const Vector3 &v, float epsilon = kNormalEpsilon)
{
return equal(length(v), 1, epsilon);
}
-Vector3 normalize(Vector3::Arg v, float epsilon = NV_EPSILON)
+static Vector3 normalize(const Vector3 &v, float epsilon)
{
float l = length(v);
- xaDebugAssert(!isZero(l, epsilon));
-#ifdef NDEBUG
- epsilon = 0; // silence unused parameter warning
-#endif
+ XA_DEBUG_ASSERT(!isZero(l, epsilon));
+ XA_UNUSED(epsilon);
Vector3 n = v * (1.0f / l);
- xaDebugAssert(isNormalized(n));
+ XA_DEBUG_ASSERT(isNormalized(n));
return n;
}
-Vector3 normalizeSafe(Vector3::Arg v, Vector3::Arg fallback, float epsilon = NV_EPSILON)
+static Vector3 normalizeSafe(const Vector3 &v, const Vector3 &fallback, float epsilon)
{
float l = length(v);
if (isZero(l, epsilon)) {
@@ -640,57 +787,423 @@ Vector3 normalizeSafe(Vector3::Arg v, Vector3::Arg fallback, float epsilon = NV_
return v * (1.0f / l);
}
-bool equal(Vector3::Arg v1, Vector3::Arg v2, float epsilon = NV_EPSILON)
+static bool equal(const Vector3 &v0, const Vector3 &v1, float epsilon)
{
- return equal(v1.x, v2.x, epsilon) && equal(v1.y, v2.y, epsilon) && equal(v1.z, v2.z, epsilon);
+ return fabs(v0.x - v1.x) <= epsilon && fabs(v0.y - v1.y) <= epsilon && fabs(v0.z - v1.z) <= epsilon;
}
-Vector3 min(Vector3::Arg a, Vector3::Arg b)
+static Vector3 min(const Vector3 &a, const Vector3 &b)
{
- return Vector3(std::min(a.x, b.x), std::min(a.y, b.y), std::min(a.z, b.z));
+ return Vector3(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z));
}
-Vector3 max(Vector3::Arg a, Vector3::Arg b)
+static Vector3 max(const Vector3 &a, const Vector3 &b)
{
- return Vector3(std::max(a.x, b.x), std::max(a.y, b.y), std::max(a.z, b.z));
+ return Vector3(max(a.x, b.x), max(a.y, b.y), max(a.z, b.z));
}
-Vector3 clamp(Vector3::Arg v, float min, float max)
+#if XA_DEBUG
+bool isFinite(const Vector3 &v)
{
- return Vector3(clamp(v.x, min, max), clamp(v.y, min, max), clamp(v.z, min, max));
+ return isFinite(v.x) && isFinite(v.y) && isFinite(v.z);
}
+#endif
-Vector3 saturate(Vector3::Arg v)
+struct Plane
{
- return Vector3(saturate(v.x), saturate(v.y), saturate(v.z));
+ Plane() = default;
+
+ Plane(const Vector3 &p1, const Vector3 &p2, const Vector3 &p3)
+ {
+ normal = cross(p2 - p1, p3 - p1);
+ dist = dot(normal, p1);
+ }
+
+ float distance(const Vector3 &p) const
+ {
+ return dot(normal, p) - dist;
+ }
+
+ void normalize()
+ {
+ const float len = length(normal);
+ if (len > 0.0f) {
+ const float il = 1.0f / len;
+ normal *= il;
+ dist *= il;
+ }
+ }
+
+ Vector3 normal;
+ float dist;
+};
+
+static bool lineIntersectsPoint(const Vector3 &point, const Vector3 &lineStart, const Vector3 &lineEnd, float *t, float epsilon)
+{
+ float tt;
+ if (!t)
+ t = &tt;
+ *t = 0.0f;
+ if (equal(lineStart, point, epsilon) || equal(lineEnd, point, epsilon))
+ return false; // Vertex lies on either line vertices.
+ const Vector3 v01 = point - lineStart;
+ const Vector3 v21 = lineEnd - lineStart;
+ const float l = length(v21);
+ const float d = length(cross(v01, v21)) / l;
+ if (!isZero(d, epsilon))
+ return false;
+ *t = dot(v01, v21) / (l * l);
+ return *t > kEpsilon && *t < 1.0f - kEpsilon;
}
-Vector3 floor(Vector3::Arg v)
+static bool sameSide(const Vector3 &p1, const Vector3 &p2, const Vector3 &a, const Vector3 &b)
{
- return Vector3(floorf(v.x), floorf(v.y), floorf(v.z));
+ const Vector3 &ab = b - a;
+ return dot(cross(ab, p1 - a), cross(ab, p2 - a)) >= 0.0f;
}
-bool isFinite(Vector3::Arg v)
+// http://blackpawn.com/texts/pointinpoly/default.html
+static bool pointInTriangle(const Vector3 &p, const Vector3 &a, const Vector3 &b, const Vector3 &c)
{
- return std::isfinite(v.x) && std::isfinite(v.y) && std::isfinite(v.z);
+ return sameSide(p, a, b, c) && sameSide(p, b, a, c) && sameSide(p, c, a, b);
}
-static uint32_t hash(const Vector3 &v, uint32_t h)
+#if XA_CLOSE_HOLES_CHECK_EDGE_INTERSECTION
+// https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm
+static bool rayIntersectsTriangle(const Vector3 &rayOrigin, const Vector3 &rayDir, const Vector3 *tri, float *t)
+{
+ *t = 0.0f;
+ const Vector3 &edge1 = tri[1] - tri[0];
+ const Vector3 &edge2 = tri[2] - tri[0];
+ const Vector3 h = cross(rayDir, edge2);
+ const float a = dot(edge1, h);
+ if (a > -kEpsilon && a < kEpsilon)
+ return false; // This ray is parallel to this triangle.
+ const float f = 1.0f / a;
+ const Vector3 s = rayOrigin - tri[0];
+ const float u = f * dot(s, h);
+ if (u < 0.0f || u > 1.0f)
+ return false;
+ const Vector3 q = cross(s, edge1);
+ const float v = f * dot(rayDir, q);
+ if (v < 0.0f || u + v > 1.0f)
+ return false;
+ // At this stage we can compute t to find out where the intersection point is on the line.
+ *t = f * dot(edge2, q);
+ if (*t > kEpsilon && *t < 1.0f - kEpsilon)
+ return true;
+ // This means that there is a line intersection but not a ray intersection.
+ return false;
+}
+#endif
+
+// From Fast-BVH
+struct AABB
{
- return sdbmFloatHash(v.component, 3, h);
+ AABB() : min(FLT_MAX, FLT_MAX, FLT_MAX), max(-FLT_MAX, -FLT_MAX, -FLT_MAX) {}
+ AABB(const Vector3 &min, const Vector3 &max) : min(min), max(max) { }
+ AABB(const Vector3 &p, float radius = 0.0f) : min(p), max(p) { if (radius > 0.0f) expand(radius); }
+
+ bool intersect(const AABB &other) const
+ {
+ return min.x <= other.max.x && max.x >= other.min.x && min.y <= other.max.y && max.y >= other.min.y && min.z <= other.max.z && max.z >= other.min.z;
+ }
+
+ void expandToInclude(const Vector3 &p)
+ {
+ min = internal::min(min, p);
+ max = internal::max(max, p);
+ }
+
+ void expandToInclude(const AABB &aabb)
+ {
+ min = internal::min(min, aabb.min);
+ max = internal::max(max, aabb.max);
+ }
+
+ void expand(float amount)
+ {
+ min -= Vector3(amount);
+ max += Vector3(amount);
+ }
+
+ Vector3 centroid() const
+ {
+ return min + (max - min) * 0.5f;
+ }
+
+ uint32_t maxDimension() const
+ {
+ const Vector3 extent = max - min;
+ uint32_t result = 0;
+ if (extent.y > extent.x) {
+ result = 1;
+ if (extent.z > extent.y)
+ result = 2;
+ }
+ else if(extent.z > extent.x)
+ result = 2;
+ return result;
+ }
+
+ Vector3 min, max;
+};
+
+template <typename T>
+static void construct_range(T * ptr, uint32_t new_size, uint32_t old_size) {
+ for (uint32_t i = old_size; i < new_size; i++) {
+ new(ptr+i) T; // placement new
+ }
+}
+
+template <typename T>
+static void construct_range(T * ptr, uint32_t new_size, uint32_t old_size, const T & elem) {
+ for (uint32_t i = old_size; i < new_size; i++) {
+ new(ptr+i) T(elem); // placement new
+ }
}
+template <typename T>
+static void construct_range(T * ptr, uint32_t new_size, uint32_t old_size, const T * src) {
+ for (uint32_t i = old_size; i < new_size; i++) {
+ new(ptr+i) T(src[i]); // placement new
+ }
+}
+
+template <typename T>
+static void destroy_range(T * ptr, uint32_t new_size, uint32_t old_size) {
+ for (uint32_t i = new_size; i < old_size; i++) {
+ (ptr+i)->~T(); // Explicit call to the destructor
+ }
+}
+
+/**
+* Replacement for std::vector that is easier to debug and provides
+* some nice foreach enumerators.
+*/
+template<typename T>
+class Array {
+public:
+ typedef uint32_t size_type;
+
+ Array(int memTag = MemTag::Default) : m_memTag(memTag), m_buffer(nullptr), m_capacity(0), m_size(0) {}
+
+ Array(const Array &a) : m_memTag(a.m_memTag), m_buffer(nullptr), m_capacity(0), m_size(0)
+ {
+ copy(a.m_buffer, a.m_size);
+ }
+
+ ~Array()
+ {
+ destroy();
+ }
+
+ const Array<T> &operator=(const Array<T> &other)
+ {
+ m_memTag = other.m_memTag;
+ m_buffer = other.m_buffer;
+ m_capacity = other.m_capacity;
+ m_size = other.m_size;
+ return *this;
+ }
+
+ const T & operator[]( uint32_t index ) const
+ {
+ XA_DEBUG_ASSERT(index < m_size);
+ return m_buffer[index];
+ }
+
+ T & operator[] ( uint32_t index )
+ {
+ XA_DEBUG_ASSERT(index < m_size);
+ return m_buffer[index];
+ }
+
+ uint32_t size() const { return m_size; }
+ const T * data() const { return m_buffer; }
+ T * data() { return m_buffer; }
+ T * begin() { return m_buffer; }
+ T * end() { return m_buffer + m_size; }
+ const T * begin() const { return m_buffer; }
+ const T * end() const { return m_buffer + m_size; }
+ bool isEmpty() const { return m_size == 0; }
+
+ void push_back( const T & val )
+ {
+ XA_DEBUG_ASSERT(&val < m_buffer || &val >= m_buffer+m_size);
+ uint32_t old_size = m_size;
+ uint32_t new_size = m_size + 1;
+ setArraySize(new_size);
+ construct_range(m_buffer, new_size, old_size, val);
+ }
+
+ void pop_back()
+ {
+ XA_DEBUG_ASSERT( m_size > 0 );
+ resize( m_size - 1 );
+ }
+
+ const T & back() const
+ {
+ XA_DEBUG_ASSERT( m_size > 0 );
+ return m_buffer[m_size-1];
+ }
+
+ T & back()
+ {
+ XA_DEBUG_ASSERT( m_size > 0 );
+ return m_buffer[m_size-1];
+ }
+
+ const T & front() const
+ {
+ XA_DEBUG_ASSERT( m_size > 0 );
+ return m_buffer[0];
+ }
+
+ T & front()
+ {
+ XA_DEBUG_ASSERT( m_size > 0 );
+ return m_buffer[0];
+ }
+
+ // Remove the element at the given index. This is an expensive operation!
+ void removeAt(uint32_t index)
+ {
+ XA_DEBUG_ASSERT(index >= 0 && index < m_size);
+ if (m_size == 1) {
+ clear();
+ }
+ else {
+ m_buffer[index].~T();
+ memmove(m_buffer+index, m_buffer+index+1, sizeof(T) * (m_size - 1 - index));
+ m_size--;
+ }
+ }
+
+ // Insert the given element at the given index shifting all the elements up.
+ void insertAt(uint32_t index, const T & val = T())
+ {
+ XA_DEBUG_ASSERT( index >= 0 && index <= m_size );
+ setArraySize(m_size + 1);
+ if (index < m_size - 1) {
+ memmove(m_buffer+index+1, m_buffer+index, sizeof(T) * (m_size - 1 - index));
+ }
+ // Copy-construct into the newly opened slot.
+ new(m_buffer+index) T(val);
+ }
+
+ void append(const Array<T> & other)
+ {
+ append(other.m_buffer, other.m_size);
+ }
+
+ void resize(uint32_t new_size)
+ {
+ uint32_t old_size = m_size;
+ // Destruct old elements (if we're shrinking).
+ destroy_range(m_buffer, new_size, old_size);
+ setArraySize(new_size);
+ // Call default constructors
+ construct_range(m_buffer, new_size, old_size);
+ }
+
+ void resize(uint32_t new_size, const T & elem)
+ {
+ XA_DEBUG_ASSERT(&elem < m_buffer || &elem > m_buffer+m_size);
+ uint32_t old_size = m_size;
+ // Destruct old elements (if we're shrinking).
+ destroy_range(m_buffer, new_size, old_size);
+ setArraySize(new_size);
+ // Call copy constructors
+ construct_range(m_buffer, new_size, old_size, elem);
+ }
+
+ void clear()
+ {
+ // Destruct old elements
+ destroy_range(m_buffer, 0, m_size);
+ m_size = 0;
+ }
+
+ void destroy()
+ {
+ clear();
+ XA_FREE(m_buffer);
+ m_buffer = nullptr;
+ m_capacity = 0;
+ m_size = 0;
+ }
+
+ void reserve(uint32_t desired_size)
+ {
+ if (desired_size > m_capacity) {
+ setArrayCapacity(desired_size);
+ }
+ }
+
+ void copy(const T * data, uint32_t count)
+ {
+ destroy_range(m_buffer, 0, m_size);
+ setArraySize(count);
+ construct_range(m_buffer, count, 0, data);
+ }
+
+ void moveTo(Array<T> &other)
+ {
+ other.destroy();
+ swap(m_buffer, other.m_buffer);
+ swap(m_capacity, other.m_capacity);
+ swap(m_size, other.m_size);
+ }
+
+protected:
+ void setArraySize(uint32_t new_size)
+ {
+ m_size = new_size;
+ if (new_size > m_capacity) {
+ uint32_t new_buffer_size;
+ if (m_capacity == 0) {
+ // first allocation is exact
+ new_buffer_size = new_size;
+ }
+ else {
+ // following allocations grow array by 25%
+ new_buffer_size = new_size + (new_size >> 2);
+ }
+ setArrayCapacity( new_buffer_size );
+ }
+ }
+ void setArrayCapacity(uint32_t new_capacity)
+ {
+ XA_DEBUG_ASSERT(new_capacity >= m_size);
+ if (new_capacity == 0) {
+ // free the buffer.
+ if (m_buffer != nullptr) {
+ XA_FREE(m_buffer);
+ m_buffer = nullptr;
+ }
+ }
+ else {
+ // realloc the buffer
+ m_buffer = XA_REALLOC(m_memTag, m_buffer, T, new_capacity);
+ }
+ m_capacity = new_capacity;
+ }
+
+ int m_memTag;
+ T * m_buffer;
+ uint32_t m_capacity;
+ uint32_t m_size;
+};
+
/// Basis class to compute tangent space basis, ortogonalizations and to
/// transform vectors from one space to another.
-class Basis
+struct Basis
{
-public:
- /// Create a null basis.
- Basis() : tangent(0, 0, 0), bitangent(0, 0, 0), normal(0, 0, 0) {}
-
- void buildFrameForDirection(Vector3::Arg d, float angle = 0)
+ void buildFrameForDirection(const Vector3 &d, float angle = 0)
{
- xaAssert(isNormalized(d));
+ XA_ASSERT(isNormalized(d));
normal = d;
// Choose minimum axis.
if (fabsf(normal.x) < fabsf(normal.y) && fabsf(normal.x) < fabsf(normal.z)) {
@@ -702,7 +1215,7 @@ public:
}
// Ortogonalize
tangent -= normal * dot(normal, tangent);
- tangent = normalize(tangent);
+ tangent = normalize(tangent, kEpsilon);
bitangent = cross(normal, tangent);
// Rotate frame around normal according to angle.
if (angle != 0.0f) {
@@ -714,9 +1227,9 @@ public:
}
}
- Vector3 tangent;
- Vector3 bitangent;
- Vector3 normal;
+ Vector3 tangent = Vector3(0.0f);
+ Vector3 bitangent = Vector3(0.0f);
+ Vector3 normal = Vector3(0.0f);
};
// Simple bit array.
@@ -724,21 +1237,12 @@ class BitArray
{
public:
BitArray() : m_size(0) {}
+
BitArray(uint32_t sz)
{
resize(sz);
}
- uint32_t size() const
- {
- return m_size;
- }
-
- void clear()
- {
- resize(0);
- }
-
void resize(uint32_t new_size)
{
m_size = new_size;
@@ -748,162 +1252,311 @@ public:
/// Get bit.
bool bitAt(uint32_t b) const
{
- xaDebugAssert( b < m_size );
+ XA_DEBUG_ASSERT( b < m_size );
return (m_wordArray[b >> 5] & (1 << (b & 31))) != 0;
}
// Set a bit.
void setBitAt(uint32_t idx)
{
- xaDebugAssert(idx < m_size);
+ XA_DEBUG_ASSERT(idx < m_size);
m_wordArray[idx >> 5] |= (1 << (idx & 31));
}
- // Toggle a bit.
- void toggleBitAt(uint32_t idx)
- {
- xaDebugAssert(idx < m_size);
- m_wordArray[idx >> 5] ^= (1 << (idx & 31));
- }
-
- // Set a bit to the given value. @@ Rename modifyBitAt?
- void setBitAt(uint32_t idx, bool b)
- {
- xaDebugAssert(idx < m_size);
- m_wordArray[idx >> 5] = setBits(m_wordArray[idx >> 5], 1 << (idx & 31), b);
- xaDebugAssert(bitAt(idx) == b);
- }
-
// Clear all the bits.
void clearAll()
{
- memset(m_wordArray.data(), 0, m_wordArray.size() * sizeof(uint32_t ));
- }
-
- // Set all the bits.
- void setAll()
- {
- memset(m_wordArray.data(), 0xFF, m_wordArray.size() * sizeof(uint32_t ));
+ memset(m_wordArray.data(), 0, m_wordArray.size() * sizeof(uint32_t));
}
private:
- // See "Conditionally set or clear bits without branching" at http://graphics.stanford.edu/~seander/bithacks.html
- uint32_t setBits(uint32_t w, uint32_t m, bool b)
- {
- return (w & ~m) | (-int(b) & m);
- }
-
// Number of bits stored.
uint32_t m_size;
// Array of bits.
- std::vector<uint32_t> m_wordArray;
+ Array<uint32_t> m_wordArray;
};
-/// Bit map. This should probably be called BitImage.
-class BitMap
+class BitImage
{
public:
- BitMap() : m_width(0), m_height(0) {}
- BitMap(uint32_t w, uint32_t h) : m_width(w), m_height(h), m_bitArray(w * h) {}
+ BitImage() : m_width(0), m_height(0), m_rowStride(0) {}
- uint32_t width() const
+ BitImage(uint32_t w, uint32_t h) : m_width(w), m_height(h)
{
- return m_width;
+ m_rowStride = (m_width + 63) >> 6;
+ m_data.resize(m_rowStride * m_height);
}
- uint32_t height() const
+
+ BitImage(const BitImage &other)
{
- return m_height;
+ m_width = other.m_width;
+ m_height = other.m_height;
+ m_rowStride = other.m_rowStride;
+ m_data.resize(m_rowStride * m_height);
+ memcpy(m_data.data(), other.m_data.data(), m_rowStride * m_height * sizeof(uint64_t));
}
- void resize(uint32_t w, uint32_t h, bool initValue)
+ const BitImage &operator=(const BitImage &other)
{
- BitArray tmp(w * h);
- if (initValue) tmp.setAll();
- else tmp.clearAll();
- // @@ Copying one bit at a time. This could be much faster.
- for (uint32_t y = 0; y < m_height; y++) {
- for (uint32_t x = 0; x < m_width; x++) {
- //tmp.setBitAt(y*w + x, bitAt(x, y));
- if (bitAt(x, y) != initValue) tmp.toggleBitAt(y * w + x);
- }
+ m_width = other.m_width;
+ m_height = other.m_height;
+ m_rowStride = other.m_rowStride;
+ m_data = other.m_data;
+ return *this;
+ }
+
+ uint32_t width() const { return m_width; }
+ uint32_t height() const { return m_height; }
+
+ void resize(uint32_t w, uint32_t h, bool discard)
+ {
+ const uint32_t rowStride = (w + 63) >> 6;
+ if (discard) {
+ m_data.resize(rowStride * h);
+ memset(m_data.data(), 0, m_data.size() * sizeof(uint64_t));
+ } else {
+ Array<uint64_t> tmp;
+ tmp.resize(rowStride * h);
+ memset(tmp.data(), 0, tmp.size() * sizeof(uint64_t));
+ // If only height has changed, can copy all rows at once.
+ if (rowStride == m_rowStride) {
+ memcpy(tmp.data(), m_data.data(), m_rowStride * min(m_height, h) * sizeof(uint64_t));
+ } else if (m_width > 0 && m_height > 0) {
+ const uint32_t height = min(m_height, h);
+ for (uint32_t i = 0; i < height; i++)
+ memcpy(&tmp[i * rowStride], &m_data[i * m_rowStride], min(rowStride, m_rowStride) * sizeof(uint64_t));
+ }
+ tmp.moveTo(m_data);
}
- std::swap(m_bitArray, tmp);
m_width = w;
m_height = h;
+ m_rowStride = rowStride;
}
bool bitAt(uint32_t x, uint32_t y) const
{
- xaDebugAssert(x < m_width && y < m_height);
- return m_bitArray.bitAt(y * m_width + x);
+ XA_DEBUG_ASSERT(x < m_width && y < m_height);
+ const uint32_t index = (x >> 6) + y * m_rowStride;
+ return (m_data[index] & (UINT64_C(1) << (uint64_t(x) & UINT64_C(63)))) != 0;
}
void setBitAt(uint32_t x, uint32_t y)
{
- xaDebugAssert(x < m_width && y < m_height);
- m_bitArray.setBitAt(y * m_width + x);
+ XA_DEBUG_ASSERT(x < m_width && y < m_height);
+ const uint32_t index = (x >> 6) + y * m_rowStride;
+ m_data[index] |= UINT64_C(1) << (uint64_t(x) & UINT64_C(63));
+ XA_DEBUG_ASSERT(bitAt(x, y));
}
void clearAll()
{
- m_bitArray.clearAll();
+ memset(m_data.data(), 0, m_data.size() * sizeof(uint64_t));
+ }
+
+ bool canBlit(const BitImage &image, uint32_t offsetX, uint32_t offsetY) const
+ {
+ for (uint32_t y = 0; y < image.m_height; y++) {
+ const uint32_t thisY = y + offsetY;
+ if (thisY >= m_height)
+ continue;
+ uint32_t x = 0;
+ for (;;) {
+ const uint32_t thisX = x + offsetX;
+ if (thisX >= m_width)
+ break;
+ const uint32_t thisBlockShift = thisX % 64;
+ const uint64_t thisBlock = m_data[(thisX >> 6) + thisY * m_rowStride] >> thisBlockShift;
+ const uint32_t blockShift = x % 64;
+ const uint64_t block = image.m_data[(x >> 6) + y * image.m_rowStride] >> blockShift;
+ if ((thisBlock & block) != 0)
+ return false;
+ x += 64 - max(thisBlockShift, blockShift);
+ if (x >= image.m_width)
+ break;
+ }
+ }
+ return true;
+ }
+
+ void dilate(uint32_t padding)
+ {
+ BitImage tmp(m_width, m_height);
+ for (uint32_t p = 0; p < padding; p++) {
+ tmp.clearAll();
+ for (uint32_t y = 0; y < m_height; y++) {
+ for (uint32_t x = 0; x < m_width; x++) {
+ bool b = bitAt(x, y);
+ if (!b) {
+ if (x > 0) {
+ b |= bitAt(x - 1, y);
+ if (y > 0) b |= bitAt(x - 1, y - 1);
+ if (y < m_height - 1) b |= bitAt(x - 1, y + 1);
+ }
+ if (y > 0) b |= bitAt(x, y - 1);
+ if (y < m_height - 1) b |= bitAt(x, y + 1);
+ if (x < m_width - 1) {
+ b |= bitAt(x + 1, y);
+ if (y > 0) b |= bitAt(x + 1, y - 1);
+ if (y < m_height - 1) b |= bitAt(x + 1, y + 1);
+ }
+ }
+ if (b)
+ tmp.setBitAt(x, y);
+ }
+ }
+ swap(m_data, tmp.m_data);
+ }
}
private:
uint32_t m_width;
uint32_t m_height;
- BitArray m_bitArray;
+ uint32_t m_rowStride; // In uint64_t's
+ Array<uint64_t> m_data;
};
-// Axis Aligned Bounding Box.
-class Box
+// From Fast-BVH
+class BVH
{
public:
- Box() {}
- Box(const Box &b) : minCorner(b.minCorner), maxCorner(b.maxCorner) {}
- Box(const Vector3 &mins, const Vector3 &maxs) : minCorner(mins), maxCorner(maxs) {}
-
- operator const float *() const
+ BVH(const Array<AABB> &objectAabbs, uint32_t leafSize = 4)
{
- return reinterpret_cast<const float *>(this);
- }
-
- // Clear the bounds.
- void clearBounds()
- {
- minCorner.set(FLT_MAX, FLT_MAX, FLT_MAX);
- maxCorner.set(-FLT_MAX, -FLT_MAX, -FLT_MAX);
- }
-
- // Return extents of the box.
- Vector3 extents() const
- {
- return (maxCorner - minCorner) * 0.5f;
+ m_objectAabbs = &objectAabbs;
+ if (m_objectAabbs->isEmpty())
+ return;
+ m_objectIds.resize(objectAabbs.size());
+ for (uint32_t i = 0; i < m_objectIds.size(); i++)
+ m_objectIds[i] = i;
+ BuildEntry todo[128];
+ uint32_t stackptr = 0;
+ const uint32_t kRoot = 0xfffffffc;
+ const uint32_t kUntouched = 0xffffffff;
+ const uint32_t kTouchedTwice = 0xfffffffd;
+ // Push the root
+ todo[stackptr].start = 0;
+ todo[stackptr].end = objectAabbs.size();
+ todo[stackptr].parent = kRoot;
+ stackptr++;
+ Node node;
+ m_nodes.reserve(objectAabbs.size() * 2);
+ uint32_t nNodes = 0;
+ while(stackptr > 0) {
+ // Pop the next item off of the stack
+ const BuildEntry &bnode = todo[--stackptr];
+ const uint32_t start = bnode.start;
+ const uint32_t end = bnode.end;
+ const uint32_t nPrims = end - start;
+ nNodes++;
+ node.start = start;
+ node.nPrims = nPrims;
+ node.rightOffset = kUntouched;
+ // Calculate the bounding box for this node
+ AABB bb(objectAabbs[m_objectIds[start]]);
+ AABB bc(objectAabbs[m_objectIds[start]].centroid());
+ for(uint32_t p = start + 1; p < end; ++p) {
+ bb.expandToInclude(objectAabbs[m_objectIds[p]]);
+ bc.expandToInclude(objectAabbs[m_objectIds[p]].centroid());
+ }
+ node.aabb = bb;
+ // If the number of primitives at this point is less than the leaf
+ // size, then this will become a leaf. (Signified by rightOffset == 0)
+ if (nPrims <= leafSize)
+ node.rightOffset = 0;
+ m_nodes.push_back(node);
+ // Child touches parent...
+ // Special case: Don't do this for the root.
+ if (bnode.parent != kRoot) {
+ m_nodes[bnode.parent].rightOffset--;
+ // When this is the second touch, this is the right child.
+ // The right child sets up the offset for the flat tree.
+ if (m_nodes[bnode.parent].rightOffset == kTouchedTwice )
+ m_nodes[bnode.parent].rightOffset = nNodes - 1 - bnode.parent;
+ }
+ // If this is a leaf, no need to subdivide.
+ if (node.rightOffset == 0)
+ continue;
+ // Set the split dimensions
+ const uint32_t split_dim = bc.maxDimension();
+ // Split on the center of the longest axis
+ const float split_coord = 0.5f * ((&bc.min.x)[split_dim] + (&bc.max.x)[split_dim]);
+ // Partition the list of objects on this split
+ uint32_t mid = start;
+ for (uint32_t i = start; i < end; ++i) {
+ const Vector3 centroid(objectAabbs[m_objectIds[i]].centroid());
+ if ((&centroid.x)[split_dim] < split_coord) {
+ swap(m_objectIds[i], m_objectIds[mid]);
+ ++mid;
+ }
+ }
+ // If we get a bad split, just choose the center...
+ if (mid == start || mid == end)
+ mid = start + (end - start) / 2;
+ // Push right child
+ todo[stackptr].start = mid;
+ todo[stackptr].end = end;
+ todo[stackptr].parent = nNodes - 1;
+ stackptr++;
+ // Push left child
+ todo[stackptr].start = start;
+ todo[stackptr].end = mid;
+ todo[stackptr].parent = nNodes - 1;
+ stackptr++;
+ }
+ }
+
+ void query(const AABB &queryAabb, Array<uint32_t> &result) const
+ {
+ result.clear();
+ // Working set
+ uint32_t todo[64];
+ int32_t stackptr = 0;
+ // "Push" on the root node to the working set
+ todo[stackptr] = 0;
+ while(stackptr >= 0) {
+ // Pop off the next node to work on.
+ const int ni = todo[stackptr--];
+ const Node &node = m_nodes[ni];
+ // Is leaf -> Intersect
+ if (node.rightOffset == 0) {
+ for(uint32_t o = 0; o < node.nPrims; ++o) {
+ const uint32_t obj = node.start + o;
+ if (queryAabb.intersect((*m_objectAabbs)[m_objectIds[obj]]))
+ result.push_back(m_objectIds[obj]);
+ }
+ } else { // Not a leaf
+ const uint32_t left = ni + 1;
+ const uint32_t right = ni + node.rightOffset;
+ if (queryAabb.intersect(m_nodes[left].aabb))
+ todo[++stackptr] = left;
+ if (queryAabb.intersect(m_nodes[right].aabb))
+ todo[++stackptr] = right;
+ }
+ }
}
- // Add a point to this box.
- void addPointToBounds(const Vector3 &p)
+private:
+ struct BuildEntry
{
- minCorner = min(minCorner, p);
- maxCorner = max(maxCorner, p);
- }
+ uint32_t parent; // If non-zero then this is the index of the parent. (used in offsets)
+ uint32_t start, end; // The range of objects in the object list covered by this node.
+ };
- // Get the volume of the box.
- float volume() const
+ struct Node
{
- Vector3 d = extents();
- return 8.0f * (d.x * d.y * d.z);
- }
+ AABB aabb;
+ uint32_t start, nPrims, rightOffset;
+ };
- Vector3 minCorner;
- Vector3 maxCorner;
+ const Array<AABB> *m_objectAabbs;
+ Array<uint32_t> m_objectIds;
+ Array<Node> m_nodes;
};
class Fit
{
public:
- static Vector3 computeCentroid(int n, const Vector3 *__restrict points)
+ static Vector3 computeCentroid(int n, const Vector3 * points)
{
Vector3 centroid(0.0f);
for (int i = 0; i < n; i++) {
@@ -913,7 +1566,7 @@ public:
return centroid;
}
- static Vector3 computeCovariance(int n, const Vector3 *__restrict points, float *__restrict covariance)
+ static Vector3 computeCovariance(int n, const Vector3 * points, float * covariance)
{
// compute the centroid
Vector3 centroid = computeCentroid(n, points);
@@ -933,25 +1586,12 @@ public:
return centroid;
}
- static bool isPlanar(int n, const Vector3 *points, float epsilon = NV_EPSILON)
- {
- // compute the centroid and covariance
- float matrix[6];
- computeCovariance(n, points, matrix);
- float eigenValues[3];
- Vector3 eigenVectors[3];
- if (!eigenSolveSymmetric3(matrix, eigenValues, eigenVectors)) {
- return false;
- }
- return eigenValues[2] < epsilon;
- }
-
// Tridiagonal solver from Charles Bloom.
// Householder transforms followed by QL decomposition.
// Seems to be based on the code from Numerical Recipes in C.
static bool eigenSolveSymmetric3(const float matrix[6], float eigenValues[3], Vector3 eigenVectors[3])
{
- xaDebugAssert(matrix != NULL && eigenValues != NULL && eigenVectors != NULL);
+ XA_DEBUG_ASSERT(matrix != nullptr && eigenValues != nullptr && eigenVectors != nullptr);
float subd[3];
float diag[3];
float work[3][3];
@@ -975,24 +1615,24 @@ public:
// eigenvectors are the columns; make them the rows :
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
- eigenVectors[j].component[i] = (float) work[i][j];
+ (&eigenVectors[j].x)[i] = (float) work[i][j];
}
}
// shuffle to sort by singular value :
if (eigenValues[2] > eigenValues[0] && eigenValues[2] > eigenValues[1]) {
- std::swap(eigenValues[0], eigenValues[2]);
- std::swap(eigenVectors[0], eigenVectors[2]);
+ swap(eigenValues[0], eigenValues[2]);
+ swap(eigenVectors[0], eigenVectors[2]);
}
if (eigenValues[1] > eigenValues[0]) {
- std::swap(eigenValues[0], eigenValues[1]);
- std::swap(eigenVectors[0], eigenVectors[1]);
+ swap(eigenValues[0], eigenValues[1]);
+ swap(eigenVectors[0], eigenVectors[1]);
}
if (eigenValues[2] > eigenValues[1]) {
- std::swap(eigenValues[1], eigenValues[2]);
- std::swap(eigenVectors[1], eigenVectors[2]);
+ swap(eigenValues[1], eigenValues[2]);
+ swap(eigenVectors[1], eigenVectors[2]);
}
- xaDebugAssert(eigenValues[0] >= eigenValues[1] && eigenValues[0] >= eigenValues[2]);
- xaDebugAssert(eigenValues[1] >= eigenValues[2]);
+ XA_DEBUG_ASSERT(eigenValues[0] >= eigenValues[1] && eigenValues[0] >= eigenValues[2]);
+ XA_DEBUG_ASSERT(eigenValues[1] >= eigenValues[2]);
return true;
}
@@ -1118,7 +1758,7 @@ public:
const FullVector &operator=(const FullVector &v)
{
- xaAssert(dimension() == v.dimension());
+ XA_ASSERT(dimension() == v.dimension());
m_array = v.m_array;
return *this;
}
@@ -1135,1698 +1775,1695 @@ public:
}
}
- void operator+=(const FullVector &v)
- {
- xaDebugAssert(dimension() == v.dimension());
- const uint32_t dim = dimension();
- for (uint32_t i = 0; i < dim; i++) {
- m_array[i] += v.m_array[i];
- }
- }
-
- void operator-=(const FullVector &v)
- {
- xaDebugAssert(dimension() == v.dimension());
- const uint32_t dim = dimension();
- for (uint32_t i = 0; i < dim; i++) {
- m_array[i] -= v.m_array[i];
- }
- }
-
- void operator*=(const FullVector &v)
- {
- xaDebugAssert(dimension() == v.dimension());
- const uint32_t dim = dimension();
- for (uint32_t i = 0; i < dim; i++) {
- m_array[i] *= v.m_array[i];
- }
- }
-
- void operator+=(float f)
- {
- const uint32_t dim = dimension();
- for (uint32_t i = 0; i < dim; i++) {
- m_array[i] += f;
- }
- }
-
- void operator-=(float f)
- {
- const uint32_t dim = dimension();
- for (uint32_t i = 0; i < dim; i++) {
- m_array[i] -= f;
- }
- }
-
- void operator*=(float f)
- {
- const uint32_t dim = dimension();
- for (uint32_t i = 0; i < dim; i++) {
- m_array[i] *= f;
- }
- }
-
private:
- std::vector<float> m_array;
+ Array<float> m_array;
};
-namespace halfedge {
-class Face;
-class Vertex;
-
-class Edge
+template<typename Key, typename Value, typename H = Hash<Key>, typename E = Equal<Key> >
+class HashMap
{
public:
- uint32_t id;
- Edge *next;
- Edge *prev; // This is not strictly half-edge, but makes algorithms easier and faster.
- Edge *pair;
- Vertex *vertex;
- Face *face;
-
- // Default constructor.
- Edge(uint32_t id) : id(id), next(NULL), prev(NULL), pair(NULL), vertex(NULL), face(NULL) {}
-
- // Vertex queries.
- const Vertex *from() const
+ HashMap(int memTag, uint32_t size) : m_memTag(memTag), m_size(size), m_numSlots(0), m_slots(nullptr), m_keys(memTag), m_values(memTag), m_next(memTag)
{
- return vertex;
}
- Vertex *from()
+ ~HashMap()
{
- return vertex;
+ if (m_slots)
+ XA_FREE(m_slots);
}
- const Vertex *to() const
- {
- return pair->vertex; // This used to be 'next->vertex', but that changed often when the connectivity of the mesh changes.
- }
+ const Value &value(uint32_t index) const { return m_values[index]; }
- Vertex *to()
+ void add(const Key &key, const Value &value)
{
- return pair->vertex;
+ if (!m_slots)
+ alloc();
+ const uint32_t hash = computeHash(key);
+ m_keys.push_back(key);
+ m_values.push_back(value);
+ m_next.push_back(m_slots[hash]);
+ m_slots[hash] = m_next.size() - 1;
}
- // Edge queries.
- void setNext(Edge *e)
+ uint32_t get(const Key &key) const
{
- next = e;
- if (e != NULL) e->prev = this;
- }
- void setPrev(Edge *e)
- {
- prev = e;
- if (e != NULL) e->next = this;
+ if (!m_slots)
+ return UINT32_MAX;
+ const uint32_t hash = computeHash(key);
+ uint32_t i = m_slots[hash];
+ E equal;
+ while (i != UINT32_MAX) {
+ if (equal(m_keys[i], key))
+ return i;
+ i = m_next[i];
+ }
+ return UINT32_MAX;
}
- // @@ It would be more simple to only check m_pair == NULL
- // Face queries.
- bool isBoundary() const
+ uint32_t getNext(uint32_t current) const
{
- return !(face && pair->face);
+ uint32_t i = m_next[current];
+ E equal;
+ while (i != UINT32_MAX) {
+ if (equal(m_keys[i], m_keys[current]))
+ return i;
+ i = m_next[i];
+ }
+ return UINT32_MAX;
}
- // @@ This is not exactly accurate, we should compare the texture coordinates...
- bool isSeam() const
+private:
+ void alloc()
{
- return vertex != pair->next->vertex || next->vertex != pair->vertex;
+ XA_DEBUG_ASSERT(m_size > 0);
+ m_numSlots = (uint32_t)(m_size * 1.3);
+ m_slots = XA_ALLOC_ARRAY(m_memTag, uint32_t, m_numSlots);
+ for (uint32_t i = 0; i < m_numSlots; i++)
+ m_slots[i] = UINT32_MAX;
+ m_keys.reserve(m_size);
+ m_values.reserve(m_size);
+ m_next.reserve(m_size);
}
- bool isNormalSeam() const;
- bool isTextureSeam() const;
-
- bool isValid() const
+ uint32_t computeHash(const Key &key) const
{
- // null face is OK.
- if (next == NULL || prev == NULL || pair == NULL || vertex == NULL) return false;
- if (next->prev != this) return false;
- if (prev->next != this) return false;
- if (pair->pair != this) return false;
- return true;
+ H hash;
+ return hash(key) % m_numSlots;
}
- float length() const;
-
- // Return angle between this edge and the previous one.
- float angle() const;
+ int m_memTag;
+ uint32_t m_size;
+ uint32_t m_numSlots;
+ uint32_t *m_slots;
+ Array<Key> m_keys;
+ Array<Value> m_values;
+ Array<uint32_t> m_next;
};
-class Vertex
+template<typename T>
+static void insertionSort(T *data, uint32_t length)
{
-public:
- uint32_t id;
- // -- GODOT start --
- uint32_t original_id;
- // -- GODOT end --
- Edge *edge;
- Vertex *next;
- Vertex *prev;
- Vector3 pos;
- Vector3 nor;
- Vector2 tex;
-
- // -- GODOT start --
- //Vertex(uint32_t id) : id(id), edge(NULL), pos(0.0f), nor(0.0f), tex(0.0f)
- Vertex(uint32_t id) : id(id), original_id(id), edge(NULL), pos(0.0f), nor(0.0f), tex(0.0f)
- // -- GODOT end --
- {
- next = this;
- prev = this;
- }
-
- // Set first edge of all colocals.
- void setEdge(Edge *e)
- {
- for (VertexIterator it(colocals()); !it.isDone(); it.advance()) {
- it.current()->edge = e;
+ for (int32_t i = 1; i < (int32_t)length; i++) {
+ T x = data[i];
+ int32_t j = i - 1;
+ while (j >= 0 && x < data[j]) {
+ data[j + 1] = data[j];
+ j--;
}
+ data[j + 1] = x;
}
+}
- // Update position of all colocals.
- void setPos(const Vector3 &p)
+class KISSRng
+{
+public:
+ uint32_t getRange(uint32_t range)
{
- for (VertexIterator it(colocals()); !it.isDone(); it.advance()) {
- it.current()->pos = p;
- }
+ if (range == 0)
+ return 0;
+ x = 69069 * x + 12345;
+ y ^= (y << 13);
+ y ^= (y >> 17);
+ y ^= (y << 5);
+ uint64_t t = 698769069ULL * z + c;
+ c = (t >> 32);
+ return (x + y + (z = (uint32_t)t)) % range;
}
- bool isFirstColocal() const
- {
- return firstColocal() == this;
- }
+private:
+ uint32_t x = 123456789, y = 362436000, z = 521288629, c = 7654321;
+};
- const Vertex *firstColocal() const
+// Based on Pierre Terdiman's and Michael Herf's source code.
+// http://www.codercorner.com/RadixSortRevisited.htm
+// http://www.stereopsis.com/radix.html
+class RadixSort
+{
+public:
+ RadixSort() : m_size(0), m_ranks(nullptr), m_ranks2(nullptr), m_validRanks(false) {}
+
+ ~RadixSort()
{
- uint32_t firstId = id;
- const Vertex *vertex = this;
- for (ConstVertexIterator it(colocals()); !it.isDone(); it.advance()) {
- if (it.current()->id < firstId) {
- firstId = vertex->id;
- vertex = it.current();
- }
- }
- return vertex;
+ // Release everything
+ XA_FREE(m_ranks2);
+ XA_FREE(m_ranks);
}
- Vertex *firstColocal()
+ RadixSort &sort(const float *input, uint32_t count)
{
- Vertex *vertex = this;
- uint32_t firstId = id;
- for (VertexIterator it(colocals()); !it.isDone(); it.advance()) {
- if (it.current()->id < firstId) {
- firstId = vertex->id;
- vertex = it.current();
+ if (input == nullptr || count == 0) return *this;
+ // Resize lists if needed
+ if (count != m_size) {
+ if (count > m_size) {
+ m_ranks2 = XA_REALLOC(MemTag::Default, m_ranks2, uint32_t, count);
+ m_ranks = XA_REALLOC(MemTag::Default, m_ranks, uint32_t, count);
}
+ m_size = count;
+ m_validRanks = false;
}
- return vertex;
- }
-
- bool isColocal(const Vertex *v) const
- {
- if (this == v) return true;
- if (pos != v->pos) return false;
- for (ConstVertexIterator it(colocals()); !it.isDone(); it.advance()) {
- if (v == it.current()) {
- return true;
+ if (count < 32) {
+ insertionSort(input, count);
+ } else {
+ // @@ Avoid touching the input multiple times.
+ for (uint32_t i = 0; i < count; i++) {
+ FloatFlip((uint32_t &)input[i]);
+ }
+ radixSort<uint32_t>((const uint32_t *)input, count);
+ for (uint32_t i = 0; i < count; i++) {
+ IFloatFlip((uint32_t &)input[i]);
}
}
- return false;
+ return *this;
}
- void linkColocal(Vertex *v)
+ RadixSort &sort(const Array<float> &input)
{
- next->prev = v;
- v->next = next;
- next = v;
- v->prev = this;
- }
- void unlinkColocal()
- {
- next->prev = prev;
- prev->next = next;
- next = this;
- prev = this;
+ return sort(input.data(), input.size());
}
- // @@ Note: This only works if linkBoundary has been called.
- bool isBoundary() const
+ // Access to results. m_ranks is a list of indices in sorted order, i.e. in the order you may further process your data
+ const uint32_t *ranks() const
{
- return (edge && !edge->face);
+ XA_DEBUG_ASSERT(m_validRanks);
+ return m_ranks;
}
- // Iterator that visits the edges around this vertex in counterclockwise order.
- class EdgeIterator //: public Iterator<Edge *>
+ uint32_t *ranks()
{
- public:
- EdgeIterator(Edge *e) : m_end(NULL), m_current(e) { }
-
- virtual void advance()
- {
- if (m_end == NULL) m_end = m_current;
- m_current = m_current->pair->next;
- //m_current = m_current->prev->pair;
- }
-
- virtual bool isDone() const
- {
- return m_end == m_current;
- }
- virtual Edge *current() const
- {
- return m_current;
- }
- Vertex *vertex() const
- {
- return m_current->vertex;
- }
+ XA_DEBUG_ASSERT(m_validRanks);
+ return m_ranks;
+ }
- private:
- Edge *m_end;
- Edge *m_current;
- };
+private:
+ uint32_t m_size;
+ uint32_t *m_ranks;
+ uint32_t *m_ranks2;
+ bool m_validRanks;
- EdgeIterator edges()
+ void FloatFlip(uint32_t &f)
{
- return EdgeIterator(edge);
+ int32_t mask = (int32_t(f) >> 31) | 0x80000000; // Warren Hunt, Manchor Ko.
+ f ^= mask;
}
- EdgeIterator edges(Edge *e)
+
+ void IFloatFlip(uint32_t &f)
{
- return EdgeIterator(e);
+ uint32_t mask = ((f >> 31) - 1) | 0x80000000; // Michael Herf.
+ f ^= mask;
}
- // Iterator that visits the edges around this vertex in counterclockwise order.
- class ConstEdgeIterator //: public Iterator<Edge *>
+ template<typename T>
+ void createHistograms(const T *buffer, uint32_t count, uint32_t *histogram)
{
- public:
- ConstEdgeIterator(const Edge *e) : m_end(NULL), m_current(e) { }
- ConstEdgeIterator(EdgeIterator it) : m_end(NULL), m_current(it.current()) { }
-
- virtual void advance()
- {
- if (m_end == NULL) m_end = m_current;
- m_current = m_current->pair->next;
- //m_current = m_current->prev->pair;
- }
-
- virtual bool isDone() const
- {
- return m_end == m_current;
- }
- virtual const Edge *current() const
- {
- return m_current;
+ const uint32_t bucketCount = sizeof(T); // (8 * sizeof(T)) / log2(radix)
+ // Init bucket pointers.
+ uint32_t *h[bucketCount];
+ for (uint32_t i = 0; i < bucketCount; i++) {
+ h[i] = histogram + 256 * i;
}
- const Vertex *vertex() const
- {
- return m_current->to();
+ // Clear histograms.
+ memset(histogram, 0, 256 * bucketCount * sizeof(uint32_t ));
+ // @@ Add support for signed integers.
+ // Build histograms.
+ const uint8_t *p = (const uint8_t *)buffer; // @@ Does this break aliasing rules?
+ const uint8_t *pe = p + count * sizeof(T);
+ while (p != pe) {
+ h[0][*p++]++, h[1][*p++]++, h[2][*p++]++, h[3][*p++]++;
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable : 4127)
+#endif
+ if (bucketCount == 8) h[4][*p++]++, h[5][*p++]++, h[6][*p++]++, h[7][*p++]++;
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
}
-
- private:
- const Edge *m_end;
- const Edge *m_current;
- };
-
- ConstEdgeIterator edges() const
- {
- return ConstEdgeIterator(edge);
- }
- ConstEdgeIterator edges(const Edge *e) const
- {
- return ConstEdgeIterator(e);
}
- // Iterator that visits all the colocal vertices.
- class VertexIterator //: public Iterator<Edge *>
+ template <typename T> void insertionSort(const T *input, uint32_t count)
{
- public:
- VertexIterator(Vertex *v) : m_end(NULL), m_current(v) { }
-
- virtual void advance()
- {
- if (m_end == NULL) m_end = m_current;
- m_current = m_current->next;
- }
-
- virtual bool isDone() const
- {
- return m_end == m_current;
- }
- virtual Vertex *current() const
- {
- return m_current;
+ if (!m_validRanks) {
+ m_ranks[0] = 0;
+ for (uint32_t i = 1; i != count; ++i) {
+ int rank = m_ranks[i] = i;
+ uint32_t j = i;
+ while (j != 0 && input[rank] < input[m_ranks[j - 1]]) {
+ m_ranks[j] = m_ranks[j - 1];
+ --j;
+ }
+ if (i != j) {
+ m_ranks[j] = rank;
+ }
+ }
+ m_validRanks = true;
+ } else {
+ for (uint32_t i = 1; i != count; ++i) {
+ int rank = m_ranks[i];
+ uint32_t j = i;
+ while (j != 0 && input[rank] < input[m_ranks[j - 1]]) {
+ m_ranks[j] = m_ranks[j - 1];
+ --j;
+ }
+ if (i != j) {
+ m_ranks[j] = rank;
+ }
+ }
}
-
- private:
- Vertex *m_end;
- Vertex *m_current;
- };
-
- VertexIterator colocals()
- {
- return VertexIterator(this);
}
- // Iterator that visits all the colocal vertices.
- class ConstVertexIterator //: public Iterator<Edge *>
+ template <typename T> void radixSort(const T *input, uint32_t count)
{
- public:
- ConstVertexIterator(const Vertex *v) : m_end(NULL), m_current(v) { }
-
- virtual void advance()
- {
- if (m_end == NULL) m_end = m_current;
- m_current = m_current->next;
- }
-
- virtual bool isDone() const
- {
- return m_end == m_current;
+ const uint32_t P = sizeof(T); // pass count
+ // Allocate histograms & offsets on the stack
+ uint32_t histogram[256 * P];
+ uint32_t *link[256];
+ createHistograms(input, count, histogram);
+ // Radix sort, j is the pass number (0=LSB, P=MSB)
+ for (uint32_t j = 0; j < P; j++) {
+ // Pointer to this bucket.
+ const uint32_t *h = &histogram[j * 256];
+ const uint8_t *inputBytes = (const uint8_t *)input; // @@ Is this aliasing legal?
+ inputBytes += j;
+ if (h[inputBytes[0]] == count) {
+ // Skip this pass, all values are the same.
+ continue;
+ }
+ // Create offsets
+ link[0] = m_ranks2;
+ for (uint32_t i = 1; i < 256; i++) link[i] = link[i - 1] + h[i - 1];
+ // Perform Radix Sort
+ if (!m_validRanks) {
+ for (uint32_t i = 0; i < count; i++) {
+ *link[inputBytes[i * P]]++ = i;
+ }
+ m_validRanks = true;
+ } else {
+ for (uint32_t i = 0; i < count; i++) {
+ const uint32_t idx = m_ranks[i];
+ *link[inputBytes[idx * P]]++ = idx;
+ }
+ }
+ // Swap pointers for next pass. Valid indices - the most recent ones - are in m_ranks after the swap.
+ swap(m_ranks, m_ranks2);
}
- virtual const Vertex *current() const
- {
- return m_current;
+ // All values were equal, generate linear ranks.
+ if (!m_validRanks) {
+ for (uint32_t i = 0; i < count; i++) {
+ m_ranks[i] = i;
+ }
+ m_validRanks = true;
}
-
- private:
- const Vertex *m_end;
- const Vertex *m_current;
- };
-
- ConstVertexIterator colocals() const
- {
- return ConstVertexIterator(this);
}
};
-bool Edge::isNormalSeam() const
-{
- return (vertex->nor != pair->next->vertex->nor || next->vertex->nor != pair->vertex->nor);
-}
-
-bool Edge::isTextureSeam() const
-{
- return (vertex->tex != pair->next->vertex->tex || next->vertex->tex != pair->vertex->tex);
-}
-
-float Edge::length() const
-{
- return internal::length(to()->pos - from()->pos);
-}
-
-float Edge::angle() const
-{
- Vector3 p = vertex->pos;
- Vector3 a = prev->vertex->pos;
- Vector3 b = next->vertex->pos;
- Vector3 v0 = a - p;
- Vector3 v1 = b - p;
- return acosf(dot(v0, v1) / (internal::length(v0) * internal::length(v1)));
-}
-
-class Face
+// Wrapping this in a class allows temporary arrays to be re-used.
+class BoundingBox2D
{
public:
- uint32_t id;
- uint16_t group;
- uint16_t material;
- Edge *edge;
-
- Face(uint32_t id) : id(id), group(uint16_t(~0)), material(uint16_t(~0)), edge(NULL) {}
+ Vector2 majorAxis() const { return m_majorAxis; }
+ Vector2 minorAxis() const { return m_minorAxis; }
+ Vector2 minCorner() const { return m_minCorner; }
+ Vector2 maxCorner() const { return m_maxCorner; }
- float area() const
- {
- float area = 0;
- const Vector3 &v0 = edge->from()->pos;
- for (ConstEdgeIterator it(edges(edge->next)); it.current() != edge->prev; it.advance()) {
- const Edge *e = it.current();
- const Vector3 &v1 = e->vertex->pos;
- const Vector3 &v2 = e->next->vertex->pos;
- area += length(cross(v1 - v0, v2 - v0));
- }
- return area * 0.5f;
- }
-
- float parametricArea() const
- {
- float area = 0;
- const Vector2 &v0 = edge->from()->tex;
- for (ConstEdgeIterator it(edges(edge->next)); it.current() != edge->prev; it.advance()) {
- const Edge *e = it.current();
- const Vector2 &v1 = e->vertex->tex;
- const Vector2 &v2 = e->next->vertex->tex;
- area += triangleArea(v0, v1, v2);
- }
- return area * 0.5f;
- }
-
- Vector3 normal() const
+ // This should compute convex hull and use rotating calipers to find the best box. Currently it uses a brute force method.
+ void compute(const Vector2 *boundaryVertices, uint32_t boundaryVertexCount, const Vector2 *vertices, uint32_t vertexCount)
{
- Vector3 n(0);
- const Vertex *vertex0 = NULL;
- for (ConstEdgeIterator it(edges()); !it.isDone(); it.advance()) {
- const Edge *e = it.current();
- xaAssert(e != NULL);
- if (vertex0 == NULL) {
- vertex0 = e->vertex;
- } else if (e->next->vertex != vertex0) {
- const halfedge::Vertex *vertex1 = e->from();
- const halfedge::Vertex *vertex2 = e->to();
- const Vector3 &p0 = vertex0->pos;
- const Vector3 &p1 = vertex1->pos;
- const Vector3 &p2 = vertex2->pos;
- Vector3 v10 = p1 - p0;
- Vector3 v20 = p2 - p0;
- n += cross(v10, v20);
+ convexHull(boundaryVertices, boundaryVertexCount, m_hull, 0.00001f);
+ // @@ Ideally I should use rotating calipers to find the best box. Using brute force for now.
+ float best_area = FLT_MAX;
+ Vector2 best_min(0);
+ Vector2 best_max(0);
+ Vector2 best_axis(0);
+ const uint32_t hullCount = m_hull.size();
+ for (uint32_t i = 0, j = hullCount - 1; i < hullCount; j = i, i++) {
+ if (equal(m_hull[i], m_hull[j], kEpsilon))
+ continue;
+ Vector2 axis = normalize(m_hull[i] - m_hull[j], 0.0f);
+ XA_DEBUG_ASSERT(isFinite(axis));
+ // Compute bounding box.
+ Vector2 box_min(FLT_MAX, FLT_MAX);
+ Vector2 box_max(-FLT_MAX, -FLT_MAX);
+ // Consider all points, not only boundary points, in case the input chart is malformed.
+ for (uint32_t v = 0; v < vertexCount; v++) {
+ const Vector2 &point = vertices[v];
+ const float x = dot(axis, point);
+ const float y = dot(Vector2(-axis.y, axis.x), point);
+ box_min.x = min(box_min.x, x);
+ box_max.x = max(box_max.x, x);
+ box_min.y = min(box_min.y, y);
+ box_max.y = max(box_max.y, y);
+ }
+ // Compute box area.
+ const float area = (box_max.x - box_min.x) * (box_max.y - box_min.y);
+ if (area < best_area) {
+ best_area = area;
+ best_min = box_min;
+ best_max = box_max;
+ best_axis = axis;
}
}
- return normalizeSafe(n, Vector3(0, 0, 1), 0.0f);
- }
-
- Vector3 centroid() const
- {
- Vector3 sum(0.0f);
- uint32_t count = 0;
- for (ConstEdgeIterator it(edges()); !it.isDone(); it.advance()) {
- const Edge *e = it.current();
- sum += e->from()->pos;
- count++;
- }
- return sum / float(count);
- }
-
- // Unnormalized face normal assuming it's a triangle.
- Vector3 triangleNormal() const
- {
- Vector3 p0 = edge->vertex->pos;
- Vector3 p1 = edge->next->vertex->pos;
- Vector3 p2 = edge->next->next->vertex->pos;
- Vector3 e0 = p2 - p0;
- Vector3 e1 = p1 - p0;
- return normalizeSafe(cross(e0, e1), Vector3(0), 0.0f);
- }
-
- Vector3 triangleNormalAreaScaled() const
- {
- Vector3 p0 = edge->vertex->pos;
- Vector3 p1 = edge->next->vertex->pos;
- Vector3 p2 = edge->next->next->vertex->pos;
- Vector3 e0 = p2 - p0;
- Vector3 e1 = p1 - p0;
- return cross(e0, e1);
- }
-
- // Average of the edge midpoints weighted by the edge length.
- // I want a point inside the triangle, but closer to the cirumcenter.
- Vector3 triangleCenter() const
- {
- Vector3 p0 = edge->vertex->pos;
- Vector3 p1 = edge->next->vertex->pos;
- Vector3 p2 = edge->next->next->vertex->pos;
- float l0 = length(p1 - p0);
- float l1 = length(p2 - p1);
- float l2 = length(p0 - p2);
- Vector3 m0 = (p0 + p1) * l0 / (l0 + l1 + l2);
- Vector3 m1 = (p1 + p2) * l1 / (l0 + l1 + l2);
- Vector3 m2 = (p2 + p0) * l2 / (l0 + l1 + l2);
- return m0 + m1 + m2;
- }
-
- bool isValid() const
- {
- uint32_t count = 0;
- for (ConstEdgeIterator it(edges()); !it.isDone(); it.advance()) {
- const Edge *e = it.current();
- if (e->face != this) return false;
- if (!e->isValid()) return false;
- if (!e->pair->isValid()) return false;
- count++;
- }
- if (count < 3) return false;
- return true;
- }
-
- bool contains(const Edge *e) const
- {
- for (ConstEdgeIterator it(edges()); !it.isDone(); it.advance()) {
- if (it.current() == e) return true;
- }
- return false;
- }
-
- uint32_t edgeCount() const
- {
- uint32_t count = 0;
- for (ConstEdgeIterator it(edges()); !it.isDone(); it.advance()) {
- ++count;
- }
- return count;
+ m_majorAxis = best_axis;
+ m_minorAxis = Vector2(-best_axis.y, best_axis.x);
+ m_minCorner = best_min;
+ m_maxCorner = best_max;
+ XA_ASSERT(isFinite(m_majorAxis) && isFinite(m_minorAxis) && isFinite(m_minCorner));
}
- // The iterator that visits the edges of this face in clockwise order.
- class EdgeIterator //: public Iterator<Edge *>
+private:
+ // Compute the convex hull using Graham Scan.
+ void convexHull(const Vector2 *input, uint32_t inputCount, Array<Vector2> &output, float epsilon)
{
- public:
- EdgeIterator(Edge *e) : m_end(NULL), m_current(e) { }
-
- virtual void advance()
- {
- if (m_end == NULL) m_end = m_current;
- m_current = m_current->next;
+ m_coords.resize(inputCount);
+ for (uint32_t i = 0; i < inputCount; i++)
+ m_coords[i] = input[i].x;
+ RadixSort radix;
+ radix.sort(m_coords);
+ const uint32_t *ranks = radix.ranks();
+ m_top.clear();
+ m_bottom.clear();
+ m_top.reserve(inputCount);
+ m_bottom.reserve(inputCount);
+ Vector2 P = input[ranks[0]];
+ Vector2 Q = input[ranks[inputCount - 1]];
+ float topy = max(P.y, Q.y);
+ float boty = min(P.y, Q.y);
+ for (uint32_t i = 0; i < inputCount; i++) {
+ Vector2 p = input[ranks[i]];
+ if (p.y >= boty)
+ m_top.push_back(p);
}
-
- virtual bool isDone() const
- {
- return m_end == m_current;
+ for (uint32_t i = 0; i < inputCount; i++) {
+ Vector2 p = input[ranks[inputCount - 1 - i]];
+ if (p.y <= topy)
+ m_bottom.push_back(p);
}
- virtual Edge *current() const
- {
- return m_current;
+ // Filter top list.
+ output.clear();
+ output.push_back(m_top[0]);
+ output.push_back(m_top[1]);
+ for (uint32_t i = 2; i < m_top.size(); ) {
+ Vector2 a = output[output.size() - 2];
+ Vector2 b = output[output.size() - 1];
+ Vector2 c = m_top[i];
+ float area = triangleArea(a, b, c);
+ if (area >= -epsilon)
+ output.pop_back();
+ if (area < -epsilon || output.size() == 1) {
+ output.push_back(c);
+ i++;
+ }
}
- Vertex *vertex() const
- {
- return m_current->vertex;
+ uint32_t top_count = output.size();
+ output.push_back(m_bottom[1]);
+ // Filter bottom list.
+ for (uint32_t i = 2; i < m_bottom.size(); ) {
+ Vector2 a = output[output.size() - 2];
+ Vector2 b = output[output.size() - 1];
+ Vector2 c = m_bottom[i];
+ float area = triangleArea(a, b, c);
+ if (area >= -epsilon)
+ output.pop_back();
+ if (area < -epsilon || output.size() == top_count) {
+ output.push_back(c);
+ i++;
+ }
}
-
- private:
- Edge *m_end;
- Edge *m_current;
- };
-
- EdgeIterator edges()
- {
- return EdgeIterator(edge);
- }
- EdgeIterator edges(Edge *e)
- {
- xaDebugAssert(contains(e));
- return EdgeIterator(e);
+ // Remove duplicate element.
+ XA_DEBUG_ASSERT(output.front() == output.back());
+ output.pop_back();
}
- // The iterator that visits the edges of this face in clockwise order.
- class ConstEdgeIterator //: public Iterator<const Edge *>
- {
- public:
- ConstEdgeIterator(const Edge *e) : m_end(NULL), m_current(e) { }
- ConstEdgeIterator(const EdgeIterator &it) : m_end(NULL), m_current(it.current()) { }
+ Array<float> m_coords;
+ Array<Vector2> m_top, m_bottom, m_hull;
+ Vector2 m_majorAxis, m_minorAxis, m_minCorner, m_maxCorner;
+};
- virtual void advance()
- {
- if (m_end == NULL) m_end = m_current;
- m_current = m_current->next;
- }
+static uint32_t meshEdgeFace(uint32_t edge) { return edge / 3; }
+static uint32_t meshEdgeIndex0(uint32_t edge) { return edge; }
- virtual bool isDone() const
- {
- return m_end == m_current;
- }
- virtual const Edge *current() const
- {
- return m_current;
- }
- const Vertex *vertex() const
- {
- return m_current->vertex;
- }
-
- private:
- const Edge *m_end;
- const Edge *m_current;
- };
+static uint32_t meshEdgeIndex1(uint32_t edge)
+{
+ const uint32_t faceFirstEdge = edge / 3 * 3;
+ return faceFirstEdge + (edge - faceFirstEdge + 1) % 3;
+}
- ConstEdgeIterator edges() const
- {
- return ConstEdgeIterator(edge);
- }
- ConstEdgeIterator edges(const Edge *e) const
+struct MeshFlags
+{
+ enum
{
- xaDebugAssert(contains(e));
- return ConstEdgeIterator(e);
- }
+ HasFaceGroups = 1<<0,
+ HasIgnoredFaces = 1<<1,
+ HasNormals = 1<<2
+ };
};
-/// Simple half edge mesh designed for dynamic mesh manipulation.
+class Mesh;
+static void meshGetBoundaryLoops(const Mesh &mesh, Array<uint32_t> &boundaryLoops);
+
class Mesh
{
public:
- Mesh() : m_colocalVertexCount(0) {}
-
- Mesh(const Mesh *mesh)
- {
- // Copy mesh vertices.
- const uint32_t vertexCount = mesh->vertexCount();
- m_vertexArray.resize(vertexCount);
- for (uint32_t v = 0; v < vertexCount; v++) {
- const Vertex *vertex = mesh->vertexAt(v);
- xaDebugAssert(vertex->id == v);
- m_vertexArray[v] = new Vertex(v);
- m_vertexArray[v]->pos = vertex->pos;
- m_vertexArray[v]->nor = vertex->nor;
- m_vertexArray[v]->tex = vertex->tex;
- }
- m_colocalVertexCount = vertexCount;
- // Copy mesh faces.
- const uint32_t faceCount = mesh->faceCount();
- std::vector<uint32_t> indexArray;
- indexArray.reserve(3);
- for (uint32_t f = 0; f < faceCount; f++) {
- const Face *face = mesh->faceAt(f);
- for (Face::ConstEdgeIterator it(face->edges()); !it.isDone(); it.advance()) {
- const Vertex *vertex = it.current()->from();
- indexArray.push_back(vertex->id);
- }
- addFace(indexArray);
- indexArray.clear();
- }
- }
-
- ~Mesh()
- {
- clear();
- }
-
- void clear()
- {
- for (size_t i = 0; i < m_vertexArray.size(); i++)
- delete m_vertexArray[i];
- m_vertexArray.clear();
- for (auto it = m_edgeMap.begin(); it != m_edgeMap.end(); it++)
- delete it->second;
- m_edgeArray.clear();
- m_edgeMap.clear();
- for (size_t i = 0; i < m_faceArray.size(); i++)
- delete m_faceArray[i];
- m_faceArray.clear();
- }
-
- Vertex *addVertex(const Vector3 &pos)
+ Mesh(float epsilon, uint32_t approxVertexCount, uint32_t approxFaceCount, uint32_t flags = 0, uint32_t id = UINT32_MAX) : m_epsilon(epsilon), m_flags(flags), m_id(id), m_faceIgnore(MemTag::Mesh), m_faceGroups(MemTag::Mesh), m_indices(MemTag::MeshIndices), m_positions(MemTag::MeshPositions), m_normals(MemTag::MeshNormals), m_texcoords(MemTag::MeshTexcoords), m_colocalVertexCount(0), m_nextColocalVertex(MemTag::MeshColocals), m_boundaryVertices(MemTag::MeshBoundaries), m_oppositeEdges(MemTag::MeshBoundaries), m_nextBoundaryEdges(MemTag::MeshBoundaries), m_edgeMap(MemTag::MeshEdgeMap, approxFaceCount * 3)
{
- xaDebugAssert(isFinite(pos));
- Vertex *v = new Vertex(m_vertexArray.size());
- v->pos = pos;
- m_vertexArray.push_back(v);
- return v;
+ m_indices.reserve(approxFaceCount * 3);
+ m_positions.reserve(approxVertexCount);
+ m_texcoords.reserve(approxVertexCount);
+ if (m_flags & MeshFlags::HasFaceGroups)
+ m_faceGroups.reserve(approxFaceCount);
+ if (m_flags & MeshFlags::HasIgnoredFaces)
+ m_faceIgnore.reserve(approxFaceCount);
+ if (m_flags & MeshFlags::HasNormals)
+ m_normals.reserve(approxVertexCount);
}
- /// Link colocal vertices based on geometric location only.
- void linkColocals()
- {
- xaPrint("--- Linking colocals:\n");
- const uint32_t vertexCount = this->vertexCount();
- std::unordered_map<Vector3, Vertex *, Hash<Vector3>, Equal<Vector3> > vertexMap;
- vertexMap.reserve(vertexCount);
- for (uint32_t v = 0; v < vertexCount; v++) {
- Vertex *vertex = vertexAt(v);
- Vertex *colocal = vertexMap[vertex->pos];
- if (colocal) {
- colocal->linkColocal(vertex);
- } else {
- vertexMap[vertex->pos] = vertex;
- }
- }
- m_colocalVertexCount = vertexMap.size();
- xaPrint("--- %d vertex positions.\n", m_colocalVertexCount);
- // @@ Remove duplicated vertices? or just leave them as colocals?
- }
+ uint32_t flags() const { return m_flags; }
+ uint32_t id() const { return m_id; }
- void linkColocalsWithCanonicalMap(const std::vector<uint32_t> &canonicalMap)
+ void addVertex(const Vector3 &pos, const Vector3 &normal = Vector3(0.0f), const Vector2 &texcoord = Vector2(0.0f))
{
- xaPrint("--- Linking colocals:\n");
- uint32_t vertexMapSize = 0;
- for (uint32_t i = 0; i < canonicalMap.size(); i++) {
- vertexMapSize = std::max(vertexMapSize, canonicalMap[i] + 1);
- }
- std::vector<Vertex *> vertexMap;
- vertexMap.resize(vertexMapSize, NULL);
- m_colocalVertexCount = 0;
- const uint32_t vertexCount = this->vertexCount();
- for (uint32_t v = 0; v < vertexCount; v++) {
- Vertex *vertex = vertexAt(v);
- Vertex *colocal = vertexMap[canonicalMap[v]];
- if (colocal != NULL) {
- xaDebugAssert(vertex->pos == colocal->pos);
- colocal->linkColocal(vertex);
- } else {
- vertexMap[canonicalMap[v]] = vertex;
- m_colocalVertexCount++;
- }
- }
- xaPrint("--- %d vertex positions.\n", m_colocalVertexCount);
+ XA_DEBUG_ASSERT(isFinite(pos));
+ m_positions.push_back(pos);
+ if (m_flags & MeshFlags::HasNormals)
+ m_normals.push_back(normal);
+ m_texcoords.push_back(texcoord);
}
- Face *addFace()
+ struct AddFaceResult
{
- Face *f = new Face(m_faceArray.size());
- m_faceArray.push_back(f);
- return f;
- }
+ enum Enum
+ {
+ OK,
+ DuplicateEdge = 1
+ };
+ };
- Face *addFace(uint32_t v0, uint32_t v1, uint32_t v2)
+ AddFaceResult::Enum addFace(uint32_t v0, uint32_t v1, uint32_t v2, bool ignore = false, bool hashEdge = true)
{
uint32_t indexArray[3];
indexArray[0] = v0;
indexArray[1] = v1;
indexArray[2] = v2;
- return addFace(indexArray, 3, 0, 3);
- }
-
- Face *addFace(uint32_t v0, uint32_t v1, uint32_t v2, uint32_t v3)
- {
- uint32_t indexArray[4];
- indexArray[0] = v0;
- indexArray[1] = v1;
- indexArray[2] = v2;
- indexArray[3] = v3;
- return addFace(indexArray, 4, 0, 4);
+ return addFace(indexArray, ignore, hashEdge);
}
- Face *addFace(const std::vector<uint32_t> &indexArray)
+ AddFaceResult::Enum addFace(const uint32_t *indices, bool ignore = false, bool hashEdge = true)
{
- return addFace(indexArray, 0, indexArray.size());
+ AddFaceResult::Enum result = AddFaceResult::OK;
+ if (m_flags & MeshFlags::HasFaceGroups)
+ m_faceGroups.push_back(UINT32_MAX);
+ if (m_flags & MeshFlags::HasIgnoredFaces)
+ m_faceIgnore.push_back(ignore);
+ const uint32_t firstIndex = m_indices.size();
+ for (uint32_t i = 0; i < 3; i++)
+ m_indices.push_back(indices[i]);
+ if (hashEdge) {
+ for (uint32_t i = 0; i < 3; i++) {
+ const uint32_t vertex0 = m_indices[firstIndex + i];
+ const uint32_t vertex1 = m_indices[firstIndex + (i + 1) % 3];
+ const EdgeKey key(vertex0, vertex1);
+ if (m_edgeMap.get(key) != UINT32_MAX)
+ result = AddFaceResult::DuplicateEdge;
+ m_edgeMap.add(key, firstIndex + i);
+ }
+ }
+ return result;
}
- Face *addFace(const std::vector<uint32_t> &indexArray, uint32_t first, uint32_t num)
+ void createColocals()
{
- return addFace(indexArray.data(), (uint32_t)indexArray.size(), first, num);
+ const uint32_t vertexCount = m_positions.size();
+ Array<AABB> aabbs;
+ aabbs.resize(vertexCount);
+ for (uint32_t i = 0; i < m_positions.size(); i++)
+ aabbs[i] = AABB(m_positions[i], m_epsilon);
+ BVH bvh(aabbs);
+ Array<uint32_t> colocals;
+ Array<uint32_t> potential;
+ m_colocalVertexCount = 0;
+ m_nextColocalVertex.resize(vertexCount, UINT32_MAX);
+ for (uint32_t i = 0; i < vertexCount; i++) {
+ if (m_nextColocalVertex[i] != UINT32_MAX)
+ continue; // Already linked.
+ // Find other vertices colocal to this one.
+ colocals.clear();
+ colocals.push_back(i); // Always add this vertex.
+ bvh.query(AABB(m_positions[i], m_epsilon), potential);
+ for (uint32_t j = 0; j < potential.size(); j++) {
+ const uint32_t otherVertex = potential[j];
+ if (otherVertex != i && equal(m_positions[i], m_positions[otherVertex], m_epsilon) && m_nextColocalVertex[otherVertex] == UINT32_MAX)
+ colocals.push_back(otherVertex);
+ }
+ if (colocals.size() == 1) {
+ // No colocals for this vertex.
+ m_nextColocalVertex[i] = i;
+ continue;
+ }
+ m_colocalVertexCount += colocals.size();
+ // Link in ascending order.
+ insertionSort(colocals.data(), colocals.size());
+ for (uint32_t j = 0; j < colocals.size(); j++)
+ m_nextColocalVertex[colocals[j]] = colocals[(j + 1) % colocals.size()];
+ XA_DEBUG_ASSERT(m_nextColocalVertex[i] != UINT32_MAX);
+ }
}
- Face *addFace(const uint32_t *indexArray, uint32_t indexCount, uint32_t first, uint32_t num)
+ // Check if the face duplicates any edges of any face already in the group.
+ bool faceDuplicatesGroupEdge(uint32_t group, uint32_t face) const
{
- xaDebugAssert(first < indexCount);
- xaDebugAssert(num <= indexCount - first);
- xaDebugAssert(num > 2);
- if (!canAddFace(indexArray, first, num)) {
- return NULL;
- }
- Face *f = new Face(m_faceArray.size());
- Edge *firstEdge = NULL;
- Edge *last = NULL;
- Edge *current = NULL;
- for (uint32_t i = 0; i < num - 1; i++) {
- current = addEdge(indexArray[first + i], indexArray[first + i + 1]);
- xaAssert(current != NULL && current->face == NULL);
- current->face = f;
- if (last != NULL) last->setNext(current);
- else firstEdge = current;
- last = current;
+ for (FaceEdgeIterator edgeIt(this, face); !edgeIt.isDone(); edgeIt.advance()) {
+ for (ColocalEdgeIterator colocalEdgeIt(this, edgeIt.vertex0(), edgeIt.vertex1()); !colocalEdgeIt.isDone(); colocalEdgeIt.advance()) {
+ if (m_faceGroups[meshEdgeFace(colocalEdgeIt.edge())] == group)
+ return true;
+ }
}
- current = addEdge(indexArray[first + num - 1], indexArray[first]);
- xaAssert(current != NULL && current->face == NULL);
- current->face = f;
- last->setNext(current);
- current->setNext(firstEdge);
- f->edge = firstEdge;
- m_faceArray.push_back(f);
- return f;
+ return false;
}
- // -- GODOT start --
- Face *addUniqueFace(uint32_t v0, uint32_t v1, uint32_t v2) {
-
- int base_vertex = m_vertexArray.size();
-
- uint32_t ids[3] = { v0, v1, v2 };
-
- Vector3 base[3] = {
- m_vertexArray[v0]->pos,
- m_vertexArray[v1]->pos,
- m_vertexArray[v2]->pos,
- };
-
- //make sure its not a degenerate
- bool degenerate = distanceSquared(base[0], base[1]) < NV_EPSILON || distanceSquared(base[0], base[2]) < NV_EPSILON || distanceSquared(base[1], base[2]) < NV_EPSILON;
- xaDebugAssert(!degenerate);
-
- float min_x = 0;
-
- for (int i = 0; i < 3; i++) {
- if (i == 0 || m_vertexArray[v0]->pos.x < min_x) {
- min_x = m_vertexArray[v0]->pos.x;
+ // Check if the face mirrors any face already in the group.
+ // i.e. don't want two-sided faces in the same group.
+ // A face mirrors another face if all edges match with opposite winding.
+ bool faceMirrorsGroupFace(uint32_t group, uint32_t face) const
+ {
+ FaceEdgeIterator edgeIt(this, face);
+ for (ColocalEdgeIterator colocalEdgeIt(this, edgeIt.vertex1(), edgeIt.vertex0()); !colocalEdgeIt.isDone(); colocalEdgeIt.advance()) {
+ const uint32_t candidateFace = meshEdgeFace(colocalEdgeIt.edge());
+ if (m_faceGroups[candidateFace] == group) {
+ // Found a match for mirrored first edge, try the other edges.
+ bool match = false;
+ for (; !edgeIt.isDone(); edgeIt.advance()) {
+ match = false;
+ for (ColocalEdgeIterator colocalEdgeIt2(this, edgeIt.vertex1(), edgeIt.vertex0()); !colocalEdgeIt2.isDone(); colocalEdgeIt2.advance()) {
+ if (meshEdgeFace(colocalEdgeIt2.edge()) == candidateFace) {
+ match = true;
+ break;
+ }
+ }
+ if (!match)
+ break;
+ }
+ if (match)
+ return true; // All edges are mirrored in this face.
+ // Try the next face.
+ edgeIt = FaceEdgeIterator(this, candidateFace);
}
}
+ return false;
+ }
- float max_x = 0;
-
- for (int j = 0; j < m_vertexArray.size(); j++) {
- if (j == 0 || m_vertexArray[j]->pos.x > max_x) { //vertex already exists
- max_x = m_vertexArray[j]->pos.x;
+ void createFaceGroups()
+ {
+ uint32_t group = 0;
+ Array<uint32_t> growFaces;
+ for (;;) {
+ // Find an unassigned face.
+ uint32_t face = UINT32_MAX;
+ for (uint32_t f = 0; f < faceCount(); f++) {
+ if (m_faceGroups[f] == UINT32_MAX && !isFaceIgnored(f)) {
+ face = f;
+ break;
+ }
}
+ if (face == UINT32_MAX)
+ break; // All faces assigned to a group (except ignored faces).
+ m_faceGroups[face] = group;
+ growFaces.clear();
+ growFaces.push_back(face);
+ // Find faces connected to the face and assign them to the same group as the face, unless they are already assigned to another group.
+ for (;;) {
+ if (growFaces.isEmpty())
+ break;
+ const uint32_t f = growFaces.back();
+ growFaces.pop_back();
+ for (FaceEdgeIterator edgeIt(this, f); !edgeIt.isDone(); edgeIt.advance()) {
+ // Iterate opposite edges. There may be more than one - non-manifold geometry can have duplicate edges.
+ // Prioritize the one with exact vertex match, not just colocal.
+ // If *any* of the opposite edges are already assigned to this group, don't do anything.
+ bool alreadyAssignedToThisGroup = false;
+ uint32_t bestConnectedFace = UINT32_MAX;
+ for (ColocalEdgeIterator oppositeEdgeIt(this, edgeIt.vertex1(), edgeIt.vertex0()); !oppositeEdgeIt.isDone(); oppositeEdgeIt.advance()) {
+ const uint32_t oppositeEdge = oppositeEdgeIt.edge();
+ const uint32_t oppositeFace = meshEdgeFace(oppositeEdge);
+ if (isFaceIgnored(oppositeFace))
+ continue; // Don't add ignored faces to group.
+ if (m_faceGroups[oppositeFace] == group) {
+ alreadyAssignedToThisGroup = true;
+ break;
+ }
+ if (m_faceGroups[oppositeFace] != UINT32_MAX)
+ continue; // Connected face is already assigned to another group.
+ if (faceDuplicatesGroupEdge(group, oppositeFace))
+ continue; // Don't want duplicate edges in a group.
+ if (faceMirrorsGroupFace(group, oppositeFace))
+ continue; // Don't want two-sided faces in a group.
+ const uint32_t oppositeVertex0 = m_indices[meshEdgeIndex0(oppositeEdge)];
+ const uint32_t oppositeVertex1 = m_indices[meshEdgeIndex1(oppositeEdge)];
+ if (bestConnectedFace == UINT32_MAX || (oppositeVertex0 == edgeIt.vertex1() && oppositeVertex1 == edgeIt.vertex0()))
+ bestConnectedFace = oppositeFace;
+ }
+ if (!alreadyAssignedToThisGroup && bestConnectedFace != UINT32_MAX) {
+ m_faceGroups[bestConnectedFace] = group;
+ growFaces.push_back(bestConnectedFace);
+ }
+ }
+ }
+ group++;
}
-
- //separate from everything else, in x axis
- for (int i = 0; i < 3; i++) {
-
- base[i].x -= min_x;
- base[i].x += max_x + 10.0;
- }
-
- for (int i = 0; i < 3; i++) {
- Vertex *v = new Vertex(m_vertexArray.size());
- v->pos = base[i];
- v->nor = m_vertexArray[ids[i]]->nor,
- v->tex = m_vertexArray[ids[i]]->tex,
-
- v->original_id = ids[i];
- m_vertexArray.push_back(v);
- }
-
- uint32_t indexArray[3];
- indexArray[0] = base_vertex + 0;
- indexArray[1] = base_vertex + 1;
- indexArray[2] = base_vertex + 2;
- return addFace(indexArray, 3, 0, 3);
}
- // -- GODOT end --
- // These functions disconnect the given element from the mesh and delete it.
-
- // @@ We must always disconnect edge pairs simultaneously.
- void disconnect(Edge *edge)
+ void createBoundaries()
{
- xaDebugAssert(edge != NULL);
- // Remove from edge list.
- if ((edge->id & 1) == 0) {
- xaDebugAssert(m_edgeArray[edge->id / 2] == edge);
- m_edgeArray[edge->id / 2] = NULL;
- }
- // Remove edge from map. @@ Store map key inside edge?
- xaDebugAssert(edge->from() != NULL && edge->to() != NULL);
- size_t removed = m_edgeMap.erase(Key(edge->from()->id, edge->to()->id));
- xaDebugAssert(removed == 1);
-#ifdef NDEBUG
- removed = 0; // silence unused parameter warning
+ const uint32_t edgeCount = m_indices.size();
+ const uint32_t vertexCount = m_positions.size();
+ m_oppositeEdges.resize(edgeCount);
+ m_boundaryVertices.resize(vertexCount);
+ for (uint32_t i = 0; i < edgeCount; i++)
+ m_oppositeEdges[i] = UINT32_MAX;
+ for (uint32_t i = 0; i < vertexCount; i++)
+ m_boundaryVertices[i] = false;
+ const bool hasFaceGroups = m_flags & MeshFlags::HasFaceGroups;
+ for (uint32_t i = 0; i < faceCount(); i++) {
+ if (isFaceIgnored(i))
+ continue;
+ for (uint32_t j = 0; j < 3; j++) {
+ const uint32_t vertex0 = m_indices[i * 3 + j];
+ const uint32_t vertex1 = m_indices[i * 3 + (j + 1) % 3];
+ // If there is an edge with opposite winding to this one, the edge isn't on a boundary.
+ const uint32_t oppositeEdge = findEdge(hasFaceGroups ? m_faceGroups[i] : UINT32_MAX, vertex1, vertex0);
+ if (oppositeEdge != UINT32_MAX) {
+#if XA_DEBUG
+ if (hasFaceGroups)
+ XA_DEBUG_ASSERT(m_faceGroups[meshEdgeFace(oppositeEdge)] == m_faceGroups[i]);
#endif
- // Disconnect from vertex.
- if (edge->vertex != NULL) {
- if (edge->vertex->edge == edge) {
- if (edge->prev && edge->prev->pair) {
- edge->vertex->edge = edge->prev->pair;
- } else if (edge->pair && edge->pair->next) {
- edge->vertex->edge = edge->pair->next;
+ XA_DEBUG_ASSERT(!isFaceIgnored(meshEdgeFace(oppositeEdge)));
+ m_oppositeEdges[i * 3 + j] = oppositeEdge;
} else {
- edge->vertex->edge = NULL;
- // @@ Remove disconnected vertex?
+ m_boundaryVertices[vertex0] = m_boundaryVertices[vertex1] = true;
}
}
}
- // Disconnect from face.
- if (edge->face != NULL) {
- if (edge->face->edge == edge) {
- if (edge->next != NULL && edge->next != edge) {
- edge->face->edge = edge->next;
- } else if (edge->prev != NULL && edge->prev != edge) {
- edge->face->edge = edge->prev;
- } else {
- edge->face->edge = NULL;
- // @@ Remove disconnected face?
+ }
+
+ void linkBoundaries()
+ {
+ const uint32_t edgeCount = m_indices.size();
+ HashMap<uint32_t, uint32_t> vertexToEdgeMap(MemTag::Mesh, edgeCount);
+ for (uint32_t i = 0; i < edgeCount; i++) {
+ const uint32_t vertex0 = m_indices[meshEdgeIndex0(i)];
+ const uint32_t vertex1 = m_indices[meshEdgeIndex1(i)];
+ vertexToEdgeMap.add(vertex0, i);
+ vertexToEdgeMap.add(vertex1, i);
+ }
+ m_nextBoundaryEdges.resize(edgeCount);
+ for (uint32_t i = 0; i < edgeCount; i++)
+ m_nextBoundaryEdges[i] = UINT32_MAX;
+ uint32_t numBoundaryLoops = 0, numUnclosedBoundaries = 0;
+ BitArray linkedEdges(edgeCount);
+ linkedEdges.clearAll();
+ for (;;) {
+ // Find the first boundary edge that hasn't been linked yet.
+ uint32_t firstEdge = UINT32_MAX;
+ for (uint32_t i = 0; i < edgeCount; i++) {
+ if (m_oppositeEdges[i] == UINT32_MAX && !linkedEdges.bitAt(i)) {
+ firstEdge = i;
+ break;
}
}
- }
- // Disconnect from previous.
- if (edge->prev) {
- if (edge->prev->next == edge) {
- edge->prev->setNext(NULL);
+ if (firstEdge == UINT32_MAX)
+ break;
+ uint32_t currentEdge = firstEdge;
+ for (;;) {
+ // Find the next boundary edge. The first vertex will be the same as (or colocal to) the current edge second vertex.
+ const uint32_t startVertex = m_indices[meshEdgeIndex1(currentEdge)];
+ uint32_t bestNextEdge = UINT32_MAX;
+ for (ColocalVertexIterator it(this, startVertex); !it.isDone(); it.advance()) {
+ uint32_t mapOtherEdgeIndex = vertexToEdgeMap.get(it.vertex());
+ while (mapOtherEdgeIndex != UINT32_MAX) {
+ const uint32_t otherEdge = vertexToEdgeMap.value(mapOtherEdgeIndex);
+ if (m_oppositeEdges[otherEdge] != UINT32_MAX)
+ goto next; // Not a boundary edge.
+ if (linkedEdges.bitAt(otherEdge))
+ goto next; // Already linked.
+ if (m_flags & MeshFlags::HasFaceGroups && m_faceGroups[meshEdgeFace(currentEdge)] != m_faceGroups[meshEdgeFace(otherEdge)])
+ goto next; // Don't cross face groups.
+ if (isFaceIgnored(meshEdgeFace(otherEdge)))
+ goto next; // Face is ignored.
+ if (m_indices[meshEdgeIndex0(otherEdge)] != it.vertex())
+ goto next; // Edge contains the vertex, but it's the wrong one.
+ // First edge (closing the boundary loop) has the highest priority.
+ // Non-colocal vertex has the next highest.
+ if (bestNextEdge != firstEdge && (bestNextEdge == UINT32_MAX || it.vertex() == startVertex))
+ bestNextEdge = otherEdge;
+ next:
+ mapOtherEdgeIndex = vertexToEdgeMap.getNext(mapOtherEdgeIndex);
+ }
+ }
+ if (bestNextEdge == UINT32_MAX) {
+ numUnclosedBoundaries++;
+ if (currentEdge == firstEdge)
+ linkedEdges.setBitAt(firstEdge); // Only 1 edge in this boundary "loop".
+ break; // Can't find a next edge.
+ }
+ m_nextBoundaryEdges[currentEdge] = bestNextEdge;
+ linkedEdges.setBitAt(bestNextEdge);
+ currentEdge = bestNextEdge;
+ if (currentEdge == firstEdge) {
+ numBoundaryLoops++;
+ break; // Closed the boundary loop.
+ }
}
- //edge->setPrev(NULL);
}
- // Disconnect from next.
- if (edge->next) {
- if (edge->next->prev == edge) {
- edge->next->setPrev(NULL);
+ // Find internal boundary loops and separate them.
+ // Detect by finding two edges in a boundary loop that have a colocal end vertex.
+ // Fix by swapping their next boundary edge.
+ // Need to start over after every fix since known boundary loops have changed.
+ Array<uint32_t> boundaryLoops;
+ fixInternalBoundary:
+ meshGetBoundaryLoops(*this, boundaryLoops);
+ for (uint32_t loop = 0; loop < boundaryLoops.size(); loop++) {
+ linkedEdges.clearAll();
+ for (Mesh::BoundaryEdgeIterator it1(this, boundaryLoops[loop]); !it1.isDone(); it1.advance()) {
+ const uint32_t e1 = it1.edge();
+ if (linkedEdges.bitAt(e1))
+ continue;
+ for (Mesh::BoundaryEdgeIterator it2(this, boundaryLoops[loop]); !it2.isDone(); it2.advance()) {
+ const uint32_t e2 = it2.edge();
+ if (e1 == e2 || !isBoundaryEdge(e2) || linkedEdges.bitAt(e2))
+ continue;
+ if (!areColocal(m_indices[meshEdgeIndex1(e1)], m_indices[meshEdgeIndex1(e2)]))
+ continue;
+ swap(m_nextBoundaryEdges[e1], m_nextBoundaryEdges[e2]);
+ linkedEdges.setBitAt(e1);
+ linkedEdges.setBitAt(e2);
+ goto fixInternalBoundary; // start over
+ }
}
- //edge->setNext(NULL);
}
}
- void remove(Edge *edge)
- {
- xaDebugAssert(edge != NULL);
- disconnect(edge);
- delete edge;
+ /// Find edge, test all colocals.
+ uint32_t findEdge(uint32_t faceGroup, uint32_t vertex0, uint32_t vertex1) const
+ {
+ uint32_t result = UINT32_MAX;
+ if (m_nextColocalVertex.isEmpty()) {
+ EdgeKey key(vertex0, vertex1);
+ uint32_t mapEdgeIndex = m_edgeMap.get(key);
+ while (mapEdgeIndex != UINT32_MAX) {
+ const uint32_t edge = m_edgeMap.value(mapEdgeIndex);
+ // Don't find edges of ignored faces.
+ if ((faceGroup == UINT32_MAX || m_faceGroups[meshEdgeFace(edge)] == faceGroup) && !isFaceIgnored(meshEdgeFace(edge))) {
+ //XA_DEBUG_ASSERT(m_id != UINT32_MAX || (m_id == UINT32_MAX && result == UINT32_MAX)); // duplicate edge - ignore on initial meshes
+ result = edge;
+#if !XA_DEBUG
+ return result;
+#endif
+ }
+ mapEdgeIndex = m_edgeMap.getNext(mapEdgeIndex);
+ }
+ } else {
+ for (ColocalVertexIterator it0(this, vertex0); !it0.isDone(); it0.advance()) {
+ for (ColocalVertexIterator it1(this, vertex1); !it1.isDone(); it1.advance()) {
+ EdgeKey key(it0.vertex(), it1.vertex());
+ uint32_t mapEdgeIndex = m_edgeMap.get(key);
+ while (mapEdgeIndex != UINT32_MAX) {
+ const uint32_t edge = m_edgeMap.value(mapEdgeIndex);
+ // Don't find edges of ignored faces.
+ if ((faceGroup == UINT32_MAX || m_faceGroups[meshEdgeFace(edge)] == faceGroup) && !isFaceIgnored(meshEdgeFace(edge))) {
+ XA_DEBUG_ASSERT(m_id != UINT32_MAX || (m_id == UINT32_MAX && result == UINT32_MAX)); // duplicate edge - ignore on initial meshes
+ result = edge;
+#if !XA_DEBUG
+ return result;
+#endif
+ }
+ mapEdgeIndex = m_edgeMap.getNext(mapEdgeIndex);
+ }
+ }
+ }
+ }
+ return result;
}
- void remove(Vertex *vertex)
+#if XA_DEBUG_EXPORT_OBJ
+ void writeObjVertices(FILE *file) const
{
- xaDebugAssert(vertex != NULL);
- // Remove from vertex list.
- m_vertexArray[vertex->id] = NULL;
- // Disconnect from colocals.
- vertex->unlinkColocal();
- // Disconnect from edges.
- if (vertex->edge != NULL) {
- // @@ Removing a connected vertex is asking for trouble...
- if (vertex->edge->vertex == vertex) {
- // @@ Connect edge to a colocal?
- vertex->edge->vertex = NULL;
- }
- vertex->setEdge(NULL);
+ for (uint32_t i = 0; i < m_positions.size(); i++)
+ fprintf(file, "v %g %g %g\n", m_positions[i].x, m_positions[i].y, m_positions[i].z);
+ if (m_flags & MeshFlags::HasNormals) {
+ for (uint32_t i = 0; i < m_normals.size(); i++)
+ fprintf(file, "vn %g %g %g\n", m_normals[i].x, m_normals[i].y, m_normals[i].z);
}
- delete vertex;
+ for (uint32_t i = 0; i < m_texcoords.size(); i++)
+ fprintf(file, "vt %g %g\n", m_texcoords[i].x, m_texcoords[i].y);
}
- void remove(Face *face)
+ void writeObjFace(FILE *file, uint32_t face) const
{
- xaDebugAssert(face != NULL);
- // Remove from face list.
- m_faceArray[face->id] = NULL;
- // Disconnect from edges.
- if (face->edge != NULL) {
- xaDebugAssert(face->edge->face == face);
- face->edge->face = NULL;
- face->edge = NULL;
+ fprintf(file, "f ");
+ for (uint32_t j = 0; j < 3; j++) {
+ const uint32_t index = m_indices[face * 3 + j] + 1; // 1-indexed
+ fprintf(file, "%d/%d/%d%c", index, index, index, j == 2 ? '\n' : ' ');
}
- delete face;
}
- // Triangulate in place.
- void triangulate()
+ void writeObjBoundaryEges(FILE *file) const
{
- bool all_triangles = true;
- const uint32_t faceCount = m_faceArray.size();
- for (uint32_t f = 0; f < faceCount; f++) {
- Face *face = m_faceArray[f];
- if (face->edgeCount() != 3) {
- all_triangles = false;
- break;
- }
- }
- if (all_triangles) {
- return;
- }
- // Do not touch vertices, but rebuild edges and faces.
- std::vector<Edge *> edgeArray;
- std::vector<Face *> faceArray;
- std::swap(edgeArray, m_edgeArray);
- std::swap(faceArray, m_faceArray);
- m_edgeMap.clear();
- for (uint32_t f = 0; f < faceCount; f++) {
- Face *face = faceArray[f];
- // Trivial fan-like triangulation.
- const uint32_t v0 = face->edge->vertex->id;
- uint32_t v2, v1 = (uint32_t)-1;
- for (Face::EdgeIterator it(face->edges()); !it.isDone(); it.advance()) {
- Edge *edge = it.current();
- v2 = edge->to()->id;
- if (v2 == v0) break;
- if (v1 != -1) addFace(v0, v1, v2);
- v1 = v2;
- }
- }
- xaDebugAssert(m_faceArray.size() > faceCount); // triangle count > face count
- linkBoundary();
- for (size_t i = 0; i < edgeArray.size(); i++)
- delete edgeArray[i];
- for (size_t i = 0; i < faceArray.size(); i++)
- delete faceArray[i];
- }
-
- /// Link boundary edges once the mesh has been created.
- void linkBoundary()
- {
- xaPrint("--- Linking boundaries:\n");
- int num = 0;
- // Create boundary edges.
- uint32_t edgeCount = this->edgeCount();
- for (uint32_t e = 0; e < edgeCount; e++) {
- Edge *edge = edgeAt(e);
- if (edge != NULL && edge->pair == NULL) {
- Edge *pair = new Edge(edge->id + 1);
- uint32_t i = edge->from()->id;
- uint32_t j = edge->next->from()->id;
- Key key(j, i);
- xaAssert(m_edgeMap.find(key) == m_edgeMap.end());
- pair->vertex = m_vertexArray[j];
- m_edgeMap[key] = pair;
- edge->pair = pair;
- pair->pair = edge;
- num++;
- }
- }
- // Link boundary edges.
- for (uint32_t e = 0; e < edgeCount; e++) {
- Edge *edge = edgeAt(e);
- if (edge != NULL && edge->pair->face == NULL) {
- linkBoundaryEdge(edge->pair);
+ if (m_oppositeEdges.isEmpty())
+ return; // Boundaries haven't been created.
+ fprintf(file, "o boundary_edges\n");
+ for (uint32_t i = 0; i < edgeCount(); i++) {
+ if (m_oppositeEdges[i] != UINT32_MAX)
+ continue;
+ fprintf(file, "l %d %d\n", m_indices[meshEdgeIndex0(i)] + 1, m_indices[meshEdgeIndex1(i)] + 1); // 1-indexed
+ }
+ }
+
+ void writeObjLinkedBoundaries(FILE *file) const
+ {
+ if (m_oppositeEdges.isEmpty() || m_nextBoundaryEdges.isEmpty())
+ return; // Boundaries haven't been created and/or linked.
+ Array<uint32_t> boundaryLoops;
+ meshGetBoundaryLoops(*this, boundaryLoops);
+ for (uint32_t i = 0; i < boundaryLoops.size(); i++) {
+ uint32_t edge = boundaryLoops[i];
+ fprintf(file, "o boundary_%04d\n", i);
+ fprintf(file, "l");
+ for (;;) {
+ const uint32_t vertex0 = m_indices[meshEdgeIndex0(edge)];
+ const uint32_t vertex1 = m_indices[meshEdgeIndex1(edge)];
+ fprintf(file, " %d", vertex0 + 1); // 1-indexed
+ edge = m_nextBoundaryEdges[edge];
+ if (edge == boundaryLoops[i] || edge == UINT32_MAX) {
+ fprintf(file, " %d\n", vertex1 + 1); // 1-indexed
+ break;
+ }
}
}
- xaPrint("--- %d boundary edges.\n", num);
}
- /*
- Fixing T-junctions.
+ void writeObjFile(const char *filename) const
+ {
+ FILE *file;
+ XA_FOPEN(file, filename, "w");
+ if (!file)
+ return;
+ writeObjVertices(file);
+ fprintf(file, "s off\n");
+ fprintf(file, "o object\n");
+ for (uint32_t i = 0; i < faceCount(); i++)
+ writeObjFace(file, i);
+ writeObjBoundaryEges(file);
+ writeObjLinkedBoundaries(file);
+ fclose(file);
+ }
+#endif
- - Find T-junctions. Find vertices that are on an edge.
- - This test is approximate.
- - Insert edges on a spatial index to speedup queries.
- - Consider only open edges, that is edges that have no pairs.
- - Consider only vertices on boundaries.
- - Close T-junction.
- - Split edge.
+ float computeSurfaceArea() const
+ {
+ float area = 0;
+ for (uint32_t f = 0; f < faceCount(); f++)
+ area += faceArea(f);
+ XA_DEBUG_ASSERT(area >= 0);
+ return area;
+ }
- */
- bool splitBoundaryEdges() // Returns true if any split was made.
- {
- std::vector<Vertex *> boundaryVertices;
- for (uint32_t i = 0; i < m_vertexArray.size(); i++) {
- Vertex *v = m_vertexArray[i];
- if (v->isBoundary()) {
- boundaryVertices.push_back(v);
- }
- }
- xaPrint("Fixing T-junctions:\n");
- int splitCount = 0;
- for (uint32_t v = 0; v < boundaryVertices.size(); v++) {
- Vertex *vertex = boundaryVertices[v];
- Vector3 x0 = vertex->pos;
- // Find edges that this vertex overlaps with.
- for (uint32_t e = 0; e < m_edgeArray.size(); e++) {
- Edge *edge = m_edgeArray[e];
- if (edge != NULL && edge->isBoundary()) {
- if (edge->from() == vertex || edge->to() == vertex) {
- continue;
- }
- Vector3 x1 = edge->from()->pos;
- Vector3 x2 = edge->to()->pos;
- Vector3 v01 = x0 - x1;
- Vector3 v21 = x2 - x1;
- float l = length(v21);
- float d = length(cross(v01, v21)) / l;
- if (isZero(d)) {
- float t = dot(v01, v21) / (l * l);
- if (t > 0.0f + NV_EPSILON && t < 1.0f - NV_EPSILON) {
- xaDebugAssert(equal(lerp(x1, x2, t), x0));
- Vertex *splitVertex = splitBoundaryEdge(edge, t, x0);
- vertex->linkColocal(splitVertex); // @@ Should we do this here?
- splitCount++;
- }
- }
- }
- }
- }
- xaPrint(" - %d edges split.\n", splitCount);
- xaDebugAssert(isValid());
- return splitCount != 0;
+ float computeParametricArea() const
+ {
+ float area = 0;
+ for (uint32_t f = 0; f < faceCount(); f++)
+ area += faceParametricArea(f);
+ return fabsf(area); // May be negative, depends on texcoord winding.
}
- // Vertices
- uint32_t vertexCount() const
+ float faceArea(uint32_t face) const
{
- return m_vertexArray.size();
+ const Vector3 &p0 = m_positions[m_indices[face * 3 + 0]];
+ const Vector3 &p1 = m_positions[m_indices[face * 3 + 1]];
+ const Vector3 &p2 = m_positions[m_indices[face * 3 + 2]];
+ return length(cross(p1 - p0, p2 - p0)) * 0.5f;
}
- const Vertex *vertexAt(int i) const
+
+ Vector3 faceCentroid(uint32_t face) const
{
- return m_vertexArray[i];
+ Vector3 sum(0.0f);
+ for (uint32_t i = 0; i < 3; i++)
+ sum += m_positions[m_indices[face * 3 + i]];
+ return sum / 3.0f;
}
- Vertex *vertexAt(int i)
+
+ Vector3 calculateFaceNormal(uint32_t face) const
{
- return m_vertexArray[i];
+ return normalizeSafe(triangleNormalAreaScaled(face), Vector3(0, 0, 1), 0.0f);
}
- uint32_t colocalVertexCount() const
+ float faceParametricArea(uint32_t face) const
{
- return m_colocalVertexCount;
+ const Vector2 &t0 = m_texcoords[m_indices[face * 3 + 0]];
+ const Vector2 &t1 = m_texcoords[m_indices[face * 3 + 1]];
+ const Vector2 &t2 = m_texcoords[m_indices[face * 3 + 2]];
+ return triangleArea(t0, t1, t2) * 0.5f;
+ }
+
+ // Average of the edge midpoints weighted by the edge length.
+ // I want a point inside the triangle, but closer to the cirumcenter.
+ Vector3 triangleCenter(uint32_t face) const
+ {
+ const Vector3 &p0 = m_positions[m_indices[face * 3 + 0]];
+ const Vector3 &p1 = m_positions[m_indices[face * 3 + 1]];
+ const Vector3 &p2 = m_positions[m_indices[face * 3 + 2]];
+ const float l0 = length(p1 - p0);
+ const float l1 = length(p2 - p1);
+ const float l2 = length(p0 - p2);
+ const Vector3 m0 = (p0 + p1) * l0 / (l0 + l1 + l2);
+ const Vector3 m1 = (p1 + p2) * l1 / (l0 + l1 + l2);
+ const Vector3 m2 = (p2 + p0) * l2 / (l0 + l1 + l2);
+ return m0 + m1 + m2;
}
- // Faces
- uint32_t faceCount() const
+ // Unnormalized face normal assuming it's a triangle.
+ Vector3 triangleNormal(uint32_t face) const
{
- return m_faceArray.size();
+ return normalizeSafe(triangleNormalAreaScaled(face), Vector3(0), 0.0f);
}
- const Face *faceAt(int i) const
+
+ Vector3 triangleNormalAreaScaled(uint32_t face) const
{
- return m_faceArray[i];
+ const Vector3 &p0 = m_positions[m_indices[face * 3 + 0]];
+ const Vector3 &p1 = m_positions[m_indices[face * 3 + 1]];
+ const Vector3 &p2 = m_positions[m_indices[face * 3 + 2]];
+ const Vector3 e0 = p2 - p0;
+ const Vector3 e1 = p1 - p0;
+ return cross(e0, e1);
}
- Face *faceAt(int i)
+
+ // @@ This is not exactly accurate, we should compare the texture coordinates...
+ bool isSeam(uint32_t edge) const
{
- return m_faceArray[i];
+ const uint32_t oppositeEdge = m_oppositeEdges[edge];
+ if (oppositeEdge == UINT32_MAX)
+ return false; // boundary edge
+ const uint32_t e0 = meshEdgeIndex0(edge);
+ const uint32_t e1 = meshEdgeIndex1(edge);
+ const uint32_t oe0 = meshEdgeIndex0(oppositeEdge);
+ const uint32_t oe1 = meshEdgeIndex1(oppositeEdge);
+ return m_indices[e0] != m_indices[oe1] || m_indices[e1] != m_indices[oe0];
}
- // Edges
- uint32_t edgeCount() const
+ bool isTextureSeam(uint32_t edge) const
{
- return m_edgeArray.size();
+ const uint32_t oppositeEdge = m_oppositeEdges[edge];
+ if (oppositeEdge == UINT32_MAX)
+ return false; // boundary edge
+ const uint32_t e0 = meshEdgeIndex0(edge);
+ const uint32_t e1 = meshEdgeIndex1(edge);
+ const uint32_t oe0 = meshEdgeIndex0(oppositeEdge);
+ const uint32_t oe1 = meshEdgeIndex1(oppositeEdge);
+ return m_texcoords[m_indices[e0]] != m_texcoords[m_indices[oe1]] || m_texcoords[m_indices[e1]] != m_texcoords[m_indices[oe0]];
}
- const Edge *edgeAt(int i) const
+
+ uint32_t firstColocal(uint32_t vertex) const
{
- return m_edgeArray[i];
+ for (ColocalVertexIterator it(this, vertex); !it.isDone(); it.advance()) {
+ if (it.vertex() < vertex)
+ vertex = it.vertex();
+ }
+ return vertex;
}
- Edge *edgeAt(int i)
+
+ bool areColocal(uint32_t vertex0, uint32_t vertex1) const
{
- return m_edgeArray[i];
+ if (vertex0 == vertex1)
+ return true;
+ if (m_nextColocalVertex.isEmpty())
+ return false;
+ for (ColocalVertexIterator it(this, vertex0); !it.isDone(); it.advance()) {
+ if (it.vertex() == vertex1)
+ return true;
+ }
+ return false;
}
- class ConstVertexIterator;
+ float epsilon() const { return m_epsilon; }
+ uint32_t edgeCount() const { return m_indices.size(); }
+ uint32_t oppositeEdge(uint32_t edge) const { return m_oppositeEdges[edge]; }
+ bool isBoundaryEdge(uint32_t edge) const { return m_oppositeEdges[edge] == UINT32_MAX; }
+ bool isBoundaryVertex(uint32_t vertex) const { return m_boundaryVertices[vertex]; }
+ uint32_t colocalVertexCount() const { return m_colocalVertexCount; }
+ uint32_t vertexCount() const { return m_positions.size(); }
+ uint32_t vertexAt(uint32_t i) const { return m_indices[i]; }
+ const Vector3 &position(uint32_t vertex) const { return m_positions[vertex]; }
+ const Vector3 &normal(uint32_t vertex) const { XA_DEBUG_ASSERT(m_flags & MeshFlags::HasNormals); return m_normals[vertex]; }
+ const Vector2 &texcoord(uint32_t vertex) const { return m_texcoords[vertex]; }
+ Vector2 &texcoord(uint32_t vertex) { return m_texcoords[vertex]; }
+ Vector2 *texcoords() { return m_texcoords.data(); }
+ uint32_t faceCount() const { return m_indices.size() / 3; }
+ uint32_t faceGroupCount() const { XA_DEBUG_ASSERT(m_flags & MeshFlags::HasFaceGroups); return m_faceGroups.size(); }
+ uint32_t faceGroupAt(uint32_t face) const { XA_DEBUG_ASSERT(m_flags & MeshFlags::HasFaceGroups); return m_faceGroups[face]; }
+ const uint32_t *indices() const { return m_indices.data(); }
+ uint32_t indexCount() const { return m_indices.size(); }
+
+private:
+ bool isFaceIgnored(uint32_t face) const { return (m_flags & MeshFlags::HasIgnoredFaces) && m_faceIgnore[face]; }
+
+ float m_epsilon;
+ uint32_t m_flags;
+ uint32_t m_id;
+ Array<bool> m_faceIgnore;
+ Array<uint32_t> m_faceGroups;
+ Array<uint32_t> m_indices;
+ Array<Vector3> m_positions;
+ Array<Vector3> m_normals;
+ Array<Vector2> m_texcoords;
+
+ // Populated by createColocals
+ uint32_t m_colocalVertexCount;
+ Array<uint32_t> m_nextColocalVertex; // In: vertex index. Out: the vertex index of the next colocal position.
+
+ // Populated by createBoundaries
+ Array<bool> m_boundaryVertices;
+ Array<uint32_t> m_oppositeEdges; // In: edge index. Out: the index of the opposite edge (i.e. wound the opposite direction). UINT32_MAX if the input edge is a boundary edge.
+
+ // Populated by linkBoundaries
+ Array<uint32_t> m_nextBoundaryEdges; // The index of the next boundary edge. UINT32_MAX if the edge is not a boundary edge.
- class VertexIterator
+ struct EdgeKey
{
- friend class ConstVertexIterator;
- public:
- VertexIterator(Mesh *mesh) : m_mesh(mesh), m_current(0) { }
+ EdgeKey() {}
+ EdgeKey(const EdgeKey &k) : v0(k.v0), v1(k.v1) {}
+ EdgeKey(uint32_t v0, uint32_t v1) : v0(v0), v1(v1) {}
- virtual void advance()
- {
- m_current++;
- }
- virtual bool isDone() const
+ void operator=(const EdgeKey &k)
{
- return m_current == m_mesh->vertexCount();
+ v0 = k.v0;
+ v1 = k.v1;
}
- virtual Vertex *current() const
+ bool operator==(const EdgeKey &k) const
{
- return m_mesh->vertexAt(m_current);
+ return v0 == k.v0 && v1 == k.v1;
}
- private:
- halfedge::Mesh *m_mesh;
- uint32_t m_current;
+ uint32_t v0;
+ uint32_t v1;
};
- VertexIterator vertices()
- {
- return VertexIterator(this);
- }
- class ConstVertexIterator
+ HashMap<EdgeKey, uint32_t> m_edgeMap;
+
+public:
+ class BoundaryEdgeIterator
{
public:
- ConstVertexIterator(const Mesh *mesh) : m_mesh(mesh), m_current(0) { }
- ConstVertexIterator(class VertexIterator &it) : m_mesh(it.m_mesh), m_current(it.m_current) { }
+ BoundaryEdgeIterator(const Mesh *mesh, uint32_t edge) : m_mesh(mesh), m_first(UINT32_MAX), m_current(edge) {}
- virtual void advance()
+ void advance()
{
- m_current++;
+ if (m_first == UINT32_MAX)
+ m_first = m_current;
+ m_current = m_mesh->m_nextBoundaryEdges[m_current];
}
- virtual bool isDone() const
+
+ bool isDone() const
{
- return m_current == m_mesh->vertexCount();
+ return m_first == m_current || m_current == UINT32_MAX;
}
- virtual const Vertex *current() const
+
+ uint32_t edge() const
{
- return m_mesh->vertexAt(m_current);
+ return m_current;
+ }
+
+ uint32_t nextEdge() const
+ {
+ return m_mesh->m_nextBoundaryEdges[m_current];
}
private:
- const halfedge::Mesh *m_mesh;
+ const Mesh *m_mesh;
+ uint32_t m_first;
uint32_t m_current;
};
- ConstVertexIterator vertices() const
- {
- return ConstVertexIterator(this);
- }
-
- class ConstFaceIterator;
- class FaceIterator
+ class ColocalVertexIterator
{
- friend class ConstFaceIterator;
public:
- FaceIterator(Mesh *mesh) : m_mesh(mesh), m_current(0) { }
+ ColocalVertexIterator(const Mesh *mesh, uint32_t v) : m_mesh(mesh), m_first(UINT32_MAX), m_current(v) {}
+
+ void advance()
+ {
+ if (m_first == UINT32_MAX)
+ m_first = m_current;
+ if (!m_mesh->m_nextColocalVertex.isEmpty())
+ m_current = m_mesh->m_nextColocalVertex[m_current];
+ }
- virtual void advance()
+ bool isDone() const
{
- m_current++;
+ return m_first == m_current;
}
- virtual bool isDone() const
+
+ uint32_t vertex() const
{
- return m_current == m_mesh->faceCount();
+ return m_current;
}
- virtual Face *current() const
+
+ const Vector3 *pos() const
{
- return m_mesh->faceAt(m_current);
+ return &m_mesh->m_positions[m_current];
}
private:
- halfedge::Mesh *m_mesh;
+ const Mesh *m_mesh;
+ uint32_t m_first;
uint32_t m_current;
};
- FaceIterator faces()
- {
- return FaceIterator(this);
- }
- class ConstFaceIterator
+ class ColocalEdgeIterator
{
public:
- ConstFaceIterator(const Mesh *mesh) : m_mesh(mesh), m_current(0) { }
- ConstFaceIterator(const FaceIterator &it) : m_mesh(it.m_mesh), m_current(it.m_current) { }
+ ColocalEdgeIterator(const Mesh *mesh, uint32_t vertex0, uint32_t vertex1) : m_mesh(mesh), m_vertex0It(mesh, vertex0), m_vertex1It(mesh, vertex1), m_vertex1(vertex1)
+ {
+ resetElement();
+ }
- virtual void advance()
+ void advance()
{
- m_current++;
+ advanceElement();
}
- virtual bool isDone() const
+
+ bool isDone() const
{
- return m_current == m_mesh->faceCount();
+ return m_vertex0It.isDone() && m_vertex1It.isDone() && m_mapEdgeIndex == UINT32_MAX;
}
- virtual const Face *current() const
+
+ uint32_t edge() const
{
- return m_mesh->faceAt(m_current);
+ return m_mesh->m_edgeMap.value(m_mapEdgeIndex);
}
private:
- const halfedge::Mesh *m_mesh;
- uint32_t m_current;
- };
- ConstFaceIterator faces() const
- {
- return ConstFaceIterator(this);
- }
-
- class ConstEdgeIterator;
+ void resetElement()
+ {
+ m_mapEdgeIndex = m_mesh->m_edgeMap.get(Mesh::EdgeKey(m_vertex0It.vertex(), m_vertex1It.vertex()));
+ while (m_mapEdgeIndex != UINT32_MAX) {
+ if (!isIgnoredFace())
+ break;
+ m_mapEdgeIndex = m_mesh->m_edgeMap.getNext(m_mapEdgeIndex);
+ }
+ if (m_mapEdgeIndex == UINT32_MAX)
+ advanceVertex1();
+ }
- class EdgeIterator
- {
- friend class ConstEdgeIterator;
- public:
- EdgeIterator(Mesh *mesh) : m_mesh(mesh), m_current(0) { }
+ void advanceElement()
+ {
+ for (;;) {
+ m_mapEdgeIndex = m_mesh->m_edgeMap.getNext(m_mapEdgeIndex);
+ if (m_mapEdgeIndex == UINT32_MAX)
+ break;
+ if (!isIgnoredFace())
+ break;
+ }
+ if (m_mapEdgeIndex == UINT32_MAX)
+ advanceVertex1();
+ }
- virtual void advance()
+ void advanceVertex0()
{
- m_current++;
+ m_vertex0It.advance();
+ if (m_vertex0It.isDone())
+ return;
+ m_vertex1It = ColocalVertexIterator(m_mesh, m_vertex1);
+ resetElement();
}
- virtual bool isDone() const
+
+ void advanceVertex1()
{
- return m_current == m_mesh->edgeCount();
+ m_vertex1It.advance();
+ if (m_vertex1It.isDone())
+ advanceVertex0();
+ else
+ resetElement();
}
- virtual Edge *current() const
+
+ bool isIgnoredFace() const
{
- return m_mesh->edgeAt(m_current);
+ const uint32_t edge = m_mesh->m_edgeMap.value(m_mapEdgeIndex);
+ return m_mesh->m_faceIgnore[meshEdgeFace(edge)];
}
- private:
- halfedge::Mesh *m_mesh;
- uint32_t m_current;
+ const Mesh *m_mesh;
+ ColocalVertexIterator m_vertex0It, m_vertex1It;
+ const uint32_t m_vertex1;
+ uint32_t m_mapEdgeIndex;
};
- EdgeIterator edges()
- {
- return EdgeIterator(this);
- }
- class ConstEdgeIterator
+ class FaceEdgeIterator
{
public:
- ConstEdgeIterator(const Mesh *mesh) : m_mesh(mesh), m_current(0) { }
- ConstEdgeIterator(const EdgeIterator &it) : m_mesh(it.m_mesh), m_current(it.m_current) { }
+ FaceEdgeIterator (const Mesh *mesh, uint32_t face) : m_mesh(mesh), m_face(face), m_relativeEdge(0)
+ {
+ m_edge = m_face * 3;
+ }
+
+ void advance()
+ {
+ if (m_relativeEdge < 3) {
+ m_edge++;
+ m_relativeEdge++;
+ }
+ }
- virtual void advance()
+ bool isDone() const
+ {
+ return m_relativeEdge == 3;
+ }
+
+ bool isBoundary() const { return m_mesh->m_oppositeEdges[m_edge] == UINT32_MAX; }
+ bool isSeam() const { return m_mesh->isSeam(m_edge); }
+ bool isTextureSeam() const { return m_mesh->isTextureSeam(m_edge); }
+ uint32_t edge() const { return m_edge; }
+ uint32_t relativeEdge() const { return m_relativeEdge; }
+ uint32_t face() const { return m_face; }
+ uint32_t oppositeEdge() const { return m_mesh->m_oppositeEdges[m_edge]; }
+
+ uint32_t oppositeFace() const
{
- m_current++;
+ const uint32_t oedge = m_mesh->m_oppositeEdges[m_edge];
+ if (oedge == UINT32_MAX)
+ return UINT32_MAX;
+ return meshEdgeFace(oedge);
}
- virtual bool isDone() const
+
+ uint32_t vertex0() const
{
- return m_current == m_mesh->edgeCount();
+ return m_mesh->m_indices[m_face * 3 + m_relativeEdge];
}
- virtual const Edge *current() const
+
+ uint32_t vertex1() const
{
- return m_mesh->edgeAt(m_current);
+ return m_mesh->m_indices[m_face * 3 + (m_relativeEdge + 1) % 3];
}
+ const Vector3 &position0() const { return m_mesh->m_positions[vertex0()]; }
+ const Vector3 &position1() const { return m_mesh->m_positions[vertex1()]; }
+ const Vector3 &normal0() const { return m_mesh->m_normals[vertex0()]; }
+ const Vector3 &normal1() const { return m_mesh->m_normals[vertex1()]; }
+ const Vector2 &texcoord0() const { return m_mesh->m_texcoords[vertex0()]; }
+ const Vector2 &texcoord1() const { return m_mesh->m_texcoords[vertex1()]; }
+
private:
- const halfedge::Mesh *m_mesh;
- uint32_t m_current;
+ const Mesh *m_mesh;
+ uint32_t m_face;
+ uint32_t m_edge;
+ uint32_t m_relativeEdge;
};
- ConstEdgeIterator edges() const
- {
- return ConstEdgeIterator(this);
- }
-
- // @@ Add half-edge iterator.
+};
- bool isValid() const
- {
- // Make sure all edges are valid.
- const uint32_t edgeCount = m_edgeArray.size();
- for (uint32_t e = 0; e < edgeCount; e++) {
- Edge *edge = m_edgeArray[e];
- if (edge != NULL) {
- if (edge->id != 2 * e) {
- return false;
+static bool meshCloseHole(Mesh *mesh, const Array<uint32_t> &holeVertices, const Vector3 &normal)
+{
+#if XA_CLOSE_HOLES_CHECK_EDGE_INTERSECTION
+ const uint32_t faceCount = mesh->faceCount();
+#endif
+ const bool compareNormal = equal(normal, Vector3(0.0f), FLT_EPSILON);
+ uint32_t frontCount = holeVertices.size();
+ Array<uint32_t> frontVertices;
+ Array<Vector3> frontPoints;
+ Array<float> frontAngles;
+ frontVertices.resize(frontCount);
+ frontPoints.resize(frontCount);
+ for (uint32_t i = 0; i < frontCount; i++) {
+ frontVertices[i] = holeVertices[i];
+ frontPoints[i] = mesh->position(frontVertices[i]);
+ }
+ while (frontCount >= 3) {
+ frontAngles.resize(frontCount);
+ float smallestAngle = kPi2, smallestAngleIgnoringNormal = kPi2;
+ uint32_t smallestAngleIndex = UINT32_MAX, smallestAngleIndexIgnoringNormal = UINT32_MAX;
+ for (uint32_t i = 0; i < frontCount; i++) {
+ const uint32_t i1 = i == 0 ? frontCount - 1 : i - 1;
+ const uint32_t i2 = i;
+ const uint32_t i3 = (i + 1) % frontCount;
+ const Vector3 edge1 = frontPoints[i1] - frontPoints[i2];
+ const Vector3 edge2 = frontPoints[i3] - frontPoints[i2];
+ frontAngles[i] = acosf(dot(edge1, edge2) / (length(edge1) * length(edge2)));
+ if (frontAngles[i] >= smallestAngle || isNan(frontAngles[i]))
+ continue;
+ // Don't duplicate edges.
+ if (mesh->findEdge(UINT32_MAX, frontVertices[i1], frontVertices[i2]) != UINT32_MAX)
+ continue;
+ if (mesh->findEdge(UINT32_MAX, frontVertices[i2], frontVertices[i3]) != UINT32_MAX)
+ continue;
+ if (mesh->findEdge(UINT32_MAX, frontVertices[i3], frontVertices[i1]) != UINT32_MAX)
+ continue;
+ /*
+ Make sure he new edge that would be formed by (i3, i1) doesn't intersect any vertices. This often happens when fixing t-junctions.
+
+ i2
+ *
+ / \
+ / \
+ i1 *--*--* i3
+ \ | /
+ \|/
+ *
+ */
+ bool intersection = false;
+ for (uint32_t j = 0; j < frontCount; j++) {
+ if (j == i1 || j == i2 || j == i3)
+ continue;
+ if (lineIntersectsPoint(frontPoints[j], frontPoints[i3], frontPoints[i1], nullptr, mesh->epsilon())) {
+ intersection = true;
+ break;
}
- if (!edge->isValid()) {
- return false;
+ }
+ if (intersection)
+ continue;
+ // Don't add the triangle if a boundary point lies on the same plane as the triangle, and is inside it.
+ intersection = false;
+ const Plane plane(frontPoints[i1], frontPoints[i2], frontPoints[i3]);
+ for (uint32_t j = 0; j < frontCount; j++) {
+ if (j == i1 || j == i2 || j == i3)
+ continue;
+ if (!isZero(plane.distance(frontPoints[j]), mesh->epsilon()))
+ continue;
+ if (pointInTriangle(frontPoints[j], frontPoints[i1], frontPoints[i2], frontPoints[i3])) {
+ intersection = true;
+ break;
}
- if (edge->pair->id != 2 * e + 1) {
- return false;
+ }
+ if (intersection)
+ continue;
+#if XA_CLOSE_HOLES_CHECK_EDGE_INTERSECTION
+ // Don't add the triangle if the new edge (i3, i1), intersects any other triangle that isn't part of the filled hole.
+ intersection = false;
+ const Vector3 newEdgeVector = frontPoints[i1] - frontPoints[i3];
+ for (uint32_t f = 0; f < faceCount; f++) {
+ Vector3 tri[3];
+ for (uint32_t j = 0; j < 3; j++)
+ tri[j] = mesh->position(mesh->vertexAt(f * 3 + j));
+ float t;
+ if (rayIntersectsTriangle(frontPoints[i3], newEdgeVector, tri, &t)) {
+ intersection = true;
+ break;
}
- if (!edge->pair->isValid()) {
- return false;
+ }
+ if (intersection)
+ continue;
+#endif
+ // Skip backwards facing triangles.
+ if (compareNormal) {
+ if (frontAngles[i] < smallestAngleIgnoringNormal) {
+ smallestAngleIgnoringNormal = frontAngles[i];
+ smallestAngleIndexIgnoringNormal = i;
}
+ const Vector3 e0 = frontPoints[i3] - frontPoints[i1];
+ const Vector3 e1 = frontPoints[i2] - frontPoints[i1];
+ const Vector3 triNormal = normalizeSafe(cross(e0, e1), Vector3(0.0f), mesh->epsilon());
+ if (dot(normal, triNormal) <= 0.0f)
+ continue;
}
+ smallestAngle = smallestAngleIgnoringNormal = frontAngles[i];
+ smallestAngleIndex = smallestAngleIndexIgnoringNormal = i;
}
- // @@ Make sure all faces are valid.
- // @@ Make sure all vertices are valid.
- return true;
+ // Closing holes failed if we don't have a smallest angle.
+ // Fallback to ignoring the backwards facing normal test if possible.
+ if (smallestAngleIndex == UINT32_MAX || smallestAngle <= 0.0f || smallestAngle >= kPi) {
+ if (smallestAngleIgnoringNormal == UINT32_MAX || smallestAngleIgnoringNormal <= 0.0f || smallestAngleIgnoringNormal >= kPi)
+ return false;
+ else
+ smallestAngleIndex = smallestAngleIndexIgnoringNormal;
+ }
+ const uint32_t i1 = smallestAngleIndex == 0 ? frontCount - 1 : smallestAngleIndex - 1;
+ const uint32_t i2 = smallestAngleIndex;
+ const uint32_t i3 = (smallestAngleIndex + 1) % frontCount;
+ const Mesh::AddFaceResult::Enum result = mesh->addFace(frontVertices[i1], frontVertices[i2], frontVertices[i3]);
+ XA_DEBUG_ASSERT(result == Mesh::AddFaceResult::OK); // Shouldn't happen due to the findEdge calls above.
+ XA_UNUSED(result);
+ frontVertices.removeAt(i2);
+ frontPoints.removeAt(i2);
+ frontCount = frontVertices.size();
}
+ return true;
+}
- // Error status:
-
- struct ErrorCode
- {
- enum Enum
- {
- AlreadyAddedEdge,
- DegenerateColocalEdge,
- DegenerateEdge,
- DuplicateEdge
- };
- };
-
- mutable ErrorCode::Enum errorCode;
- mutable uint32_t errorIndex0;
- mutable uint32_t errorIndex1;
+static bool meshCloseHoles(Mesh *mesh, const Array<uint32_t> &boundaryLoops, const Vector3 &normal, Array<uint32_t> &holeFaceCounts)
+{
+ holeFaceCounts.clear();
+ // Compute lengths.
+ const uint32_t boundaryCount = boundaryLoops.size();
+ Array<float> boundaryLengths;
+ Array<uint32_t> boundaryEdgeCounts;
+ boundaryEdgeCounts.resize(boundaryCount);
+ for (uint32_t i = 0; i < boundaryCount; i++) {
+ float boundaryLength = 0.0f;
+ boundaryEdgeCounts[i] = 0;
+ for (Mesh::BoundaryEdgeIterator it(mesh, boundaryLoops[i]); !it.isDone(); it.advance()) {
+ const Vector3 &t0 = mesh->position(mesh->vertexAt(meshEdgeIndex0(it.edge())));
+ const Vector3 &t1 = mesh->position(mesh->vertexAt(meshEdgeIndex1(it.edge())));
+ boundaryLength += length(t1 - t0);
+ boundaryEdgeCounts[i]++;
+ }
+ boundaryLengths.push_back(boundaryLength);
+ }
+ // Find disk boundary.
+ uint32_t diskBoundary = 0;
+ float maxLength = boundaryLengths[0];
+ for (uint32_t i = 1; i < boundaryCount; i++) {
+ if (boundaryLengths[i] > maxLength) {
+ maxLength = boundaryLengths[i];
+ diskBoundary = i;
+ }
+ }
+ // Close holes.
+ Array<uint32_t> holeVertices;
+ Array<Vector3> holePoints;
+ bool result = true;
+ for (uint32_t i = 0; i < boundaryCount; i++) {
+ if (diskBoundary == i)
+ continue; // Skip disk boundary.
+ holeVertices.resize(boundaryEdgeCounts[i]);
+ holePoints.resize(boundaryEdgeCounts[i]);
+ // Winding is backwards for internal boundaries.
+ uint32_t e = 0;
+ for (Mesh::BoundaryEdgeIterator it(mesh, boundaryLoops[i]); !it.isDone(); it.advance()) {
+ const uint32_t vertex = mesh->vertexAt(meshEdgeIndex0(it.edge()));
+ holeVertices[boundaryEdgeCounts[i] - 1 - e] = vertex;
+ holePoints[boundaryEdgeCounts[i] - 1 - e] = mesh->position(vertex);
+ e++;
+ }
+ const uint32_t oldFaceCount = mesh->faceCount();
+ if (!meshCloseHole(mesh, holeVertices, normal))
+ result = false; // Return false if any hole failed to close, but keep trying to close other holes.
+ holeFaceCounts.push_back(mesh->faceCount() - oldFaceCount);
+ }
+ return result;
+}
-private:
- // Return true if the face can be added to the manifold mesh.
- bool canAddFace(const std::vector<uint32_t> &indexArray, uint32_t first, uint32_t num) const
- {
- return canAddFace(indexArray.data(), first, num);
+static bool meshIsPlanar(const Mesh &mesh)
+{
+ const Vector3 p1 = mesh.position(mesh.vertexAt(0));
+ const Vector3 p2 = mesh.position(mesh.vertexAt(1));
+ const Vector3 p3 = mesh.position(mesh.vertexAt(2));
+ const Plane plane(p1, p2, p3);
+ const uint32_t vertexCount = mesh.vertexCount();
+ for (uint32_t v = 0; v < vertexCount; v++) {
+ const float d = plane.distance(mesh.position(v));
+ if (!isZero(d, mesh.epsilon()))
+ return false;
}
+ return true;
+}
- bool canAddFace(const uint32_t *indexArray, uint32_t first, uint32_t num) const
- {
- for (uint32_t j = num - 1, i = 0; i < num; j = i++) {
- if (!canAddEdge(indexArray[first + j], indexArray[first + i])) {
- errorIndex0 = indexArray[first + j];
- errorIndex1 = indexArray[first + i];
- return false;
- }
- }
- // We also have to make sure the face does not have any duplicate edge!
- for (uint32_t i = 0; i < num; i++) {
- int i0 = indexArray[first + i + 0];
- int i1 = indexArray[first + (i + 1) % num];
- for (uint32_t j = i + 1; j < num; j++) {
- int j0 = indexArray[first + j + 0];
- int j1 = indexArray[first + (j + 1) % num];
- if (i0 == j0 && i1 == j1) {
- errorCode = ErrorCode::DuplicateEdge;
- errorIndex0 = i0;
- errorIndex1 = i1;
- return false;
- }
- }
- }
- return true;
- }
+/*
+Fixing T-junctions.
- // Return true if the edge doesn't exist or doesn't have any adjacent face.
- bool canAddEdge(uint32_t i, uint32_t j) const
- {
- if (i == j) {
- // Skip degenerate edges.
- errorCode = ErrorCode::DegenerateEdge;
- return false;
- }
- // Same check, but taking into account colocal vertices.
- const Vertex *v0 = vertexAt(i);
- const Vertex *v1 = vertexAt(j);
- for (Vertex::ConstVertexIterator it(v0->colocals()); !it.isDone(); it.advance()) {
- if (it.current() == v1) {
- // Skip degenerate edges.
- errorCode = ErrorCode::DegenerateColocalEdge;
- return false;
- }
- }
- // Make sure edge has not been added yet.
- Edge *edge = findEdge(i, j);
- // We ignore edges that don't have an adjacent face yet, since this face could become the edge's face.
- if (!(edge == NULL || edge->face == NULL)) {
- errorCode = ErrorCode::AlreadyAddedEdge;
- return false;
- }
- return true;
- }
+- Find T-junctions. Find vertices that are on an edge.
+- This test is approximate.
+- Insert edges on a spatial index to speedup queries.
+- Consider only open edges, that is edges that have no pairs.
+- Consider only vertices on boundaries.
+- Close T-junction.
+- Split edge.
- Edge *addEdge(uint32_t i, uint32_t j)
+*/
+struct SplitEdge
+{
+ uint32_t edge;
+ float t;
+ uint32_t vertex;
+
+ bool operator<(const SplitEdge &other) const
{
- xaAssert(i != j);
- Edge *edge = findEdge(i, j);
- if (edge != NULL) {
- // Edge may already exist, but its face must not be set.
- xaDebugAssert(edge->face == NULL);
- // Nothing else to do!
- } else {
- // Add new edge.
- // Lookup pair.
- Edge *pair = findEdge(j, i);
- if (pair != NULL) {
- // Create edge with same id.
- edge = new Edge(pair->id + 1);
- // Link edge pairs.
- edge->pair = pair;
- pair->pair = edge;
- // @@ I'm not sure this is necessary!
- pair->vertex->setEdge(pair);
- } else {
- // Create edge.
- edge = new Edge(2 * m_edgeArray.size());
- // Add only unpaired edges.
- m_edgeArray.push_back(edge);
- }
- edge->vertex = m_vertexArray[i];
- m_edgeMap[Key(i, j)] = edge;
+ if (edge < other.edge)
+ return true;
+ else if (edge == other.edge) {
+ if (t < other.t)
+ return true;
}
- // Face and Next are set by addFace.
- return edge;
+ return false;
}
+};
- /// Find edge, test all colocals.
- Edge *findEdge(uint32_t i, uint32_t j) const
- {
- Edge *edge = NULL;
- const Vertex *v0 = vertexAt(i);
- const Vertex *v1 = vertexAt(j);
- // Test all colocal pairs.
- for (Vertex::ConstVertexIterator it0(v0->colocals()); !it0.isDone(); it0.advance()) {
- for (Vertex::ConstVertexIterator it1(v1->colocals()); !it1.isDone(); it1.advance()) {
- Key key(it0.current()->id, it1.current()->id);
- if (edge == NULL) {
- auto edgeIt = m_edgeMap.find(key);
- if (edgeIt != m_edgeMap.end())
- edge = (*edgeIt).second;
- #if !defined(_DEBUG)
- if (edge != NULL) return edge;
- #endif
- } else {
- // Make sure that only one edge is found.
- xaDebugAssert(m_edgeMap.find(key) == m_edgeMap.end());
+// Returns nullptr if there were no t-junctions to fix.
+static Mesh *meshFixTJunctions(const Mesh &inputMesh, bool *duplicatedEdge, bool *failed, uint32_t *fixedTJunctionsCount)
+{
+ if (duplicatedEdge)
+ *duplicatedEdge = false;
+ if (failed)
+ *failed = false;
+ Array<SplitEdge> splitEdges;
+ const uint32_t vertexCount = inputMesh.vertexCount();
+ const uint32_t edgeCount = inputMesh.edgeCount();
+ for (uint32_t v = 0; v < vertexCount; v++) {
+ if (!inputMesh.isBoundaryVertex(v))
+ continue;
+ // Find edges that this vertex overlaps with.
+ const Vector3 &pos = inputMesh.position(v);
+ for (uint32_t e = 0; e < edgeCount; e++) {
+ if (!inputMesh.isBoundaryEdge(e))
+ continue;
+ const Vector3 &edgePos1 = inputMesh.position(inputMesh.vertexAt(meshEdgeIndex0(e)));
+ const Vector3 &edgePos2 = inputMesh.position(inputMesh.vertexAt(meshEdgeIndex1(e)));
+ float t;
+ if (!lineIntersectsPoint(pos, edgePos1, edgePos2, &t, inputMesh.epsilon()))
+ continue;
+ SplitEdge splitEdge;
+ splitEdge.edge = e;
+ splitEdge.t = t;
+ splitEdge.vertex = v;
+ splitEdges.push_back(splitEdge);
+ }
+ }
+ if (splitEdges.isEmpty())
+ return nullptr;
+ const uint32_t faceCount = inputMesh.faceCount();
+ Mesh *mesh = XA_NEW(MemTag::Mesh, Mesh, inputMesh.epsilon(), vertexCount + splitEdges.size(), faceCount);
+ for (uint32_t v = 0; v < vertexCount; v++)
+ mesh->addVertex(inputMesh.position(v));
+ Array<uint32_t> indexArray;
+ indexArray.reserve(4);
+ Array<SplitEdge> faceSplitEdges;
+ faceSplitEdges.reserve(4);
+ for (uint32_t f = 0; f < faceCount; f++) {
+ // Find t-junctions in this face.
+ faceSplitEdges.clear();
+ for (uint32_t i = 0; i < splitEdges.size(); i++) {
+ if (meshEdgeFace(splitEdges[i].edge) == f)
+ faceSplitEdges.push_back(splitEdges[i]);
+ }
+ if (!faceSplitEdges.isEmpty()) {
+ // Need to split edges in winding order when a single edge has multiple t-junctions.
+ insertionSort(faceSplitEdges.data(), faceSplitEdges.size());
+ indexArray.clear();
+ for (Mesh::FaceEdgeIterator it(&inputMesh, f); !it.isDone(); it.advance()) {
+ indexArray.push_back(it.vertex0());
+ for (uint32_t se = 0; se < faceSplitEdges.size(); se++) {
+ const SplitEdge &splitEdge = faceSplitEdges[se];
+ if (splitEdge.edge == it.edge())
+ indexArray.push_back(splitEdge.vertex);
}
}
+ if (!meshCloseHole(mesh, indexArray, Vector3(0.0f))) {
+ if (failed)
+ *failed = true;
+ }
+ } else {
+ // No t-junctions in this face. Copy from input mesh.
+ if (mesh->addFace(&inputMesh.indices()[f * 3]) == Mesh::AddFaceResult::DuplicateEdge) {
+ if (duplicatedEdge)
+ *duplicatedEdge = true;
+ }
}
- return edge;
- }
-
- /// Link this boundary edge.
- void linkBoundaryEdge(Edge *edge)
- {
- xaAssert(edge->face == NULL);
- // Make sure next pointer has not been set. @@ We want to be able to relink boundary edges after mesh changes.
- Edge *next = edge;
- while (next->pair->face != NULL) {
- // Get pair prev
- Edge *e = next->pair->next;
- while (e->next != next->pair) {
- e = e->next;
- }
- next = e;
- }
- edge->setNext(next->pair);
- // Adjust vertex edge, so that it's the boundary edge. (required for isBoundary())
- if (edge->vertex->edge != edge) {
- // Multiple boundaries in the same edge.
- edge->vertex->edge = edge;
- }
- }
-
- Vertex *splitBoundaryEdge(Edge *edge, float t, const Vector3 &pos)
- {
- /*
- We want to go from this configuration:
-
- + +
- | ^
- edge |<->| pair
- v |
- + +
-
- To this one:
-
- + +
- | ^
- e0 |<->| p0
- v |
- vertex + +
- | ^
- e1 |<->| p1
- v |
- + +
-
- */
- Edge *pair = edge->pair;
- // Make sure boundaries are linked.
- xaDebugAssert(pair != NULL);
- // Make sure edge is a boundary edge.
- xaDebugAssert(pair->face == NULL);
- // Add new vertex.
- Vertex *vertex = addVertex(pos);
- vertex->nor = lerp(edge->from()->nor, edge->to()->nor, t);
- vertex->tex = lerp(edge->from()->tex, edge->to()->tex, t);
- disconnect(edge);
- disconnect(pair);
- // Add edges.
- Edge *e0 = addEdge(edge->from()->id, vertex->id);
- Edge *p0 = addEdge(vertex->id, pair->to()->id);
- Edge *e1 = addEdge(vertex->id, edge->to()->id);
- Edge *p1 = addEdge(pair->from()->id, vertex->id);
- // Link edges.
- e0->setNext(e1);
- p1->setNext(p0);
- e0->setPrev(edge->prev);
- e1->setNext(edge->next);
- p1->setPrev(pair->prev);
- p0->setNext(pair->next);
- xaDebugAssert(e0->next == e1);
- xaDebugAssert(e1->prev == e0);
- xaDebugAssert(p1->next == p0);
- xaDebugAssert(p0->prev == p1);
- xaDebugAssert(p0->pair == e0);
- xaDebugAssert(e0->pair == p0);
- xaDebugAssert(p1->pair == e1);
- xaDebugAssert(e1->pair == p1);
- // Link faces.
- e0->face = edge->face;
- e1->face = edge->face;
- // Link vertices.
- edge->from()->setEdge(e0);
- vertex->setEdge(e1);
- delete edge;
- delete pair;
- return vertex;
}
+ if (fixedTJunctionsCount)
+ *fixedTJunctionsCount = splitEdges.size();
+ return mesh;
+}
-private:
- std::vector<Vertex *> m_vertexArray;
- std::vector<Edge *> m_edgeArray;
- std::vector<Face *> m_faceArray;
-
- struct Key
- {
- Key() {}
- Key(const Key &k) : p0(k.p0), p1(k.p1) {}
- Key(uint32_t v0, uint32_t v1) : p0(v0), p1(v1) {}
- void operator=(const Key &k)
- {
- p0 = k.p0;
- p1 = k.p1;
- }
- bool operator==(const Key &k) const
- {
- return p0 == k.p0 && p1 == k.p1;
- }
-
- uint32_t p0;
- uint32_t p1;
- };
-
- friend struct Hash<Mesh::Key>;
- std::unordered_map<Key, Edge *, Hash<Key>, Equal<Key> > m_edgeMap;
- uint32_t m_colocalVertexCount;
-};
+// boundaryLoops are the first edges for each boundary loop.
+static void meshGetBoundaryLoops(const Mesh &mesh, Array<uint32_t> &boundaryLoops)
+{
+ const uint32_t edgeCount = mesh.edgeCount();
+ BitArray bitFlags(edgeCount);
+ bitFlags.clearAll();
+ boundaryLoops.clear();
+ // Search for boundary edges. Mark all the edges that belong to the same boundary.
+ for (uint32_t e = 0; e < edgeCount; e++) {
+ if (bitFlags.bitAt(e) || !mesh.isBoundaryEdge(e))
+ continue;
+ for (Mesh::BoundaryEdgeIterator it(&mesh, e); !it.isDone(); it.advance())
+ bitFlags.setBitAt(it.edge());
+ boundaryLoops.push_back(e);
+ }
+}
class MeshTopology
{
public:
MeshTopology(const Mesh *mesh)
{
- buildTopologyInfo(mesh);
- }
-
- /// Determine if the mesh is connected.
- bool isConnected() const
- {
- return m_connectedCount == 1;
- }
-
- /// Determine if the mesh is closed. (Each edge is shared by two faces)
- bool isClosed() const
- {
- return m_boundaryCount == 0;
- }
-
- /// Return true if the mesh has the topology of a disk.
- bool isDisk() const
- {
- return isConnected() && m_boundaryCount == 1/* && m_eulerNumber == 1*/;
- }
-
-private:
- void buildTopologyInfo(const Mesh *mesh)
- {
const uint32_t vertexCount = mesh->colocalVertexCount();
const uint32_t faceCount = mesh->faceCount();
const uint32_t edgeCount = mesh->edgeCount();
- xaPrint( "--- Building mesh topology:\n" );
- std::vector<uint32_t> stack(faceCount);
+ Array<uint32_t> stack(MemTag::Default);
+ stack.reserve(faceCount);
BitArray bitFlags(faceCount);
bitFlags.clearAll();
// Compute connectivity.
- xaPrint( "--- Computing connectivity.\n" );
m_connectedCount = 0;
for (uint32_t f = 0; f < faceCount; f++ ) {
- if ( bitFlags.bitAt(f) == false ) {
+ if (bitFlags.bitAt(f) == false) {
m_connectedCount++;
- stack.push_back( f );
- while ( !stack.empty() ) {
+ stack.push_back(f);
+ while (!stack.isEmpty()) {
const uint32_t top = stack.back();
- xaAssert(top != uint32_t(~0));
+ XA_ASSERT(top != uint32_t(~0));
stack.pop_back();
- if ( bitFlags.bitAt(top) == false ) {
+ if (bitFlags.bitAt(top) == false) {
bitFlags.setBitAt(top);
- const Face *face = mesh->faceAt(top);
- const Edge *firstEdge = face->edge;
- const Edge *edge = firstEdge;
- do {
- const Face *neighborFace = edge->pair->face;
- if (neighborFace != NULL) {
- stack.push_back(neighborFace->id);
- }
- edge = edge->next;
- } while (edge != firstEdge);
+ for (Mesh::FaceEdgeIterator it(mesh, top); !it.isDone(); it.advance()) {
+ const uint32_t oppositeFace = it.oppositeFace();
+ if (oppositeFace != UINT32_MAX)
+ stack.push_back(oppositeFace);
+ }
}
}
}
}
- xaAssert(stack.empty());
- xaPrint( "--- %d connected components.\n", m_connectedCount );
+ XA_ASSERT(stack.isEmpty());
// Count boundary loops.
- xaPrint( "--- Counting boundary loops.\n" );
m_boundaryCount = 0;
bitFlags.resize(edgeCount);
bitFlags.clearAll();
// Don't forget to link the boundary otherwise this won't work.
for (uint32_t e = 0; e < edgeCount; e++) {
- const Edge *startEdge = mesh->edgeAt(e);
- if (startEdge != NULL && startEdge->isBoundary() && bitFlags.bitAt(e) == false) {
- xaDebugAssert(startEdge->face != NULL);
- xaDebugAssert(startEdge->pair->face == NULL);
- startEdge = startEdge->pair;
- m_boundaryCount++;
- const Edge *edge = startEdge;
- do {
- bitFlags.setBitAt(edge->id / 2);
- edge = edge->next;
- } while (startEdge != edge);
- }
- }
- xaPrint("--- %d boundary loops found.\n", m_boundaryCount );
+ if (bitFlags.bitAt(e) || !mesh->isBoundaryEdge(e))
+ continue;
+ m_boundaryCount++;
+ for (Mesh::BoundaryEdgeIterator it(mesh, e); !it.isDone(); it.advance())
+ bitFlags.setBitAt(it.edge());
+ }
// Compute euler number.
m_eulerNumber = vertexCount - edgeCount + faceCount;
- xaPrint("--- Euler number: %d.\n", m_eulerNumber);
// Compute genus. (only valid on closed connected surfaces)
m_genus = -1;
- if ( isClosed() && isConnected() ) {
+ if (isClosed() && isConnected())
m_genus = (2 - m_eulerNumber) / 2;
- xaPrint("--- Genus: %d.\n", m_genus);
- }
+ }
+
+ /// Determine if the mesh is connected.
+ bool isConnected() const
+ {
+ return m_connectedCount == 1;
+ }
+
+ /// Determine if the mesh is closed. (Each edge is shared by two faces)
+ bool isClosed() const
+ {
+ return m_boundaryCount == 0;
+ }
+
+ /// Return true if the mesh has the topology of a disk.
+ bool isDisk() const
+ {
+ return isConnected() && m_boundaryCount == 1/* && m_eulerNumber == 1*/;
}
private:
@@ -2843,702 +3480,320 @@ private:
int m_genus;
};
-float computeSurfaceArea(const halfedge::Mesh *mesh)
-{
- float area = 0;
- for (halfedge::Mesh::ConstFaceIterator it(mesh->faces()); !it.isDone(); it.advance()) {
- const halfedge::Face *face = it.current();
- area += face->area();
- }
- xaDebugAssert(area >= 0);
- return area;
-}
-
-float computeParametricArea(const halfedge::Mesh *mesh)
-{
- float area = 0;
- for (halfedge::Mesh::ConstFaceIterator it(mesh->faces()); !it.isDone(); it.advance()) {
- const halfedge::Face *face = it.current();
- area += face->parametricArea();
- }
- return area;
-}
-
-uint32_t countMeshTriangles(const Mesh *mesh)
+struct Progress
{
- const uint32_t faceCount = mesh->faceCount();
- uint32_t triangleCount = 0;
- for (uint32_t f = 0; f < faceCount; f++) {
- const Face *face = mesh->faceAt(f);
- uint32_t edgeCount = face->edgeCount();
- xaDebugAssert(edgeCount > 2);
- triangleCount += edgeCount - 2;
- }
- return triangleCount;
-}
-
-Mesh *unifyVertices(const Mesh *inputMesh)
-{
- Mesh *mesh = new Mesh;
- // Only add the first colocal.
- const uint32_t vertexCount = inputMesh->vertexCount();
- for (uint32_t v = 0; v < vertexCount; v++) {
- const Vertex *vertex = inputMesh->vertexAt(v);
- if (vertex->isFirstColocal()) {
- mesh->addVertex(vertex->pos);
- }
- }
- std::vector<uint32_t> indexArray;
- // Add new faces pointing to first colocals.
- uint32_t faceCount = inputMesh->faceCount();
- for (uint32_t f = 0; f < faceCount; f++) {
- const Face *face = inputMesh->faceAt(f);
- indexArray.clear();
- for (Face::ConstEdgeIterator it(face->edges()); !it.isDone(); it.advance()) {
- const Edge *edge = it.current();
- const Vertex *vertex = edge->vertex->firstColocal();
- indexArray.push_back(vertex->id);
- }
- mesh->addFace(indexArray);
- }
- mesh->linkBoundary();
- return mesh;
-}
-
-static bool pointInTriangle(const Vector2 &p, const Vector2 &a, const Vector2 &b, const Vector2 &c)
-{
- return triangleArea(a, b, p) >= 0.00001f &&
- triangleArea(b, c, p) >= 0.00001f &&
- triangleArea(c, a, p) >= 0.00001f;
-}
-
-// This is doing a simple ear-clipping algorithm that skips invalid triangles. Ideally, we should
-// also sort the ears by angle, start with the ones that have the smallest angle and proceed in order.
-Mesh *triangulate(const Mesh *inputMesh)
-{
- Mesh *mesh = new Mesh;
- // Add all vertices.
- const uint32_t vertexCount = inputMesh->vertexCount();
- for (uint32_t v = 0; v < vertexCount; v++) {
- const Vertex *vertex = inputMesh->vertexAt(v);
- mesh->addVertex(vertex->pos);
- }
- std::vector<int> polygonVertices;
- std::vector<float> polygonAngles;
- std::vector<Vector2> polygonPoints;
- const uint32_t faceCount = inputMesh->faceCount();
- for (uint32_t f = 0; f < faceCount; f++) {
- const Face *face = inputMesh->faceAt(f);
- xaDebugAssert(face != NULL);
- const uint32_t edgeCount = face->edgeCount();
- xaDebugAssert(edgeCount >= 3);
- polygonVertices.clear();
- polygonVertices.reserve(edgeCount);
- if (edgeCount == 3) {
- // Simple case for triangles.
- for (Face::ConstEdgeIterator it(face->edges()); !it.isDone(); it.advance()) {
- const Edge *edge = it.current();
- const Vertex *vertex = edge->vertex;
- polygonVertices.push_back(vertex->id);
- }
- int v0 = polygonVertices[0];
- int v1 = polygonVertices[1];
- int v2 = polygonVertices[2];
- mesh->addFace(v0, v1, v2);
- } else {
- // Build 2D polygon projecting vertices onto normal plane.
- // Faces are not necesarily planar, this is for example the case, when the face comes from filling a hole. In such cases
- // it's much better to use the best fit plane.
- const Vector3 fn = face->normal();
- Basis basis;
- basis.buildFrameForDirection(fn);
- polygonPoints.clear();
- polygonPoints.reserve(edgeCount);
- polygonAngles.clear();
- polygonAngles.reserve(edgeCount);
- for (Face::ConstEdgeIterator it(face->edges()); !it.isDone(); it.advance()) {
- const Edge *edge = it.current();
- const Vertex *vertex = edge->vertex;
- polygonVertices.push_back(vertex->id);
- Vector2 p;
- p.x = dot(basis.tangent, vertex->pos);
- p.y = dot(basis.bitangent, vertex->pos);
- polygonPoints.push_back(p);
- }
- polygonAngles.resize(edgeCount);
- while (polygonVertices.size() > 2) {
- uint32_t size = polygonVertices.size();
- // Update polygon angles. @@ Update only those that have changed.
- float minAngle = 2 * PI;
- uint32_t bestEar = 0; // Use first one if none of them is valid.
- bool bestIsValid = false;
- for (uint32_t i = 0; i < size; i++) {
- uint32_t i0 = i;
- uint32_t i1 = (i + 1) % size; // Use Sean's polygon interation trick.
- uint32_t i2 = (i + 2) % size;
- Vector2 p0 = polygonPoints[i0];
- Vector2 p1 = polygonPoints[i1];
- Vector2 p2 = polygonPoints[i2];
-
- // -- GODOT start --
- bool degenerate = distance(p0, p1) < NV_EPSILON || distance(p0, p2) < NV_EPSILON || distance(p1, p2) < NV_EPSILON;
- if (degenerate) {
- continue;
- }
- // -- GODOT end --
-
- float d = clamp(dot(p0 - p1, p2 - p1) / (length(p0 - p1) * length(p2 - p1)), -1.0f, 1.0f);
- float angle = acosf(d);
- float area = triangleArea(p0, p1, p2);
- if (area < 0.0f) angle = 2.0f * PI - angle;
- polygonAngles[i1] = angle;
- if (angle < minAngle || !bestIsValid) {
- // Make sure this is a valid ear, if not, skip this point.
- bool valid = true;
- for (uint32_t j = 0; j < size; j++) {
- if (j == i0 || j == i1 || j == i2) continue;
- Vector2 p = polygonPoints[j];
- if (pointInTriangle(p, p0, p1, p2)) {
- valid = false;
- break;
- }
- }
- if (valid || !bestIsValid) {
- minAngle = angle;
- bestEar = i1;
- bestIsValid = valid;
- }
- }
- }
- // -- GODOT start --
- if (!bestIsValid)
- break;
- // -- GODOT end --
-
- xaDebugAssert(minAngle <= 2 * PI);
- // Clip best ear:
- uint32_t i0 = (bestEar + size - 1) % size;
- uint32_t i1 = (bestEar + 0) % size;
- uint32_t i2 = (bestEar + 1) % size;
- int v0 = polygonVertices[i0];
- int v1 = polygonVertices[i1];
- int v2 = polygonVertices[i2];
- mesh->addFace(v0, v1, v2);
- polygonVertices.erase(polygonVertices.begin() + i1);
- polygonPoints.erase(polygonPoints.begin() + i1);
- polygonAngles.erase(polygonAngles.begin() + i1);
- }
- }
- }
- mesh->linkBoundary();
- return mesh;
-}
-
-} // namespace halfedge
-
-/// Mersenne twister random number generator.
-class MTRand
-{
-public:
- enum time_e { Time };
- enum { N = 624 }; // length of state vector
- enum { M = 397 };
-
- /// Constructor that uses the current time as the seed.
- MTRand( time_e )
+ Progress(ProgressCategory::Enum category, ProgressFunc func, void *userData, uint32_t maxValue) : value(0), cancel(false), m_category(category), m_func(func), m_userData(userData), m_maxValue(maxValue), m_progress(0)
{
- seed((uint32_t )time(NULL));
- }
-
- /// Constructor that uses the given seed.
- MTRand( uint32_t s = 0 )
- {
- seed(s);
- }
-
- /// Provide a new seed.
- void seed( uint32_t s )
- {
- initialize(s);
- reload();
+ if (m_func) {
+ if (!m_func(category, 0, userData))
+ cancel = true;
+ }
}
- /// Get a random number between 0 - 65536.
- uint32_t get()
+ ~Progress()
{
- // Pull a 32-bit integer from the generator state
- // Every other access function simply transforms the numbers extracted here
- if ( left == 0 ) {
- reload();
+ if (m_func) {
+ if (!m_func(m_category, 100, m_userData))
+ cancel = true;
}
- left--;
- uint32_t s1;
- s1 = *next++;
- s1 ^= (s1 >> 11);
- s1 ^= (s1 << 7) & 0x9d2c5680U;
- s1 ^= (s1 << 15) & 0xefc60000U;
- return ( s1 ^ (s1 >> 18) );
- };
-
- /// Get a random number on [0, max] interval.
- uint32_t getRange( uint32_t max )
- {
- if (max == 0) return 0;
- if (max == NV_UINT32_MAX) return get();
- const uint32_t np2 = nextPowerOfTwo( max + 1 ); // @@ This fails if max == NV_UINT32_MAX
- const uint32_t mask = np2 - 1;
- uint32_t n;
- do {
- n = get() & mask;
- } while ( n > max );
- return n;
}
-private:
- void initialize( uint32_t seed )
+ void update()
{
- // Initialize generator state with seed
- // See Knuth TAOCP Vol 2, 3rd Ed, p.106 for multiplier.
- // In previous versions, most significant bits (MSBs) of the seed affect
- // only MSBs of the state array. Modified 9 Jan 2002 by Makoto Matsumoto.
- uint32_t *s = state;
- uint32_t *r = state;
- int i = 1;
- *s++ = seed & 0xffffffffUL;
- for ( ; i < N; ++i ) {
- *s++ = ( 1812433253UL * ( *r ^ (*r >> 30) ) + i ) & 0xffffffffUL;
- r++;
+ if (!m_func)
+ return;
+ m_mutex.lock();
+ const uint32_t newProgress = uint32_t(ceilf(value.load() / (float)m_maxValue * 100.0f));
+ if (newProgress != m_progress && newProgress < 100) {
+ m_progress = newProgress;
+ if (!m_func(m_category, m_progress, m_userData))
+ cancel = true;
}
+ m_mutex.unlock();
}
- void reload()
+ void setMaxValue(uint32_t maxValue)
{
- // Generate N new values in state
- // Made clearer and faster by Matthew Bellew (matthew.bellew@home.com)
- uint32_t *p = state;
- int i;
- for ( i = N - M; i--; ++p )
- *p = twist( p[M], p[0], p[1] );
- for ( i = M; --i; ++p )
- *p = twist( p[M - N], p[0], p[1] );
- *p = twist( p[M - N], p[0], state[0] );
- left = N, next = state;
+ m_mutex.lock();
+ m_maxValue = maxValue;
+ m_mutex.unlock();
}
- uint32_t hiBit( uint32_t u ) const
- {
- return u & 0x80000000U;
- }
- uint32_t loBit( uint32_t u ) const
- {
- return u & 0x00000001U;
- }
- uint32_t loBits( uint32_t u ) const
- {
- return u & 0x7fffffffU;
- }
- uint32_t mixBits( uint32_t u, uint32_t v ) const
- {
- return hiBit(u) | loBits(v);
- }
- uint32_t twist( uint32_t m, uint32_t s0, uint32_t s1 ) const
- {
- return m ^ (mixBits(s0, s1) >> 1) ^ ((~loBit(s1) + 1) & 0x9908b0dfU);
- }
+ std::atomic<uint32_t> value;
+ std::atomic<bool> cancel;
- uint32_t state[N]; // internal state
- uint32_t *next; // next value to get from state
- int left; // number of values left before reload needed
+private:
+ ProgressCategory::Enum m_category;
+ ProgressFunc m_func;
+ void *m_userData;
+ uint32_t m_maxValue;
+ uint32_t m_progress;
+ std::mutex m_mutex;
};
-namespace morton {
-// Code from ryg:
-// http://fgiesen.wordpress.com/2009/12/13/decoding-morton-codes/
-
-// Inverse of part1By1 - "delete" all odd-indexed bits
-uint32_t compact1By1(uint32_t x)
-{
- x &= 0x55555555; // x = -f-e -d-c -b-a -9-8 -7-6 -5-4 -3-2 -1-0
- x = (x ^ (x >> 1)) & 0x33333333; // x = --fe --dc --ba --98 --76 --54 --32 --10
- x = (x ^ (x >> 2)) & 0x0f0f0f0f; // x = ---- fedc ---- ba98 ---- 7654 ---- 3210
- x = (x ^ (x >> 4)) & 0x00ff00ff; // x = ---- ---- fedc ba98 ---- ---- 7654 3210
- x = (x ^ (x >> 8)) & 0x0000ffff; // x = ---- ---- ---- ---- fedc ba98 7654 3210
- return x;
-}
-
-// Inverse of part1By2 - "delete" all bits not at positions divisible by 3
-uint32_t compact1By2(uint32_t x)
+struct Spinlock
{
- x &= 0x09249249; // x = ---- 9--8 --7- -6-- 5--4 --3- -2-- 1--0
- x = (x ^ (x >> 2)) & 0x030c30c3; // x = ---- --98 ---- 76-- --54 ---- 32-- --10
- x = (x ^ (x >> 4)) & 0x0300f00f; // x = ---- --98 ---- ---- 7654 ---- ---- 3210
- x = (x ^ (x >> 8)) & 0xff0000ff; // x = ---- --98 ---- ---- ---- ---- 7654 3210
- x = (x ^ (x >> 16)) & 0x000003ff; // x = ---- ---- ---- ---- ---- --98 7654 3210
- return x;
-}
-
-uint32_t decodeMorton2X(uint32_t code)
-{
- return compact1By1(code >> 0);
-}
+ void lock() { while(m_lock.test_and_set(std::memory_order_acquire)) {} }
+ void unlock() { m_lock.clear(std::memory_order_release); }
-uint32_t decodeMorton2Y(uint32_t code)
-{
- return compact1By1(code >> 1);
-}
+private:
+ std::atomic_flag m_lock = ATOMIC_FLAG_INIT;
+};
-uint32_t decodeMorton3X(uint32_t code)
+struct TaskGroupHandle
{
- return compact1By2(code >> 0);
-}
+ uint32_t value = UINT32_MAX;
+};
-uint32_t decodeMorton3Y(uint32_t code)
+struct Task
{
- return compact1By2(code >> 1);
-}
+ void (*func)(void *userData);
+ void *userData;
+};
-uint32_t decodeMorton3Z(uint32_t code)
+#if XA_MULTITHREADED
+class TaskScheduler
{
- return compact1By2(code >> 2);
-}
-} // namespace morton
-
-// A simple, dynamic proximity grid based on Jon's code.
-// Instead of storing pointers here I store indices.
-struct ProximityGrid
-{
- void init(const Box &box, uint32_t count)
- {
- cellArray.clear();
- // Determine grid size.
- float cellWidth;
- Vector3 diagonal = box.extents() * 2.f;
- float volume = box.volume();
- if (equal(volume, 0)) {
- // Degenerate box, treat like a quad.
- Vector2 quad;
- if (diagonal.x < diagonal.y && diagonal.x < diagonal.z) {
- quad.x = diagonal.y;
- quad.y = diagonal.z;
- } else if (diagonal.y < diagonal.x && diagonal.y < diagonal.z) {
- quad.x = diagonal.x;
- quad.y = diagonal.z;
- } else {
- quad.x = diagonal.x;
- quad.y = diagonal.y;
- }
- float cellArea = quad.x * quad.y / count;
- cellWidth = sqrtf(cellArea); // pow(cellArea, 1.0f / 2.0f);
- } else {
- // Ideally we want one cell per point.
- float cellVolume = volume / count;
- cellWidth = powf(cellVolume, 1.0f / 3.0f);
- }
- xaDebugAssert(cellWidth != 0);
- sx = std::max(1, ftoi_ceil(diagonal.x / cellWidth));
- sy = std::max(1, ftoi_ceil(diagonal.y / cellWidth));
- sz = std::max(1, ftoi_ceil(diagonal.z / cellWidth));
- invCellSize.x = float(sx) / diagonal.x;
- invCellSize.y = float(sy) / diagonal.y;
- invCellSize.z = float(sz) / diagonal.z;
- cellArray.resize(sx * sy * sz);
- corner = box.minCorner; // @@ Align grid better?
- }
-
- int index_x(float x) const
- {
- return clamp(ftoi_floor((x - corner.x) * invCellSize.x), 0, sx - 1);
- }
-
- int index_y(float y) const
+public:
+ TaskScheduler() : m_shutdown(false)
{
- return clamp(ftoi_floor((y - corner.y) * invCellSize.y), 0, sy - 1);
+ // Max with current task scheduler usage is 1 per thread + 1 deep nesting, but allow for some slop.
+ m_maxGroups = std::thread::hardware_concurrency() * 4;
+ m_groups = XA_ALLOC_ARRAY(MemTag::Default, TaskGroup, m_maxGroups);
+ for (uint32_t i = 0; i < m_maxGroups; i++) {
+ new (&m_groups[i]) TaskGroup();
+ m_groups[i].free = true;
+ m_groups[i].ref = 0;
+ }
+ m_workers.resize(std::thread::hardware_concurrency() <= 1 ? 1 : std::thread::hardware_concurrency() - 1);
+ for (uint32_t i = 0; i < m_workers.size(); i++) {
+ m_workers[i].wakeup = false;
+ m_workers[i].thread = XA_NEW(MemTag::Default, std::thread, workerThread, this, &m_workers[i]);
+ }
}
- int index_z(float z) const
+ ~TaskScheduler()
{
- return clamp(ftoi_floor((z - corner.z) * invCellSize.z), 0, sz - 1);
+ m_shutdown = true;
+ for (uint32_t i = 0; i < m_workers.size(); i++) {
+ Worker &worker = m_workers[i];
+ XA_DEBUG_ASSERT(worker.thread);
+ worker.wakeup = true;
+ worker.cv.notify_one();
+ if (worker.thread->joinable())
+ worker.thread->join();
+ worker.thread->~thread();
+ XA_FREE(worker.thread);
+ }
+ for (uint32_t i = 0; i < m_maxGroups; i++)
+ m_groups[i].~TaskGroup();
+ XA_FREE(m_groups);
}
- int index(int x, int y, int z) const
+ TaskGroupHandle createTaskGroup(uint32_t reserveSize = 0)
{
- xaDebugAssert(x >= 0 && x < sx);
- xaDebugAssert(y >= 0 && y < sy);
- xaDebugAssert(z >= 0 && z < sz);
- int idx = (z * sy + y) * sx + x;
- xaDebugAssert(idx >= 0 && uint32_t(idx) < cellArray.size());
- return idx;
+ // Claim the first free group.
+ for (uint32_t i = 0; i < m_maxGroups; i++) {
+ TaskGroup &group = m_groups[i];
+ bool expected = true;
+ if (!group.free.compare_exchange_strong(expected, false))
+ continue;
+ group.queueLock.lock();
+ group.queueHead = 0;
+ group.queue.clear();
+ group.queue.reserve(reserveSize);
+ group.queueLock.unlock();
+ TaskGroupHandle handle;
+ handle.value = i;
+ return handle;
+ }
+ XA_DEBUG_ASSERT(false);
+ TaskGroupHandle handle;
+ handle.value = UINT32_MAX;
+ return handle;
}
- uint32_t mortonCount() const
+ void run(TaskGroupHandle handle, Task task)
{
- uint64_t s = uint64_t(max3(sx, sy, sz));
- s = nextPowerOfTwo(s);
- if (s > 1024) {
- return uint32_t(s * s * min3(sx, sy, sz));
+ XA_DEBUG_ASSERT(handle.value != UINT32_MAX);
+ TaskGroup &group = m_groups[handle.value];
+ group.queueLock.lock();
+ group.queue.push_back(task);
+ group.queueLock.unlock();
+ group.ref++;
+ // Wake up a worker to run this task.
+ for (uint32_t i = 0; i < m_workers.size(); i++) {
+ m_workers[i].wakeup = true;
+ m_workers[i].cv.notify_one();
}
- return uint32_t(s * s * s);
}
- int mortonIndex(uint32_t code) const
+ void wait(TaskGroupHandle *handle)
{
- uint32_t x, y, z;
- uint32_t s = uint32_t(max3(sx, sy, sz));
- if (s > 1024) {
- // Use layered two-dimensional morton order.
- s = nextPowerOfTwo(s);
- uint32_t layer = code / (s * s);
- code = code % (s * s);
- uint32_t layer_count = uint32_t(min3(sx, sy, sz));
- if (sx == (int)layer_count) {
- x = layer;
- y = morton::decodeMorton2X(code);
- z = morton::decodeMorton2Y(code);
- } else if (sy == (int)layer_count) {
- x = morton::decodeMorton2Y(code);
- y = layer;
- z = morton::decodeMorton2X(code);
- } else { /*if (sz == layer_count)*/
- x = morton::decodeMorton2X(code);
- y = morton::decodeMorton2Y(code);
- z = layer;
- }
- } else {
- x = morton::decodeMorton3X(code);
- y = morton::decodeMorton3Y(code);
- z = morton::decodeMorton3Z(code);
+ if (handle->value == UINT32_MAX) {
+ XA_DEBUG_ASSERT(false);
+ return;
}
- if (x >= uint32_t(sx) || y >= uint32_t(sy) || z >= uint32_t(sz)) {
- return -1;
+ // Run tasks from the group queue until empty.
+ TaskGroup &group = m_groups[handle->value];
+ for (;;) {
+ Task *task = nullptr;
+ group.queueLock.lock();
+ if (group.queueHead < group.queue.size())
+ task = &group.queue[group.queueHead++];
+ group.queueLock.unlock();
+ if (!task)
+ break;
+ task->func(task->userData);
+ group.ref--;
}
- return index(x, y, z);
+ // Even though the task queue is empty, workers can still be running tasks.
+ while (group.ref > 0)
+ std::this_thread::yield();
+ group.free = true;
+ handle->value = UINT32_MAX;
}
- void add(const Vector3 &pos, uint32_t key)
+private:
+ struct TaskGroup
{
- int x = index_x(pos.x);
- int y = index_y(pos.y);
- int z = index_z(pos.z);
- uint32_t idx = index(x, y, z);
- cellArray[idx].indexArray.push_back(key);
- }
+ std::atomic<bool> free;
+ Array<Task> queue; // Items are never removed. queueHead is incremented to pop items.
+ uint32_t queueHead = 0;
+ Spinlock queueLock;
+ std::atomic<uint32_t> ref; // Increment when a task is enqueued, decrement when a task finishes.
+ };
- // Gather all points inside the given sphere.
- // Radius is assumed to be small, so we don't bother culling the cells.
- void gather(const Vector3 &position, float radius, std::vector<uint32_t> &indexArray)
+ struct Worker
{
- int x0 = index_x(position.x - radius);
- int x1 = index_x(position.x + radius);
- int y0 = index_y(position.y - radius);
- int y1 = index_y(position.y + radius);
- int z0 = index_z(position.z - radius);
- int z1 = index_z(position.z + radius);
- for (int z = z0; z <= z1; z++) {
- for (int y = y0; y <= y1; y++) {
- for (int x = x0; x <= x1; x++) {
- int idx = index(x, y, z);
- indexArray.insert(indexArray.begin(), cellArray[idx].indexArray.begin(), cellArray[idx].indexArray.end());
+ std::thread *thread = nullptr;
+ std::mutex mutex;
+ std::condition_variable cv;
+ std::atomic<bool> wakeup;
+ };
+
+ TaskGroup *m_groups;
+ uint32_t m_maxGroups;
+ Array<Worker> m_workers;
+ std::atomic<bool> m_shutdown;
+
+ static void workerThread(TaskScheduler *scheduler, Worker *worker)
+ {
+ std::unique_lock<std::mutex> lock(worker->mutex);
+ for (;;) {
+ worker->cv.wait(lock, [=]{ return worker->wakeup.load(); });
+ worker->wakeup = false;
+ for (;;) {
+ if (scheduler->m_shutdown)
+ return;
+ // Look for a task in any of the groups and run it.
+ TaskGroup *group = nullptr;
+ Task *task = nullptr;
+ for (uint32_t i = 0; i < scheduler->m_maxGroups; i++) {
+ group = &scheduler->m_groups[i];
+ if (group->free || group->ref == 0)
+ continue;
+ group->queueLock.lock();
+ if (group->queueHead < group->queue.size()) {
+ task = &group->queue[group->queueHead++];
+ group->queueLock.unlock();
+ break;
+ }
+ group->queueLock.unlock();
}
+ if (!task)
+ break;
+ task->func(task->userData);
+ group->ref--;
}
}
}
-
- struct Cell {
- std::vector<uint32_t> indexArray;
- };
-
- std::vector<Cell> cellArray;
-
- Vector3 corner;
- Vector3 invCellSize;
- int sx, sy, sz;
};
-
-// Based on Pierre Terdiman's and Michael Herf's source code.
-// http://www.codercorner.com/RadixSortRevisited.htm
-// http://www.stereopsis.com/radix.html
-class RadixSort
+#else
+class TaskScheduler
{
public:
- RadixSort() : m_size(0), m_ranks(NULL), m_ranks2(NULL), m_validRanks(false) {}
- ~RadixSort()
+ ~TaskScheduler()
{
- // Release everything
- free(m_ranks2);
- free(m_ranks);
+ for (uint32_t i = 0; i < m_groups.size(); i++)
+ destroyGroup({ i });
}
- RadixSort &sort(const float *input, uint32_t count)
+ TaskGroupHandle createTaskGroup(uint32_t reserveSize = 0)
{
- if (input == NULL || count == 0) return *this;
- // Resize lists if needed
- if (count != m_size) {
- if (count > m_size) {
- m_ranks2 = (uint32_t *)realloc(m_ranks2, sizeof(uint32_t ) * count);
- m_ranks = (uint32_t *)realloc(m_ranks, sizeof(uint32_t ) * count);
- }
- m_size = count;
- m_validRanks = false;
- }
- if (count < 32) {
- insertionSort(input, count);
- } else {
- // @@ Avoid touching the input multiple times.
- for (uint32_t i = 0; i < count; i++) {
- FloatFlip((uint32_t &)input[i]);
- }
- radixSort<uint32_t>((const uint32_t *)input, count);
- for (uint32_t i = 0; i < count; i++) {
- IFloatFlip((uint32_t &)input[i]);
- }
- }
- return *this;
+ TaskGroup *group = XA_NEW(MemTag::Default, TaskGroup);
+ group->queue.reserve(reserveSize);
+ m_groups.push_back(group);
+ TaskGroupHandle handle;
+ handle.value = m_groups.size() - 1;
+ return handle;
}
- RadixSort &sort(const std::vector<float> &input)
+ void run(TaskGroupHandle handle, Task task)
{
- return sort(input.data(), input.size());
+ m_groups[handle.value]->queue.push_back(task);
}
- // Access to results. m_ranks is a list of indices in sorted order, i.e. in the order you may further process your data
- const uint32_t *ranks() const
+ void wait(TaskGroupHandle *handle)
{
- xaDebugAssert(m_validRanks);
- return m_ranks;
- }
- uint32_t *ranks()
- {
- xaDebugAssert(m_validRanks);
- return m_ranks;
+ if (handle->value == UINT32_MAX) {
+ XA_DEBUG_ASSERT(false);
+ return;
+ }
+ TaskGroup *group = m_groups[handle->value];
+ for (uint32_t i = 0; i < group->queue.size(); i++)
+ group->queue[i].func(group->queue[i].userData);
+ group->queue.clear();
+ destroyGroup(*handle);
+ handle->value = UINT32_MAX;
}
private:
- uint32_t m_size;
- uint32_t *m_ranks;
- uint32_t *m_ranks2;
- bool m_validRanks;
-
- void FloatFlip(uint32_t &f)
+ void destroyGroup(TaskGroupHandle handle)
{
- int32_t mask = (int32_t(f) >> 31) | 0x80000000; // Warren Hunt, Manchor Ko.
- f ^= mask;
+ TaskGroup *group = m_groups[handle.value];
+ if (group) {
+ group->~TaskGroup();
+ XA_FREE(group);
+ m_groups[handle.value] = nullptr;
+ }
}
- void IFloatFlip(uint32_t &f)
+ struct TaskGroup
{
- uint32_t mask = ((f >> 31) - 1) | 0x80000000; // Michael Herf.
- f ^= mask;
- }
+ Array<Task> queue;
+ };
- template<typename T>
- void createHistograms(const T *buffer, uint32_t count, uint32_t *histogram)
- {
- const uint32_t bucketCount = sizeof(T); // (8 * sizeof(T)) / log2(radix)
- // Init bucket pointers.
- uint32_t *h[bucketCount];
- for (uint32_t i = 0; i < bucketCount; i++) {
- h[i] = histogram + 256 * i;
- }
- // Clear histograms.
- memset(histogram, 0, 256 * bucketCount * sizeof(uint32_t ));
- // @@ Add support for signed integers.
- // Build histograms.
- const uint8_t *p = (const uint8_t *)buffer; // @@ Does this break aliasing rules?
- const uint8_t *pe = p + count * sizeof(T);
- while (p != pe) {
- h[0][*p++]++, h[1][*p++]++, h[2][*p++]++, h[3][*p++]++;
-#ifdef _MSC_VER
-#pragma warning(push)
-#pragma warning(disable : 4127)
-#endif
- if (bucketCount == 8) h[4][*p++]++, h[5][*p++]++, h[6][*p++]++, h[7][*p++]++;
-#ifdef _MSC_VER
-#pragma warning(pop)
+ Array<TaskGroup *> m_groups;
+};
#endif
- }
- }
- template <typename T> void insertionSort(const T *input, uint32_t count)
- {
- if (!m_validRanks) {
- m_ranks[0] = 0;
- for (uint32_t i = 1; i != count; ++i) {
- int rank = m_ranks[i] = i;
- uint32_t j = i;
- while (j != 0 && input[rank] < input[m_ranks[j - 1]]) {
- m_ranks[j] = m_ranks[j - 1];
- --j;
- }
- if (i != j) {
- m_ranks[j] = rank;
- }
- }
- m_validRanks = true;
- } else {
- for (uint32_t i = 1; i != count; ++i) {
- int rank = m_ranks[i];
- uint32_t j = i;
- while (j != 0 && input[rank] < input[m_ranks[j - 1]]) {
- m_ranks[j] = m_ranks[j - 1];
- --j;
- }
- if (i != j) {
- m_ranks[j] = rank;
- }
- }
- }
- }
+struct UvMeshChart
+{
+ Array<uint32_t> indices;
+ uint32_t material;
+};
- template <typename T> void radixSort(const T *input, uint32_t count)
- {
- const uint32_t P = sizeof(T); // pass count
- // Allocate histograms & offsets on the stack
- uint32_t histogram[256 * P];
- uint32_t *link[256];
- createHistograms(input, count, histogram);
- // Radix sort, j is the pass number (0=LSB, P=MSB)
- for (uint32_t j = 0; j < P; j++) {
- // Pointer to this bucket.
- const uint32_t *h = &histogram[j * 256];
- const uint8_t *inputBytes = (const uint8_t *)input; // @@ Is this aliasing legal?
- inputBytes += j;
- if (h[inputBytes[0]] == count) {
- // Skip this pass, all values are the same.
- continue;
- }
- // Create offsets
- link[0] = m_ranks2;
- for (uint32_t i = 1; i < 256; i++) link[i] = link[i - 1] + h[i - 1];
- // Perform Radix Sort
- if (!m_validRanks) {
- for (uint32_t i = 0; i < count; i++) {
- *link[inputBytes[i * P]]++ = i;
- }
- m_validRanks = true;
- } else {
- for (uint32_t i = 0; i < count; i++) {
- const uint32_t idx = m_ranks[i];
- *link[inputBytes[idx * P]]++ = idx;
- }
- }
- // Swap pointers for next pass. Valid indices - the most recent ones - are in m_ranks after the swap.
- std::swap(m_ranks, m_ranks2);
- }
- // All values were equal, generate linear ranks.
- if (!m_validRanks) {
- for (uint32_t i = 0; i < count; i++) {
- m_ranks[i] = i;
- }
- m_validRanks = true;
- }
- }
+struct UvMesh
+{
+ UvMeshDecl decl;
+ Array<uint32_t> indices;
+ Array<UvMeshChart *> charts;
+ Array<uint32_t> vertexToChartMap;
+};
+
+struct UvMeshInstance
+{
+ UvMesh *mesh;
+ Array<Vector2> texcoords;
+ bool rotateCharts;
};
namespace raster {
class ClippedTriangle
{
public:
- ClippedTriangle(Vector2::Arg a, Vector2::Arg b, Vector2::Arg c)
+ ClippedTriangle(const Vector2 &a, const Vector2 &b, const Vector2 &c)
{
m_numVertices = 3;
m_activeVertexBuffer = 0;
@@ -3549,16 +3804,6 @@ public:
m_vertexBuffers[1] = m_verticesB;
}
- uint32_t vertexCount()
- {
- return m_numVertices;
- }
-
- const Vector2 *vertices()
- {
- return m_vertexBuffers[m_activeVertexBuffer];
- }
-
void clipHorizontalPlane(float offset, float clipdirection)
{
Vector2 *v = m_vertexBuffers[m_activeVertexBuffer];
@@ -3581,7 +3826,6 @@ public:
dy1in = dy2in;
}
m_numVertices = p;
- //for (uint32_t k=0; k<m_numVertices; k++) printf("(%f, %f)\n", v2[k].x, v2[k].y); printf("\n");
}
void clipVerticalPlane(float offset, float clipdirection )
@@ -3608,7 +3852,7 @@ public:
m_numVertices = p;
}
- void computeAreaCentroid()
+ void computeArea()
{
Vector2 *v = m_vertexBuffers[m_activeVertexBuffer];
v[m_numVertices] = v[0];
@@ -3622,25 +3866,15 @@ public:
centroidy += f * (v[k].y + v[k + 1].y);
}
m_area = 0.5f * fabsf(m_area);
- if (m_area == 0) {
- m_centroid = Vector2(0.0f);
- } else {
- m_centroid = Vector2(centroidx / (6 * m_area), centroidy / (6 * m_area));
- }
}
void clipAABox(float x0, float y0, float x1, float y1)
{
- clipVerticalPlane ( x0, -1);
- clipHorizontalPlane( y0, -1);
- clipVerticalPlane ( x1, 1);
- clipHorizontalPlane( y1, 1);
- computeAreaCentroid();
- }
-
- Vector2 centroid()
- {
- return m_centroid;
+ clipVerticalPlane(x0, -1);
+ clipHorizontalPlane(y0, -1);
+ clipVerticalPlane(x1, 1);
+ clipHorizontalPlane(y1, 1);
+ computeArea();
}
float area()
@@ -3652,212 +3886,50 @@ private:
Vector2 m_verticesA[7 + 1];
Vector2 m_verticesB[7 + 1];
Vector2 *m_vertexBuffers[2];
- uint32_t m_numVertices;
- uint32_t m_activeVertexBuffer;
- float m_area;
- Vector2 m_centroid;
+ uint32_t m_numVertices;
+ uint32_t m_activeVertexBuffer;
+ float m_area;
};
/// A callback to sample the environment. Return false to terminate rasterization.
-typedef bool (* SamplingCallback)(void *param, int x, int y, Vector3::Arg bar, Vector3::Arg dx, Vector3::Arg dy, float coverage);
+typedef bool (*SamplingCallback)(void *param, int x, int y);
/// A triangle for rasterization.
struct Triangle
{
- Triangle(Vector2::Arg v0, Vector2::Arg v1, Vector2::Arg v2, Vector3::Arg t0, Vector3::Arg t1, Vector3::Arg t2)
+ Triangle(const Vector2 &v0, const Vector2 &v1, const Vector2 &v2)
{
// Init vertices.
this->v1 = v0;
this->v2 = v2;
this->v3 = v1;
- // Set barycentric coordinates.
- this->t1 = t0;
- this->t2 = t2;
- this->t3 = t1;
// make sure every triangle is front facing.
flipBackface();
// Compute deltas.
- valid = computeDeltas();
computeUnitInwardNormals();
}
- /// Compute texture space deltas.
- /// This method takes two edge vectors that form a basis, determines the
- /// coordinates of the canonic vectors in that basis, and computes the
- /// texture gradient that corresponds to those vectors.
- bool computeDeltas()
+ bool isValid()
{
- Vector2 e0 = v3 - v1;
- Vector2 e1 = v2 - v1;
- Vector3 de0 = t3 - t1;
- Vector3 de1 = t2 - t1;
- float denom = 1.0f / (e0.y * e1.x - e1.y * e0.x);
- if (!std::isfinite(denom)) {
- return false;
- }
- float lambda1 = - e1.y * denom;
- float lambda2 = e0.y * denom;
- float lambda3 = e1.x * denom;
- float lambda4 = - e0.x * denom;
- dx = de0 * lambda1 + de1 * lambda2;
- dy = de0 * lambda3 + de1 * lambda4;
- return true;
- }
-
- bool draw(const Vector2 &extents, bool enableScissors, SamplingCallback cb, void *param)
- {
- // 28.4 fixed-point coordinates
- const int Y1 = ftoi_round(16.0f * v1.y);
- const int Y2 = ftoi_round(16.0f * v2.y);
- const int Y3 = ftoi_round(16.0f * v3.y);
- const int X1 = ftoi_round(16.0f * v1.x);
- const int X2 = ftoi_round(16.0f * v2.x);
- const int X3 = ftoi_round(16.0f * v3.x);
- // Deltas
- const int DX12 = X1 - X2;
- const int DX23 = X2 - X3;
- const int DX31 = X3 - X1;
- const int DY12 = Y1 - Y2;
- const int DY23 = Y2 - Y3;
- const int DY31 = Y3 - Y1;
- // Fixed-point deltas
- const int FDX12 = DX12 << 4;
- const int FDX23 = DX23 << 4;
- const int FDX31 = DX31 << 4;
- const int FDY12 = DY12 << 4;
- const int FDY23 = DY23 << 4;
- const int FDY31 = DY31 << 4;
- int minx, miny, maxx, maxy;
- if (enableScissors) {
- int frustumX0 = 0 << 4;
- int frustumY0 = 0 << 4;
- int frustumX1 = (int)extents.x << 4;
- int frustumY1 = (int)extents.y << 4;
- // Bounding rectangle
- minx = (std::max(min3(X1, X2, X3), frustumX0) + 0xF) >> 4;
- miny = (std::max(min3(Y1, Y2, Y3), frustumY0) + 0xF) >> 4;
- maxx = (std::min(max3(X1, X2, X3), frustumX1) + 0xF) >> 4;
- maxy = (std::min(max3(Y1, Y2, Y3), frustumY1) + 0xF) >> 4;
- } else {
- // Bounding rectangle
- minx = (min3(X1, X2, X3) + 0xF) >> 4;
- miny = (min3(Y1, Y2, Y3) + 0xF) >> 4;
- maxx = (max3(X1, X2, X3) + 0xF) >> 4;
- maxy = (max3(Y1, Y2, Y3) + 0xF) >> 4;
- }
- // Block size, standard 8x8 (must be power of two)
- const int q = 8;
- // @@ This won't work when minx,miny are negative. This code path is not used. Leaving as is for now.
- xaAssert(minx >= 0);
- xaAssert(miny >= 0);
- // Start in corner of 8x8 block
- minx &= ~(q - 1);
- miny &= ~(q - 1);
- // Half-edge constants
- int C1 = DY12 * X1 - DX12 * Y1;
- int C2 = DY23 * X2 - DX23 * Y2;
- int C3 = DY31 * X3 - DX31 * Y3;
- // Correct for fill convention
- if (DY12 < 0 || (DY12 == 0 && DX12 > 0)) C1++;
- if (DY23 < 0 || (DY23 == 0 && DX23 > 0)) C2++;
- if (DY31 < 0 || (DY31 == 0 && DX31 > 0)) C3++;
- // Loop through blocks
- for (int y = miny; y < maxy; y += q) {
- for (int x = minx; x < maxx; x += q) {
- // Corners of block
- int x0 = x << 4;
- int x1 = (x + q - 1) << 4;
- int y0 = y << 4;
- int y1 = (y + q - 1) << 4;
- // Evaluate half-space functions
- bool a00 = C1 + DX12 * y0 - DY12 * x0 > 0;
- bool a10 = C1 + DX12 * y0 - DY12 * x1 > 0;
- bool a01 = C1 + DX12 * y1 - DY12 * x0 > 0;
- bool a11 = C1 + DX12 * y1 - DY12 * x1 > 0;
- int a = (a00 << 0) | (a10 << 1) | (a01 << 2) | (a11 << 3);
- bool b00 = C2 + DX23 * y0 - DY23 * x0 > 0;
- bool b10 = C2 + DX23 * y0 - DY23 * x1 > 0;
- bool b01 = C2 + DX23 * y1 - DY23 * x0 > 0;
- bool b11 = C2 + DX23 * y1 - DY23 * x1 > 0;
- int b = (b00 << 0) | (b10 << 1) | (b01 << 2) | (b11 << 3);
- bool c00 = C3 + DX31 * y0 - DY31 * x0 > 0;
- bool c10 = C3 + DX31 * y0 - DY31 * x1 > 0;
- bool c01 = C3 + DX31 * y1 - DY31 * x0 > 0;
- bool c11 = C3 + DX31 * y1 - DY31 * x1 > 0;
- int c = (c00 << 0) | (c10 << 1) | (c01 << 2) | (c11 << 3);
- // Skip block when outside an edge
- if (a == 0x0 || b == 0x0 || c == 0x0) continue;
- // Accept whole block when totally covered
- if (a == 0xF && b == 0xF && c == 0xF) {
- Vector3 texRow = t1 + dy * (y0 - v1.y) + dx * (x0 - v1.x);
- for (int iy = y; iy < y + q; iy++) {
- Vector3 tex = texRow;
- for (int ix = x; ix < x + q; ix++) {
- //Vector3 tex = t1 + dx * (ix - v1.x) + dy * (iy - v1.y);
- if (!cb(param, ix, iy, tex, dx, dy, 1.0)) {
- // early out.
- return false;
- }
- tex += dx;
- }
- texRow += dy;
- }
- } else { // Partially covered block
- int CY1 = C1 + DX12 * y0 - DY12 * x0;
- int CY2 = C2 + DX23 * y0 - DY23 * x0;
- int CY3 = C3 + DX31 * y0 - DY31 * x0;
- Vector3 texRow = t1 + dy * (y0 - v1.y) + dx * (x0 - v1.x);
- for (int iy = y; iy < y + q; iy++) {
- int CX1 = CY1;
- int CX2 = CY2;
- int CX3 = CY3;
- Vector3 tex = texRow;
- for (int ix = x; ix < x + q; ix++) {
- if (CX1 > 0 && CX2 > 0 && CX3 > 0) {
- if (!cb(param, ix, iy, tex, dx, dy, 1.0)) {
- // early out.
- return false;
- }
- }
- CX1 -= FDY12;
- CX2 -= FDY23;
- CX3 -= FDY31;
- tex += dx;
- }
- CY1 += FDX12;
- CY2 += FDX23;
- CY3 += FDX31;
- texRow += dy;
- }
- }
- }
- }
- return true;
+ const Vector2 e0 = v3 - v1;
+ const Vector2 e1 = v2 - v1;
+ const float denom = 1.0f / (e0.y * e1.x - e1.y * e0.x);
+ return isFinite(denom);
}
// extents has to be multiple of BK_SIZE!!
- bool drawAA(const Vector2 &extents, bool enableScissors, SamplingCallback cb, void *param)
+ bool drawAA(const Vector2 &extents, SamplingCallback cb, void *param)
{
- const float PX_INSIDE = 1.0f/sqrt(2.0f);
- const float PX_OUTSIDE = -1.0f/sqrt(2.0f);
+ const float PX_INSIDE = 1.0f/sqrtf(2.0f);
+ const float PX_OUTSIDE = -1.0f/sqrtf(2.0f);
const float BK_SIZE = 8;
- const float BK_INSIDE = sqrt(BK_SIZE*BK_SIZE/2.0f);
- const float BK_OUTSIDE = -sqrt(BK_SIZE*BK_SIZE/2.0f);
-
- float minx, miny, maxx, maxy;
- if (enableScissors) {
- // Bounding rectangle
- minx = floorf(std::max(min3(v1.x, v2.x, v3.x), 0.0f));
- miny = floorf(std::max(min3(v1.y, v2.y, v3.y), 0.0f));
- maxx = ceilf( std::min(max3(v1.x, v2.x, v3.x), extents.x - 1.0f));
- maxy = ceilf( std::min(max3(v1.y, v2.y, v3.y), extents.y - 1.0f));
- } else {
- // Bounding rectangle
- minx = floorf(min3(v1.x, v2.x, v3.x));
- miny = floorf(min3(v1.y, v2.y, v3.y));
- maxx = ceilf( max3(v1.x, v2.x, v3.x));
- maxy = ceilf( max3(v1.y, v2.y, v3.y));
- }
+ const float BK_INSIDE = sqrtf(BK_SIZE*BK_SIZE/2.0f);
+ const float BK_OUTSIDE = -sqrtf(BK_SIZE*BK_SIZE/2.0f);
+ // Bounding rectangle
+ float minx = floorf(max(min3(v1.x, v2.x, v3.x), 0.0f));
+ float miny = floorf(max(min3(v1.y, v2.y, v3.y), 0.0f));
+ float maxx = ceilf( min(max3(v1.x, v2.x, v3.x), extents.x - 1.0f));
+ float maxy = ceilf( min(max3(v1.y, v2.y, v3.y), extents.y - 1.0f));
// There's no reason to align the blocks to the viewport, instead we align them to the origin of the triangle bounds.
minx = floorf(minx);
miny = floorf(miny);
@@ -3885,47 +3957,32 @@ struct Triangle
if ( (aC <= BK_OUTSIDE) || (bC <= BK_OUTSIDE) || (cC <= BK_OUTSIDE) ) continue;
// Accept whole block when totally covered
if ( (aC >= BK_INSIDE) && (bC >= BK_INSIDE) && (cC >= BK_INSIDE) ) {
- Vector3 texRow = t1 + dy * (y0 - v1.y) + dx * (x0 - v1.x);
for (float y = y0; y < y0 + BK_SIZE; y++) {
- Vector3 tex = texRow;
for (float x = x0; x < x0 + BK_SIZE; x++) {
- if (!cb(param, (int)x, (int)y, tex, dx, dy, 1.0f)) {
+ if (!cb(param, (int)x, (int)y)) {
return false;
}
- tex += dx;
}
- texRow += dy;
}
} else { // Partially covered block
float CY1 = C1 + n1.x * x0 + n1.y * y0;
float CY2 = C2 + n2.x * x0 + n2.y * y0;
float CY3 = C3 + n3.x * x0 + n3.y * y0;
- Vector3 texRow = t1 + dy * (y0 - v1.y) + dx * (x0 - v1.x);
for (float y = y0; y < y0 + BK_SIZE; y++) { // @@ This is not clipping to scissor rectangle correctly.
float CX1 = CY1;
float CX2 = CY2;
float CX3 = CY3;
- Vector3 tex = texRow;
for (float x = x0; x < x0 + BK_SIZE; x++) { // @@ This is not clipping to scissor rectangle correctly.
if (CX1 >= PX_INSIDE && CX2 >= PX_INSIDE && CX3 >= PX_INSIDE) {
- // pixel completely covered
- Vector3 tex2 = t1 + dx * (x - v1.x) + dy * (y - v1.y);
- if (!cb(param, (int)x, (int)y, tex2, dx, dy, 1.0f)) {
+ if (!cb(param, (int)x, (int)y)) {
return false;
}
} else if ((CX1 >= PX_OUTSIDE) && (CX2 >= PX_OUTSIDE) && (CX3 >= PX_OUTSIDE)) {
// triangle partially covers pixel. do clipping.
ClippedTriangle ct(v1 - Vector2(x, y), v2 - Vector2(x, y), v3 - Vector2(x, y));
ct.clipAABox(-0.5, -0.5, 0.5, 0.5);
- Vector2 centroid = ct.centroid();
- float area = ct.area();
- if (area > 0.0f) {
- Vector3 texCent = tex - dx * centroid.x - dy * centroid.y;
- //xaAssert(texCent.x >= -0.1f && texCent.x <= 1.1f); // @@ Centroid is not very exact...
- //xaAssert(texCent.y >= -0.1f && texCent.y <= 1.1f);
- //xaAssert(texCent.z >= -0.1f && texCent.z <= 1.1f);
- //Vector3 texCent2 = t1 + dx * (x - v1.x) + dy * (y - v1.y);
- if (!cb(param, (int)x, (int)y, texCent, dx, dy, area)) {
+ if (ct.area() > 0.0f) {
+ if (!cb(param, (int)x, (int)y)) {
return false;
}
}
@@ -3933,12 +3990,10 @@ struct Triangle
CX1 += n1.x;
CX2 += n2.x;
CX3 += n3.x;
- tex += dx;
}
CY1 += n1.y;
CY2 += n2.y;
CY3 += n3.y;
- texRow += dy;
}
}
}
@@ -3953,9 +4008,6 @@ struct Triangle
Vector2 hv = v1;
v1 = v2;
v2 = hv; // swap pos
- Vector3 ht = t1;
- t1 = t2;
- t2 = ht; // swap tex
}
}
@@ -3976,77 +4028,24 @@ struct Triangle
// Vertices.
Vector2 v1, v2, v3;
Vector2 n1, n2, n3; // unit inward normals
- Vector3 t1, t2, t3;
-
- // Deltas.
- Vector3 dx, dy;
-
- float sign;
- bool valid;
-};
-
-enum Mode
-{
- Mode_Nearest,
- Mode_Antialiased
};
// Process the given triangle. Returns false if rasterization was interrupted by the callback.
-static bool drawTriangle(Mode mode, Vector2::Arg extents, bool enableScissors, const Vector2 v[3], SamplingCallback cb, void *param)
+static bool drawTriangle(const Vector2 &extents, const Vector2 v[3], SamplingCallback cb, void *param)
{
- Triangle tri(v[0], v[1], v[2], Vector3(1, 0, 0), Vector3(0, 1, 0), Vector3(0, 0, 1));
+ Triangle tri(v[0], v[1], v[2]);
// @@ It would be nice to have a conservative drawing mode that enlarges the triangle extents by one texel and is able to handle degenerate triangles.
// @@ Maybe the simplest thing to do would be raster triangle edges.
- if (tri.valid) {
- if (mode == Mode_Antialiased) {
- return tri.drawAA(extents, enableScissors, cb, param);
- }
- if (mode == Mode_Nearest) {
- return tri.draw(extents, enableScissors, cb, param);
- }
- }
+ if (tri.isValid())
+ return tri.drawAA(extents, cb, param);
return true;
}
-// Process the given quad. Returns false if rasterization was interrupted by the callback.
-static bool drawQuad(Mode mode, Vector2::Arg extents, bool enableScissors, const Vector2 v[4], SamplingCallback cb, void *param)
-{
- bool sign0 = triangleArea2(v[0], v[1], v[2]) > 0.0f;
- bool sign1 = triangleArea2(v[0], v[2], v[3]) > 0.0f;
- // Divide the quad into two non overlapping triangles.
- if (sign0 == sign1) {
- Triangle tri0(v[0], v[1], v[2], Vector3(0, 0, 0), Vector3(1, 0, 0), Vector3(1, 1, 0));
- Triangle tri1(v[0], v[2], v[3], Vector3(0, 0, 0), Vector3(1, 1, 0), Vector3(0, 1, 0));
- if (tri0.valid && tri1.valid) {
- if (mode == Mode_Antialiased) {
- return tri0.drawAA(extents, enableScissors, cb, param) && tri1.drawAA(extents, enableScissors, cb, param);
- } else {
- return tri0.draw(extents, enableScissors, cb, param) && tri1.draw(extents, enableScissors, cb, param);
- }
- }
- } else {
- Triangle tri0(v[0], v[1], v[3], Vector3(0, 0, 0), Vector3(1, 0, 0), Vector3(0, 1, 0));
- Triangle tri1(v[1], v[2], v[3], Vector3(1, 0, 0), Vector3(1, 1, 0), Vector3(0, 1, 0));
- if (tri0.valid && tri1.valid) {
- if (mode == Mode_Antialiased) {
- return tri0.drawAA(extents, enableScissors, cb, param) && tri1.drawAA(extents, enableScissors, cb, param);
- } else {
- return tri0.draw(extents, enableScissors, cb, param) && tri1.draw(extents, enableScissors, cb, param);
- }
- }
- }
- return true;
-}
} // namespace raster
// Full and sparse vector and matrix classes. BLAS subset.
// Pseudo-BLAS interface.
namespace sparse {
-enum Transpose
-{
- NoTransposed = 0,
- Transposed = 1
-};
/**
* Sparse matrix class. The matrix is assumed to be sparse and to have
@@ -4072,8 +4071,8 @@ public:
const Matrix &operator=(const Matrix &m)
{
- xaAssert(width() == m.width());
- xaAssert(height() == m.height());
+ XA_ASSERT(width() == m.width());
+ XA_ASSERT(height() == m.height());
m_array = m.m_array;
return *this;
}
@@ -4085,8 +4084,8 @@ public:
// x is column, y is row
float getCoefficient(uint32_t x, uint32_t y) const
{
- xaDebugAssert( x < width() );
- xaDebugAssert( y < height() );
+ XA_DEBUG_ASSERT( x < width() );
+ XA_DEBUG_ASSERT( y < height() );
const uint32_t count = m_array[y].size();
for (uint32_t i = 0; i < count; i++) {
if (m_array[y][i].x == x) return m_array[y][i].v;
@@ -4096,8 +4095,8 @@ public:
void setCoefficient(uint32_t x, uint32_t y, float f)
{
- xaDebugAssert( x < width() );
- xaDebugAssert( y < height() );
+ XA_DEBUG_ASSERT( x < width() );
+ XA_DEBUG_ASSERT( y < height() );
const uint32_t count = m_array[y].size();
for (uint32_t i = 0; i < count; i++) {
if (m_array[y][i].x == x) {
@@ -4113,7 +4112,7 @@ public:
float dotRow(uint32_t y, const FullVector &v) const
{
- xaDebugAssert( y < height() );
+ XA_DEBUG_ASSERT( y < height() );
const uint32_t count = m_array[y].size();
float sum = 0;
for (uint32_t i = 0; i < count; i++) {
@@ -4124,7 +4123,7 @@ public:
void madRow(uint32_t y, float alpha, FullVector &v) const
{
- xaDebugAssert(y < height());
+ XA_DEBUG_ASSERT(y < height());
const uint32_t count = m_array[y].size();
for (uint32_t i = 0; i < count; i++) {
v[m_array[y][i].x] += alpha * m_array[y][i].v;
@@ -4133,33 +4132,24 @@ public:
void clearRow(uint32_t y)
{
- xaDebugAssert( y < height() );
+ XA_DEBUG_ASSERT( y < height() );
m_array[y].clear();
}
- void scaleRow(uint32_t y, float f)
- {
- xaDebugAssert( y < height() );
- const uint32_t count = m_array[y].size();
- for (uint32_t i = 0; i < count; i++) {
- m_array[y][i].v *= f;
- }
- }
-
- const std::vector<Coefficient> &getRow(uint32_t y) const { return m_array[y]; }
+ const Array<Coefficient> &getRow(uint32_t y) const { return m_array[y]; }
private:
/// Number of columns.
const uint32_t m_width;
/// Array of matrix elements.
- std::vector< std::vector<Coefficient> > m_array;
+ Array< Array<Coefficient> > m_array;
};
// y = a * x + y
static void saxpy(float a, const FullVector &x, FullVector &y)
{
- xaDebugAssert(x.dimension() == y.dimension());
+ XA_DEBUG_ASSERT(x.dimension() == y.dimension());
const uint32_t dim = x.dimension();
for (uint32_t i = 0; i < dim; i++) {
y[i] += a * x[i];
@@ -4168,7 +4158,7 @@ static void saxpy(float a, const FullVector &x, FullVector &y)
static void copy(const FullVector &x, FullVector &y)
{
- xaDebugAssert(x.dimension() == y.dimension());
+ XA_DEBUG_ASSERT(x.dimension() == y.dimension());
const uint32_t dim = x.dimension();
for (uint32_t i = 0; i < dim; i++) {
y[i] = x[i];
@@ -4185,7 +4175,7 @@ static void scal(float a, FullVector &x)
static float dot(const FullVector &x, const FullVector &y)
{
- xaDebugAssert(x.dimension() == y.dimension());
+ XA_DEBUG_ASSERT(x.dimension() == y.dimension());
const uint32_t dim = x.dimension();
float sum = 0;
for (uint32_t i = 0; i < dim; i++) {
@@ -4194,61 +4184,35 @@ static float dot(const FullVector &x, const FullVector &y)
return sum;
}
-static void mult(Transpose TM, const Matrix &M, const FullVector &x, FullVector &y)
-{
- const uint32_t w = M.width();
- const uint32_t h = M.height();
- if (TM == Transposed) {
- xaDebugAssert( h == x.dimension() );
- xaDebugAssert( w == y.dimension() );
- y.fill(0.0f);
- for (uint32_t i = 0; i < h; i++) {
- M.madRow(i, x[i], y);
- }
- } else {
- xaDebugAssert( w == x.dimension() );
- xaDebugAssert( h == y.dimension() );
- for (uint32_t i = 0; i < h; i++) {
- y[i] = M.dotRow(i, x);
- }
- }
-}
-
// y = M * x
static void mult(const Matrix &M, const FullVector &x, FullVector &y)
{
- mult(NoTransposed, M, x, y);
-}
-
-static void sgemv(float alpha, Transpose TA, const Matrix &A, const FullVector &x, float beta, FullVector &y)
-{
- const uint32_t w = A.width();
- const uint32_t h = A.height();
- if (TA == Transposed) {
- xaDebugAssert( h == x.dimension() );
- xaDebugAssert( w == y.dimension() );
- for (uint32_t i = 0; i < h; i++) {
- A.madRow(i, alpha * x[i], y);
- }
- } else {
- xaDebugAssert( w == x.dimension() );
- xaDebugAssert( h == y.dimension() );
- for (uint32_t i = 0; i < h; i++) {
- y[i] = alpha * A.dotRow(i, x) + beta * y[i];
- }
- }
+ uint32_t w = M.width();
+ uint32_t h = M.height();
+ XA_DEBUG_ASSERT( w == x.dimension() );
+ XA_UNUSED(w);
+ XA_DEBUG_ASSERT( h == y.dimension() );
+ for (uint32_t i = 0; i < h; i++)
+ y[i] = M.dotRow(i, x);
}
// y = alpha*A*x + beta*y
static void sgemv(float alpha, const Matrix &A, const FullVector &x, float beta, FullVector &y)
{
- sgemv(alpha, NoTransposed, A, x, beta, y);
+ const uint32_t w = A.width();
+ const uint32_t h = A.height();
+ XA_DEBUG_ASSERT( w == x.dimension() );
+ XA_DEBUG_ASSERT( h == y.dimension() );
+ XA_UNUSED(w);
+ XA_UNUSED(h);
+ for (uint32_t i = 0; i < h; i++)
+ y[i] = alpha * A.dotRow(i, x) + beta * y[i];
}
// dot y-row of A by x-column of B
static float dotRowColumn(int y, const Matrix &A, int x, const Matrix &B)
{
- const std::vector<Matrix::Coefficient> &row = A.getRow(y);
+ const Array<Matrix::Coefficient> &row = A.getRow(y);
const uint32_t count = row.size();
float sum = 0.0f;
for (uint32_t i = 0; i < count; i++) {
@@ -4258,96 +4222,54 @@ static float dotRowColumn(int y, const Matrix &A, int x, const Matrix &B)
return sum;
}
-// dot y-row of A by x-row of B
-static float dotRowRow(int y, const Matrix &A, int x, const Matrix &B)
-{
- const std::vector<Matrix::Coefficient> &row = A.getRow(y);
- const uint32_t count = row.size();
- float sum = 0.0f;
- for (uint32_t i = 0; i < count; i++) {
- const Matrix::Coefficient &c = row[i];
- sum += c.v * B.getCoefficient(c.x, x);
- }
- return sum;
-}
-
-// dot y-column of A by x-column of B
-static float dotColumnColumn(int y, const Matrix &A, int x, const Matrix &B)
-{
- xaDebugAssert(A.height() == B.height());
- const uint32_t h = A.height();
- float sum = 0.0f;
- for (uint32_t i = 0; i < h; i++) {
- sum += A.getCoefficient(y, i) * B.getCoefficient(x, i);
- }
- return sum;
-}
-
static void transpose(const Matrix &A, Matrix &B)
{
- xaDebugAssert(A.width() == B.height());
- xaDebugAssert(B.width() == A.height());
+ XA_DEBUG_ASSERT(A.width() == B.height());
+ XA_DEBUG_ASSERT(B.width() == A.height());
const uint32_t w = A.width();
for (uint32_t x = 0; x < w; x++) {
B.clearRow(x);
}
const uint32_t h = A.height();
for (uint32_t y = 0; y < h; y++) {
- const std::vector<Matrix::Coefficient> &row = A.getRow(y);
+ const Array<Matrix::Coefficient> &row = A.getRow(y);
const uint32_t count = row.size();
for (uint32_t i = 0; i < count; i++) {
const Matrix::Coefficient &c = row[i];
- xaDebugAssert(c.x < w);
+ XA_DEBUG_ASSERT(c.x < w);
B.setCoefficient(y, c.x, c.v);
}
}
}
-static void sgemm(float alpha, Transpose TA, const Matrix &A, Transpose TB, const Matrix &B, float beta, Matrix &C)
+static void sgemm(float alpha, const Matrix &A, const Matrix &B, float beta, Matrix &C)
{
const uint32_t w = C.width();
const uint32_t h = C.height();
- uint32_t aw = (TA == NoTransposed) ? A.width() : A.height();
- uint32_t ah = (TA == NoTransposed) ? A.height() : A.width();
- uint32_t bw = (TB == NoTransposed) ? B.width() : B.height();
- uint32_t bh = (TB == NoTransposed) ? B.height() : B.width();
- xaDebugAssert(aw == bh);
- xaDebugAssert(bw == ah);
- xaDebugAssert(w == bw);
- xaDebugAssert(h == ah);
-#ifdef NDEBUG
- aw = ah = bw = bh = 0; // silence unused parameter warning
+#if XA_DEBUG
+ const uint32_t aw = A.width();
+ const uint32_t ah = A.height();
+ const uint32_t bw = B.width();
+ const uint32_t bh = B.height();
+ XA_DEBUG_ASSERT(aw == bh);
+ XA_DEBUG_ASSERT(bw == ah);
+ XA_DEBUG_ASSERT(w == bw);
+ XA_DEBUG_ASSERT(h == ah);
#endif
for (uint32_t y = 0; y < h; y++) {
for (uint32_t x = 0; x < w; x++) {
float c = beta * C.getCoefficient(x, y);
- if (TA == NoTransposed && TB == NoTransposed) {
- // dot y-row of A by x-column of B.
- c += alpha * dotRowColumn(y, A, x, B);
- } else if (TA == Transposed && TB == Transposed) {
- // dot y-column of A by x-row of B.
- c += alpha * dotRowColumn(x, B, y, A);
- } else if (TA == Transposed && TB == NoTransposed) {
- // dot y-column of A by x-column of B.
- c += alpha * dotColumnColumn(y, A, x, B);
- } else if (TA == NoTransposed && TB == Transposed) {
- // dot y-row of A by x-row of B.
- c += alpha * dotRowRow(y, A, x, B);
- }
+ // dot y-row of A by x-column of B.
+ c += alpha * dotRowColumn(y, A, x, B);
C.setCoefficient(x, y, c);
}
}
}
-static void mult(Transpose TA, const Matrix &A, Transpose TB, const Matrix &B, Matrix &C)
-{
- sgemm(1.0f, TA, A, TB, B, 0.0f, C);
-}
-
// C = A * B
static void mult(const Matrix &A, const Matrix &B, Matrix &C)
{
- mult(NoTransposed, A, NoTransposed, B, C);
+ sgemm(1.0f, A, B, 0.0f, C);
}
} // namespace sparse
@@ -4357,10 +4279,10 @@ class JacobiPreconditioner
public:
JacobiPreconditioner(const sparse::Matrix &M, bool symmetric) : m_inverseDiagonal(M.width())
{
- xaAssert(M.isSquare());
+ XA_ASSERT(M.isSquare());
for (uint32_t x = 0; x < M.width(); x++) {
float elem = M.getCoefficient(x, x);
- //xaDebugAssert( elem != 0.0f ); // This can be zero in the presence of zero area triangles.
+ //XA_DEBUG_ASSERT( elem != 0.0f ); // This can be zero in the presence of zero area triangles.
if (symmetric) {
m_inverseDiagonal[x] = (elem != 0) ? 1.0f / sqrtf(fabsf(elem)) : 1.0f;
} else {
@@ -4371,8 +4293,8 @@ public:
void apply(const FullVector &x, FullVector &y) const
{
- xaDebugAssert(x.dimension() == m_inverseDiagonal.dimension());
- xaDebugAssert(y.dimension() == m_inverseDiagonal.dimension());
+ XA_DEBUG_ASSERT(x.dimension() == m_inverseDiagonal.dimension());
+ XA_DEBUG_ASSERT(y.dimension() == m_inverseDiagonal.dimension());
// @@ Wrap vector component-wise product into a separate function.
const uint32_t D = x.dimension();
for (uint32_t i = 0; i < D; i++) {
@@ -4391,9 +4313,9 @@ public:
// Solve the symmetric system: At·A·x = At·b
static bool LeastSquaresSolver(const sparse::Matrix &A, const FullVector &b, FullVector &x, float epsilon = 1e-5f)
{
- xaDebugAssert(A.width() == x.dimension());
- xaDebugAssert(A.height() == b.dimension());
- xaDebugAssert(A.height() >= A.width()); // @@ If height == width we could solve it directly...
+ XA_DEBUG_ASSERT(A.width() == x.dimension());
+ XA_DEBUG_ASSERT(A.height() == b.dimension());
+ XA_DEBUG_ASSERT(A.height() >= A.width()); // @@ If height == width we could solve it directly...
const uint32_t D = A.width();
sparse::Matrix At(A.height(), A.width());
sparse::transpose(A, At);
@@ -4407,12 +4329,12 @@ public:
// See section 10.4.3 in: Mesh Parameterization: Theory and Practice, Siggraph Course Notes, August 2007
static bool LeastSquaresSolver(const sparse::Matrix &A, const FullVector &b, FullVector &x, const uint32_t *lockedParameters, uint32_t lockedCount, float epsilon = 1e-5f)
{
- xaDebugAssert(A.width() == x.dimension());
- xaDebugAssert(A.height() == b.dimension());
- xaDebugAssert(A.height() >= A.width() - lockedCount);
+ XA_DEBUG_ASSERT(A.width() == x.dimension());
+ XA_DEBUG_ASSERT(A.height() == b.dimension());
+ XA_DEBUG_ASSERT(A.height() >= A.width() - lockedCount);
// @@ This is not the most efficient way of building a system with reduced degrees of freedom. It would be faster to do it on the fly.
const uint32_t D = A.width() - lockedCount;
- xaDebugAssert(D > 0);
+ XA_DEBUG_ASSERT(D > 0);
// Compute: b - Al * xl
FullVector b_Alxl(b);
for (uint32_t y = 0; y < A.height(); y++) {
@@ -4504,62 +4426,12 @@ private:
* Jonhathan Richard Shewchuk.
*
**/
- static bool ConjugateGradientSolver(const sparse::Matrix &A, const FullVector &b, FullVector &x, float epsilon)
- {
- xaDebugAssert( A.isSquare() );
- xaDebugAssert( A.width() == b.dimension() );
- xaDebugAssert( A.width() == x.dimension() );
- int i = 0;
- const int D = A.width();
- const int i_max = 4 * D; // Convergence should be linear, but in some cases, it's not.
- FullVector r(D); // residual
- FullVector p(D); // search direction
- FullVector q(D); //
- float delta_0;
- float delta_old;
- float delta_new;
- float alpha;
- float beta;
- // r = b - A·x;
- sparse::copy(b, r);
- sparse::sgemv(-1, A, x, 1, r);
- // p = r;
- sparse::copy(r, p);
- delta_new = sparse::dot( r, r );
- delta_0 = delta_new;
- while (i < i_max && delta_new > epsilon * epsilon * delta_0) {
- i++;
- // q = A·p
- mult(A, p, q);
- // alpha = delta_new / p·q
- alpha = delta_new / sparse::dot( p, q );
- // x = alfa·p + x
- sparse::saxpy(alpha, p, x);
- if ((i & 31) == 0) { // recompute r after 32 steps
- // r = b - A·x
- sparse::copy(b, r);
- sparse::sgemv(-1, A, x, 1, r);
- } else {
- // r = r - alpha·q
- sparse::saxpy(-alpha, q, r);
- }
- delta_old = delta_new;
- delta_new = sparse::dot( r, r );
- beta = delta_new / delta_old;
- // p = beta·p + r
- sparse::scal(beta, p);
- sparse::saxpy(1, r, p);
- }
- return delta_new <= epsilon * epsilon * delta_0;
- }
-
-
// Conjugate gradient with preconditioner.
static bool ConjugateGradientSolver(const JacobiPreconditioner &preconditioner, const sparse::Matrix &A, const FullVector &b, FullVector &x, float epsilon)
{
- xaDebugAssert( A.isSquare() );
- xaDebugAssert( A.width() == b.dimension() );
- xaDebugAssert( A.width() == x.dimension() );
+ XA_DEBUG_ASSERT( A.isSquare() );
+ XA_DEBUG_ASSERT( A.width() == b.dimension() );
+ XA_DEBUG_ASSERT( A.width() == x.dimension() );
int i = 0;
const int D = A.width();
const int i_max = 4 * D; // Convergence should be linear, but in some cases, it's not.
@@ -4582,7 +4454,7 @@ private:
while (i < i_max && delta_new > epsilon * epsilon * delta_0) {
i++;
// q = A·p
- mult(A, p, q);
+ sparse::mult(A, p, q);
// alpha = delta_new / p·q
alpha = delta_new / sparse::dot(p, q);
// x = alfa·p + x
@@ -4609,59 +4481,59 @@ private:
static bool SymmetricSolver(const sparse::Matrix &A, const FullVector &b, FullVector &x, float epsilon = 1e-5f)
{
- xaDebugAssert(A.height() == A.width());
- xaDebugAssert(A.height() == b.dimension());
- xaDebugAssert(b.dimension() == x.dimension());
+ XA_DEBUG_ASSERT(A.height() == A.width());
+ XA_DEBUG_ASSERT(A.height() == b.dimension());
+ XA_DEBUG_ASSERT(b.dimension() == x.dimension());
JacobiPreconditioner jacobi(A, true);
return ConjugateGradientSolver(jacobi, A, b, x, epsilon);
}
};
namespace param {
-class Atlas;
-class Chart;
// Fast sweep in 3 directions
-static bool findApproximateDiameterVertices(halfedge::Mesh *mesh, halfedge::Vertex **a, halfedge::Vertex **b)
+static bool findApproximateDiameterVertices(Mesh *mesh, uint32_t *a, uint32_t *b)
{
- xaDebugAssert(mesh != NULL);
- xaDebugAssert(a != NULL);
- xaDebugAssert(b != NULL);
+ XA_DEBUG_ASSERT(a != nullptr);
+ XA_DEBUG_ASSERT(b != nullptr);
const uint32_t vertexCount = mesh->vertexCount();
- halfedge::Vertex *minVertex[3];
- halfedge::Vertex *maxVertex[3];
- minVertex[0] = minVertex[1] = minVertex[2] = NULL;
- maxVertex[0] = maxVertex[1] = maxVertex[2] = NULL;
+ uint32_t minVertex[3];
+ uint32_t maxVertex[3];
+ minVertex[0] = minVertex[1] = minVertex[2] = UINT32_MAX;
+ maxVertex[0] = maxVertex[1] = maxVertex[2] = UINT32_MAX;
for (uint32_t v = 1; v < vertexCount; v++) {
- halfedge::Vertex *vertex = mesh->vertexAt(v);
- xaDebugAssert(vertex != NULL);
- if (vertex->isBoundary()) {
- minVertex[0] = minVertex[1] = minVertex[2] = vertex;
- maxVertex[0] = maxVertex[1] = maxVertex[2] = vertex;
+ if (mesh->isBoundaryVertex(v)) {
+ minVertex[0] = minVertex[1] = minVertex[2] = v;
+ maxVertex[0] = maxVertex[1] = maxVertex[2] = v;
break;
}
}
- if (minVertex[0] == NULL) {
+ if (minVertex[0] == UINT32_MAX) {
// Input mesh has not boundaries.
return false;
}
for (uint32_t v = 1; v < vertexCount; v++) {
- halfedge::Vertex *vertex = mesh->vertexAt(v);
- xaDebugAssert(vertex != NULL);
- if (!vertex->isBoundary()) {
+ if (!mesh->isBoundaryVertex(v)) {
// Skip interior vertices.
continue;
}
- if (vertex->pos.x < minVertex[0]->pos.x) minVertex[0] = vertex;
- else if (vertex->pos.x > maxVertex[0]->pos.x) maxVertex[0] = vertex;
- if (vertex->pos.y < minVertex[1]->pos.y) minVertex[1] = vertex;
- else if (vertex->pos.y > maxVertex[1]->pos.y) maxVertex[1] = vertex;
- if (vertex->pos.z < minVertex[2]->pos.z) minVertex[2] = vertex;
- else if (vertex->pos.z > maxVertex[2]->pos.z) maxVertex[2] = vertex;
+ const Vector3 &pos = mesh->position(v);
+ if (pos.x < mesh->position(minVertex[0]).x)
+ minVertex[0] = v;
+ else if (pos.x > mesh->position(maxVertex[0]).x)
+ maxVertex[0] = v;
+ if (pos.y < mesh->position(minVertex[1]).y)
+ minVertex[1] = v;
+ else if (pos.y > mesh->position(maxVertex[1]).y)
+ maxVertex[1] = v;
+ if (pos.z < mesh->position(minVertex[2]).z)
+ minVertex[2] = v;
+ else if (pos.z > mesh->position(maxVertex[2]).z)
+ maxVertex[2] = v;
}
float lengths[3];
for (int i = 0; i < 3; i++) {
- lengths[i] = length(minVertex[i]->pos - maxVertex[i]->pos);
+ lengths[i] = length(mesh->position(minVertex[i]) - mesh->position(maxVertex[i]));
}
if (lengths[0] > lengths[1] && lengths[0] > lengths[2]) {
*a = minVertex[0];
@@ -4678,34 +4550,28 @@ static bool findApproximateDiameterVertices(halfedge::Mesh *mesh, halfedge::Vert
// Conformal relations from Brecht Van Lommel (based on ABF):
-static float vec_angle_cos(Vector3::Arg v1, Vector3::Arg v2, Vector3::Arg v3)
+static float vec_angle_cos(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3)
{
Vector3 d1 = v1 - v2;
Vector3 d2 = v3 - v2;
return clamp(dot(d1, d2) / (length(d1) * length(d2)), -1.0f, 1.0f);
}
-static float vec_angle(Vector3::Arg v1, Vector3::Arg v2, Vector3::Arg v3)
+static float vec_angle(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3)
{
float dot = vec_angle_cos(v1, v2, v3);
return acosf(dot);
}
-static void triangle_angles(Vector3::Arg v1, Vector3::Arg v2, Vector3::Arg v3, float *a1, float *a2, float *a3)
+static void triangle_angles(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, float *a1, float *a2, float *a3)
{
*a1 = vec_angle(v3, v1, v2);
*a2 = vec_angle(v1, v2, v3);
- *a3 = PI - *a2 - *a1;
+ *a3 = kPi - *a2 - *a1;
}
-static void setup_abf_relations(sparse::Matrix &A, int row, const halfedge::Vertex *v0, const halfedge::Vertex *v1, const halfedge::Vertex *v2)
+static void setup_abf_relations(sparse::Matrix &A, int row, int id0, int id1, int id2, const Vector3 &p0, const Vector3 &p1, const Vector3 &p2)
{
- int id0 = v0->id;
- int id1 = v1->id;
- int id2 = v2->id;
- Vector3 p0 = v0->pos;
- Vector3 p1 = v1->pos;
- Vector3 p2 = v2->pos;
// @@ IC: Wouldn't it be more accurate to return cos and compute 1-cos^2?
// It does indeed seem to be a little bit more robust.
// @@ Need to revisit this more carefully!
@@ -4715,19 +4581,19 @@ static void setup_abf_relations(sparse::Matrix &A, int row, const halfedge::Vert
float s1 = sinf(a1);
float s2 = sinf(a2);
if (s1 > s0 && s1 > s2) {
- std::swap(s1, s2);
- std::swap(s0, s1);
- std::swap(a1, a2);
- std::swap(a0, a1);
- std::swap(id1, id2);
- std::swap(id0, id1);
+ swap(s1, s2);
+ swap(s0, s1);
+ swap(a1, a2);
+ swap(a0, a1);
+ swap(id1, id2);
+ swap(id0, id1);
} else if (s0 > s1 && s0 > s2) {
- std::swap(s0, s2);
- std::swap(s0, s1);
- std::swap(a0, a2);
- std::swap(a0, a1);
- std::swap(id0, id2);
- std::swap(id0, id1);
+ swap(s0, s2);
+ swap(s0, s1);
+ swap(a0, a2);
+ swap(a0, a1);
+ swap(id0, id2);
+ swap(id0, id1);
}
float c0 = cosf(a0);
float ratio = (s2 == 0.0f) ? 1.0f : s1 / s2;
@@ -4755,14 +4621,13 @@ static void setup_abf_relations(sparse::Matrix &A, int row, const halfedge::Vert
A.setCoefficient(v2_id, 2 * row + 1, 1);
}
-bool computeLeastSquaresConformalMap(halfedge::Mesh *mesh)
+static bool computeLeastSquaresConformalMap(Mesh *mesh)
{
- xaDebugAssert(mesh != NULL);
// For this to work properly, mesh should not have colocals that have the same
// attributes, unless you want the vertices to actually have different texcoords.
const uint32_t vertexCount = mesh->vertexCount();
const uint32_t D = 2 * vertexCount;
- const uint32_t N = 2 * halfedge::countMeshTriangles(mesh);
+ const uint32_t N = 2 * mesh->faceCount();
// N is the number of equations (one per triangle)
// D is the number of variables (one per vertex; there are 2 pinned vertices).
if (N < D - 4) {
@@ -4774,118 +4639,64 @@ bool computeLeastSquaresConformalMap(halfedge::Mesh *mesh)
// Fill b:
b.fill(0.0f);
// Fill x:
- halfedge::Vertex *v0;
- halfedge::Vertex *v1;
+ uint32_t v0, v1;
if (!findApproximateDiameterVertices(mesh, &v0, &v1)) {
// Mesh has no boundaries.
return false;
}
- if (v0->tex == v1->tex) {
+ if (mesh->texcoord(v0) == mesh->texcoord(v1)) {
// LSCM expects an existing parameterization.
return false;
}
for (uint32_t v = 0; v < vertexCount; v++) {
- halfedge::Vertex *vertex = mesh->vertexAt(v);
- xaDebugAssert(vertex != NULL);
// Initial solution.
- x[2 * v + 0] = vertex->tex.x;
- x[2 * v + 1] = vertex->tex.y;
+ x[2 * v + 0] = mesh->texcoord(v).x;
+ x[2 * v + 1] = mesh->texcoord(v).y;
}
// Fill A:
const uint32_t faceCount = mesh->faceCount();
for (uint32_t f = 0, t = 0; f < faceCount; f++) {
- const halfedge::Face *face = mesh->faceAt(f);
- xaDebugAssert(face != NULL);
- xaDebugAssert(face->edgeCount() == 3);
- const halfedge::Vertex *vertex0 = NULL;
- for (halfedge::Face::ConstEdgeIterator it(face->edges()); !it.isDone(); it.advance()) {
- const halfedge::Edge *edge = it.current();
- xaAssert(edge != NULL);
- if (vertex0 == NULL) {
- vertex0 = edge->vertex;
- } else if (edge->next->vertex != vertex0) {
- const halfedge::Vertex *vertex1 = edge->from();
- const halfedge::Vertex *vertex2 = edge->to();
- setup_abf_relations(A, t, vertex0, vertex1, vertex2);
- //setup_conformal_map_relations(A, t, vertex0, vertex1, vertex2);
- t++;
- }
- }
+ const uint32_t vertex0 = mesh->vertexAt(f * 3 + 0);
+ const uint32_t vertex1 = mesh->vertexAt(f * 3 + 1);
+ const uint32_t vertex2 = mesh->vertexAt(f * 3 + 2);
+ setup_abf_relations(A, t, vertex0, vertex1, vertex2, mesh->position(vertex0), mesh->position(vertex1), mesh->position(vertex2));
+ t++;
}
const uint32_t lockedParameters[] = {
- 2 * v0->id + 0,
- 2 * v0->id + 1,
- 2 * v1->id + 0,
- 2 * v1->id + 1
+ 2 * v0 + 0,
+ 2 * v0 + 1,
+ 2 * v1 + 0,
+ 2 * v1 + 1
};
// Solve
Solver::LeastSquaresSolver(A, b, x, lockedParameters, 4, 0.000001f);
// Map x back to texcoords:
- for (uint32_t v = 0; v < vertexCount; v++) {
- halfedge::Vertex *vertex = mesh->vertexAt(v);
- xaDebugAssert(vertex != NULL);
- vertex->tex = Vector2(x[2 * v + 0], x[2 * v + 1]);
- }
+ for (uint32_t v = 0; v < vertexCount; v++)
+ mesh->texcoord(v) = Vector2(x[2 * v + 0], x[2 * v + 1]);
return true;
}
-bool computeOrthogonalProjectionMap(halfedge::Mesh *mesh)
+static bool computeOrthogonalProjectionMap(Mesh *mesh)
{
- Vector3 axis[2];
uint32_t vertexCount = mesh->vertexCount();
- std::vector<Vector3> points(vertexCount);
- points.resize(vertexCount);
- for (uint32_t i = 0; i < vertexCount; i++) {
- points[i] = mesh->vertexAt(i)->pos;
- }
// Avoid redundant computations.
float matrix[6];
- Fit::computeCovariance(vertexCount, points.data(), matrix);
- if (matrix[0] == 0 && matrix[3] == 0 && matrix[5] == 0) {
+ Fit::computeCovariance(vertexCount, &mesh->position(0), matrix);
+ if (matrix[0] == 0 && matrix[3] == 0 && matrix[5] == 0)
return false;
- }
float eigenValues[3];
Vector3 eigenVectors[3];
- if (!Fit::eigenSolveSymmetric3(matrix, eigenValues, eigenVectors)) {
+ if (!Fit::eigenSolveSymmetric3(matrix, eigenValues, eigenVectors))
return false;
- }
- axis[0] = normalize(eigenVectors[0]);
- axis[1] = normalize(eigenVectors[1]);
+ Vector3 axis[2];
+ axis[0] = normalize(eigenVectors[0], kEpsilon);
+ axis[1] = normalize(eigenVectors[1], kEpsilon);
// Project vertices to plane.
- for (halfedge::Mesh::VertexIterator it(mesh->vertices()); !it.isDone(); it.advance()) {
- halfedge::Vertex *vertex = it.current();
- vertex->tex.x = dot(axis[0], vertex->pos);
- vertex->tex.y = dot(axis[1], vertex->pos);
- }
+ for (uint32_t i = 0; i < vertexCount; i++)
+ mesh->texcoord(i) = Vector2(dot(axis[0], mesh->position(i)), dot(axis[1], mesh->position(i)));
return true;
}
-void computeSingleFaceMap(halfedge::Mesh *mesh)
-{
- xaDebugAssert(mesh != NULL);
- xaDebugAssert(mesh->faceCount() == 1);
- halfedge::Face *face = mesh->faceAt(0);
- xaAssert(face != NULL);
- Vector3 p0 = face->edge->from()->pos;
- Vector3 p1 = face->edge->to()->pos;
- Vector3 X = normalizeSafe(p1 - p0, Vector3(0.0f), 0.0f);
- Vector3 Z = face->normal();
- Vector3 Y = normalizeSafe(cross(Z, X), Vector3(0.0f), 0.0f);
- uint32_t i = 0;
- for (halfedge::Face::EdgeIterator it(face->edges()); !it.isDone(); it.advance(), i++) {
- halfedge::Vertex *vertex = it.vertex();
- xaAssert(vertex != NULL);
- if (i == 0) {
- vertex->tex = Vector2(0);
- } else {
- Vector3 pn = vertex->pos;
- float xn = dot((pn - p0), X);
- float yn = dot((pn - p0), Y);
- vertex->tex = Vector2(xn, yn);
- }
- }
-}
-
// Dummy implementation of a priority queue using sort at insertion.
// - Insertion is o(n)
// - Smallest element goes at the end, so that popping it is o(1).
@@ -4894,7 +4705,7 @@ void computeSingleFaceMap(halfedge::Mesh *mesh)
// @@ Searcing at removal would remove the need for sorting when priorities change.
struct PriorityQueue
{
- PriorityQueue(uint32_t size = UINT_MAX) : maxSize(size) {}
+ PriorityQueue(uint32_t size = UINT32_MAX) : maxSize(size) {}
void push(float priority, uint32_t face)
{
@@ -4904,10 +4715,9 @@ struct PriorityQueue
if (pairs[i].priority > priority) break;
}
Pair p = { priority, face };
- pairs.insert(pairs.begin() + i, p);
- if (pairs.size() > maxSize) {
- pairs.erase(pairs.begin());
- }
+ pairs.insertAt(i, p);
+ if (pairs.size() > maxSize)
+ pairs.removeAt(0);
}
// push face out of order, to be sorted later.
@@ -4949,7 +4759,7 @@ struct PriorityQueue
struct Pair
{
- bool operator <(const Pair &p) const
+ bool operator<(const Pair &p) const
{
return priority > p.priority; // !! Sort in inverse priority order!
}
@@ -4958,164 +4768,411 @@ struct PriorityQueue
uint32_t face;
};
- std::vector<Pair> pairs;
+ Array<Pair> pairs;
};
struct ChartBuildData
{
- ChartBuildData(int id) : id(id)
- {
- planeNormal = Vector3(0);
- centroid = Vector3(0);
- coneAxis = Vector3(0);
- coneAngle = 0;
- area = 0;
- boundaryLength = 0;
- normalSum = Vector3(0);
- centroidSum = Vector3(0);
- }
-
- int id;
-
- // Proxy info:
- Vector3 planeNormal;
- Vector3 centroid;
- Vector3 coneAxis;
- float coneAngle;
-
- float area;
- float boundaryLength;
- Vector3 normalSum;
- Vector3 centroidSum;
-
- std::vector<uint32_t> seeds; // @@ These could be a pointers to the halfedge faces directly.
- std::vector<uint32_t> faces;
+ int id = -1;
+ Vector3 averageNormal = Vector3(0.0f);
+ float area = 0.0f;
+ float boundaryLength = 0.0f;
+ Vector3 normalSum = Vector3(0.0f);
+ Vector3 centroidSum = Vector3(0.0f); // Sum of chart face centroids.
+ Vector3 centroid = Vector3(0.0f); // Average centroid of chart faces.
+ Array<uint32_t> seeds;
+ Array<uint32_t> faces;
PriorityQueue candidates;
+ Basis basis; // Of first face.
};
struct AtlasBuilder
{
- AtlasBuilder(const halfedge::Mesh *m) : mesh(m), facesLeft(m->faceCount())
+ // @@ Hardcoded to 10?
+ AtlasBuilder(const Mesh *mesh, Array<uint32_t> *meshFaces, const ChartOptions &options) : m_mesh(mesh), m_meshFaces(meshFaces), m_facesLeft(mesh->faceCount()), m_bestTriangles(10), m_options(options)
{
- const uint32_t faceCount = m->faceCount();
- faceChartArray.resize(faceCount, -1);
- faceCandidateArray.resize(faceCount, (uint32_t)-1);
+ XA_PROFILE_START(atlasBuilderInit)
+ const uint32_t faceCount = m_mesh->faceCount();
+ if (meshFaces) {
+ m_ignoreFaces.resize(faceCount, true);
+ for (uint32_t f = 0; f < meshFaces->size(); f++)
+ m_ignoreFaces[(*meshFaces)[f]] = false;
+ m_facesLeft = meshFaces->size();
+ } else {
+ m_ignoreFaces.resize(faceCount, false);
+ }
+ m_faceChartArray.resize(faceCount, -1);
+ m_faceCandidateArray.resize(faceCount, (uint32_t)-1);
+ m_texcoords.resize(faceCount * 3);
// @@ Floyd for the whole mesh is too slow. We could compute floyd progressively per patch as the patch grows. We need a better solution to compute most central faces.
//computeShortestPaths();
// Precompute edge lengths and face areas.
- uint32_t edgeCount = m->edgeCount();
- edgeLengths.resize(edgeCount);
- for (uint32_t i = 0; i < edgeCount; i++) {
- uint32_t id = m->edgeAt(i)->id;
- xaDebugAssert(id / 2 == i);
-#ifdef NDEBUG
- id = 0; // silence unused parameter warning
-#endif
- edgeLengths[i] = m->edgeAt(i)->length();
- }
- faceAreas.resize(faceCount);
- for (uint32_t i = 0; i < faceCount; i++) {
- faceAreas[i] = m->faceAt(i)->area();
+ const uint32_t edgeCount = m_mesh->edgeCount();
+ m_edgeLengths.resize(edgeCount, 0.0f);
+ m_faceAreas.resize(m_mesh->faceCount(), 0.0f);
+ m_faceNormals.resize(m_mesh->faceCount());
+ for (uint32_t f = 0; f < faceCount; f++) {
+ if (m_ignoreFaces[f])
+ continue;
+ for (Mesh::FaceEdgeIterator it(m_mesh, f); !it.isDone(); it.advance()) {
+ m_edgeLengths[it.edge()] = internal::length(it.position1() - it.position0());
+ XA_DEBUG_ASSERT(m_edgeLengths[it.edge()] > 0.0f);
+ }
+ m_faceAreas[f] = mesh->faceArea(f);
+ XA_DEBUG_ASSERT(m_faceAreas[f] > 0.0f);
+ m_faceNormals[f] = m_mesh->triangleNormal(f);
}
+ XA_PROFILE_END(atlasBuilderInit)
}
~AtlasBuilder()
{
- const uint32_t chartCount = chartArray.size();
+ const uint32_t chartCount = m_chartArray.size();
for (uint32_t i = 0; i < chartCount; i++) {
- delete chartArray[i];
+ m_chartArray[i]->~ChartBuildData();
+ XA_FREE(m_chartArray[i]);
}
}
- void markUnchartedFaces(const std::vector<uint32_t> &unchartedFaces)
+ uint32_t facesLeft() const { return m_facesLeft; }
+ uint32_t chartCount() const { return m_chartArray.size(); }
+ const Array<uint32_t> &chartFaces(uint32_t i) const { return m_chartArray[i]->faces; }
+ const Basis &chartBasis(uint32_t chartIndex) const { return m_chartArray[chartIndex]->basis; }
+
+ void placeSeeds(float threshold)
{
- const uint32_t unchartedFaceCount = unchartedFaces.size();
- for (uint32_t i = 0; i < unchartedFaceCount; i++) {
- uint32_t f = unchartedFaces[i];
- faceChartArray[f] = -2;
- //faceCandidateArray[f] = -2; // @@ ?
- removeCandidate(f);
- }
- xaDebugAssert(facesLeft >= unchartedFaceCount);
- facesLeft -= unchartedFaceCount;
+ // Instead of using a predefiened number of seeds:
+ // - Add seeds one by one, growing chart until a certain treshold.
+ // - Undo charts and restart growing process.
+ // @@ How can we give preference to faces far from sharp features as in the LSCM paper?
+ // - those points can be found using a simple flood filling algorithm.
+ // - how do we weight the probabilities?
+ while (m_facesLeft > 0)
+ createRandomChart(threshold);
}
- void computeShortestPaths()
+ // Returns true if any of the charts can grow more.
+ bool growCharts(float threshold, uint32_t faceCount)
{
- const uint32_t faceCount = mesh->faceCount();
- shortestPaths.resize(faceCount * faceCount, FLT_MAX);
- // Fill edges:
+ XA_PROFILE_START(atlasBuilderGrowCharts)
+ // Using one global list.
+ faceCount = min(faceCount, m_facesLeft);
+ bool canAddAny = false;
for (uint32_t i = 0; i < faceCount; i++) {
- shortestPaths[i * faceCount + i] = 0.0f;
- const halfedge::Face *face_i = mesh->faceAt(i);
- Vector3 centroid_i = face_i->centroid();
- for (halfedge::Face::ConstEdgeIterator it(face_i->edges()); !it.isDone(); it.advance()) {
- const halfedge::Edge *edge = it.current();
- if (!edge->isBoundary()) {
- const halfedge::Face *face_j = edge->pair->face;
- uint32_t j = face_j->id;
- Vector3 centroid_j = face_j->centroid();
- shortestPaths[i * faceCount + j] = shortestPaths[j * faceCount + i] = length(centroid_i - centroid_j);
- }
+ const Candidate &candidate = getBestCandidate();
+ if (candidate.metric > threshold) {
+ XA_PROFILE_END(atlasBuilderGrowCharts)
+ return false; // Can't grow more.
}
+ createFaceTexcoords(candidate.chart, candidate.face);
+ if (!canAddFaceToChart(candidate.chart, candidate.face))
+ continue;
+ addFaceToChart(candidate.chart, candidate.face);
+ canAddAny = true;
}
- // Use Floyd-Warshall algorithm to compute all paths:
- for (uint32_t k = 0; k < faceCount; k++) {
- for (uint32_t i = 0; i < faceCount; i++) {
- for (uint32_t j = 0; j < faceCount; j++) {
- shortestPaths[i * faceCount + j] = std::min(shortestPaths[i * faceCount + j], shortestPaths[i * faceCount + k] + shortestPaths[k * faceCount + j]);
- }
+ XA_PROFILE_END(atlasBuilderGrowCharts)
+ return canAddAny && m_facesLeft != 0; // Can continue growing.
+ }
+
+ void resetCharts()
+ {
+ const uint32_t faceCount = m_mesh->faceCount();
+ for (uint32_t i = 0; i < faceCount; i++) {
+ m_faceChartArray[i] = -1;
+ m_faceCandidateArray[i] = (uint32_t)-1;
+ }
+ m_facesLeft = m_meshFaces ? m_meshFaces->size() : faceCount;
+ m_candidateArray.clear();
+ const uint32_t chartCount = m_chartArray.size();
+ for (uint32_t i = 0; i < chartCount; i++) {
+ ChartBuildData *chart = m_chartArray[i];
+ const uint32_t seed = chart->seeds.back();
+ chart->area = 0.0f;
+ chart->boundaryLength = 0.0f;
+ chart->normalSum = Vector3(0.0f);
+ chart->centroidSum = Vector3(0.0f);
+ chart->centroid = Vector3(0.0f);
+ chart->faces.clear();
+ chart->candidates.clear();
+ addFaceToChart(chart, seed);
+ }
+#if XA_GROW_CHARTS_COPLANAR
+ for (uint32_t i = 0; i < chartCount; i++) {
+ ChartBuildData *chart = m_chartArray[i];
+ growChartCoplanar(chart);
+ }
+#endif
+ }
+
+ void updateCandidates(ChartBuildData *chart, uint32_t f)
+ {
+ // Traverse neighboring faces, add the ones that do not belong to any chart yet.
+ for (Mesh::FaceEdgeIterator it(m_mesh, f); !it.isDone(); it.advance()) {
+ if (!it.isBoundary() && !m_ignoreFaces[it.oppositeFace()] && m_faceChartArray[it.oppositeFace()] == -1)
+ chart->candidates.push(it.oppositeFace());
+ }
+ }
+
+ void updateProxies()
+ {
+ const uint32_t chartCount = m_chartArray.size();
+ for (uint32_t i = 0; i < chartCount; i++)
+ updateProxy(m_chartArray[i]);
+ }
+
+ bool relocateSeeds()
+ {
+ bool anySeedChanged = false;
+ const uint32_t chartCount = m_chartArray.size();
+ for (uint32_t i = 0; i < chartCount; i++) {
+ if (relocateSeed(m_chartArray[i])) {
+ anySeedChanged = true;
}
}
+ return anySeedChanged;
}
- void placeSeeds(float threshold, uint32_t maxSeedCount)
+ void fillHoles(float threshold)
{
- // Instead of using a predefiened number of seeds:
- // - Add seeds one by one, growing chart until a certain treshold.
- // - Undo charts and restart growing process.
- // @@ How can we give preference to faces far from sharp features as in the LSCM paper?
- // - those points can be found using a simple flood filling algorithm.
- // - how do we weight the probabilities?
- for (uint32_t i = 0; i < maxSeedCount; i++) {
- if (facesLeft == 0) {
- // No faces left, stop creating seeds.
+ while (m_facesLeft > 0)
+ createRandomChart(threshold);
+ }
+
+#if XA_MERGE_CHARTS
+ void mergeCharts()
+ {
+ XA_PROFILE_START(atlasBuilderMergeCharts)
+ Array<float> sharedBoundaryLengths;
+ Array<float> sharedBoundaryLengthsNoSeams;
+ Array<uint32_t> sharedBoundaryEdgeCountNoSeams;
+ Array<Vector2> tempTexcoords;
+ const uint32_t chartCount = m_chartArray.size();
+ // Merge charts progressively until there's none left to merge.
+ for (;;) {
+ bool merged = false;
+ for (int c = chartCount - 1; c >= 0; c--) {
+ ChartBuildData *chart = m_chartArray[c];
+ if (chart == nullptr)
+ continue;
+ float externalBoundaryLength = 0.0f;
+ sharedBoundaryLengths.clear();
+ sharedBoundaryLengths.resize(chartCount, 0.0f);
+ sharedBoundaryLengthsNoSeams.clear();
+ sharedBoundaryLengthsNoSeams.resize(chartCount, 0.0f);
+ sharedBoundaryEdgeCountNoSeams.clear();
+ sharedBoundaryEdgeCountNoSeams.resize(chartCount, 0u);
+ const uint32_t faceCount = chart->faces.size();
+ for (uint32_t i = 0; i < faceCount; i++) {
+ const uint32_t f = chart->faces[i];
+ for (Mesh::FaceEdgeIterator it(m_mesh, f); !it.isDone(); it.advance()) {
+ const float l = m_edgeLengths[it.edge()];
+ if (it.isBoundary() || m_ignoreFaces[it.oppositeFace()]) {
+ externalBoundaryLength += l;
+ } else {
+ const int neighborChart = m_faceChartArray[it.oppositeFace()];
+ if (m_chartArray[neighborChart] != chart) {
+ if ((it.isSeam() && (isNormalSeam(it.edge()) || it.isTextureSeam()))) {
+ externalBoundaryLength += l;
+ } else {
+ sharedBoundaryLengths[neighborChart] += l;
+ }
+ sharedBoundaryLengthsNoSeams[neighborChart] += l;
+ sharedBoundaryEdgeCountNoSeams[neighborChart]++;
+ }
+ }
+ }
+ }
+ for (int cc = chartCount - 1; cc >= 0; cc--) {
+ if (cc == c)
+ continue;
+ ChartBuildData *chart2 = m_chartArray[cc];
+ if (chart2 == nullptr)
+ continue;
+ // Compare proxies.
+ if (dot(chart2->averageNormal, chart->averageNormal) < XA_MERGE_CHARTS_MIN_NORMAL_DEVIATION)
+ continue;
+ // Obey max chart area and boundary length.
+ if (m_options.maxChartArea > 0.0f && chart->area + chart2->area > m_options.maxChartArea)
+ continue;
+ if (m_options.maxBoundaryLength > 0.0f && chart->boundaryLength + chart2->boundaryLength - sharedBoundaryLengthsNoSeams[cc] > m_options.maxBoundaryLength)
+ continue;
+ // Merge if chart2 has a single face.
+ // chart1 must have more than 1 face.
+ // chart2 area must be <= 10% of chart1 area.
+ if (sharedBoundaryLengthsNoSeams[cc] > 0.0f && chart->faces.size() > 1 && chart2->faces.size() == 1 && chart2->area <= chart->area * 0.1f)
+ goto merge;
+ // Merge if chart2 has two faces (probably a quad), and chart1 bounds at least 2 of its edges.
+ if (chart2->faces.size() == 2 && sharedBoundaryEdgeCountNoSeams[cc] >= 2)
+ goto merge;
+ // Merge if chart2 is wholely inside chart1, ignoring seams.
+ if (sharedBoundaryLengthsNoSeams[cc] > 0.0f && equal(sharedBoundaryLengthsNoSeams[cc], chart2->boundaryLength, kEpsilon))
+ goto merge;
+ if (sharedBoundaryLengths[cc] > 0.2f * max(0.0f, chart->boundaryLength - externalBoundaryLength) ||
+ sharedBoundaryLengths[cc] > 0.75f * chart2->boundaryLength)
+ goto merge;
+ continue;
+ merge:
+ // Create texcoords for chart 2 using chart 1 basis. Backup chart 2 texcoords for restoration if charts cannot be merged.
+ tempTexcoords.resize(chart2->faces.size());
+ for (uint32_t i = 0; i < chart2->faces.size(); i++) {
+ const uint32_t face = chart2->faces[i];
+ tempTexcoords[i] = m_texcoords[face];
+ createFaceTexcoords(chart, face);
+ }
+ if (!canMergeCharts(chart, chart2)) {
+ // Restore chart 2 texcoords.
+ for (uint32_t i = 0; i < chart2->faces.size(); i++)
+ m_texcoords[chart2->faces[i]] = tempTexcoords[i];
+ continue;
+ }
+ mergeChart(chart, chart2, sharedBoundaryLengthsNoSeams[cc]);
+ merged = true;
+ break;
+ }
+ if (merged)
+ break;
+ }
+ if (!merged)
break;
+ }
+ // Remove deleted charts.
+ for (int c = 0; c < int32_t(m_chartArray.size()); /*do not increment if removed*/) {
+ if (m_chartArray[c] == nullptr) {
+ m_chartArray.removeAt(c);
+ // Update m_faceChartArray.
+ const uint32_t faceCount = m_faceChartArray.size();
+ for (uint32_t i = 0; i < faceCount; i++) {
+ XA_DEBUG_ASSERT(m_faceChartArray[i] != c);
+ XA_DEBUG_ASSERT(m_faceChartArray[i] <= int32_t(m_chartArray.size()));
+ if (m_faceChartArray[i] > c) {
+ m_faceChartArray[i]--;
+ }
+ }
+ } else {
+ m_chartArray[c]->id = c;
+ c++;
}
- createRandomChart(threshold);
}
+ XA_PROFILE_END(atlasBuilderMergeCharts)
}
+#endif
+private:
void createRandomChart(float threshold)
{
- ChartBuildData *chart = new ChartBuildData(chartArray.size());
- chartArray.push_back(chart);
+ ChartBuildData *chart = XA_NEW(MemTag::Default, ChartBuildData);
+ chart->id = (int)m_chartArray.size();
+ m_chartArray.push_back(chart);
// Pick random face that is not used by any chart yet.
- uint32_t randomFaceIdx = rand.getRange(facesLeft - 1);
- uint32_t i = 0;
- for (uint32_t f = 0; f != randomFaceIdx; f++, i++) {
- while (faceChartArray[i] != -1) i++;
- }
- while (faceChartArray[i] != -1) i++;
- chart->seeds.push_back(i);
- addFaceToChart(chart, i, true);
+ uint32_t face = m_rand.getRange(m_mesh->faceCount() - 1);
+ while (m_ignoreFaces[face] || m_faceChartArray[face] != -1) {
+ if (++face >= m_mesh->faceCount())
+ face = 0;
+ }
+ chart->seeds.push_back(face);
+ addFaceToChart(chart, face, true);
+#if XA_GROW_CHARTS_COPLANAR
+ growChartCoplanar(chart);
+#endif
// Grow the chart as much as possible within the given threshold.
- growChart(chart, threshold * 0.5f, facesLeft);
- //growCharts(threshold - threshold * 0.75f / chartCount(), facesLeft);
+ growChart(chart, threshold, m_facesLeft);
+ }
+
+ void createFaceTexcoords(ChartBuildData *chart, uint32_t face)
+ {
+ for (uint32_t i = 0; i < 3; i++) {
+ const Vector3 &pos = m_mesh->position(m_mesh->vertexAt(face * 3 + i));
+ m_texcoords[face * 3 + i] = Vector2(dot(chart->basis.tangent, pos), dot(chart->basis.bitangent, pos));
+ }
+ }
+
+ bool isChartBoundaryEdge(ChartBuildData *chart, uint32_t edge) const
+ {
+ const uint32_t oppositeEdge = m_mesh->oppositeEdge(edge);
+ const uint32_t oppositeFace = meshEdgeFace(oppositeEdge);
+ return oppositeEdge == UINT32_MAX || m_ignoreFaces[oppositeFace] || m_faceChartArray[oppositeFace] != chart->id;
+ }
+
+ bool canAddFaceToChart(ChartBuildData *chart, uint32_t face)
+ {
+ // Find face edges that are on a mesh boundary or form a boundary with another chart.
+ uint32_t edgesToCompare[3];
+ for (uint32_t i = 0; i < 3; i++) {
+ const uint32_t edge = face * 3 + i;
+ const uint32_t oppositeEdge = m_mesh->oppositeEdge(edge);
+ const uint32_t oppositeFace = meshEdgeFace(oppositeEdge);
+ if (oppositeEdge == UINT32_MAX || m_ignoreFaces[oppositeFace] || m_faceChartArray[oppositeFace] != chart->id)
+ edgesToCompare[i] = edge;
+ else
+ edgesToCompare[i] = UINT32_MAX;
+ }
+ // All edges on boundary? This can happen if the face is surrounded by the chart.
+ if (edgesToCompare[0] == UINT32_MAX && edgesToCompare[1] == UINT32_MAX && edgesToCompare[2] == UINT32_MAX)
+ return true;
+ // Check if any valid face edge intersects the chart boundary.
+ for (uint32_t i = 0; i < chart->faces.size(); i++) {
+ const uint32_t chartFace = chart->faces[i];
+ for (uint32_t j = 0; j < 3; j++) {
+ const uint32_t chartEdge = chartFace * 3 + j;
+ if (!isChartBoundaryEdge(chart, chartEdge))
+ continue;
+ // Don't check chart boundary edges that border the face.
+ const uint32_t oppositeChartEdge = m_mesh->oppositeEdge(chartEdge);
+ if (meshEdgeFace(oppositeChartEdge) == face)
+ continue;
+ for (uint32_t k = 0; k < 3; k++) {
+ if (edgesToCompare[k] == UINT32_MAX)
+ continue;
+ const uint32_t e1 = chartEdge;
+ const uint32_t e2 = edgesToCompare[k];
+ if (linesIntersect(m_texcoords[meshEdgeIndex0(e1)], m_texcoords[meshEdgeIndex1(e1)], m_texcoords[meshEdgeIndex0(e2)], m_texcoords[meshEdgeIndex1(e2)], m_mesh->epsilon()))
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ bool canMergeCharts(ChartBuildData *chart1, ChartBuildData *chart2)
+ {
+ for (uint32_t f1 = 0; f1 < chart1->faces.size(); f1++) {
+ const uint32_t face1 = chart1->faces[f1];
+ for (uint32_t i = 0; i < 3; i++) {
+ const uint32_t edge1 = face1 * 3 + i;
+ if (!isChartBoundaryEdge(chart1, edge1))
+ continue;
+ for (uint32_t f2 = 0; f2 < chart2->faces.size(); f2++) {
+ const uint32_t face2 = chart2->faces[f2];
+ for (uint32_t j = 0; j < 3; j++) {
+ const uint32_t edge2 = face2 * 3 + j;
+ if (!isChartBoundaryEdge(chart2, edge2))
+ continue;
+ if (linesIntersect(m_texcoords[meshEdgeIndex0(edge1)], m_texcoords[meshEdgeIndex1(edge1)], m_texcoords[meshEdgeIndex0(edge2)], m_texcoords[meshEdgeIndex1(edge2)], m_mesh->epsilon()))
+ return false;
+ }
+ }
+ }
+ }
+ return true;
}
void addFaceToChart(ChartBuildData *chart, uint32_t f, bool recomputeProxy = false)
{
+ // Use the first face normal as the chart basis.
+ if (chart->faces.isEmpty()) {
+ chart->basis.buildFrameForDirection(m_faceNormals[f]);
+ createFaceTexcoords(chart, f);
+ }
// Add face to chart.
chart->faces.push_back(f);
- xaDebugAssert(faceChartArray[f] == -1);
- faceChartArray[f] = chart->id;
- facesLeft--;
+ XA_DEBUG_ASSERT(m_faceChartArray[f] == -1);
+ m_faceChartArray[f] = chart->id;
+ m_facesLeft--;
// Update area and boundary length.
chart->area = evaluateChartArea(chart, f);
chart->boundaryLength = evaluateBoundaryLength(chart, f);
chart->normalSum = evaluateChartNormalSum(chart, f);
- chart->centroidSum = evaluateChartCentroidSum(chart, f);
+ chart->centroidSum += m_mesh->triangleCenter(f);
if (recomputeProxy) {
// Update proxy and candidate's priorities.
updateProxy(chart);
@@ -5126,142 +5183,93 @@ struct AtlasBuilder
updatePriorities(chart);
}
- // Returns true if any of the charts can grow more.
- bool growCharts(float threshold, uint32_t faceCount)
- {
- // Using one global list.
- faceCount = std::min(faceCount, facesLeft);
- for (uint32_t i = 0; i < faceCount; i++) {
- const Candidate &candidate = getBestCandidate();
- if (candidate.metric > threshold) {
- return false; // Can't grow more.
- }
- addFaceToChart(candidate.chart, candidate.face);
- }
- return facesLeft != 0; // Can continue growing.
- }
-
bool growChart(ChartBuildData *chart, float threshold, uint32_t faceCount)
{
// Try to add faceCount faces within threshold to chart.
for (uint32_t i = 0; i < faceCount; ) {
- if (chart->candidates.count() == 0 || chart->candidates.firstPriority() > threshold) {
+ if (chart->candidates.count() == 0 || chart->candidates.firstPriority() > threshold)
return false;
- }
- uint32_t f = chart->candidates.pop();
- if (faceChartArray[f] == -1) {
- addFaceToChart(chart, f);
- i++;
- }
+ const uint32_t f = chart->candidates.pop();
+ if (m_faceChartArray[f] != -1)
+ continue;
+ createFaceTexcoords(chart, f);
+ if (!canAddFaceToChart(chart, f))
+ continue;
+ addFaceToChart(chart, f);
+ i++;
}
- if (chart->candidates.count() == 0 || chart->candidates.firstPriority() > threshold) {
+ if (chart->candidates.count() == 0 || chart->candidates.firstPriority() > threshold)
return false;
- }
return true;
}
- void resetCharts()
- {
- const uint32_t faceCount = mesh->faceCount();
- for (uint32_t i = 0; i < faceCount; i++) {
- faceChartArray[i] = -1;
- faceCandidateArray[i] = (uint32_t)-1;
- }
- facesLeft = faceCount;
- candidateArray.clear();
- const uint32_t chartCount = chartArray.size();
- for (uint32_t i = 0; i < chartCount; i++) {
- ChartBuildData *chart = chartArray[i];
- const uint32_t seed = chart->seeds.back();
- chart->area = 0.0f;
- chart->boundaryLength = 0.0f;
- chart->normalSum = Vector3(0);
- chart->centroidSum = Vector3(0);
- chart->faces.clear();
- chart->candidates.clear();
- addFaceToChart(chart, seed);
- }
- }
-
- void updateCandidates(ChartBuildData *chart, uint32_t f)
+#if XA_GROW_CHARTS_COPLANAR
+ void growChartCoplanar(ChartBuildData *chart)
{
- const halfedge::Face *face = mesh->faceAt(f);
- // Traverse neighboring faces, add the ones that do not belong to any chart yet.
- for (halfedge::Face::ConstEdgeIterator it(face->edges()); !it.isDone(); it.advance()) {
- const halfedge::Edge *edge = it.current()->pair;
- if (!edge->isBoundary()) {
- uint32_t faceId = edge->face->id;
- if (faceChartArray[faceId] == -1) {
- chart->candidates.push(faceId);
+ XA_DEBUG_ASSERT(!chart->faces.isEmpty());
+ const Vector3 chartNormal = m_faceNormals[chart->faces[0]];
+ m_growFaces.clear();
+ for (uint32_t f = 0; f < chart->faces.size(); f++)
+ m_growFaces.push_back(chart->faces[f]);
+ for (;;) {
+ if (m_growFaces.isEmpty())
+ break;
+ const uint32_t face = m_growFaces.back();
+ m_growFaces.pop_back();
+ for (Mesh::FaceEdgeIterator it(m_mesh, face); !it.isDone(); it.advance()) {
+ if (it.isBoundary() || m_ignoreFaces[it.oppositeFace()] || m_faceChartArray[it.oppositeFace()] != -1)
+ continue;
+ if (equal(dot(chartNormal, m_faceNormals[it.oppositeFace()]), 1.0f, kEpsilon)) {
+ createFaceTexcoords(chart, it.oppositeFace());
+ addFaceToChart(chart, it.oppositeFace());
+ m_growFaces.push_back(it.oppositeFace());
}
}
}
}
+#endif
- void updateProxies()
- {
- const uint32_t chartCount = chartArray.size();
- for (uint32_t i = 0; i < chartCount; i++) {
- updateProxy(chartArray[i]);
- }
- }
-
- void updateProxy(ChartBuildData *chart)
+ void updateProxy(ChartBuildData *chart) const
{
//#pragma message(NV_FILE_LINE "TODO: Use best fit plane instead of average normal.")
- chart->planeNormal = normalizeSafe(chart->normalSum, Vector3(0), 0.0f);
+ chart->averageNormal = normalizeSafe(chart->normalSum, Vector3(0), 0.0f);
chart->centroid = chart->centroidSum / float(chart->faces.size());
}
- bool relocateSeeds()
- {
- bool anySeedChanged = false;
- const uint32_t chartCount = chartArray.size();
- for (uint32_t i = 0; i < chartCount; i++) {
- if (relocateSeed(chartArray[i])) {
- anySeedChanged = true;
- }
- }
- return anySeedChanged;
- }
-
bool relocateSeed(ChartBuildData *chart)
{
- Vector3 centroid = computeChartCentroid(chart);
- const uint32_t N = 10; // @@ Hardcoded to 10?
- PriorityQueue bestTriangles(N);
// Find the first N triangles that fit the proxy best.
const uint32_t faceCount = chart->faces.size();
+ m_bestTriangles.clear();
for (uint32_t i = 0; i < faceCount; i++) {
float priority = evaluateProxyFitMetric(chart, chart->faces[i]);
- bestTriangles.push(priority, chart->faces[i]);
+ m_bestTriangles.push(priority, chart->faces[i]);
}
- // Of those, choose the most central triangle.
- uint32_t mostCentral;
+ // Of those, choose the least central triangle.
+ uint32_t leastCentral = 0;
float maxDistance = -1;
- const uint32_t bestCount = bestTriangles.count();
+ const uint32_t bestCount = m_bestTriangles.count();
for (uint32_t i = 0; i < bestCount; i++) {
- const halfedge::Face *face = mesh->faceAt(bestTriangles.pairs[i].face);
- Vector3 faceCentroid = face->triangleCenter();
- float distance = length(centroid - faceCentroid);
+ Vector3 faceCentroid = m_mesh->triangleCenter(m_bestTriangles.pairs[i].face);
+ float distance = length(chart->centroid - faceCentroid);
if (distance > maxDistance) {
maxDistance = distance;
- mostCentral = bestTriangles.pairs[i].face;
+ leastCentral = m_bestTriangles.pairs[i].face;
}
}
- xaDebugAssert(maxDistance >= 0);
+ XA_DEBUG_ASSERT(maxDistance >= 0);
// In order to prevent k-means cyles we record all the previously chosen seeds.
- uint32_t index = std::find(chart->seeds.begin(), chart->seeds.end(), mostCentral) - chart->seeds.begin();
- if (index < chart->seeds.size()) {
- // Move new seed to the end of the seed array.
- uint32_t last = chart->seeds.size() - 1;
- std::swap(chart->seeds[index], chart->seeds[last]);
- return false;
- } else {
- // Append new seed.
- chart->seeds.push_back(mostCentral);
- return true;
+ for (uint32_t i = 0; i < chart->seeds.size(); i++) {
+ if (chart->seeds[i] == leastCentral) {
+ // Move new seed to the end of the seed array.
+ uint32_t last = chart->seeds.size() - 1;
+ swap(chart->seeds[i], chart->seeds[last]);
+ return false;
+ }
}
+ // Append new seed.
+ chart->seeds.push_back(leastCentral);
+ return true;
}
void updatePriorities(ChartBuildData *chart)
@@ -5269,299 +5277,197 @@ struct AtlasBuilder
// Re-evaluate candidate priorities.
uint32_t candidateCount = chart->candidates.count();
for (uint32_t i = 0; i < candidateCount; i++) {
- chart->candidates.pairs[i].priority = evaluatePriority(chart, chart->candidates.pairs[i].face);
- if (faceChartArray[chart->candidates.pairs[i].face] == -1) {
- updateCandidate(chart, chart->candidates.pairs[i].face, chart->candidates.pairs[i].priority);
- }
+ PriorityQueue::Pair &pair = chart->candidates.pairs[i];
+ pair.priority = evaluatePriority(chart, pair.face);
+ if (m_faceChartArray[pair.face] == -1)
+ updateCandidate(chart, pair.face, pair.priority);
}
// Sort candidates.
chart->candidates.sort();
}
// Evaluate combined metric.
- float evaluatePriority(ChartBuildData *chart, uint32_t face)
+ float evaluatePriority(ChartBuildData *chart, uint32_t face) const
{
// Estimate boundary length and area:
- float newBoundaryLength = evaluateBoundaryLength(chart, face);
- float newChartArea = evaluateChartArea(chart, face);
- float F = evaluateProxyFitMetric(chart, face);
- float C = evaluateRoundnessMetric(chart, face, newBoundaryLength, newChartArea);
- float P = evaluateStraightnessMetric(chart, face);
+ const float newChartArea = evaluateChartArea(chart, face);
+ const float newBoundaryLength = evaluateBoundaryLength(chart, face);
+ // Enforce limits strictly:
+ if (m_options.maxChartArea > 0.0f && newChartArea > m_options.maxChartArea)
+ return FLT_MAX;
+ if (m_options.maxBoundaryLength > 0.0f && newBoundaryLength > m_options.maxBoundaryLength)
+ return FLT_MAX;
+ if (dot(m_faceNormals[face], chart->averageNormal) < 0.5f)
+ return FLT_MAX;
// Penalize faces that cross seams, reward faces that close seams or reach boundaries.
- float N = evaluateNormalSeamMetric(chart, face);
- float T = evaluateTextureSeamMetric(chart, face);
+ // Make sure normal seams are fully respected:
+ const float N = evaluateNormalSeamMetric(chart, face);
+ if (m_options.normalSeamMetricWeight >= 1000.0f && N > 0.0f)
+ return FLT_MAX;
+ float cost = m_options.normalSeamMetricWeight * N;
+ if (m_options.proxyFitMetricWeight > 0.0f)
+ cost += m_options.proxyFitMetricWeight * evaluateProxyFitMetric(chart, face);
+ if (m_options.roundnessMetricWeight > 0.0f)
+ cost += m_options.roundnessMetricWeight * evaluateRoundnessMetric(chart, face, newBoundaryLength, newChartArea);
+ if (m_options.straightnessMetricWeight > 0.0f)
+ cost += m_options.straightnessMetricWeight * evaluateStraightnessMetric(chart, face);
+ if (m_options.textureSeamMetricWeight > 0.0f)
+ cost += m_options.textureSeamMetricWeight * evaluateTextureSeamMetric(chart, face);
//float R = evaluateCompletenessMetric(chart, face);
//float D = evaluateDihedralAngleMetric(chart, face);
// @@ Add a metric based on local dihedral angle.
// @@ Tweaking the normal and texture seam metrics.
// - Cause more impedance. Never cross 90 degree edges.
- // -
- float cost = float(
- options.proxyFitMetricWeight * F +
- options.roundnessMetricWeight * C +
- options.straightnessMetricWeight * P +
- options.normalSeamMetricWeight * N +
- options.textureSeamMetricWeight * T);
- // Enforce limits strictly:
- if (newChartArea > options.maxChartArea) cost = FLT_MAX;
- if (newBoundaryLength > options.maxBoundaryLength) cost = FLT_MAX;
- // Make sure normal seams are fully respected:
- if (options.normalSeamMetricWeight >= 1000 && N != 0) cost = FLT_MAX;
- xaAssert(std::isfinite(cost));
+ XA_DEBUG_ASSERT(isFinite(cost));
return cost;
}
// Returns a value in [0-1].
- float evaluateProxyFitMetric(ChartBuildData *chart, uint32_t f)
+ float evaluateProxyFitMetric(ChartBuildData *chart, uint32_t f) const
{
- const halfedge::Face *face = mesh->faceAt(f);
- Vector3 faceNormal = face->triangleNormal();
+ const Vector3 faceNormal = m_faceNormals[f];
// Use plane fitting metric for now:
- return 1 - dot(faceNormal, chart->planeNormal); // @@ normal deviations should be weighted by face area
+ return 1 - dot(faceNormal, chart->averageNormal); // @@ normal deviations should be weighted by face area
}
- float evaluateRoundnessMetric(ChartBuildData *chart, uint32_t /*face*/, float newBoundaryLength, float newChartArea)
+ float evaluateRoundnessMetric(ChartBuildData *chart, uint32_t /*face*/, float newBoundaryLength, float newChartArea) const
{
float roundness = square(chart->boundaryLength) / chart->area;
float newRoundness = square(newBoundaryLength) / newChartArea;
if (newRoundness > roundness) {
- return square(newBoundaryLength) / (newChartArea * 4 * PI);
+ return square(newBoundaryLength) / (newChartArea * 4.0f * kPi);
} else {
// Offer no impedance to faces that improve roundness.
return 0;
}
}
- float evaluateStraightnessMetric(ChartBuildData *chart, uint32_t f)
+ float evaluateStraightnessMetric(ChartBuildData *chart, uint32_t f) const
{
float l_out = 0.0f;
float l_in = 0.0f;
- const halfedge::Face *face = mesh->faceAt(f);
- for (halfedge::Face::ConstEdgeIterator it(face->edges()); !it.isDone(); it.advance()) {
- const halfedge::Edge *edge = it.current();
- float l = edgeLengths[edge->id / 2];
- if (edge->isBoundary()) {
+ for (Mesh::FaceEdgeIterator it(m_mesh, f); !it.isDone(); it.advance()) {
+ float l = m_edgeLengths[it.edge()];
+ if (it.isBoundary() || m_ignoreFaces[it.oppositeFace()]) {
l_out += l;
} else {
- uint32_t neighborFaceId = edge->pair->face->id;
- if (faceChartArray[neighborFaceId] != chart->id) {
+ if (m_faceChartArray[it.oppositeFace()] != chart->id) {
l_out += l;
} else {
l_in += l;
}
}
}
- xaDebugAssert(l_in != 0.0f); // Candidate face must be adjacent to chart. @@ This is not true if the input mesh has zero-length edges.
+ XA_DEBUG_ASSERT(l_in != 0.0f); // Candidate face must be adjacent to chart. @@ This is not true if the input mesh has zero-length edges.
float ratio = (l_out - l_in) / (l_out + l_in);
- return std::min(ratio, 0.0f); // Only use the straightness metric to close gaps.
+ return min(ratio, 0.0f); // Only use the straightness metric to close gaps.
+ }
+
+ bool isNormalSeam(uint32_t edge) const
+ {
+ const uint32_t oppositeEdge = m_mesh->oppositeEdge(edge);
+ if (oppositeEdge == UINT32_MAX)
+ return false; // boundary edge
+ if (m_mesh->flags() & MeshFlags::HasNormals) {
+ const uint32_t v0 = m_mesh->vertexAt(meshEdgeIndex0(edge));
+ const uint32_t v1 = m_mesh->vertexAt(meshEdgeIndex1(edge));
+ const uint32_t ov0 = m_mesh->vertexAt(meshEdgeIndex0(oppositeEdge));
+ const uint32_t ov1 = m_mesh->vertexAt(meshEdgeIndex1(oppositeEdge));
+ return m_mesh->normal(v0) != m_mesh->normal(ov1) || m_mesh->normal(v1) != m_mesh->normal(ov0);
+ }
+ return m_faceNormals[meshEdgeFace(edge)] != m_faceNormals[meshEdgeFace(oppositeEdge)];
}
- float evaluateNormalSeamMetric(ChartBuildData *chart, uint32_t f)
+ float evaluateNormalSeamMetric(ChartBuildData *chart, uint32_t f) const
{
float seamFactor = 0.0f;
float totalLength = 0.0f;
- const halfedge::Face *face = mesh->faceAt(f);
- for (halfedge::Face::ConstEdgeIterator it(face->edges()); !it.isDone(); it.advance()) {
- const halfedge::Edge *edge = it.current();
- if (edge->isBoundary()) {
+ for (Mesh::FaceEdgeIterator it(m_mesh, f); !it.isDone(); it.advance()) {
+ if (it.isBoundary() || m_ignoreFaces[it.oppositeFace()])
continue;
- }
- const uint32_t neighborFaceId = edge->pair->face->id;
- if (faceChartArray[neighborFaceId] != chart->id) {
+ if (m_faceChartArray[it.oppositeFace()] != chart->id)
continue;
- }
- //float l = edge->length();
- float l = edgeLengths[edge->id / 2];
+ float l = m_edgeLengths[it.edge()];
totalLength += l;
- if (!edge->isSeam()) {
+ if (!it.isSeam())
continue;
- }
// Make sure it's a normal seam.
- if (edge->isNormalSeam()) {
- float d0 = clamp(dot(edge->vertex->nor, edge->pair->next->vertex->nor), 0.0f, 1.0f);
- float d1 = clamp(dot(edge->next->vertex->nor, edge->pair->vertex->nor), 0.0f, 1.0f);
- l *= 1 - (d0 + d1) * 0.5f;
+ if (isNormalSeam(it.edge())) {
+ float d;
+ if (m_mesh->flags() & MeshFlags::HasNormals) {
+ const Vector3 &n0 = m_mesh->normal(it.vertex0());
+ const Vector3 &n1 = m_mesh->normal(it.vertex1());
+ const Vector3 &on0 = m_mesh->normal(m_mesh->vertexAt(meshEdgeIndex0(it.oppositeEdge())));
+ const Vector3 &on1 = m_mesh->normal(m_mesh->vertexAt(meshEdgeIndex1(it.oppositeEdge())));
+ const float d0 = clamp(dot(n0, on1), 0.0f, 1.0f);
+ const float d1 = clamp(dot(n1, on0), 0.0f, 1.0f);
+ d = (d0 + d1) * 0.5f;
+ } else {
+ d = clamp(dot(m_faceNormals[f], m_faceNormals[meshEdgeFace(it.oppositeEdge())]), 0.0f, 1.0f);
+ }
+ l *= 1 - d;
seamFactor += l;
}
}
- if (seamFactor == 0) return 0.0f;
+ if (seamFactor <= 0.0f)
+ return 0.0f;
return seamFactor / totalLength;
}
- float evaluateTextureSeamMetric(ChartBuildData *chart, uint32_t f)
+ float evaluateTextureSeamMetric(ChartBuildData *chart, uint32_t f) const
{
float seamLength = 0.0f;
float totalLength = 0.0f;
- const halfedge::Face *face = mesh->faceAt(f);
- for (halfedge::Face::ConstEdgeIterator it(face->edges()); !it.isDone(); it.advance()) {
- const halfedge::Edge *edge = it.current();
- if (edge->isBoundary()) {
+ for (Mesh::FaceEdgeIterator it(m_mesh, f); !it.isDone(); it.advance()) {
+ if (it.isBoundary() || m_ignoreFaces[it.oppositeFace()])
continue;
- }
- const uint32_t neighborFaceId = edge->pair->face->id;
- if (faceChartArray[neighborFaceId] != chart->id) {
+ if (m_faceChartArray[it.oppositeFace()] != chart->id)
continue;
- }
- //float l = edge->length();
- float l = edgeLengths[edge->id / 2];
+ float l = m_edgeLengths[it.edge()];
totalLength += l;
- if (!edge->isSeam()) {
+ if (!it.isSeam())
continue;
- }
// Make sure it's a texture seam.
- if (edge->isTextureSeam()) {
+ if (it.isTextureSeam())
seamLength += l;
- }
}
- if (seamLength == 0.0f) {
+ if (seamLength == 0.0f)
return 0.0f; // Avoid division by zero.
- }
return seamLength / totalLength;
}
- float evaluateChartArea(ChartBuildData *chart, uint32_t f)
+ float evaluateChartArea(ChartBuildData *chart, uint32_t f) const
{
- const halfedge::Face *face = mesh->faceAt(f);
- return chart->area + faceAreas[face->id];
+ return chart->area + m_faceAreas[f];
}
- float evaluateBoundaryLength(ChartBuildData *chart, uint32_t f)
+ float evaluateBoundaryLength(ChartBuildData *chart, uint32_t f) const
{
float boundaryLength = chart->boundaryLength;
// Add new edges, subtract edges shared with the chart.
- const halfedge::Face *face = mesh->faceAt(f);
- for (halfedge::Face::ConstEdgeIterator it(face->edges()); !it.isDone(); it.advance()) {
- const halfedge::Edge *edge = it.current();
- //float edgeLength = edge->length();
- float edgeLength = edgeLengths[edge->id / 2];
- if (edge->isBoundary()) {
+ for (Mesh::FaceEdgeIterator it(m_mesh, f); !it.isDone(); it.advance()) {
+ const float edgeLength = m_edgeLengths[it.edge()];
+ if (it.isBoundary() || m_ignoreFaces[it.oppositeFace()]) {
boundaryLength += edgeLength;
} else {
- uint32_t neighborFaceId = edge->pair->face->id;
- if (faceChartArray[neighborFaceId] != chart->id) {
+ if (m_faceChartArray[it.oppositeFace()] != chart->id)
boundaryLength += edgeLength;
- } else {
+ else
boundaryLength -= edgeLength;
- }
}
}
- return std::max(0.0f, boundaryLength); // @@ Hack!
- }
-
- Vector3 evaluateChartNormalSum(ChartBuildData *chart, uint32_t f)
- {
- const halfedge::Face *face = mesh->faceAt(f);
- return chart->normalSum + face->triangleNormalAreaScaled();
+ return max(0.0f, boundaryLength); // @@ Hack!
}
- Vector3 evaluateChartCentroidSum(ChartBuildData *chart, uint32_t f)
+ Vector3 evaluateChartNormalSum(ChartBuildData *chart, uint32_t f) const
{
- const halfedge::Face *face = mesh->faceAt(f);
- return chart->centroidSum + face->centroid();
- }
-
- Vector3 computeChartCentroid(const ChartBuildData *chart)
- {
- Vector3 centroid(0);
- const uint32_t faceCount = chart->faces.size();
- for (uint32_t i = 0; i < faceCount; i++) {
- const halfedge::Face *face = mesh->faceAt(chart->faces[i]);
- centroid += face->triangleCenter();
- }
- return centroid / float(faceCount);
- }
-
- void fillHoles(float threshold)
- {
- while (facesLeft > 0)
- createRandomChart(threshold);
- }
-
- void mergeCharts()
- {
- std::vector<float> sharedBoundaryLengths;
- const uint32_t chartCount = chartArray.size();
- for (int c = chartCount - 1; c >= 0; c--) {
- sharedBoundaryLengths.clear();
- sharedBoundaryLengths.resize(chartCount, 0.0f);
- ChartBuildData *chart = chartArray[c];
- float externalBoundary = 0.0f;
- const uint32_t faceCount = chart->faces.size();
- for (uint32_t i = 0; i < faceCount; i++) {
- uint32_t f = chart->faces[i];
- const halfedge::Face *face = mesh->faceAt(f);
- for (halfedge::Face::ConstEdgeIterator it(face->edges()); !it.isDone(); it.advance()) {
- const halfedge::Edge *edge = it.current();
- //float l = edge->length();
- float l = edgeLengths[edge->id / 2];
- if (edge->isBoundary()) {
- externalBoundary += l;
- } else {
- uint32_t neighborFace = edge->pair->face->id;
- uint32_t neighborChart = faceChartArray[neighborFace];
- if (neighborChart != (uint32_t)c) {
- if ((edge->isSeam() && (edge->isNormalSeam() || edge->isTextureSeam())) || neighborChart == -2) {
- externalBoundary += l;
- } else {
- sharedBoundaryLengths[neighborChart] += l;
- }
- }
- }
- }
- }
- for (int cc = chartCount - 1; cc >= 0; cc--) {
- if (cc == c)
- continue;
- ChartBuildData *chart2 = chartArray[cc];
- if (chart2 == NULL)
- continue;
- if (sharedBoundaryLengths[cc] > 0.8 * std::max(0.0f, chart->boundaryLength - externalBoundary)) {
- // Try to avoid degenerate configurations.
- if (chart2->boundaryLength > sharedBoundaryLengths[cc]) {
- if (dot(chart2->planeNormal, chart->planeNormal) > -0.25) {
- mergeChart(chart2, chart, sharedBoundaryLengths[cc]);
- delete chart;
- chartArray[c] = NULL;
- break;
- }
- }
- }
- if (sharedBoundaryLengths[cc] > 0.20 * std::max(0.0f, chart->boundaryLength - externalBoundary)) {
- // Compare proxies.
- if (dot(chart2->planeNormal, chart->planeNormal) > 0) {
- mergeChart(chart2, chart, sharedBoundaryLengths[cc]);
- delete chart;
- chartArray[c] = NULL;
- break;
- }
- }
- }
- }
- // Remove deleted charts.
- for (int c = 0; c < int32_t(chartArray.size()); /*do not increment if removed*/) {
- if (chartArray[c] == NULL) {
- chartArray.erase(chartArray.begin() + c);
- // Update faceChartArray.
- const uint32_t faceCount = faceChartArray.size();
- for (uint32_t i = 0; i < faceCount; i++) {
- xaDebugAssert (faceChartArray[i] != -1);
- xaDebugAssert (faceChartArray[i] != c);
- xaDebugAssert (faceChartArray[i] <= int32_t(chartArray.size()));
- if (faceChartArray[i] > c) {
- faceChartArray[i]--;
- }
- }
- } else {
- chartArray[c]->id = c;
- c++;
- }
- }
+ return chart->normalSum + m_mesh->triangleNormalAreaScaled(f);
}
// @@ Cleanup.
struct Candidate {
- uint32_t face;
ChartBuildData *chart;
+ uint32_t face;
float metric;
};
@@ -5570,48 +5476,48 @@ struct AtlasBuilder
{
uint32_t best = 0;
float bestCandidateMetric = FLT_MAX;
- const uint32_t candidateCount = candidateArray.size();
- xaAssert(candidateCount > 0);
+ const uint32_t candidateCount = m_candidateArray.size();
+ XA_ASSERT(candidateCount > 0);
for (uint32_t i = 0; i < candidateCount; i++) {
- const Candidate &candidate = candidateArray[i];
+ const Candidate &candidate = m_candidateArray[i];
if (candidate.metric < bestCandidateMetric) {
bestCandidateMetric = candidate.metric;
best = i;
}
}
- return candidateArray[best];
+ return m_candidateArray[best];
}
void removeCandidate(uint32_t f)
{
- int c = faceCandidateArray[f];
+ int c = m_faceCandidateArray[f];
if (c != -1) {
- faceCandidateArray[f] = (uint32_t)-1;
- if (c == int(candidateArray.size() - 1)) {
- candidateArray.pop_back();
+ m_faceCandidateArray[f] = (uint32_t)-1;
+ if (c == int(m_candidateArray.size() - 1)) {
+ m_candidateArray.pop_back();
} else {
// Replace with last.
- candidateArray[c] = candidateArray[candidateArray.size() - 1];
- candidateArray.pop_back();
- faceCandidateArray[candidateArray[c].face] = c;
+ m_candidateArray[c] = m_candidateArray[m_candidateArray.size() - 1];
+ m_candidateArray.pop_back();
+ m_faceCandidateArray[m_candidateArray[c].face] = c;
}
}
}
void updateCandidate(ChartBuildData *chart, uint32_t f, float metric)
{
- if (faceCandidateArray[f] == -1) {
- const uint32_t index = candidateArray.size();
- faceCandidateArray[f] = index;
- candidateArray.resize(index + 1);
- candidateArray[index].face = f;
- candidateArray[index].chart = chart;
- candidateArray[index].metric = metric;
+ if (m_faceCandidateArray[f] == (uint32_t)-1) {
+ const uint32_t index = m_candidateArray.size();
+ m_faceCandidateArray[f] = index;
+ m_candidateArray.resize(index + 1);
+ m_candidateArray[index].face = f;
+ m_candidateArray[index].chart = chart;
+ m_candidateArray[index].metric = metric;
} else {
- int c = faceCandidateArray[f];
- xaDebugAssert(c != -1);
- Candidate &candidate = candidateArray[c];
- xaDebugAssert(candidate.face == f);
+ const uint32_t c = m_faceCandidateArray[f];
+ XA_DEBUG_ASSERT(c != (uint32_t)-1);
+ Candidate &candidate = m_candidateArray[c];
+ XA_DEBUG_ASSERT(candidate.face == f);
if (metric < candidate.metric || chart == candidate.chart) {
candidate.metric = metric;
candidate.chart = chart;
@@ -5624,803 +5530,585 @@ struct AtlasBuilder
const uint32_t faceCount = chart->faces.size();
for (uint32_t i = 0; i < faceCount; i++) {
uint32_t f = chart->faces[i];
- xaDebugAssert(faceChartArray[f] == chart->id);
- faceChartArray[f] = owner->id;
+ XA_DEBUG_ASSERT(m_faceChartArray[f] == chart->id);
+ m_faceChartArray[f] = owner->id;
owner->faces.push_back(f);
}
// Update adjacencies?
owner->area += chart->area;
owner->boundaryLength += chart->boundaryLength - sharedBoundaryLength;
owner->normalSum += chart->normalSum;
- owner->centroidSum += chart->centroidSum;
updateProxy(owner);
- }
+ // Delete chart.
+ m_chartArray[chart->id] = nullptr;
+ chart->~ChartBuildData();
+ XA_FREE(chart);
+ }
+
+ const Mesh *m_mesh;
+ const Array<uint32_t> *m_meshFaces;
+ Array<bool> m_ignoreFaces;
+ Array<float> m_edgeLengths;
+ Array<float> m_faceAreas;
+ Array<Vector3> m_faceNormals;
+ Array<Vector2> m_texcoords;
+ Array<uint32_t> m_growFaces;
+ uint32_t m_facesLeft;
+ Array<int> m_faceChartArray;
+ Array<ChartBuildData *> m_chartArray;
+ Array<Candidate> m_candidateArray;
+ Array<uint32_t> m_faceCandidateArray; // Map face index to candidate index.
+ PriorityQueue m_bestTriangles;
+ KISSRng m_rand;
+ ChartOptions m_options;
+};
+// Estimate quality of existing parameterization.
+struct ParameterizationQuality
+{
+ uint32_t totalTriangleCount = 0;
+ uint32_t flippedTriangleCount = 0;
+ uint32_t zeroAreaTriangleCount = 0;
+ float parametricArea = 0.0f;
+ float geometricArea = 0.0f;
+ float stretchMetric = 0.0f;
+ float maxStretchMetric = 0.0f;
+ float conformalMetric = 0.0f;
+ float authalicMetric = 0.0f;
+ bool boundaryIntersection = false;
+};
- uint32_t chartCount() const { return chartArray.size(); }
- const std::vector<uint32_t> &chartFaces(uint32_t i) const { return chartArray[i]->faces; }
+static ParameterizationQuality calculateParameterizationQuality(const Mesh *mesh, Array<uint32_t> *flippedFaces)
+{
+ XA_DEBUG_ASSERT(mesh != nullptr);
+ ParameterizationQuality quality;
+ const uint32_t faceCount = mesh->faceCount();
+ uint32_t firstBoundaryEdge = UINT32_MAX;
+ for (uint32_t e = 0; e < mesh->edgeCount(); e++) {
+ if (mesh->isBoundaryEdge(e)) {
+ firstBoundaryEdge = e;
+ }
+ }
+ XA_DEBUG_ASSERT(firstBoundaryEdge != UINT32_MAX);
+ for (Mesh::BoundaryEdgeIterator it1(mesh, firstBoundaryEdge); !it1.isDone(); it1.advance()) {
+ const uint32_t edge1 = it1.edge();
+ for (Mesh::BoundaryEdgeIterator it2(mesh, firstBoundaryEdge); !it2.isDone(); it2.advance()) {
+ const uint32_t edge2 = it2.edge();
+ // Skip self and edges directly connected to edge1.
+ if (edge1 == edge2 || it1.nextEdge() == edge2 || it2.nextEdge() == edge1)
+ continue;
+ const Vector2 &a1 = mesh->texcoord(mesh->vertexAt(meshEdgeIndex0(edge1)));
+ const Vector2 &a2 = mesh->texcoord(mesh->vertexAt(meshEdgeIndex1(edge1)));
+ const Vector2 &b1 = mesh->texcoord(mesh->vertexAt(meshEdgeIndex0(edge2)));
+ const Vector2 &b2 = mesh->texcoord(mesh->vertexAt(meshEdgeIndex1(edge2)));
+ if (linesIntersect(a1, a2, b1, b2, mesh->epsilon())) {
+ quality.boundaryIntersection = true;
+ break;
+ }
+ }
+ if (quality.boundaryIntersection)
+ break;
+ }
+ if (flippedFaces)
+ flippedFaces->clear();
+ for (uint32_t f = 0; f < faceCount; f++) {
+ Vector3 pos[3];
+ Vector2 texcoord[3];
+ for (int i = 0; i < 3; i++) {
+ const uint32_t v = mesh->vertexAt(f * 3 + i);
+ pos[i] = mesh->position(v);
+ texcoord[i] = mesh->texcoord(v);
+ }
+ quality.totalTriangleCount++;
+ // Evaluate texture stretch metric. See:
+ // - "Texture Mapping Progressive Meshes", Sander, Snyder, Gortler & Hoppe
+ // - "Mesh Parameterization: Theory and Practice", Siggraph'07 Course Notes, Hormann, Levy & Sheffer.
+ const float t1 = texcoord[0].x;
+ const float s1 = texcoord[0].y;
+ const float t2 = texcoord[1].x;
+ const float s2 = texcoord[1].y;
+ const float t3 = texcoord[2].x;
+ const float s3 = texcoord[2].y;
+ float parametricArea = ((s2 - s1) * (t3 - t1) - (s3 - s1) * (t2 - t1)) / 2;
+ if (isZero(parametricArea, kAreaEpsilon)) {
+ quality.zeroAreaTriangleCount++;
+ continue;
+ }
+ if (parametricArea < 0.0f) {
+ // Count flipped triangles.
+ quality.flippedTriangleCount++;
+ if (flippedFaces)
+ flippedFaces->push_back(f);
+ parametricArea = fabsf(parametricArea);
+ }
+ const float geometricArea = length(cross(pos[1] - pos[0], pos[2] - pos[0])) / 2;
+ const Vector3 Ss = (pos[0] * (t2 - t3) + pos[1] * (t3 - t1) + pos[2] * (t1 - t2)) / (2 * parametricArea);
+ const Vector3 St = (pos[0] * (s3 - s2) + pos[1] * (s1 - s3) + pos[2] * (s2 - s1)) / (2 * parametricArea);
+ const float a = dot(Ss, Ss); // E
+ const float b = dot(Ss, St); // F
+ const float c = dot(St, St); // G
+ // Compute eigen-values of the first fundamental form:
+ const float sigma1 = sqrtf(0.5f * max(0.0f, a + c - sqrtf(square(a - c) + 4 * square(b)))); // gamma uppercase, min eigenvalue.
+ const float sigma2 = sqrtf(0.5f * max(0.0f, a + c + sqrtf(square(a - c) + 4 * square(b)))); // gamma lowercase, max eigenvalue.
+ XA_ASSERT(sigma2 > sigma1 || equal(sigma1, sigma2, kEpsilon));
+ // isometric: sigma1 = sigma2 = 1
+ // conformal: sigma1 / sigma2 = 1
+ // authalic: sigma1 * sigma2 = 1
+ const float rmsStretch = sqrtf((a + c) * 0.5f);
+ const float rmsStretch2 = sqrtf((square(sigma1) + square(sigma2)) * 0.5f);
+ XA_DEBUG_ASSERT(equal(rmsStretch, rmsStretch2, 0.01f));
+ XA_UNUSED(rmsStretch2);
+ quality.stretchMetric += square(rmsStretch) * geometricArea;
+ quality.maxStretchMetric = max(quality.maxStretchMetric, sigma2);
+ if (!isZero(sigma1, 0.000001f)) {
+ // sigma1 is zero when geometricArea is zero.
+ quality.conformalMetric += (sigma2 / sigma1) * geometricArea;
+ }
+ quality.authalicMetric += (sigma1 * sigma2) * geometricArea;
+ // Accumulate total areas.
+ quality.geometricArea += geometricArea;
+ quality.parametricArea += parametricArea;
+ //triangleConformalEnergy(q, p);
+ }
+ if (quality.flippedTriangleCount + quality.zeroAreaTriangleCount == quality.totalTriangleCount) {
+ // If all triangles are flipped, then none are.
+ if (flippedFaces)
+ flippedFaces->clear();
+ quality.flippedTriangleCount = 0;
+ }
+ if (quality.flippedTriangleCount > quality.totalTriangleCount / 2)
+ {
+ // If more than half the triangles are flipped, reverse the flipped / not flipped classification.
+ quality.flippedTriangleCount = quality.totalTriangleCount - quality.flippedTriangleCount;
+ if (flippedFaces) {
+ Array<uint32_t> temp(*flippedFaces);
+ flippedFaces->clear();
+ for (uint32_t f = 0; f < faceCount; f++) {
+ bool match = false;
+ for (uint32_t ff = 0; ff < temp.size(); ff++) {
+ if (temp[ff] == f) {
+ match = true;
+ break;
+ }
+ }
+ if (!match)
+ flippedFaces->push_back(f);
+ }
+ }
+ }
+ XA_DEBUG_ASSERT(isFinite(quality.parametricArea) && quality.parametricArea >= 0);
+ XA_DEBUG_ASSERT(isFinite(quality.geometricArea) && quality.geometricArea >= 0);
+ XA_DEBUG_ASSERT(isFinite(quality.stretchMetric));
+ XA_DEBUG_ASSERT(isFinite(quality.maxStretchMetric));
+ XA_DEBUG_ASSERT(isFinite(quality.conformalMetric));
+ XA_DEBUG_ASSERT(isFinite(quality.authalicMetric));
+ if (quality.geometricArea <= 0.0f) {
+ quality.stretchMetric = 0.0f;
+ quality.maxStretchMetric = 0.0f;
+ quality.conformalMetric = 0.0f;
+ quality.authalicMetric = 0.0f;
+ } else {
+ const float normFactor = sqrtf(quality.parametricArea / quality.geometricArea);
+ quality.stretchMetric = sqrtf(quality.stretchMetric / quality.geometricArea) * normFactor;
+ quality.maxStretchMetric *= normFactor;
+ quality.conformalMetric = sqrtf(quality.conformalMetric / quality.geometricArea);
+ quality.authalicMetric = sqrtf(quality.authalicMetric / quality.geometricArea);
+ }
+ return quality;
+}
- const halfedge::Mesh *mesh;
- uint32_t facesLeft;
- std::vector<int> faceChartArray;
- std::vector<ChartBuildData *> chartArray;
- std::vector<float> shortestPaths;
- std::vector<float> edgeLengths;
- std::vector<float> faceAreas;
- std::vector<Candidate> candidateArray; //
- std::vector<uint32_t> faceCandidateArray; // Map face index to candidate index.
- MTRand rand;
- CharterOptions options;
+struct ChartWarningFlags
+{
+ enum Enum
+ {
+ CloseHolesFailed = 1<<1,
+ FixTJunctionsDuplicatedEdge = 1<<2,
+ FixTJunctionsFailed = 1<<3,
+ TriangulateDuplicatedEdge = 1<<4,
+ };
};
/// A chart is a connected set of faces with a certain topology (usually a disk).
class Chart
{
public:
- Chart() : m_isDisk(false), m_isVertexMapped(false) {}
-
- void build(const halfedge::Mesh *originalMesh, const std::vector<uint32_t> &faceArray)
+ Chart(const Mesh *originalMesh, const Array<uint32_t> &faceArray, const Basis &basis, uint32_t meshId, uint32_t chartGroupId, uint32_t chartId) : m_basis(basis), m_mesh(nullptr), m_unifiedMesh(nullptr), m_isDisk(false), m_isOrtho(false), m_isPlanar(false), m_warningFlags(0), m_closedHolesCount(0), m_fixedTJunctionsCount(0), m_faceArray(faceArray)
{
+ XA_UNUSED(meshId);
+ XA_UNUSED(chartGroupId);
+ XA_UNUSED(chartId);
// Copy face indices.
- m_faceArray = faceArray;
- const uint32_t meshVertexCount = originalMesh->vertexCount();
- m_chartMesh.reset(new halfedge::Mesh());
- m_unifiedMesh.reset(new halfedge::Mesh());
- std::vector<uint32_t> chartMeshIndices(meshVertexCount, (uint32_t)~0);
- std::vector<uint32_t> unifiedMeshIndices(meshVertexCount, (uint32_t)~0);
+ m_mesh = XA_NEW(MemTag::Mesh, Mesh, originalMesh->epsilon(), faceArray.size() * 3, faceArray.size());
+ m_unifiedMesh = XA_NEW(MemTag::Mesh, Mesh, originalMesh->epsilon(), faceArray.size() * 3, faceArray.size());
+ Array<uint32_t> chartMeshIndices;
+ chartMeshIndices.resize(originalMesh->vertexCount(), (uint32_t)~0);
+ Array<uint32_t> unifiedMeshIndices;
+ unifiedMeshIndices.resize(originalMesh->vertexCount(), (uint32_t)~0);
// Add vertices.
const uint32_t faceCount = faceArray.size();
for (uint32_t f = 0; f < faceCount; f++) {
- const halfedge::Face *face = originalMesh->faceAt(faceArray[f]);
- xaDebugAssert(face != NULL);
- for (halfedge::Face::ConstEdgeIterator it(face->edges()); !it.isDone(); it.advance()) {
- const halfedge::Vertex *vertex = it.current()->vertex;
- const halfedge::Vertex *unifiedVertex = vertex->firstColocal();
- if (unifiedMeshIndices[unifiedVertex->id] == ~0) {
- unifiedMeshIndices[unifiedVertex->id] = m_unifiedMesh->vertexCount();
- xaDebugAssert(vertex->pos == unifiedVertex->pos);
- m_unifiedMesh->addVertex(vertex->pos);
+ for (uint32_t i = 0; i < 3; i++) {
+ const uint32_t vertex = originalMesh->vertexAt(faceArray[f] * 3 + i);
+ const uint32_t unifiedVertex = originalMesh->firstColocal(vertex);
+ if (unifiedMeshIndices[unifiedVertex] == (uint32_t)~0) {
+ unifiedMeshIndices[unifiedVertex] = m_unifiedMesh->vertexCount();
+ XA_DEBUG_ASSERT(equal(originalMesh->position(vertex), originalMesh->position(unifiedVertex), originalMesh->epsilon()));
+ m_unifiedMesh->addVertex(originalMesh->position(vertex));
}
- if (chartMeshIndices[vertex->id] == ~0) {
- chartMeshIndices[vertex->id] = m_chartMesh->vertexCount();
- // -- GODOT start --
- //m_chartToOriginalMap.push_back(vertex->id);
- m_chartToOriginalMap.push_back(vertex->original_id);
- // -- GODOT end --
- m_chartToUnifiedMap.push_back(unifiedMeshIndices[unifiedVertex->id]);
- halfedge::Vertex *v = m_chartMesh->addVertex(vertex->pos);
- v->nor = vertex->nor;
- v->tex = vertex->tex;
+ if (chartMeshIndices[vertex] == (uint32_t)~0) {
+ chartMeshIndices[vertex] = m_mesh->vertexCount();
+ m_chartToOriginalMap.push_back(vertex);
+ m_chartToUnifiedMap.push_back(unifiedMeshIndices[unifiedVertex]);
+ m_mesh->addVertex(originalMesh->position(vertex), Vector3(0.0f), originalMesh->texcoord(vertex));
}
}
}
- // This is ignoring the canonical map:
- // - Is it really necessary to link colocals?
- m_chartMesh->linkColocals();
- //m_unifiedMesh->linkColocals(); // Not strictly necessary, no colocals in the unified mesh. # Wrong.
- // This check is not valid anymore, if the original mesh vertices were linked with a canonical map, then it might have
- // some colocal vertices that were unlinked. So, the unified mesh might have some duplicate vertices, because firstColocal()
- // is not guaranteed to return the same vertex for two colocal vertices.
- //xaAssert(m_chartMesh->colocalVertexCount() == m_unifiedMesh->vertexCount());
- // Is that OK? What happens in meshes were that happens? Does anything break? Apparently not...
- std::vector<uint32_t> faceIndices;
- faceIndices.reserve(7);
// Add faces.
for (uint32_t f = 0; f < faceCount; f++) {
- const halfedge::Face *face = originalMesh->faceAt(faceArray[f]);
- xaDebugAssert(face != NULL);
- faceIndices.clear();
- for (halfedge::Face::ConstEdgeIterator it(face->edges()); !it.isDone(); it.advance()) {
- const halfedge::Vertex *vertex = it.current()->vertex;
- xaDebugAssert(vertex != NULL);
- faceIndices.push_back(chartMeshIndices[vertex->id]);
- }
- m_chartMesh->addFace(faceIndices);
- faceIndices.clear();
- for (halfedge::Face::ConstEdgeIterator it(face->edges()); !it.isDone(); it.advance()) {
- const halfedge::Vertex *vertex = it.current()->vertex;
- xaDebugAssert(vertex != NULL);
- vertex = vertex->firstColocal();
- faceIndices.push_back(unifiedMeshIndices[vertex->id]);
- }
- m_unifiedMesh->addFace(faceIndices);
- }
- m_chartMesh->linkBoundary();
- m_unifiedMesh->linkBoundary();
- //exportMesh(m_unifiedMesh.ptr(), "debug_input.obj");
- if (m_unifiedMesh->splitBoundaryEdges()) {
- m_unifiedMesh.reset(halfedge::unifyVertices(m_unifiedMesh.get()));
- }
- //exportMesh(m_unifiedMesh.ptr(), "debug_split.obj");
- // Closing the holes is not always the best solution and does not fix all the problems.
- // We need to do some analysis of the holes and the genus to:
- // - Find cuts that reduce genus.
- // - Find cuts to connect holes.
- // - Use minimal spanning trees or seamster.
- if (!closeHoles()) {
- /*static int pieceCount = 0;
- StringBuilder fileName;
- fileName.format("debug_hole_%d.obj", pieceCount++);
- exportMesh(m_unifiedMesh.ptr(), fileName.str());*/
- }
- m_unifiedMesh.reset(halfedge::triangulate(m_unifiedMesh.get()));
- //exportMesh(m_unifiedMesh.ptr(), "debug_triangulated.obj");
- // Analyze chart topology.
- halfedge::MeshTopology topology(m_unifiedMesh.get());
- m_isDisk = topology.isDisk();
- }
-
- void buildVertexMap(const halfedge::Mesh *originalMesh, const std::vector<uint32_t> &unchartedMaterialArray)
- {
- xaAssert(m_chartMesh.get() == NULL && m_unifiedMesh.get() == NULL);
- m_isVertexMapped = true;
- // Build face indices.
- m_faceArray.clear();
- const uint32_t meshFaceCount = originalMesh->faceCount();
- for (uint32_t f = 0; f < meshFaceCount; f++) {
- const halfedge::Face *face = originalMesh->faceAt(f);
- if (std::find(unchartedMaterialArray.begin(), unchartedMaterialArray.end(), face->material) != unchartedMaterialArray.end()) {
- m_faceArray.push_back(f);
- }
- }
- const uint32_t faceCount = m_faceArray.size();
- if (faceCount == 0) {
- return;
- }
- // @@ The chartMesh construction is basically the same as with regular charts, don't duplicate!
- const uint32_t meshVertexCount = originalMesh->vertexCount();
- m_chartMesh.reset(new halfedge::Mesh());
- std::vector<uint32_t> chartMeshIndices(meshVertexCount, (uint32_t)~0);
- // Vertex map mesh only has disconnected vertices.
- for (uint32_t f = 0; f < faceCount; f++) {
- const halfedge::Face *face = originalMesh->faceAt(m_faceArray[f]);
- xaDebugAssert(face != NULL);
- for (halfedge::Face::ConstEdgeIterator it(face->edges()); !it.isDone(); it.advance()) {
- const halfedge::Vertex *vertex = it.current()->vertex;
- if (chartMeshIndices[vertex->id] == ~0) {
- chartMeshIndices[vertex->id] = m_chartMesh->vertexCount();
- // -- GODOT start --
- //m_chartToOriginalMap.push_back(vertex->id);
- m_chartToOriginalMap.push_back(vertex->original_id);
- // -- GODOT end --
- halfedge::Vertex *v = m_chartMesh->addVertex(vertex->pos);
- v->nor = vertex->nor;
- v->tex = vertex->tex; // @@ Not necessary.
- }
+ uint32_t indices[3], unifiedIndices[3];
+ for (uint32_t i = 0; i < 3; i++) {
+ const uint32_t vertex = originalMesh->vertexAt(faceArray[f] * 3 + i);
+ indices[i] = chartMeshIndices[vertex];
+ unifiedIndices[i] = unifiedMeshIndices[originalMesh->firstColocal(vertex)];
+ }
+ Mesh::AddFaceResult::Enum result = m_mesh->addFace(indices);
+ XA_UNUSED(result);
+ XA_DEBUG_ASSERT(result == Mesh::AddFaceResult::OK);
+#if XA_DEBUG
+ // Unifying colocals may create degenerate edges. e.g. if two triangle vertices are colocal.
+ for (int i = 0; i < 3; i++) {
+ const uint32_t index1 = unifiedIndices[i];
+ const uint32_t index2 = unifiedIndices[(i + 1) % 3];
+ XA_DEBUG_ASSERT(index1 != index2);
}
- }
- // @@ Link colocals using the original mesh canonical map? Build canonical map on the fly? Do we need to link colocals at all for this?
- //m_chartMesh->linkColocals();
- std::vector<uint32_t> faceIndices;
- faceIndices.reserve(7);
- // Add faces.
- for (uint32_t f = 0; f < faceCount; f++) {
- const halfedge::Face *face = originalMesh->faceAt(m_faceArray[f]);
- xaDebugAssert(face != NULL);
- faceIndices.clear();
- for (halfedge::Face::ConstEdgeIterator it(face->edges()); !it.isDone(); it.advance()) {
- const halfedge::Vertex *vertex = it.current()->vertex;
- xaDebugAssert(vertex != NULL);
- xaDebugAssert(chartMeshIndices[vertex->id] != ~0);
- faceIndices.push_back(chartMeshIndices[vertex->id]);
- }
- halfedge::Face *new_face = m_chartMesh->addFace(faceIndices);
- xaDebugAssert(new_face != NULL);
-#ifdef NDEBUG
- new_face = NULL; // silence unused parameter warning
#endif
- }
- m_chartMesh->linkBoundary();
- const uint32_t chartVertexCount = m_chartMesh->vertexCount();
- Box bounds;
- bounds.clearBounds();
- for (uint32_t i = 0; i < chartVertexCount; i++) {
- halfedge::Vertex *vertex = m_chartMesh->vertexAt(i);
- bounds.addPointToBounds(vertex->pos);
- }
- ProximityGrid grid;
- grid.init(bounds, chartVertexCount);
- for (uint32_t i = 0; i < chartVertexCount; i++) {
- halfedge::Vertex *vertex = m_chartMesh->vertexAt(i);
- grid.add(vertex->pos, i);
- }
- uint32_t texelCount = 0;
- const float positionThreshold = 0.01f;
- const float normalThreshold = 0.01f;
- uint32_t verticesVisited = 0;
- uint32_t cellsVisited = 0;
- std::vector<int> vertexIndexArray(chartVertexCount, -1); // Init all indices to -1.
- // Traverse vertices in morton order. @@ It may be more interesting to sort them based on orientation.
- const uint32_t cellCodeCount = grid.mortonCount();
- for (uint32_t cellCode = 0; cellCode < cellCodeCount; cellCode++) {
- int cell = grid.mortonIndex(cellCode);
- if (cell < 0) continue;
- cellsVisited++;
- const std::vector<uint32_t> &indexArray = grid.cellArray[cell].indexArray;
- for (uint32_t i = 0; i < indexArray.size(); i++) {
- uint32_t idx = indexArray[i];
- halfedge::Vertex *vertex = m_chartMesh->vertexAt(idx);
- xaDebugAssert(vertexIndexArray[idx] == -1);
- std::vector<uint32_t> neighbors;
- grid.gather(vertex->pos, positionThreshold, /*ref*/neighbors);
- // Compare against all nearby vertices, cluster greedily.
- for (uint32_t j = 0; j < neighbors.size(); j++) {
- uint32_t otherIdx = neighbors[j];
- if (vertexIndexArray[otherIdx] != -1) {
- halfedge::Vertex *otherVertex = m_chartMesh->vertexAt(otherIdx);
- if (distance(vertex->pos, otherVertex->pos) < positionThreshold &&
- distance(vertex->nor, otherVertex->nor) < normalThreshold) {
- vertexIndexArray[idx] = vertexIndexArray[otherIdx];
- break;
+ result = m_unifiedMesh->addFace(unifiedIndices);
+ XA_UNUSED(result);
+ XA_DEBUG_ASSERT(result == Mesh::AddFaceResult::OK);
+ }
+ m_mesh->createBoundaries(); // For AtlasPacker::computeBoundingBox
+ m_unifiedMesh->createBoundaries();
+ m_unifiedMesh->linkBoundaries();
+ m_isPlanar = meshIsPlanar(*m_unifiedMesh);
+ if (m_isPlanar) {
+ m_isDisk = true;
+ } else {
+#if XA_DEBUG_EXPORT_OBJ_BEFORE_FIX_TJUNCTION
+ m_unifiedMesh->writeObjFile("debug_before_fix_tjunction.obj");
+#endif
+ bool duplicatedEdge = false, failed = false;
+ XA_PROFILE_START(fixChartMeshTJunctions)
+ Mesh *fixedUnifiedMesh = meshFixTJunctions(*m_unifiedMesh, &duplicatedEdge, &failed, &m_fixedTJunctionsCount);
+ XA_PROFILE_END(fixChartMeshTJunctions)
+ if (fixedUnifiedMesh) {
+ if (duplicatedEdge)
+ m_warningFlags |= ChartWarningFlags::FixTJunctionsDuplicatedEdge;
+ if (failed)
+ m_warningFlags |= ChartWarningFlags::FixTJunctionsFailed;
+ m_unifiedMesh->~Mesh();
+ XA_FREE(m_unifiedMesh);
+ m_unifiedMesh = fixedUnifiedMesh;
+ m_unifiedMesh->createBoundaries();
+ m_unifiedMesh->linkBoundaries();
+ }
+ // See if there are any holes that need closing.
+ Array<uint32_t> boundaryLoops;
+ meshGetBoundaryLoops(*m_unifiedMesh, boundaryLoops);
+ if (boundaryLoops.size() > 1) {
+#if XA_DEBUG_EXPORT_OBJ_CLOSE_HOLES_ERROR
+ const uint32_t faceCountBeforeHolesClosed = m_unifiedMesh->faceCount();
+#endif
+ // Closing the holes is not always the best solution and does not fix all the problems.
+ // We need to do some analysis of the holes and the genus to:
+ // - Find cuts that reduce genus.
+ // - Find cuts to connect holes.
+ // - Use minimal spanning trees or seamster.
+ Array<uint32_t> holeFaceCounts;
+ XA_PROFILE_START(closeChartMeshHoles)
+ failed = !meshCloseHoles(m_unifiedMesh, boundaryLoops, basis.normal, holeFaceCounts);
+ XA_PROFILE_END(closeChartMeshHoles)
+ m_unifiedMesh->createBoundaries();
+ m_unifiedMesh->linkBoundaries();
+ meshGetBoundaryLoops(*m_unifiedMesh, boundaryLoops);
+ if (failed || boundaryLoops.size() > 1)
+ m_warningFlags |= ChartWarningFlags::CloseHolesFailed;
+ m_closedHolesCount = holeFaceCounts.size();
+#if XA_DEBUG_EXPORT_OBJ_CLOSE_HOLES_ERROR
+ if (m_warningFlags & ChartWarningFlags::CloseHolesFailed) {
+ char filename[256];
+ XA_SPRINTF(filename, sizeof(filename), "debug_mesh_%03u_chartgroup_%03u_chart_%03u_close_holes_error.obj", meshId, chartGroupId, chartId);
+ FILE *file;
+ XA_FOPEN(file, filename, "w");
+ if (file) {
+ m_unifiedMesh->writeObjVertices(file);
+ fprintf(file, "s off\n");
+ fprintf(file, "o object\n");
+ for (uint32_t i = 0; i < faceCountBeforeHolesClosed; i++)
+ m_unifiedMesh->writeObjFace(file, i);
+ uint32_t face = faceCountBeforeHolesClosed;
+ for (uint32_t i = 0; i < holeFaceCounts.size(); i++) {
+ fprintf(file, "s off\n");
+ fprintf(file, "o hole%u\n", i);
+ for (uint32_t j = 0; j < holeFaceCounts[i]; j++) {
+ m_unifiedMesh->writeObjFace(file, face);
+ face++;
+ }
}
+ m_unifiedMesh->writeObjBoundaryEges(file);
+ m_unifiedMesh->writeObjLinkedBoundaries(file);
+ fclose(file);
}
}
- // If index not assigned, assign new one.
- if (vertexIndexArray[idx] == -1) {
- vertexIndexArray[idx] = texelCount++;
- }
- verticesVisited++;
- }
- }
- xaDebugAssert(cellsVisited == grid.cellArray.size());
- xaDebugAssert(verticesVisited == chartVertexCount);
- vertexMapWidth = ftoi_ceil(sqrtf(float(texelCount)));
- vertexMapWidth = (vertexMapWidth + 3) & ~3; // Width aligned to 4.
- vertexMapHeight = vertexMapWidth == 0 ? 0 : (texelCount + vertexMapWidth - 1) / vertexMapWidth;
- //vertexMapHeight = (vertexMapHeight + 3) & ~3; // Height aligned to 4.
- xaDebugAssert(vertexMapWidth >= vertexMapHeight);
- xaPrint("Reduced vertex count from %d to %d.\n", chartVertexCount, texelCount);
- // Lay down the clustered vertices in morton order.
- std::vector<uint32_t> texelCodes(texelCount);
- // For each texel, assign one morton code.
- uint32_t texelCode = 0;
- for (uint32_t i = 0; i < texelCount; i++) {
- uint32_t x, y;
- do {
- x = morton::decodeMorton2X(texelCode);
- y = morton::decodeMorton2Y(texelCode);
- texelCode++;
- } while (x >= uint32_t(vertexMapWidth) || y >= uint32_t(vertexMapHeight));
- texelCodes[i] = texelCode - 1;
- }
- for (uint32_t i = 0; i < chartVertexCount; i++) {
- halfedge::Vertex *vertex = m_chartMesh->vertexAt(i);
- int idx = vertexIndexArray[i];
- if (idx != -1) {
- uint32_t tc = texelCodes[idx];
- uint32_t x = morton::decodeMorton2X(tc);
- uint32_t y = morton::decodeMorton2Y(tc);
- vertex->tex.x = float(x);
- vertex->tex.y = float(y);
- }
- }
- }
-
- bool closeHoles()
- {
- xaDebugAssert(!m_isVertexMapped);
- std::vector<halfedge::Edge *> boundaryEdges;
- getBoundaryEdges(m_unifiedMesh.get(), boundaryEdges);
- uint32_t boundaryCount = boundaryEdges.size();
- if (boundaryCount <= 1) {
- // Nothing to close.
- return true;
- }
- // Compute lengths and areas.
- std::vector<float> boundaryLengths;
- for (uint32_t i = 0; i < boundaryCount; i++) {
- const halfedge::Edge *startEdge = boundaryEdges[i];
- xaAssert(startEdge->face == NULL);
- //float boundaryEdgeCount = 0;
- float boundaryLength = 0.0f;
- //Vector3 boundaryCentroid(zero);
- const halfedge::Edge *edge = startEdge;
- do {
- Vector3 t0 = edge->from()->pos;
- Vector3 t1 = edge->to()->pos;
- //boundaryEdgeCount++;
- boundaryLength += length(t1 - t0);
- //boundaryCentroid += edge->vertex()->pos;
- edge = edge->next;
- } while (edge != startEdge);
- boundaryLengths.push_back(boundaryLength);
- //boundaryCentroids.append(boundaryCentroid / boundaryEdgeCount);
- }
- // Find disk boundary.
- uint32_t diskBoundary = 0;
- float maxLength = boundaryLengths[0];
- for (uint32_t i = 1; i < boundaryCount; i++) {
- if (boundaryLengths[i] > maxLength) {
- maxLength = boundaryLengths[i];
- diskBoundary = i;
- }
- }
- // Close holes.
- for (uint32_t i = 0; i < boundaryCount; i++) {
- if (diskBoundary == i) {
- // Skip disk boundary.
- continue;
+#endif
}
- halfedge::Edge *startEdge = boundaryEdges[i];
- xaDebugAssert(startEdge != NULL);
- xaDebugAssert(startEdge->face == NULL);
- std::vector<halfedge::Vertex *> vertexLoop;
- std::vector<halfedge::Edge *> edgeLoop;
- halfedge::Edge *edge = startEdge;
- do {
- halfedge::Vertex *vertex = edge->next->vertex; // edge->to()
- uint32_t j;
- for (j = 0; j < vertexLoop.size(); j++) {
- if (vertex->isColocal(vertexLoop[j])) {
- break;
- }
- }
- bool isCrossing = (j != vertexLoop.size());
- if (isCrossing) {
- halfedge::Edge *prev = edgeLoop[j]; // Previous edge before the loop.
- halfedge::Edge *next = edge->next; // Next edge after the loop.
- xaDebugAssert(prev->to()->isColocal(next->from()));
- // Close loop.
- edgeLoop.push_back(edge);
- closeLoop(j + 1, edgeLoop);
- // Link boundary loop.
- prev->setNext(next);
- vertex->setEdge(next);
- // Start over again.
- vertexLoop.clear();
- edgeLoop.clear();
- edge = startEdge;
- vertex = edge->to();
- }
- vertexLoop.push_back(vertex);
- edgeLoop.push_back(edge);
- edge = edge->next;
- } while (edge != startEdge);
- closeLoop(0, edgeLoop);
+ // Note: MeshTopology needs linked boundaries.
+ MeshTopology topology(m_unifiedMesh);
+ m_isDisk = topology.isDisk();
+#if XA_DEBUG_EXPORT_OBJ_NOT_DISK
+ if (!m_isDisk) {
+ char filename[256];
+ XA_SPRINTF(filename, sizeof(filename), "debug_mesh_%03u_chartgroup_%03u_chart_%03u_not_disk.obj", meshId, chartGroupId, chartId);
+ m_unifiedMesh->writeObjFile(filename);
+ }
+#endif
}
- getBoundaryEdges(m_unifiedMesh.get(), boundaryEdges);
- boundaryCount = boundaryEdges.size();
- xaDebugAssert(boundaryCount == 1);
- return boundaryCount == 1;
- }
-
- bool isDisk() const
- {
- return m_isDisk;
- }
- bool isVertexMapped() const
- {
- return m_isVertexMapped;
- }
-
- uint32_t vertexCount() const
- {
- return m_chartMesh->vertexCount();
- }
- uint32_t colocalVertexCount() const
- {
- return m_unifiedMesh->vertexCount();
}
- uint32_t faceCount() const
+ ~Chart()
{
- return m_faceArray.size();
- }
- uint32_t faceAt(uint32_t i) const
- {
- return m_faceArray[i];
- }
-
- const halfedge::Mesh *chartMesh() const
- {
- return m_chartMesh.get();
- }
- halfedge::Mesh *chartMesh()
- {
- return m_chartMesh.get();
- }
- const halfedge::Mesh *unifiedMesh() const
- {
- return m_unifiedMesh.get();
- }
- halfedge::Mesh *unifiedMesh()
- {
- return m_unifiedMesh.get();
+ if (m_mesh) {
+ m_mesh->~Mesh();
+ XA_FREE(m_mesh);
+ }
+ if (m_unifiedMesh) {
+ m_unifiedMesh->~Mesh();
+ XA_FREE(m_unifiedMesh);
+ }
}
- //uint32_t vertexIndex(uint32_t i) const { return m_vertexIndexArray[i]; }
+ const Basis &basis() const { return m_basis; }
+ bool isDisk() const { return m_isDisk; }
+ bool isOrtho() const { return m_isOrtho; }
+ bool isPlanar() const { return m_isPlanar; }
+ uint32_t warningFlags() const { return m_warningFlags; }
+ uint32_t closedHolesCount() const { return m_closedHolesCount; }
+ uint32_t fixedTJunctionsCount() const { return m_fixedTJunctionsCount; }
+ const ParameterizationQuality &paramQuality() const { return m_paramQuality; }
+#if XA_DEBUG_EXPORT_OBJ_INVALID_PARAMETERIZATION
+ const Array<uint32_t> &paramFlippedFaces() const { return m_paramFlippedFaces; }
+#endif
+ uint32_t mapFaceToSourceFace(uint32_t i) const { return m_faceArray[i]; }
+ const Mesh *mesh() const { return m_mesh; }
+ Mesh *mesh() { return m_mesh; }
+ const Mesh *unifiedMesh() const { return m_unifiedMesh; }
+ Mesh *unifiedMesh() { return m_unifiedMesh; }
+ uint32_t mapChartVertexToOriginalVertex(uint32_t i) const { return m_chartToOriginalMap[i]; }
- uint32_t mapChartVertexToOriginalVertex(uint32_t i) const
- {
- return m_chartToOriginalMap[i];
- }
- uint32_t mapChartVertexToUnifiedVertex(uint32_t i) const
+ void evaluateOrthoParameterizationQuality()
{
- return m_chartToUnifiedMap[i];
+ XA_PROFILE_START(parameterizeChartsEvaluateQuality)
+ m_paramQuality = calculateParameterizationQuality(m_unifiedMesh, nullptr);
+ XA_PROFILE_END(parameterizeChartsEvaluateQuality)
+ // Use orthogonal parameterization if quality is acceptable.
+ if (!m_paramQuality.boundaryIntersection && m_paramQuality.geometricArea > 0.0f && m_paramQuality.stretchMetric <= 1.1f && m_paramQuality.maxStretchMetric <= 1.25f)
+ m_isOrtho = true;
}
- const std::vector<uint32_t> &faceArray() const
+ void evaluateParameterizationQuality()
{
- return m_faceArray;
+ XA_PROFILE_START(parameterizeChartsEvaluateQuality)
+#if XA_DEBUG_EXPORT_OBJ_INVALID_PARAMETERIZATION
+ m_paramQuality = calculateParameterizationQuality(m_unifiedMesh, &m_paramFlippedFaces);
+#else
+ m_paramQuality = calculateParameterizationQuality(m_unifiedMesh, nullptr);
+#endif
+ XA_PROFILE_END(parameterizeChartsEvaluateQuality)
}
// Transfer parameterization from unified mesh to chart mesh.
void transferParameterization()
{
- xaDebugAssert(!m_isVertexMapped);
- uint32_t vertexCount = m_chartMesh->vertexCount();
- for (uint32_t v = 0; v < vertexCount; v++) {
- halfedge::Vertex *vertex = m_chartMesh->vertexAt(v);
- halfedge::Vertex *unifiedVertex = m_unifiedMesh->vertexAt(mapChartVertexToUnifiedVertex(v));
- vertex->tex = unifiedVertex->tex;
- }
+ const uint32_t vertexCount = m_mesh->vertexCount();
+ for (uint32_t v = 0; v < vertexCount; v++)
+ m_mesh->texcoord(v) = m_unifiedMesh->texcoord(m_chartToUnifiedMap[v]);
}
float computeSurfaceArea() const
{
- return halfedge::computeSurfaceArea(m_chartMesh.get()) * scale;
+ return m_mesh->computeSurfaceArea();
}
float computeParametricArea() const
{
- // This only makes sense in parameterized meshes.
- xaDebugAssert(m_isDisk);
- xaDebugAssert(!m_isVertexMapped);
- return halfedge::computeParametricArea(m_chartMesh.get());
+ return m_mesh->computeParametricArea();
}
Vector2 computeParametricBounds() const
{
- // This only makes sense in parameterized meshes.
- xaDebugAssert(m_isDisk);
- xaDebugAssert(!m_isVertexMapped);
- Box bounds;
- bounds.clearBounds();
- uint32_t vertexCount = m_chartMesh->vertexCount();
+ Vector2 minCorner(FLT_MAX, FLT_MAX);
+ Vector2 maxCorner(-FLT_MAX, -FLT_MAX);
+ const uint32_t vertexCount = m_mesh->vertexCount();
for (uint32_t v = 0; v < vertexCount; v++) {
- halfedge::Vertex *vertex = m_chartMesh->vertexAt(v);
- bounds.addPointToBounds(Vector3(vertex->tex, 0));
+ minCorner = min(minCorner, m_mesh->texcoord(v));
+ maxCorner = max(maxCorner, m_mesh->texcoord(v));
}
- return bounds.extents().xy();
+ return (maxCorner - minCorner) * 0.5f;
}
- float scale = 1.0f;
- uint32_t vertexMapWidth;
- uint32_t vertexMapHeight;
- bool blockAligned = true;
-
private:
- bool closeLoop(uint32_t start, const std::vector<halfedge::Edge *> &loop)
- {
- const uint32_t vertexCount = loop.size() - start;
- xaDebugAssert(vertexCount >= 3);
- if (vertexCount < 3) return false;
- xaDebugAssert(loop[start]->vertex->isColocal(loop[start + vertexCount - 1]->to()));
- // If the hole is planar, then we add a single face that will be properly triangulated later.
- // If the hole is not planar, we add a triangle fan with a vertex at the hole centroid.
- // This is still a bit of a hack. There surely are better hole filling algorithms out there.
- std::vector<Vector3> points(vertexCount);
- for (uint32_t i = 0; i < vertexCount; i++) {
- points[i] = loop[start + i]->vertex->pos;
- }
- bool isPlanar = Fit::isPlanar(vertexCount, points.data());
- if (isPlanar) {
- // Add face and connect edges.
- halfedge::Face *face = m_unifiedMesh->addFace();
- for (uint32_t i = 0; i < vertexCount; i++) {
- halfedge::Edge *edge = loop[start + i];
- edge->face = face;
- edge->setNext(loop[start + (i + 1) % vertexCount]);
- }
- face->edge = loop[start];
- xaDebugAssert(face->isValid());
- } else {
- // If the polygon is not planar, we just cross our fingers, and hope this will work:
- // Compute boundary centroid:
- Vector3 centroidPos(0);
- for (uint32_t i = 0; i < vertexCount; i++) {
- centroidPos += points[i];
- }
- centroidPos *= (1.0f / vertexCount);
- halfedge::Vertex *centroid = m_unifiedMesh->addVertex(centroidPos);
- // Add one pair of edges for each boundary vertex.
- for (uint32_t j = vertexCount - 1, i = 0; i < vertexCount; j = i++) {
- halfedge::Face *face = m_unifiedMesh->addFace(centroid->id, loop[start + j]->vertex->id, loop[start + i]->vertex->id);
- xaDebugAssert(face != NULL);
-#ifdef NDEBUG
- face = NULL; // silence unused parameter warning
-#endif
- }
- }
- return true;
- }
-
- static void getBoundaryEdges(halfedge::Mesh *mesh, std::vector<halfedge::Edge *> &boundaryEdges)
- {
- xaDebugAssert(mesh != NULL);
- const uint32_t edgeCount = mesh->edgeCount();
- BitArray bitFlags(edgeCount);
- bitFlags.clearAll();
- boundaryEdges.clear();
- // Search for boundary edges. Mark all the edges that belong to the same boundary.
- for (uint32_t e = 0; e < edgeCount; e++) {
- halfedge::Edge *startEdge = mesh->edgeAt(e);
- if (startEdge != NULL && startEdge->isBoundary() && bitFlags.bitAt(e) == false) {
- xaDebugAssert(startEdge->face != NULL);
- xaDebugAssert(startEdge->pair->face == NULL);
- startEdge = startEdge->pair;
- const halfedge::Edge *edge = startEdge;
- do {
- xaDebugAssert(edge->face == NULL);
- xaDebugAssert(bitFlags.bitAt(edge->id / 2) == false);
- bitFlags.setBitAt(edge->id / 2);
- edge = edge->next;
- } while (startEdge != edge);
- boundaryEdges.push_back(startEdge);
- }
- }
- }
-
- // Chart mesh.
- std::auto_ptr<halfedge::Mesh> m_chartMesh;
+ Basis m_basis;
+ Mesh *m_mesh;
+ Mesh *m_unifiedMesh;
+ bool m_isDisk, m_isOrtho, m_isPlanar;
+ uint32_t m_warningFlags;
+ uint32_t m_closedHolesCount, m_fixedTJunctionsCount;
- std::auto_ptr<halfedge::Mesh> m_unifiedMesh;
- bool m_isDisk;
- bool m_isVertexMapped;
-
// List of faces of the original mesh that belong to this chart.
- std::vector<uint32_t> m_faceArray;
+ Array<uint32_t> m_faceArray;
// Map vertices of the chart mesh to vertices of the original mesh.
- std::vector<uint32_t> m_chartToOriginalMap;
+ Array<uint32_t> m_chartToOriginalMap;
+
+ Array<uint32_t> m_chartToUnifiedMap;
- std::vector<uint32_t> m_chartToUnifiedMap;
+ ParameterizationQuality m_paramQuality;
+#if XA_DEBUG_EXPORT_OBJ_INVALID_PARAMETERIZATION
+ Array<uint32_t> m_paramFlippedFaces;
+#endif
};
-// Estimate quality of existing parameterization.
-class ParameterizationQuality
+struct CreateChartTaskArgs
{
-public:
- ParameterizationQuality()
- {
- m_totalTriangleCount = 0;
- m_flippedTriangleCount = 0;
- m_zeroAreaTriangleCount = 0;
- m_parametricArea = 0.0f;
- m_geometricArea = 0.0f;
- m_stretchMetric = 0.0f;
- m_maxStretchMetric = 0.0f;
- m_conformalMetric = 0.0f;
- m_authalicMetric = 0.0f;
- }
-
- ParameterizationQuality(const halfedge::Mesh *mesh)
- {
- xaDebugAssert(mesh != NULL);
- m_totalTriangleCount = 0;
- m_flippedTriangleCount = 0;
- m_zeroAreaTriangleCount = 0;
- m_parametricArea = 0.0f;
- m_geometricArea = 0.0f;
- m_stretchMetric = 0.0f;
- m_maxStretchMetric = 0.0f;
- m_conformalMetric = 0.0f;
- m_authalicMetric = 0.0f;
- const uint32_t faceCount = mesh->faceCount();
- for (uint32_t f = 0; f < faceCount; f++) {
- const halfedge::Face *face = mesh->faceAt(f);
- const halfedge::Vertex *vertex0 = NULL;
- Vector3 p[3];
- Vector2 t[3];
- for (halfedge::Face::ConstEdgeIterator it(face->edges()); !it.isDone(); it.advance()) {
- const halfedge::Edge *edge = it.current();
- if (vertex0 == NULL) {
- vertex0 = edge->vertex;
- p[0] = vertex0->pos;
- t[0] = vertex0->tex;
- } else if (edge->to() != vertex0) {
- p[1] = edge->from()->pos;
- p[2] = edge->to()->pos;
- t[1] = edge->from()->tex;
- t[2] = edge->to()->tex;
- processTriangle(p, t);
- }
- }
- }
- if (m_flippedTriangleCount + m_zeroAreaTriangleCount == faceCount) {
- // If all triangles are flipped, then none is.
- m_flippedTriangleCount = 0;
- }
- xaDebugAssert(std::isfinite(m_parametricArea) && m_parametricArea >= 0);
- xaDebugAssert(std::isfinite(m_geometricArea) && m_geometricArea >= 0);
- xaDebugAssert(std::isfinite(m_stretchMetric));
- xaDebugAssert(std::isfinite(m_maxStretchMetric));
- xaDebugAssert(std::isfinite(m_conformalMetric));
- xaDebugAssert(std::isfinite(m_authalicMetric));
- }
-
- bool isValid() const
- {
- return m_flippedTriangleCount == 0; // @@ Does not test for self-overlaps.
- }
-
- float rmsStretchMetric() const
- {
- if (m_geometricArea == 0) return 0.0f;
- float normFactor = sqrtf(m_parametricArea / m_geometricArea);
- return sqrtf(m_stretchMetric / m_geometricArea) * normFactor;
- }
-
- float maxStretchMetric() const
- {
- if (m_geometricArea == 0) return 0.0f;
- float normFactor = sqrtf(m_parametricArea / m_geometricArea);
- return m_maxStretchMetric * normFactor;
- }
-
- float rmsConformalMetric() const
- {
- if (m_geometricArea == 0) return 0.0f;
- return sqrtf(m_conformalMetric / m_geometricArea);
- }
+ const Mesh *mesh;
+ const Array<uint32_t> *faceArray;
+ const Basis *basis;
+ uint32_t meshId;
+ uint32_t chartGroupId;
+ uint32_t chartId;
+ Chart **chart;
+};
- float maxAuthalicMetric() const
- {
- if (m_geometricArea == 0) return 0.0f;
- return sqrtf(m_authalicMetric / m_geometricArea);
- }
+static void runCreateChartTask(void *userData)
+{
+ XA_PROFILE_START(createChartMeshesThread)
+ auto args = (CreateChartTaskArgs *)userData;
+ *(args->chart) = XA_NEW(MemTag::Default, Chart, args->mesh, *(args->faceArray), *(args->basis), args->meshId, args->chartGroupId, args->chartId);
+ XA_PROFILE_END(createChartMeshesThread)
+}
- void operator+=(const ParameterizationQuality &pq)
- {
- m_totalTriangleCount += pq.m_totalTriangleCount;
- m_flippedTriangleCount += pq.m_flippedTriangleCount;
- m_zeroAreaTriangleCount += pq.m_zeroAreaTriangleCount;
- m_parametricArea += pq.m_parametricArea;
- m_geometricArea += pq.m_geometricArea;
- m_stretchMetric += pq.m_stretchMetric;
- m_maxStretchMetric = std::max(m_maxStretchMetric, pq.m_maxStretchMetric);
- m_conformalMetric += pq.m_conformalMetric;
- m_authalicMetric += pq.m_authalicMetric;
- }
+struct ParameterizeChartTaskArgs
+{
+ Chart *chart;
+ ParameterizeFunc func;
+};
-private:
- void processTriangle(Vector3 q[3], Vector2 p[3])
- {
- m_totalTriangleCount++;
- // Evaluate texture stretch metric. See:
- // - "Texture Mapping Progressive Meshes", Sander, Snyder, Gortler & Hoppe
- // - "Mesh Parameterization: Theory and Practice", Siggraph'07 Course Notes, Hormann, Levy & Sheffer.
- float t1 = p[0].x;
- float s1 = p[0].y;
- float t2 = p[1].x;
- float s2 = p[1].y;
- float t3 = p[2].x;
- float s3 = p[2].y;
- float geometricArea = length(cross(q[1] - q[0], q[2] - q[0])) / 2;
- float parametricArea = ((s2 - s1) * (t3 - t1) - (s3 - s1) * (t2 - t1)) / 2;
- if (isZero(parametricArea)) {
- m_zeroAreaTriangleCount++;
- return;
- }
- Vector3 Ss = (q[0] * (t2 - t3) + q[1] * (t3 - t1) + q[2] * (t1 - t2)) / (2 * parametricArea);
- Vector3 St = (q[0] * (s3 - s2) + q[1] * (s1 - s3) + q[2] * (s2 - s1)) / (2 * parametricArea);
- float a = dot(Ss, Ss); // E
- float b = dot(Ss, St); // F
- float c = dot(St, St); // G
- // Compute eigen-values of the first fundamental form:
- float sigma1 = sqrtf(0.5f * std::max(0.0f, a + c - sqrtf(square(a - c) + 4 * square(b)))); // gamma uppercase, min eigenvalue.
- float sigma2 = sqrtf(0.5f * std::max(0.0f, a + c + sqrtf(square(a - c) + 4 * square(b)))); // gamma lowercase, max eigenvalue.
- xaAssert(sigma2 >= sigma1);
- // isometric: sigma1 = sigma2 = 1
- // conformal: sigma1 / sigma2 = 1
- // authalic: sigma1 * sigma2 = 1
- float rmsStretch = sqrtf((a + c) * 0.5f);
- float rmsStretch2 = sqrtf((square(sigma1) + square(sigma2)) * 0.5f);
- xaDebugAssert(equal(rmsStretch, rmsStretch2, 0.01f));
-#ifdef NDEBUG
- rmsStretch2 = 0; // silence unused parameter warning
+static void runParameterizeChartTask(void *userData)
+{
+ auto args = (ParameterizeChartTaskArgs *)userData;
+ Mesh *mesh = args->chart->unifiedMesh();
+ XA_PROFILE_START(parameterizeChartsOrthogonal)
+#if 1
+ computeOrthogonalProjectionMap(mesh);
+#else
+ for (uint32_t i = 0; i < vertexCount; i++)
+ mesh->texcoord(i) = Vector2(dot(args->chart->basis().tangent, mesh->position(i)), dot(args->chart->basis().bitangent, mesh->position(i)));
#endif
- if (parametricArea < 0.0f) {
- // Count flipped triangles.
- m_flippedTriangleCount++;
- parametricArea = fabsf(parametricArea);
- }
- m_stretchMetric += square(rmsStretch) * geometricArea;
- m_maxStretchMetric = std::max(m_maxStretchMetric, sigma2);
- if (!isZero(sigma1, 0.000001f)) {
- // sigma1 is zero when geometricArea is zero.
- m_conformalMetric += (sigma2 / sigma1) * geometricArea;
- }
- m_authalicMetric += (sigma1 * sigma2) * geometricArea;
- // Accumulate total areas.
- m_geometricArea += geometricArea;
- m_parametricArea += parametricArea;
- //triangleConformalEnergy(q, p);
- }
-
- uint32_t m_totalTriangleCount;
- uint32_t m_flippedTriangleCount;
- uint32_t m_zeroAreaTriangleCount;
- float m_parametricArea;
- float m_geometricArea;
- float m_stretchMetric;
- float m_maxStretchMetric;
- float m_conformalMetric;
- float m_authalicMetric;
-};
+ XA_PROFILE_END(parameterizeChartsOrthogonal)
+ args->chart->evaluateOrthoParameterizationQuality();
+ if (!args->chart->isOrtho() && !args->chart->isPlanar()) {
+ XA_PROFILE_START(parameterizeChartsLSCM)
+ if (args->func)
+ args->func(&mesh->position(0).x, &mesh->texcoord(0).x, mesh->vertexCount(), mesh->indices(), mesh->indexCount());
+ else if (args->chart->isDisk())
+ computeLeastSquaresConformalMap(mesh);
+ XA_PROFILE_END(parameterizeChartsLSCM)
+ args->chart->evaluateParameterizationQuality();
+ }
+ // @@ Check that parameterization quality is above a certain threshold.
+ // Transfer parameterization from unified mesh to chart mesh.
+ args->chart->transferParameterization();
+}
-// Set of charts corresponding to a single mesh.
-class MeshCharts
+// Set of charts corresponding to mesh faces in the same face group.
+class ChartGroup
{
public:
- MeshCharts(const halfedge::Mesh *mesh) : m_mesh(mesh) {}
-
- ~MeshCharts()
- {
- for (size_t i = 0; i < m_chartArray.size(); i++)
- delete m_chartArray[i];
- }
-
- uint32_t chartCount() const
- {
- return m_chartArray.size();
- }
- uint32_t vertexCount () const
- {
- return m_totalVertexCount;
- }
-
- const Chart *chartAt(uint32_t i) const
- {
- return m_chartArray[i];
- }
- Chart *chartAt(uint32_t i)
- {
- return m_chartArray[i];
- }
-
- // Extract the charts of the input mesh.
- void extractCharts()
- {
- const uint32_t faceCount = m_mesh->faceCount();
- int first = 0;
- std::vector<uint32_t> queue;
- queue.reserve(faceCount);
- BitArray bitFlags(faceCount);
- bitFlags.clearAll();
+ ChartGroup(uint32_t id, const Mesh *sourceMesh, uint32_t faceGroup) : m_sourceId(sourceMesh->id()), m_id(id), m_isVertexMap(faceGroup == UINT32_MAX), m_paramAddedChartsCount(0), m_paramDeletedChartsCount(0)
+ {
+ // Create new mesh from the source mesh, using faces that belong to this group.
+ const uint32_t sourceFaceCount = sourceMesh->faceCount();
+ for (uint32_t f = 0; f < sourceFaceCount; f++) {
+ if (sourceMesh->faceGroupAt(f) == faceGroup)
+ m_faceToSourceFaceMap.push_back(f);
+ }
+ // Only initial meshes have face groups and ignored faces. The only flag we care about is HasNormals.
+ const uint32_t faceCount = m_faceToSourceFaceMap.size();
+ m_mesh = XA_NEW(MemTag::Mesh, Mesh, sourceMesh->epsilon(), faceCount * 3, faceCount, sourceMesh->flags() & MeshFlags::HasNormals);
+ XA_DEBUG_ASSERT(faceCount > 0);
+ Array<uint32_t> meshIndices;
+ meshIndices.resize(sourceMesh->vertexCount(), (uint32_t)~0);
for (uint32_t f = 0; f < faceCount; f++) {
- if (bitFlags.bitAt(f) == false) {
- // Start new patch. Reset queue.
- first = 0;
- queue.clear();
- queue.push_back(f);
- bitFlags.setBitAt(f);
- while (first != (int)queue.size()) {
- const halfedge::Face *face = m_mesh->faceAt(queue[first]);
- // Visit face neighbors of queue[first]
- for (halfedge::Face::ConstEdgeIterator it(face->edges()); !it.isDone(); it.advance()) {
- const halfedge::Edge *edge = it.current();
- xaDebugAssert(edge->pair != NULL);
- if (!edge->isBoundary() && /*!edge->isSeam()*/
- //!(edge->from()->tex() != edge->pair()->to()->tex() || edge->to()->tex() != edge->pair()->from()->tex()))
- !(edge->from() != edge->pair->to() || edge->to() != edge->pair->from())) { // Preserve existing seams (not just texture seams).
- const halfedge::Face *neighborFace = edge->pair->face;
- xaDebugAssert(neighborFace != NULL);
- if (bitFlags.bitAt(neighborFace->id) == false) {
- queue.push_back(neighborFace->id);
- bitFlags.setBitAt(neighborFace->id);
- }
- }
- }
- first++;
+ const uint32_t face = m_faceToSourceFaceMap[f];
+ for (uint32_t i = 0; i < 3; i++) {
+ const uint32_t vertex = sourceMesh->vertexAt(face * 3 + i);
+ if (meshIndices[vertex] == (uint32_t)~0) {
+ meshIndices[vertex] = m_mesh->vertexCount();
+ m_vertexToSourceVertexMap.push_back(vertex);
+ Vector3 normal(0.0f);
+ if (sourceMesh->flags() & MeshFlags::HasNormals)
+ normal = sourceMesh->normal(vertex);
+ m_mesh->addVertex(sourceMesh->position(vertex), normal, sourceMesh->texcoord(vertex));
}
- Chart *chart = new Chart();
- chart->build(m_mesh, queue);
- m_chartArray.push_back(chart);
}
}
+ // Add faces.
+ for (uint32_t f = 0; f < faceCount; f++) {
+ const uint32_t face = m_faceToSourceFaceMap[f];
+ uint32_t indices[3];
+ for (uint32_t i = 0; i < 3; i++) {
+ const uint32_t vertex = sourceMesh->vertexAt(face * 3 + i);
+ XA_DEBUG_ASSERT(meshIndices[vertex] != (uint32_t)~0);
+ indices[i] = meshIndices[vertex];
+ }
+ // Don't copy flags, it doesn't matter if a face is ignored after this point. All ignored faces get their own vertex map (m_isVertexMap) ChartGroup.
+ // Don't hash edges if m_isVertexMap, they may be degenerate.
+ Mesh::AddFaceResult::Enum result = m_mesh->addFace(indices, false, !m_isVertexMap);
+ XA_UNUSED(result);
+ XA_DEBUG_ASSERT(result == Mesh::AddFaceResult::OK);
+ }
+ if (!m_isVertexMap) {
+ m_mesh->createColocals();
+ m_mesh->createBoundaries();
+ m_mesh->linkBoundaries();
+ }
+#if XA_DEBUG_EXPORT_OBJ_CHART_GROUPS
+ char filename[256];
+ XA_SPRINTF(filename, sizeof(filename), "debug_mesh_%03u_chartgroup_%03u.obj", m_sourceId, m_id);
+ m_mesh->writeObjFile(filename);
+#else
+ XA_UNUSED(m_id);
+#endif
+ }
+
+ ~ChartGroup()
+ {
+ m_mesh->~Mesh();
+ XA_FREE(m_mesh);
+ for (uint32_t i = 0; i < m_chartArray.size(); i++) {
+ m_chartArray[i]->~Chart();
+ XA_FREE(m_chartArray[i]);
+ }
}
+ uint32_t chartCount() const { return m_chartArray.size(); }
+ Chart *chartAt(uint32_t i) const { return m_chartArray[i]; }
+ uint32_t paramAddedChartsCount() const { return m_paramAddedChartsCount; }
+ uint32_t paramDeletedChartsCount() const { return m_paramDeletedChartsCount; }
+ bool isVertexMap() const { return m_isVertexMap; }
+ uint32_t mapFaceToSourceFace(uint32_t face) const { return m_faceToSourceFaceMap[face]; }
+ uint32_t mapVertexToSourceVertex(uint32_t i) const { return m_vertexToSourceVertexMap[i]; }
+ const Mesh *mesh() const { return m_mesh; }
+
/*
Compute charts using a simple segmentation algorithm.
@@ -6481,867 +6169,1304 @@ public:
- emphasize roundness metrics to prevent those cases.
- If interior self-overlaps: preserve boundary parameterization and use mean-value map.
*/
- void computeCharts(const CharterOptions &options, const std::vector<uint32_t> &unchartedMaterialArray)
- {
- Chart *vertexMap = NULL;
- if (unchartedMaterialArray.size() != 0) {
- vertexMap = new Chart();
- vertexMap->buildVertexMap(m_mesh, unchartedMaterialArray);
- if (vertexMap->faceCount() == 0) {
- delete vertexMap;
- vertexMap = NULL;
- }
- }
- AtlasBuilder builder(m_mesh);
- if (vertexMap != NULL) {
- // Mark faces that do not need to be charted.
- builder.markUnchartedFaces(vertexMap->faceArray());
- m_chartArray.push_back(vertexMap);
- }
- if (builder.facesLeft != 0) {
- // Tweak these values:
- const float maxThreshold = 2;
- const uint32_t growFaceCount = 32;
- const uint32_t maxIterations = 4;
- builder.options = options;
- //builder.options.proxyFitMetricWeight *= 0.75; // relax proxy fit weight during initial seed placement.
- //builder.options.roundnessMetricWeight = 0;
- //builder.options.straightnessMetricWeight = 0;
- // This seems a reasonable estimate.
- uint32_t maxSeedCount = std::max(6U, builder.facesLeft);
- // Create initial charts greedely.
- xaPrint("### Placing seeds\n");
- builder.placeSeeds(maxThreshold, maxSeedCount);
- xaPrint("### Placed %d seeds (max = %d)\n", builder.chartCount(), maxSeedCount);
- builder.updateProxies();
- builder.mergeCharts();
- #if 1
- xaPrint("### Relocating seeds\n");
- builder.relocateSeeds();
- xaPrint("### Reset charts\n");
- builder.resetCharts();
- if (vertexMap != NULL) {
- builder.markUnchartedFaces(vertexMap->faceArray());
- }
- builder.options = options;
- xaPrint("### Growing charts\n");
- // Restart process growing charts in parallel.
- uint32_t iteration = 0;
- while (true) {
- if (!builder.growCharts(maxThreshold, growFaceCount)) {
- xaPrint("### Can't grow anymore\n");
- // If charts cannot grow more: fill holes, merge charts, relocate seeds and start new iteration.
- xaPrint("### Filling holes\n");
- builder.fillHoles(maxThreshold);
- xaPrint("### Using %d charts now\n", builder.chartCount());
- builder.updateProxies();
- xaPrint("### Merging charts\n");
- builder.mergeCharts();
- xaPrint("### Using %d charts now\n", builder.chartCount());
- xaPrint("### Reseeding\n");
- if (!builder.relocateSeeds()) {
- xaPrint("### Cannot relocate seeds anymore\n");
- // Done!
- break;
- }
- if (iteration == maxIterations) {
- xaPrint("### Reached iteration limit\n");
- break;
- }
- iteration++;
- xaPrint("### Reset charts\n");
- builder.resetCharts();
- if (vertexMap != NULL) {
- builder.markUnchartedFaces(vertexMap->faceArray());
- }
- xaPrint("### Growing charts\n");
- }
- };
- #endif
- // Make sure no holes are left!
- xaDebugAssert(builder.facesLeft == 0);
- const uint32_t chartCount = builder.chartArray.size();
- for (uint32_t i = 0; i < chartCount; i++) {
- Chart *chart = new Chart();
- m_chartArray.push_back(chart);
- chart->build(m_mesh, builder.chartFaces(i));
- }
- }
- const uint32_t chartCount = m_chartArray.size();
- // Build face indices.
- m_faceChart.resize(m_mesh->faceCount());
- m_faceIndex.resize(m_mesh->faceCount());
+ void computeCharts(TaskScheduler *taskScheduler, const ChartOptions &options)
+ {
+ m_chartOptions = options;
+ // This function may be called multiple times, so destroy existing charts.
+ for (uint32_t i = 0; i < m_chartArray.size(); i++) {
+ m_chartArray[i]->~Chart();
+ XA_FREE(m_chartArray[i]);
+ }
+ m_chartArray.clear();
+#if XA_DEBUG_SINGLE_CHART
+ Array<uint32_t> chartFaces;
+ chartFaces.resize(m_mesh->faceCount());
+ for (uint32_t i = 0; i < chartFaces.size(); i++)
+ chartFaces[i] = i;
+ Chart *chart = XA_NEW(MemTag::Default, Chart, m_mesh, chartFaces, m_sourceId, m_id, 0);
+ m_chartArray.push_back(chart);
+#else
+ XA_PROFILE_START(atlasBuilder)
+ AtlasBuilder builder(m_mesh, nullptr, options);
+ runAtlasBuilder(builder, options);
+ XA_PROFILE_END(atlasBuilder)
+ const uint32_t chartCount = builder.chartCount();
+ m_chartArray.resize(chartCount);
+ Array<CreateChartTaskArgs> taskArgs;
+ taskArgs.resize(chartCount);
for (uint32_t i = 0; i < chartCount; i++) {
- const Chart *chart = m_chartArray[i];
- const uint32_t faceCount = chart->faceCount();
- for (uint32_t f = 0; f < faceCount; f++) {
- uint32_t idx = chart->faceAt(f);
- m_faceChart[idx] = i;
- m_faceIndex[idx] = f;
- }
+ CreateChartTaskArgs &args = taskArgs[i];
+ args.mesh = m_mesh;
+ args.faceArray = &builder.chartFaces(i);
+ args.basis = &builder.chartBasis(i);
+ args.meshId = m_sourceId;
+ args.chartGroupId = m_id;
+ args.chartId = i;
+ args.chart = &m_chartArray[i];
+ }
+ XA_PROFILE_START(createChartMeshesReal)
+ TaskGroupHandle taskGroup = taskScheduler->createTaskGroup(chartCount);
+ for (uint32_t i = 0; i < chartCount; i++) {
+ Task task;
+ task.userData = &taskArgs[i];
+ task.func = runCreateChartTask;
+ taskScheduler->run(taskGroup, task);
}
- // Build an exclusive prefix sum of the chart vertex counts.
- m_chartVertexCountPrefixSum.resize(chartCount);
- if (chartCount > 0) {
- m_chartVertexCountPrefixSum[0] = 0;
- for (uint32_t i = 1; i < chartCount; i++) {
- const Chart *chart = m_chartArray[i - 1];
- m_chartVertexCountPrefixSum[i] = m_chartVertexCountPrefixSum[i - 1] + chart->vertexCount();
+ taskScheduler->wait(&taskGroup);
+ XA_PROFILE_END(createChartMeshesReal)
+#endif
+#if XA_DEBUG_EXPORT_OBJ_CHARTS
+ char filename[256];
+ XA_SPRINTF(filename, sizeof(filename), "debug_mesh_%03u_chartgroup_%03u_charts.obj", m_sourceId, m_id);
+ FILE *file;
+ XA_FOPEN(file, filename, "w");
+ if (file) {
+ m_mesh->writeObjVertices(file);
+ for (uint32_t i = 0; i < chartCount; i++) {
+ fprintf(file, "o chart_%04d\n", i);
+ fprintf(file, "s off\n");
+ const Array<uint32_t> &faces = builder.chartFaces(i);
+ for (uint32_t f = 0; f < faces.size(); f++)
+ m_mesh->writeObjFace(file, faces[f]);
}
- m_totalVertexCount = m_chartVertexCountPrefixSum[chartCount - 1] + m_chartArray[chartCount - 1]->vertexCount();
- } else {
- m_totalVertexCount = 0;
+ m_mesh->writeObjBoundaryEges(file);
+ m_mesh->writeObjLinkedBoundaries(file);
+ fclose(file);
}
+#endif
}
- void parameterizeCharts()
+ void parameterizeCharts(TaskScheduler *taskScheduler, ParameterizeFunc func)
{
- ParameterizationQuality globalParameterizationQuality;
- // Parameterize the charts.
- uint32_t diskCount = 0;
const uint32_t chartCount = m_chartArray.size();
- for (uint32_t i = 0; i < chartCount; i++)
- {
+ Array<ParameterizeChartTaskArgs> taskArgs;
+ taskArgs.resize(chartCount);
+ TaskGroupHandle taskGroup = taskScheduler->createTaskGroup(chartCount);
+ for (uint32_t i = 0; i < chartCount; i++) {
+ ParameterizeChartTaskArgs &args = taskArgs[i];
+ args.chart = m_chartArray[i];
+ args.func = func;
+ Task task;
+ task.userData = &args;
+ task.func = runParameterizeChartTask;
+ taskScheduler->run(taskGroup, task);
+ }
+ taskScheduler->wait(&taskGroup);
+#if XA_RECOMPUTE_CHARTS
+ // Find charts with invalid parameterizations.
+ Array<Chart *> invalidCharts;
+ for (uint32_t i = 0; i < chartCount; i++) {
Chart *chart = m_chartArray[i];
-
- bool isValid = false;
-
- if (chart->isVertexMapped())
- {
- continue;
- }
-
- if (chart->isDisk())
- {
- diskCount++;
- ParameterizationQuality chartParameterizationQuality;
- if (chart->faceCount() == 1) {
- computeSingleFaceMap(chart->unifiedMesh());
- chartParameterizationQuality = ParameterizationQuality(chart->unifiedMesh());
- } else {
- computeOrthogonalProjectionMap(chart->unifiedMesh());
- ParameterizationQuality orthogonalQuality(chart->unifiedMesh());
- computeLeastSquaresConformalMap(chart->unifiedMesh());
- ParameterizationQuality lscmQuality(chart->unifiedMesh());
- chartParameterizationQuality = lscmQuality;
- }
- isValid = chartParameterizationQuality.isValid();
- if (!isValid) {
- xaPrint("*** Invalid parameterization.\n");
+ const ParameterizationQuality &quality = chart->paramQuality();
+ if (quality.boundaryIntersection || quality.flippedTriangleCount > 0)
+ invalidCharts.push_back(chart);
+ }
+ if (invalidCharts.isEmpty())
+ return;
+ // Recompute charts with invalid parameterizations.
+ Array<uint32_t> meshFaces;
+ for (uint32_t i = 0; i < invalidCharts.size(); i++) {
+ Chart *invalidChart = invalidCharts[i];
+ const Mesh *invalidMesh = invalidChart->mesh();
+ const uint32_t faceCount = invalidMesh->faceCount();
+ meshFaces.resize(faceCount);
+ float invalidChartArea = 0.0f;
+ for (uint32_t j = 0; j < faceCount; j++) {
+ meshFaces[j] = invalidChart->mapFaceToSourceFace(j);
+ invalidChartArea += invalidMesh->faceArea(j);
+ }
+ ChartOptions options = m_chartOptions;
+ options.maxChartArea = invalidChartArea * 0.2f;
+ options.maxThreshold = 0.25f;
+ options.maxIterations = 3;
+ AtlasBuilder builder(m_mesh, &meshFaces, options);
+ runAtlasBuilder(builder, options);
+ for (uint32_t j = 0; j < builder.chartCount(); j++) {
+ Chart *chart = XA_NEW(MemTag::Default, Chart, m_mesh, builder.chartFaces(j), builder.chartBasis(j), m_sourceId, m_id, m_chartArray.size());
+ m_chartArray.push_back(chart);
+ m_paramAddedChartsCount++;
+ }
+#if XA_DEBUG_EXPORT_OBJ_RECOMPUTED_CHARTS
+ char filename[256];
+ XA_SPRINTF(filename, sizeof(filename), "debug_mesh_%03u_chartgroup_%03u_recomputed_chart_%u.obj", m_sourceId, m_id, i);
+ FILE *file;
+ XA_FOPEN(file, filename, "w");
+ if (file) {
+ m_mesh->writeObjVertices(file);
+ for (uint32_t j = 0; j < builder.chartCount(); j++) {
+ fprintf(file, "o chart_%04d\n", j);
+ fprintf(file, "s off\n");
+ const Array<uint32_t> &faces = builder.chartFaces(j);
+ for (uint32_t f = 0; f < faces.size(); f++)
+ m_mesh->writeObjFace(file, faces[f]);
}
- // @@ Check that parameterization quality is above a certain threshold.
- // @@ Detect boundary self-intersections.
- globalParameterizationQuality += chartParameterizationQuality;
+ fclose(file);
}
-
- // Transfer parameterization from unified mesh to chart mesh.
- chart->transferParameterization();
-
+#endif
+ }
+ // Parameterize the new charts.
+ taskGroup = taskScheduler->createTaskGroup(m_chartArray.size() - chartCount);
+ taskArgs.resize(m_chartArray.size() - chartCount);
+ for (uint32_t i = chartCount; i < m_chartArray.size(); i++) {
+ ParameterizeChartTaskArgs &args = taskArgs[i - chartCount];
+ args.chart = m_chartArray[i];
+ args.func = func;
+ Task task;
+ task.userData = &args;
+ task.func = runParameterizeChartTask;
+ taskScheduler->run(taskGroup, task);
+ }
+ taskScheduler->wait(&taskGroup);
+ // Remove and delete the invalid charts.
+ for (uint32_t i = 0; i < invalidCharts.size(); i++) {
+ Chart *chart = invalidCharts[i];
+ removeChart(chart);
+ chart->~Chart();
+ XA_FREE(chart);
+ m_paramDeletedChartsCount++;
}
- xaPrint(" Parameterized %d/%d charts.\n", diskCount, chartCount);
- xaPrint(" RMS stretch metric: %f\n", globalParameterizationQuality.rmsStretchMetric());
- xaPrint(" MAX stretch metric: %f\n", globalParameterizationQuality.maxStretchMetric());
- xaPrint(" RMS conformal metric: %f\n", globalParameterizationQuality.rmsConformalMetric());
- xaPrint(" RMS authalic metric: %f\n", globalParameterizationQuality.maxAuthalicMetric());
+#endif
}
- uint32_t faceChartAt(uint32_t i) const
- {
- return m_faceChart[i];
- }
- uint32_t faceIndexWithinChartAt(uint32_t i) const
+private:
+ void runAtlasBuilder(AtlasBuilder &builder, const ChartOptions &options)
{
- return m_faceIndex[i];
+ if (builder.facesLeft() == 0)
+ return;
+ // This seems a reasonable estimate.
+ XA_PROFILE_START(atlasBuilderCreateInitialCharts)
+ // Create initial charts greedely.
+ builder.placeSeeds(options.maxThreshold * 0.5f);
+ if (options.maxIterations == 0) {
+ XA_DEBUG_ASSERT(builder.facesLeft() == 0);
+ XA_PROFILE_END(atlasBuilderCreateInitialCharts)
+ return;
+ }
+ builder.updateProxies();
+ builder.relocateSeeds();
+ builder.resetCharts();
+ XA_PROFILE_END(atlasBuilderCreateInitialCharts)
+ // Restart process growing charts in parallel.
+ uint32_t iteration = 0;
+ while (true) {
+ if (!builder.growCharts(options.maxThreshold, options.growFaceCount)) {
+ // If charts cannot grow more: fill holes, merge charts, relocate seeds and start new iteration.
+ builder.fillHoles(options.maxThreshold * 0.5f);
+ builder.updateProxies();
+#if XA_MERGE_CHARTS
+ builder.mergeCharts();
+#endif
+ if (++iteration == options.maxIterations)
+ break;
+ if (!builder.relocateSeeds())
+ break;
+ builder.resetCharts();
+ }
+ }
+ // Make sure no holes are left!
+ XA_DEBUG_ASSERT(builder.facesLeft() == 0);
}
- uint32_t vertexCountBeforeChartAt(uint32_t i) const
+ void removeChart(const Chart *chart)
{
- return m_chartVertexCountPrefixSum[i];
+ for (uint32_t i = 0; i < m_chartArray.size(); i++) {
+ if (m_chartArray[i] == chart) {
+ m_chartArray.removeAt(i);
+ return;
+ }
+ }
}
-private:
+ uint32_t m_sourceId, m_id;
+ bool m_isVertexMap;
+ Mesh *m_mesh;
+ Array<uint32_t> m_faceToSourceFaceMap; // List of faces of the source mesh that belong to this chart group.
+ Array<uint32_t> m_vertexToSourceVertexMap; // Map vertices of the mesh to vertices of the source mesh.
+ Array<Chart *> m_chartArray;
+ ChartOptions m_chartOptions;
+ uint32_t m_paramAddedChartsCount; // Number of new charts added by recomputing charts with invalid parameterizations.
+ uint32_t m_paramDeletedChartsCount; // Number of charts with invalid parameterizations that were deleted, after charts were recomputed.
+};
- const halfedge::Mesh *m_mesh;
+struct CreateChartGroupTaskArgs
+{
+ uint32_t faceGroup;
+ uint32_t groupId;
+ const Mesh *mesh;
+ ChartGroup **chartGroup;
+};
- std::vector<Chart *> m_chartArray;
+static void runCreateChartGroupTask(void *userData)
+{
+ XA_PROFILE_START(addMeshCreateChartGroupsThread)
+ auto args = (CreateChartGroupTaskArgs *)userData;
+ *(args->chartGroup) = XA_NEW(MemTag::Default, ChartGroup, args->groupId, args->mesh, args->faceGroup);
+ XA_PROFILE_END(addMeshCreateChartGroupsThread)
+}
- std::vector<uint32_t> m_chartVertexCountPrefixSum;
- uint32_t m_totalVertexCount;
+struct ComputeChartsTaskArgs
+{
+ TaskScheduler *taskScheduler;
+ ChartGroup *chartGroup;
+ const ChartOptions *options;
+ Progress *progress;
+};
- std::vector<uint32_t> m_faceChart; // the chart of every face of the input mesh.
- std::vector<uint32_t> m_faceIndex; // the index within the chart for every face of the input mesh.
+static void runComputeChartsJob(void *userData)
+{
+ auto args = (ComputeChartsTaskArgs *)userData;
+ if (args->progress->cancel)
+ return;
+ XA_PROFILE_START(computeChartsThread)
+ args->chartGroup->computeCharts(args->taskScheduler, *args->options);
+ XA_PROFILE_END(computeChartsThread)
+ args->progress->value++;
+ args->progress->update();
+}
+
+struct ParameterizeChartsTaskArgs
+{
+ TaskScheduler *taskScheduler;
+ ChartGroup *chartGroup;
+ ParameterizeFunc func;
+ Progress *progress;
};
-/// An atlas is a set of charts.
+static void runParameterizeChartsJob(void *userData)
+{
+ auto args = (ParameterizeChartsTaskArgs *)userData;
+ if (args->progress->cancel)
+ return;
+ XA_PROFILE_START(parameterizeChartsThread)
+ args->chartGroup->parameterizeCharts(args->taskScheduler, args->func);
+ XA_PROFILE_END(parameterizeChartsThread)
+ args->progress->value++;
+ args->progress->update();
+}
+
+/// An atlas is a set of chart groups.
class Atlas
{
public:
+ Atlas() : m_chartsComputed(false), m_chartsParameterized(false) {}
+
~Atlas()
{
- for (size_t i = 0; i < m_meshChartsArray.size(); i++)
- delete m_meshChartsArray[i];
+ for (uint32_t i = 0; i < m_chartGroups.size(); i++) {
+ m_chartGroups[i]->~ChartGroup();
+ XA_FREE(m_chartGroups[i]);
+ }
}
- uint32_t meshCount() const
- {
- return m_meshChartsArray.size();
- }
+ bool chartsComputed() const { return m_chartsComputed; }
+ bool chartsParameterized() const { return m_chartsParameterized; }
- const MeshCharts *meshAt(uint32_t i) const
+ uint32_t chartGroupCount(uint32_t mesh) const
{
- return m_meshChartsArray[i];
+ uint32_t count = 0;
+ for (uint32_t i = 0; i < m_chartGroups.size(); i++) {
+ if (m_chartGroupSourceMeshes[i] == mesh)
+ count++;
+ }
+ return count;
}
- MeshCharts *meshAt(uint32_t i)
+ const ChartGroup *chartGroupAt(uint32_t mesh, uint32_t group) const
{
- return m_meshChartsArray[i];
+ for (uint32_t c = 0; c < m_chartGroups.size(); c++) {
+ if (m_chartGroupSourceMeshes[c] != mesh)
+ continue;
+ if (group == 0)
+ return m_chartGroups[c];
+ group--;
+ }
+ return nullptr;
}
uint32_t chartCount() const
{
uint32_t count = 0;
- for (uint32_t c = 0; c < m_meshChartsArray.size(); c++) {
- count += m_meshChartsArray[c]->chartCount();
- }
+ for (uint32_t i = 0; i < m_chartGroups.size(); i++)
+ count += m_chartGroups[i]->chartCount();
return count;
}
- const Chart *chartAt(uint32_t i) const
+ Chart *chartAt(uint32_t i)
{
- for (uint32_t c = 0; c < m_meshChartsArray.size(); c++) {
- uint32_t count = m_meshChartsArray[c]->chartCount();
+ for (uint32_t c = 0; c < m_chartGroups.size(); c++) {
+ uint32_t count = m_chartGroups[c]->chartCount();
if (i < count) {
- return m_meshChartsArray[c]->chartAt(i);
+ return m_chartGroups[c]->chartAt(i);
}
i -= count;
}
- return NULL;
+ return nullptr;
}
- Chart *chartAt(uint32_t i)
+ // This function is thread safe.
+ void addMesh(TaskScheduler *taskScheduler, const Mesh *mesh)
{
- for (uint32_t c = 0; c < m_meshChartsArray.size(); c++) {
- uint32_t count = m_meshChartsArray[c]->chartCount();
- if (i < count) {
- return m_meshChartsArray[c]->chartAt(i);
+ // Get list of face groups.
+ const uint32_t faceCount = mesh->faceCount();
+ Array<uint32_t> faceGroups;
+ for (uint32_t f = 0; f < faceCount; f++) {
+ const uint32_t group = mesh->faceGroupAt(f);
+ bool exists = false;
+ for (uint32_t g = 0; g < faceGroups.size(); g++) {
+ if (faceGroups[g] == group) {
+ exists = true;
+ break;
+ }
}
- i -= count;
+ if (!exists)
+ faceGroups.push_back(group);
+ }
+ // Create one chart group per face group.
+ // Chart group creation is slow since it copies a chunk of the source mesh, so use tasks.
+ Array<ChartGroup *> chartGroups;
+ chartGroups.resize(faceGroups.size());
+ Array<CreateChartGroupTaskArgs> taskArgs;
+ taskArgs.resize(chartGroups.size());
+ for (uint32_t g = 0; g < chartGroups.size(); g++) {
+ CreateChartGroupTaskArgs &args = taskArgs[g];
+ args.chartGroup = &chartGroups[g];
+ args.faceGroup = faceGroups[g];
+ args.groupId = g;
+ args.mesh = mesh;
+ }
+ TaskGroupHandle taskGroup = taskScheduler->createTaskGroup(chartGroups.size());
+ for (uint32_t g = 0; g < chartGroups.size(); g++) {
+ Task task;
+ task.userData = &taskArgs[g];
+ task.func = runCreateChartGroupTask;
+ taskScheduler->run(taskGroup, task);
+ }
+ taskScheduler->wait(&taskGroup);
+ // Thread-safe append.
+ m_addMeshMutex.lock();
+ for (uint32_t g = 0; g < chartGroups.size(); g++) {
+ m_chartGroups.push_back(chartGroups[g]);
+ m_chartGroupSourceMeshes.push_back(mesh->id());
+ }
+ m_addMeshMutex.unlock();
+ }
+
+ bool computeCharts(TaskScheduler *taskScheduler, const ChartOptions &options, ProgressFunc progressFunc, void *progressUserData)
+ {
+ m_chartsComputed = false;
+ m_chartsParameterized = false;
+ // Ignore vertex maps.
+ uint32_t chartGroupCount = 0;
+ for (uint32_t i = 0; i < m_chartGroups.size(); i++) {
+ if (!m_chartGroups[i]->isVertexMap())
+ chartGroupCount++;
+ }
+ Progress progress(ProgressCategory::ComputeCharts, progressFunc, progressUserData, chartGroupCount);
+ Array<ComputeChartsTaskArgs> taskArgs;
+ taskArgs.reserve(chartGroupCount);
+ for (uint32_t i = 0; i < m_chartGroups.size(); i++) {
+ if (!m_chartGroups[i]->isVertexMap()) {
+ ComputeChartsTaskArgs args;
+ args.taskScheduler = taskScheduler;
+ args.chartGroup = m_chartGroups[i];
+ args.options = &options;
+ args.progress = &progress;
+ taskArgs.push_back(args);
+ }
+ }
+ // Sort chart groups by mesh indexCount.
+ m_chartGroupsRadix = RadixSort();
+ Array<float> chartGroupSortData;
+ chartGroupSortData.resize(chartGroupCount);
+ for (uint32_t i = 0; i < chartGroupCount; i++)
+ chartGroupSortData[i] = (float)taskArgs[i].chartGroup->mesh()->indexCount();
+ m_chartGroupsRadix.sort(chartGroupSortData);
+ // Larger chart group meshes are added first to reduce the chance of thread starvation.
+ TaskGroupHandle taskGroup = taskScheduler->createTaskGroup(chartGroupCount);
+ for (uint32_t i = 0; i < chartGroupCount; i++) {
+ Task task;
+ task.userData = &taskArgs[m_chartGroupsRadix.ranks()[chartGroupCount - i - 1]];
+ task.func = runComputeChartsJob;
+ taskScheduler->run(taskGroup, task);
+ }
+ taskScheduler->wait(&taskGroup);
+ if (progress.cancel)
+ return false;
+ m_chartsComputed = true;
+ return true;
+ }
+
+ bool parameterizeCharts(TaskScheduler *taskScheduler, ParameterizeFunc func, ProgressFunc progressFunc, void *progressUserData)
+ {
+ m_chartsParameterized = false;
+ // Ignore vertex maps.
+ uint32_t chartGroupCount = 0;
+ for (uint32_t i = 0; i < m_chartGroups.size(); i++) {
+ if (!m_chartGroups[i]->isVertexMap())
+ chartGroupCount++;
+ }
+ Progress progress(ProgressCategory::ParameterizeCharts, progressFunc, progressUserData, chartGroupCount);
+ Array<ParameterizeChartsTaskArgs> taskArgs;
+ taskArgs.reserve(chartGroupCount);
+ for (uint32_t i = 0; i < m_chartGroups.size(); i++) {
+ if (!m_chartGroups[i]->isVertexMap()) {
+ ParameterizeChartsTaskArgs args;
+ args.taskScheduler = taskScheduler;
+ args.chartGroup = m_chartGroups[i];
+ args.func = func;
+ args.progress = &progress;
+ taskArgs.push_back(args);
+ }
+ }
+ // Larger chart group meshes are added first to reduce the chance of thread starvation.
+ TaskGroupHandle taskGroup = taskScheduler->createTaskGroup(chartGroupCount);
+ for (uint32_t i = 0; i < chartGroupCount; i++) {
+ Task task;
+ task.userData = &taskArgs[m_chartGroupsRadix.ranks()[chartGroupCount - i - 1]];
+ task.func = runParameterizeChartsJob;
+ taskScheduler->run(taskGroup, task);
+ }
+ taskScheduler->wait(&taskGroup);
+ if (progress.cancel)
+ return false;
+ // Save original texcoords so PackCharts can be called multiple times (packing overwrites the texcoords).
+ const uint32_t nCharts = chartCount();
+ m_originalChartTexcoords.resize(nCharts);
+ for (uint32_t i = 0; i < nCharts; i++) {
+ const Mesh *mesh = chartAt(i)->mesh();
+ m_originalChartTexcoords[i].resize(mesh->vertexCount());
+ for (uint32_t j = 0; j < mesh->vertexCount(); j++)
+ m_originalChartTexcoords[i][j] = mesh->texcoord(j);
}
- return NULL;
+ m_chartsParameterized = true;
+ return true;
}
- // Add mesh charts and takes ownership.
- // Extract the charts and add to this atlas.
- void addMeshCharts(MeshCharts *meshCharts)
+ void restoreOriginalChartTexcoords()
{
- m_meshChartsArray.push_back(meshCharts);
+ const uint32_t nCharts = chartCount();
+ for (uint32_t i = 0; i < nCharts; i++) {
+ Mesh *mesh = chartAt(i)->mesh();
+ for (uint32_t j = 0; j < mesh->vertexCount(); j++)
+ mesh->texcoord(j) = m_originalChartTexcoords[i][j];
+ }
}
- void extractCharts(const halfedge::Mesh *mesh)
+private:
+ std::mutex m_addMeshMutex;
+ bool m_chartsComputed;
+ bool m_chartsParameterized;
+ Array<ChartGroup *> m_chartGroups;
+ RadixSort m_chartGroupsRadix; // By mesh indexCount.
+ Array<uint32_t> m_chartGroupSourceMeshes;
+ Array<Array<Vector2> > m_originalChartTexcoords;
+};
+
+} // namespace param
+
+namespace pack {
+
+#if XA_DEBUG_EXPORT_ATLAS_IMAGES
+const uint8_t TGA_TYPE_RGB = 2;
+const uint8_t TGA_ORIGIN_UPPER = 0x20;
+
+#pragma pack(push, 1)
+struct TgaHeader
+{
+ uint8_t id_length;
+ uint8_t colormap_type;
+ uint8_t image_type;
+ uint16_t colormap_index;
+ uint16_t colormap_length;
+ uint8_t colormap_size;
+ uint16_t x_origin;
+ uint16_t y_origin;
+ uint16_t width;
+ uint16_t height;
+ uint8_t pixel_size;
+ uint8_t flags;
+ enum { Size = 18 };
+};
+#pragma pack(pop)
+
+static void WriteTga(const char *filename, const uint8_t *data, uint32_t width, uint32_t height)
+{
+ XA_DEBUG_ASSERT(sizeof(TgaHeader) == TgaHeader::Size);
+ FILE *f;
+ XA_FOPEN(f, filename, "wb");
+ if (!f)
+ return;
+ TgaHeader tga;
+ tga.id_length = 0;
+ tga.colormap_type = 0;
+ tga.image_type = TGA_TYPE_RGB;
+ tga.colormap_index = 0;
+ tga.colormap_length = 0;
+ tga.colormap_size = 0;
+ tga.x_origin = 0;
+ tga.y_origin = 0;
+ tga.width = (uint16_t)width;
+ tga.height = (uint16_t)height;
+ tga.pixel_size = 24;
+ tga.flags = TGA_ORIGIN_UPPER;
+ fwrite(&tga, sizeof(TgaHeader), 1, f);
+ fwrite(data, sizeof(uint8_t), width * height * 3, f);
+ fclose(f);
+}
+#endif
+
+class AtlasImage
+{
+public:
+ AtlasImage(uint32_t width, uint32_t height) : m_width(width), m_height(height)
{
- MeshCharts *meshCharts = new MeshCharts(mesh);
- meshCharts->extractCharts();
- addMeshCharts(meshCharts);
+ m_data.resize(m_width * m_height);
+ memset(m_data.data(), 0, sizeof(uint32_t) * m_data.size());
}
- void computeCharts(const halfedge::Mesh *mesh, const CharterOptions &options, const std::vector<uint32_t> &unchartedMaterialArray)
+ void resize(uint32_t width, uint32_t height)
{
- MeshCharts *meshCharts = new MeshCharts(mesh);
- meshCharts->computeCharts(options, unchartedMaterialArray);
- addMeshCharts(meshCharts);
+ Array<uint32_t> data;
+ data.resize(width * height);
+ memset(data.data(), 0, sizeof(uint32_t) * data.size());
+ for (uint32_t y = 0; y < min(m_height, height); y++)
+ memcpy(&data[y * width], &m_data[y * m_width], min(m_width, width) * sizeof(uint32_t));
+ m_width = width;
+ m_height = height;
+ swap(m_data, data);
}
- void parameterizeCharts()
+ void addChart(uint32_t chartIndex, const BitImage *image, bool imageHasPadding, int atlas_w, int atlas_h, int offset_x, int offset_y)
{
- for (uint32_t i = 0; i < m_meshChartsArray.size(); i++) {
- m_meshChartsArray[i]->parameterizeCharts();
+ const int w = image->width();
+ const int h = image->height();
+ for (int y = 0; y < h; y++) {
+ const int yy = y + offset_y;
+ if (yy < 0)
+ continue;
+ for (int x = 0; x < w; x++) {
+ const int xx = x + offset_x;
+ if (xx >= 0 && xx < atlas_w && yy < atlas_h && image->bitAt(x, y)) {
+ const uint32_t dataOffset = xx + yy * m_width;
+ if (m_data[dataOffset] != 0)
+ continue;
+ uint32_t value = chartIndex | kImageHasChartIndexBit;
+ if (imageHasPadding)
+ value |= kImageIsPaddingBit;
+ m_data[dataOffset] = value;
+ }
+ }
}
}
+ void copyTo(uint32_t *dest, uint32_t destWidth, uint32_t destHeight) const
+ {
+ for (uint32_t y = 0; y < destHeight; y++)
+ memcpy(&dest[y * destWidth], &m_data[y * m_width], destWidth * sizeof(uint32_t));
+ }
+
+#if XA_DEBUG_EXPORT_ATLAS_IMAGES
+ void writeTga(const char *filename, uint32_t width, uint32_t height) const
+ {
+ Array<uint8_t> image;
+ image.resize(width * height * 3);
+ for (uint32_t y = 0; y < height; y++) {
+ if (y >= m_height)
+ continue;
+ for (uint32_t x = 0; x < width; x++) {
+ if (x >= m_width)
+ continue;
+ const uint32_t data = m_data[x + y * m_width];
+ if (!(data & kImageHasChartIndexBit))
+ continue;
+ const uint32_t chartIndex = data & kImageChartIndexMask;
+ uint8_t *color = &image[(x + y * width) * 3];
+ if (data & kImageIsPaddingBit) {
+ color[0] = 255;
+ color[1] = 0;
+ color[2] = 255;
+ } else {
+ const int mix = 192;
+ srand((unsigned int)chartIndex);
+ color[0] = uint8_t((rand() % 255 + mix) * 0.5f);
+ color[1] = uint8_t((rand() % 255 + mix) * 0.5f);
+ color[2] = uint8_t((rand() % 255 + mix) * 0.5f);
+ }
+ }
+ }
+ WriteTga(filename, image.data(), width, height);
+ }
+#endif
+
private:
- std::vector<MeshCharts *> m_meshChartsArray;
+ uint32_t m_width, m_height;
+ Array<uint32_t> m_data;
+};
+
+struct Chart
+{
+ int32_t atlasIndex;
+ uint32_t material;
+ uint32_t indexCount;
+ const uint32_t *indices;
+ float parametricArea;
+ float surfaceArea;
+ Vector2 *vertices;
+ uint32_t vertexCount;
+ Array<uint32_t> uniqueVertices;
+ bool allowRotate;
+ // bounding box
+ Vector2 majorAxis, minorAxis, minCorner, maxCorner;
+
+ Vector2 &uniqueVertexAt(uint32_t v) { return uniqueVertices.isEmpty() ? vertices[v] : vertices[uniqueVertices[v]]; }
+ uint32_t uniqueVertexCount() const { return uniqueVertices.isEmpty() ? vertexCount : uniqueVertices.size(); }
+};
+
+struct FindChartLocationBruteForceTaskArgs
+{
+ std::atomic<bool> *finished; // One of the tasks found a location that doesn't expand the atlas.
+ Vector2i startPosition;
+ const BitImage *atlasBitImage;
+ const BitImage *chartBitImage;
+ const BitImage *chartBitImageRotated;
+ int w, h;
+ bool blockAligned, resizableAtlas, allowRotate;
+ // out
+ bool best_insideAtlas;
+ int best_metric, best_x, best_y, best_w, best_h, best_r;
};
-struct AtlasPacker
+static void runFindChartLocationBruteForceTask(void *userData)
+{
+ XA_PROFILE_START(packChartsFindLocationThread)
+ auto args = (FindChartLocationBruteForceTaskArgs *)userData;
+ args->best_metric = INT_MAX;
+ if (args->finished->load())
+ return;
+ // Try two different orientations.
+ for (int r = 0; r < 2; r++) {
+ int cw = args->chartBitImage->width();
+ int ch = args->chartBitImage->height();
+ if (r == 1) {
+ if (args->allowRotate)
+ swap(cw, ch);
+ else
+ break;
+ }
+ const int y = args->startPosition.y;
+ const int stepSize = args->blockAligned ? 4 : 1;
+ for (int x = args->startPosition.x; x <= args->w + stepSize; x += stepSize) { // + 1 not really necessary here.
+ if (!args->resizableAtlas && (x > (int)args->atlasBitImage->width() - cw || y > (int)args->atlasBitImage->height() - ch))
+ continue;
+ if (args->finished->load())
+ break;
+ // Early out if metric not better.
+ const int area = max(args->w, x + cw) * max(args->h, y + ch);
+ const int extents = max(max(args->w, x + cw), max(args->h, y + ch));
+ const int metric = extents * extents + area;
+ if (metric > args->best_metric)
+ continue;
+ // If metric is the same, pick the one closest to the origin.
+ if (metric == args->best_metric && max(x, y) >= max(args->best_x, args->best_y))
+ continue;
+ if (!args->atlasBitImage->canBlit(r == 1 ? *(args->chartBitImageRotated) : *(args->chartBitImage), x, y))
+ continue;
+ args->best_metric = metric;
+ args->best_insideAtlas = area == args->w * args->h;
+ args->best_x = x;
+ args->best_y = y;
+ args->best_w = cw;
+ args->best_h = ch;
+ args->best_r = r;
+ if (args->best_insideAtlas) {
+ args->finished->store(true);
+ break;
+ }
+ }
+ }
+ XA_PROFILE_END(packChartsFindLocationThread)
+}
+
+struct Atlas
{
- AtlasPacker(Atlas *atlas) : m_atlas(atlas), m_width(0), m_height(0)
+ ~Atlas()
{
- // Save the original uvs.
- m_originalChartUvs.resize(m_atlas->chartCount());
- for (uint32_t i = 0; i < m_atlas->chartCount(); i++) {
- const halfedge::Mesh *mesh = atlas->chartAt(i)->chartMesh();
- m_originalChartUvs[i].resize(mesh->vertexCount());
- for (uint32_t j = 0; j < mesh->vertexCount(); j++)
- m_originalChartUvs[i][j] = mesh->vertexAt(j)->tex;
+ for (uint32_t i = 0; i < m_bitImages.size(); i++) {
+ m_bitImages[i]->~BitImage();
+ XA_FREE(m_bitImages[i]);
+ }
+ for (uint32_t i = 0; i < m_charts.size(); i++) {
+ m_charts[i]->~Chart();
+ XA_FREE(m_charts[i]);
}
}
uint32_t getWidth() const { return m_width; }
uint32_t getHeight() const { return m_height; }
+ uint32_t getNumAtlases() const { return m_bitImages.size(); }
+ float getTexelsPerUnit() const { return m_texelsPerUnit; }
+ const Chart *getChart(uint32_t index) const { return m_charts[index]; }
+ uint32_t getChartCount() const { return m_charts.size(); }
+ const Array<AtlasImage *> &getImages() const { return m_atlasImages; }
+ float getUtilization(uint32_t atlas) const { return m_utilization[atlas]; }
+
+ void addChart(param::Chart *paramChart)
+ {
+ Mesh *mesh = paramChart->mesh();
+ Chart *chart = XA_NEW(MemTag::Default, Chart);
+ chart->atlasIndex = -1;
+ chart->material = 0;
+ chart->indexCount = mesh->indexCount();
+ chart->indices = mesh->indices();
+ chart->parametricArea = paramChart->computeParametricArea();
+ if (chart->parametricArea < kAreaEpsilon) {
+ // When the parametric area is too small we use a rough approximation to prevent divisions by very small numbers.
+ const Vector2 bounds = paramChart->computeParametricBounds();
+ chart->parametricArea = bounds.x * bounds.y;
+ }
+ chart->surfaceArea = paramChart->computeSurfaceArea();
+ chart->vertices = mesh->texcoords();
+ chart->vertexCount = mesh->vertexCount();
+ chart->allowRotate = true;
+ // Compute list of boundary vertices.
+ Array<Vector2> boundary;
+ boundary.reserve(16);
+ for (uint32_t v = 0; v < chart->vertexCount; v++) {
+ if (mesh->isBoundaryVertex(v))
+ boundary.push_back(mesh->texcoord(v));
+ }
+ XA_DEBUG_ASSERT(boundary.size() > 0);
+ // Compute bounding box of chart.
+ m_boundingBox.compute(boundary.data(), boundary.size(), mesh->texcoords(), mesh->vertexCount());
+ chart->majorAxis = m_boundingBox.majorAxis();
+ chart->minorAxis = m_boundingBox.minorAxis();
+ chart->minCorner = m_boundingBox.minCorner();
+ chart->maxCorner = m_boundingBox.maxCorner();
+ m_charts.push_back(chart);
+ }
+
+ void addUvMeshCharts(UvMeshInstance *mesh)
+ {
+ BitArray vertexUsed(mesh->texcoords.size());
+ Array<Vector2> boundary;
+ boundary.reserve(16);
+ for (uint32_t c = 0; c < mesh->mesh->charts.size(); c++) {
+ UvMeshChart *uvChart = mesh->mesh->charts[c];
+ Chart *chart = XA_NEW(MemTag::Default, Chart);
+ chart->atlasIndex = -1;
+ chart->material = uvChart->material;
+ chart->indexCount = uvChart->indices.size();
+ chart->indices = uvChart->indices.data();
+ chart->vertices = mesh->texcoords.data();
+ chart->vertexCount = mesh->texcoords.size();
+ chart->allowRotate = mesh->rotateCharts;
+ // Find unique vertices.
+ vertexUsed.clearAll();
+ for (uint32_t i = 0; i < chart->indexCount; i++) {
+ const uint32_t vertex = chart->indices[i];
+ if (!vertexUsed.bitAt(vertex)) {
+ vertexUsed.setBitAt(vertex);
+ chart->uniqueVertices.push_back(vertex);
+ }
+ }
+ // Compute parametric and surface areas.
+ chart->parametricArea = 0.0f;
+ for (uint32_t f = 0; f < chart->indexCount / 3; f++) {
+ const Vector2 &v1 = chart->vertices[chart->indices[f * 3 + 0]];
+ const Vector2 &v2 = chart->vertices[chart->indices[f * 3 + 1]];
+ const Vector2 &v3 = chart->vertices[chart->indices[f * 3 + 2]];
+ chart->parametricArea += fabsf(triangleArea(v1, v2, v3));
+ }
+ chart->parametricArea *= 0.5f;
+ chart->surfaceArea = chart->parametricArea; // Identical for UV meshes.
+ if (chart->parametricArea < kAreaEpsilon) {
+ // When the parametric area is too small we use a rough approximation to prevent divisions by very small numbers.
+ Vector2 minCorner(FLT_MAX, FLT_MAX);
+ Vector2 maxCorner(-FLT_MAX, -FLT_MAX);
+ for (uint32_t v = 0; v < chart->uniqueVertexCount(); v++) {
+ minCorner = min(minCorner, chart->uniqueVertexAt(v));
+ maxCorner = max(maxCorner, chart->uniqueVertexAt(v));
+ }
+ const Vector2 bounds = (maxCorner - minCorner) * 0.5f;
+ chart->parametricArea = bounds.x * bounds.y;
+ }
+ // Compute list of boundary vertices.
+ // Using all unique vertices for simplicity, can compute real boundaries if this is too slow.
+ boundary.clear();
+ for (uint32_t v = 0; v < chart->uniqueVertexCount(); v++)
+ boundary.push_back(chart->uniqueVertexAt(v));
+ XA_DEBUG_ASSERT(boundary.size() > 0);
+ // Compute bounding box of chart.
+ m_boundingBox.compute(boundary.data(), boundary.size(), boundary.data(), boundary.size());
+ chart->majorAxis = m_boundingBox.majorAxis();
+ chart->minorAxis = m_boundingBox.minorAxis();
+ chart->minCorner = m_boundingBox.minCorner();
+ chart->maxCorner = m_boundingBox.maxCorner();
+ m_charts.push_back(chart);
+ }
+ }
// Pack charts in the smallest possible rectangle.
- void packCharts(const PackerOptions &options)
- {
- const uint32_t chartCount = m_atlas->chartCount();
- if (chartCount == 0) return;
- float texelsPerUnit = 1;
- if (options.method == PackMethod::TexelArea)
- texelsPerUnit = options.texelArea;
- for (int iteration = 0;; iteration++) {
- m_rand = MTRand();
- std::vector<float> chartOrderArray(chartCount);
- std::vector<Vector2> chartExtents(chartCount);
+ bool packCharts(TaskScheduler *taskScheduler, const PackOptions &options, ProgressFunc progressFunc, void *progressUserData)
+ {
+ if (progressFunc) {
+ if (!progressFunc(ProgressCategory::PackCharts, 0, progressUserData))
+ return false;
+ }
+ const uint32_t chartCount = m_charts.size();
+ XA_PRINT("Packing %u charts\n", chartCount);
+ if (chartCount == 0) {
+ if (progressFunc) {
+ if (!progressFunc(ProgressCategory::PackCharts, 100, progressUserData))
+ return false;
+ }
+ return true;
+ }
+ uint32_t resolution = options.resolution;
+ m_texelsPerUnit = options.texelsPerUnit;
+ if (resolution <= 0 || m_texelsPerUnit <= 0) {
+ if (resolution <= 0 && m_texelsPerUnit <= 0)
+ resolution = 1024;
float meshArea = 0;
- for (uint32_t c = 0; c < chartCount; c++) {
- Chart *chart = m_atlas->chartAt(c);
- if (!chart->isVertexMapped() && !chart->isDisk()) {
- chartOrderArray[c] = 0;
- // Skip non-disks.
- continue;
- }
- Vector2 extents(0.0f);
- if (chart->isVertexMapped()) {
- // Arrange vertices in a rectangle.
- extents.x = float(chart->vertexMapWidth);
- extents.y = float(chart->vertexMapHeight);
+ for (uint32_t c = 0; c < chartCount; c++)
+ meshArea += m_charts[c]->surfaceArea;
+ if (resolution <= 0) {
+ // Estimate resolution based on the mesh surface area and given texel scale.
+ const float texelCount = max(1.0f, meshArea * square(m_texelsPerUnit) / 0.75f); // Assume 75% utilization.
+ resolution = max(1u, nextPowerOfTwo(uint32_t(sqrtf(texelCount))));
+ }
+ if (m_texelsPerUnit <= 0) {
+ // Estimate a suitable texelsPerUnit to fit the given resolution.
+ const float texelCount = max(1.0f, meshArea / 0.75f); // Assume 75% utilization.
+ m_texelsPerUnit = sqrtf((resolution * resolution) / texelCount);
+ XA_PRINT(" Estimating texelsPerUnit as %g\n", m_texelsPerUnit);
+ }
+ }
+ Array<float> chartOrderArray;
+ chartOrderArray.resize(chartCount);
+ Array<Vector2> chartExtents;
+ chartExtents.resize(chartCount);
+ float minChartPerimeter = FLT_MAX, maxChartPerimeter = 0.0f;
+ for (uint32_t c = 0; c < chartCount; c++) {
+ Chart *chart = m_charts[c];
+ //chartOrderArray[c] = chart.surfaceArea;
+ // Compute chart scale
+ float scale = (chart->surfaceArea / chart->parametricArea) * m_texelsPerUnit;
+ if (chart->parametricArea == 0) { // < kAreaEpsilon)
+ scale = 0;
+ }
+ XA_ASSERT(isFinite(scale));
+ // Sort charts by perimeter. @@ This is sometimes producing somewhat unexpected results. Is this right?
+ //chartOrderArray[c] = ((chart->maxCorner.x - chart->minCorner.x) + (chart->maxCorner.y - chart->minCorner.y)) * scale;
+ // Translate, rotate and scale vertices. Compute extents.
+ Vector2 minCorner(FLT_MAX, FLT_MAX);
+ if (!chart->allowRotate) {
+ for (uint32_t i = 0; i < chart->uniqueVertexCount(); i++)
+ minCorner = min(minCorner, chart->uniqueVertexAt(i));
+ }
+ Vector2 extents(0.0f);
+ for (uint32_t i = 0; i < chart->uniqueVertexCount(); i++) {
+ Vector2 &texcoord = chart->uniqueVertexAt(i);
+ if (chart->allowRotate) {
+ const float x = dot(texcoord, chart->majorAxis);
+ const float y = dot(texcoord, chart->minorAxis);
+ texcoord.x = x;
+ texcoord.y = y;
+ texcoord -= chart->minCorner;
} else {
- // Compute surface area to sort charts.
- float chartArea = chart->computeSurfaceArea();
- meshArea += chartArea;
- //chartOrderArray[c] = chartArea;
- // Compute chart scale
- float parametricArea = fabsf(chart->computeParametricArea()); // @@ There doesn't seem to be anything preventing parametric area to be negative.
- if (parametricArea < NV_EPSILON) {
- // When the parametric area is too small we use a rough approximation to prevent divisions by very small numbers.
- Vector2 bounds = chart->computeParametricBounds();
- parametricArea = bounds.x * bounds.y;
- }
- float scale = (chartArea / parametricArea) * texelsPerUnit;
- if (parametricArea == 0) { // < NV_EPSILON)
- scale = 0;
- }
- xaAssert(std::isfinite(scale));
- // Compute bounding box of chart.
- Vector2 majorAxis, minorAxis, origin, end;
- computeBoundingBox(chart, &majorAxis, &minorAxis, &origin, &end);
- xaAssert(isFinite(majorAxis) && isFinite(minorAxis) && isFinite(origin));
- // Sort charts by perimeter. @@ This is sometimes producing somewhat unexpected results. Is this right?
- //chartOrderArray[c] = ((end.x - origin.x) + (end.y - origin.y)) * scale;
- // Translate, rotate and scale vertices. Compute extents.
- halfedge::Mesh *mesh = chart->chartMesh();
- const uint32_t vertexCount = mesh->vertexCount();
- for (uint32_t i = 0; i < vertexCount; i++) {
- halfedge::Vertex *vertex = mesh->vertexAt(i);
- //Vector2 t = vertex->tex - origin;
- Vector2 tmp;
- tmp.x = dot(vertex->tex, majorAxis);
- tmp.y = dot(vertex->tex, minorAxis);
- tmp -= origin;
- tmp *= scale;
- if (tmp.x < 0 || tmp.y < 0) {
- xaPrint("tmp: %f %f\n", tmp.x, tmp.y);
- xaPrint("scale: %f\n", scale);
- xaPrint("origin: %f %f\n", origin.x, origin.y);
- xaPrint("majorAxis: %f %f\n", majorAxis.x, majorAxis.y);
- xaPrint("minorAxis: %f %f\n", minorAxis.x, minorAxis.y);
- xaDebugAssert(false);
- }
- //xaAssert(tmp.x >= 0 && tmp.y >= 0);
- vertex->tex = tmp;
- xaAssert(std::isfinite(vertex->tex.x) && std::isfinite(vertex->tex.y));
- extents = max(extents, tmp);
- }
- xaDebugAssert(extents.x >= 0 && extents.y >= 0);
- // Limit chart size.
- if (extents.x > 1024 || extents.y > 1024) {
- float limit = std::max(extents.x, extents.y);
- scale = 1024 / (limit + 1);
- for (uint32_t i = 0; i < vertexCount; i++) {
- halfedge::Vertex *vertex = mesh->vertexAt(i);
- vertex->tex *= scale;
- }
- extents *= scale;
- xaDebugAssert(extents.x <= 1024 && extents.y <= 1024);
- }
- // Scale the charts to use the entire texel area available. So, if the width is 0.1 we could scale it to 1 without increasing the lightmap usage and making a better
- // use of it. In many cases this also improves the look of the seams, since vertices on the chart boundaries have more chances of being aligned with the texel centers.
- float scale_x = 1.0f;
- float scale_y = 1.0f;
- float divide_x = 1.0f;
- float divide_y = 1.0f;
- if (extents.x > 0) {
- int cw = ftoi_ceil(extents.x);
- if (options.blockAlign && chart->blockAligned) {
- // Align all chart extents to 4x4 blocks, but taking padding into account.
- if (options.conservative) {
- cw = align(cw + 2, 4) - 2;
- } else {
- cw = align(cw + 1, 4) - 1;
- }
- }
- scale_x = (float(cw) - NV_EPSILON);
- divide_x = extents.x;
- extents.x = float(cw);
- }
- if (extents.y > 0) {
- int ch = ftoi_ceil(extents.y);
- if (options.blockAlign && chart->blockAligned) {
- // Align all chart extents to 4x4 blocks, but taking padding into account.
- if (options.conservative) {
- ch = align(ch + 2, 4) - 2;
- } else {
- ch = align(ch + 1, 4) - 1;
- }
- }
- scale_y = (float(ch) - NV_EPSILON);
- divide_y = extents.y;
- extents.y = float(ch);
- }
- for (uint32_t v = 0; v < vertexCount; v++) {
- halfedge::Vertex *vertex = mesh->vertexAt(v);
- vertex->tex.x /= divide_x;
- vertex->tex.y /= divide_y;
- vertex->tex.x *= scale_x;
- vertex->tex.y *= scale_y;
- xaAssert(std::isfinite(vertex->tex.x) && std::isfinite(vertex->tex.y));
- }
+ texcoord -= minCorner;
+ }
+ texcoord *= scale;
+ XA_DEBUG_ASSERT(texcoord.x >= 0 && texcoord.y >= 0);
+ XA_DEBUG_ASSERT(isFinite(texcoord.x) && isFinite(texcoord.y));
+ extents = max(extents, texcoord);
+ }
+ XA_DEBUG_ASSERT(extents.x >= 0 && extents.y >= 0);
+ // Limit chart size.
+ const float maxChartSize = (float)options.maxChartSize;
+ if (extents.x > maxChartSize || extents.y > maxChartSize) {
+ const float limit = max(extents.x, extents.y);
+ scale = maxChartSize / (limit + 1.0f);
+ for (uint32_t i = 0; i < chart->uniqueVertexCount(); i++)
+ chart->uniqueVertexAt(i) *= scale;
+ extents *= scale;
+ XA_DEBUG_ASSERT(extents.x <= maxChartSize && extents.y <= maxChartSize);
+ }
+ // Scale the charts to use the entire texel area available. So, if the width is 0.1 we could scale it to 1 without increasing the lightmap usage and making a better
+ // use of it. In many cases this also improves the look of the seams, since vertices on the chart boundaries have more chances of being aligned with the texel centers.
+ float scale_x = 1.0f;
+ float scale_y = 1.0f;
+ float divide_x = 1.0f;
+ float divide_y = 1.0f;
+ if (extents.x > 0) {
+ int cw = ftoi_ceil(extents.x);
+ if (options.blockAlign) {
+ // Align all chart extents to 4x4 blocks, but taking padding into account.
+ cw = align(cw + 2, 4) - 2;
+ }
+ scale_x = (float(cw) - kEpsilon);
+ divide_x = extents.x;
+ extents.x = float(cw);
+ }
+ if (extents.y > 0) {
+ int ch = ftoi_ceil(extents.y);
+ if (options.blockAlign) {
+ // Align all chart extents to 4x4 blocks, but taking padding into account.
+ ch = align(ch + 2, 4) - 2;
+ }
+ scale_y = (float(ch) - kEpsilon);
+ divide_y = extents.y;
+ extents.y = float(ch);
+ }
+ for (uint32_t v = 0; v < chart->uniqueVertexCount(); v++) {
+ Vector2 &texcoord = chart->uniqueVertexAt(v);
+ texcoord.x /= divide_x;
+ texcoord.y /= divide_y;
+ texcoord.x *= scale_x;
+ texcoord.y *= scale_y;
+ XA_ASSERT(isFinite(texcoord.x) && isFinite(texcoord.y));
+ }
+ chartExtents[c] = extents;
+ // Sort charts by perimeter.
+ chartOrderArray[c] = extents.x + extents.y;
+ minChartPerimeter = min(minChartPerimeter, chartOrderArray[c]);
+ maxChartPerimeter = max(maxChartPerimeter, chartOrderArray[c]);
+ }
+ // Sort charts by perimeter.
+ m_radix = RadixSort();
+ m_radix.sort(chartOrderArray);
+ const uint32_t *ranks = m_radix.ranks();
+ // Divide chart perimeter range into buckets.
+ const float chartPerimeterBucketSize = (maxChartPerimeter - minChartPerimeter) / 16.0f;
+ uint32_t currentChartBucket = 0;
+ Array<Vector2i> chartStartPositions; // per atlas
+ chartStartPositions.push_back(Vector2i(0, 0));
+ // Pack sorted charts.
+#if XA_DEBUG_EXPORT_ATLAS_IMAGES
+ const bool createImage = true;
+#else
+ const bool createImage = options.createImage;
+#endif
+ BitImage chartBitImage, chartBitImageRotated;
+ int atlasWidth = 0, atlasHeight = 0;
+ const bool resizableAtlas = !(options.resolution > 0 && options.texelsPerUnit > 0.0f);
+ int progress = 0;
+ for (uint32_t i = 0; i < chartCount; i++) {
+ uint32_t c = ranks[chartCount - i - 1]; // largest chart first
+ Chart *chart = m_charts[c];
+ // @@ Add special cases for dot and line charts. @@ Lightmap rasterizer also needs to handle these special cases.
+ // @@ We could also have a special case for chart quads. If the quad surface <= 4 texels, align vertices with texel centers and do not add padding. May be very useful for foliage.
+ // @@ In general we could reduce the padding of all charts by one texel by using a rasterizer that takes into account the 2-texel footprint of the tent bilinear filter. For example,
+ // if we have a chart that is less than 1 texel wide currently we add one texel to the left and one texel to the right creating a 3-texel-wide bitImage. However, if we know that the
+ // chart is only 1 texel wide we could align it so that it only touches the footprint of two texels:
+ // | | <- Touches texels 0, 1 and 2.
+ // | | <- Only touches texels 0 and 1.
+ // \ \ / \ / /
+ // \ X X /
+ // \ / \ / \ /
+ // V V V
+ // 0 1 2
+ XA_PROFILE_START(packChartsRasterize)
+ // Leave room for padding.
+ chartBitImage.resize(ftoi_ceil(chartExtents[c].x) + 1 + options.padding * 2, ftoi_ceil(chartExtents[c].y) + 1 + options.padding * 2, true);
+ if (chart->allowRotate)
+ chartBitImageRotated.resize(chartBitImage.height(), chartBitImage.width(), true);
+ // Rasterize chart faces.
+ const uint32_t faceCount = chart->indexCount / 3;
+ for (uint32_t f = 0; f < faceCount; f++) {
+ // Offset vertices by padding.
+ Vector2 vertices[3];
+ for (uint32_t v = 0; v < 3; v++)
+ vertices[v] = chart->vertices[chart->indices[f * 3 + v]] + Vector2(0.5f) + Vector2(float(options.padding));
+ DrawTriangleCallbackArgs args;
+ args.chartBitImage = &chartBitImage;
+ args.chartBitImageRotated = chart->allowRotate ? &chartBitImageRotated : nullptr;
+ raster::drawTriangle(Vector2((float)chartBitImage.width(), (float)chartBitImage.height()), vertices, drawTriangleCallback, &args);
+ }
+ // Expand chart by padding pixels. (dilation)
+ BitImage chartBitImageNoPadding(chartBitImage), chartBitImageNoPaddingRotated(chartBitImageRotated);
+ if (options.padding > 0) {
+ XA_PROFILE_START(packChartsDilate)
+ chartBitImage.dilate(options.padding);
+ if (chart->allowRotate)
+ chartBitImageRotated.dilate(options.padding);
+ XA_PROFILE_END(packChartsDilate)
+ }
+ XA_PROFILE_END(packChartsRasterize)
+ // Update brute force bucketing.
+ if (options.bruteForce) {
+ if (chartOrderArray[c] > minChartPerimeter && chartOrderArray[c] <= maxChartPerimeter - (chartPerimeterBucketSize * (currentChartBucket + 1))) {
+ // Moved to a smaller bucket, reset start location.
+ for (uint32_t j = 0; j < chartStartPositions.size(); j++)
+ chartStartPositions[j] = Vector2i(0, 0);
+ currentChartBucket++;
}
- chartExtents[c] = extents;
- // Sort charts by perimeter.
- chartOrderArray[c] = extents.x + extents.y;
- }
- // @@ We can try to improve compression of small charts by sorting them by proximity like we do with vertex samples.
- // @@ How to do that? One idea: compute chart centroid, insert into grid, compute morton index of the cell, sort based on morton index.
- // @@ We would sort by morton index, first, then quantize the chart sizes, so that all small charts have the same size, and sort by size preserving the morton order.
- //xaPrint("Sorting charts.\n");
- // Sort charts by area.
- m_radix = RadixSort();
- m_radix.sort(chartOrderArray);
- const uint32_t *ranks = m_radix.ranks();
- // First iteration - guess texelsPerUnit.
- if (options.method != PackMethod::TexelArea && iteration == 0) {
- // Estimate size of the map based on the mesh surface area and given texel scale.
- const float texelCount = std::max(1.0f, meshArea * square(texelsPerUnit) / 0.75f); // Assume 75% utilization.
- texelsPerUnit = sqrt((options.resolution * options.resolution) / texelCount);
- resetUvs();
- continue;
}
- // Init bit map.
- m_bitmap.clearAll();
- m_bitmap.resize(options.resolution, options.resolution, false);
- int w = 0;
- int h = 0;
- // Add sorted charts to bitmap.
- for (uint32_t i = 0; i < chartCount; i++) {
- uint32_t c = ranks[chartCount - i - 1]; // largest chart first
- Chart *chart = m_atlas->chartAt(c);
- if (!chart->isVertexMapped() && !chart->isDisk()) continue;
- //float scale_x = 1;
- //float scale_y = 1;
- BitMap chart_bitmap;
- if (chart->isVertexMapped()) {
- chart->blockAligned = false;
- // Init all bits to 1.
- chart_bitmap.resize(ftoi_ceil(chartExtents[c].x), ftoi_ceil(chartExtents[c].y), /*initValue=*/true);
- // @@ Another alternative would be to try to map each vertex to a different texel trying to fill all the available unused texels.
- } else {
- // @@ Add special cases for dot and line charts. @@ Lightmap rasterizer also needs to handle these special cases.
- // @@ We could also have a special case for chart quads. If the quad surface <= 4 texels, align vertices with texel centers and do not add padding. May be very useful for foliage.
- // @@ In general we could reduce the padding of all charts by one texel by using a rasterizer that takes into account the 2-texel footprint of the tent bilinear filter. For example,
- // if we have a chart that is less than 1 texel wide currently we add one texel to the left and one texel to the right creating a 3-texel-wide bitmap. However, if we know that the
- // chart is only 1 texel wide we could align it so that it only touches the footprint of two texels:
- // | | <- Touches texels 0, 1 and 2.
- // | | <- Only touches texels 0 and 1.
- // \ \ / \ / /
- // \ X X /
- // \ / \ / \ /
- // V V V
- // 0 1 2
- if (options.conservative) {
- // Init all bits to 0.
- chart_bitmap.resize(ftoi_ceil(chartExtents[c].x) + 1 + options.padding, ftoi_ceil(chartExtents[c].y) + 1 + options.padding, /*initValue=*/false); // + 2 to add padding on both sides.
- // Rasterize chart and dilate.
- drawChartBitmapDilate(chart, &chart_bitmap, options.padding);
- } else {
- // Init all bits to 0.
- chart_bitmap.resize(ftoi_ceil(chartExtents[c].x) + 1, ftoi_ceil(chartExtents[c].y) + 1, /*initValue=*/false); // Add half a texels on each side.
- // Rasterize chart and dilate.
- drawChartBitmap(chart, &chart_bitmap, Vector2(1), Vector2(0.5));
- }
+ // Find a location to place the chart in the atlas.
+ uint32_t currentAtlas = 0;
+ int best_x = 0, best_y = 0;
+ int best_cw = 0, best_ch = 0;
+ int best_r = 0;
+ for (;;)
+ {
+ bool firstChartInBitImage = false;
+ if (currentAtlas + 1 > m_bitImages.size()) {
+ // Chart doesn't fit in the current bitImage, create a new one.
+ BitImage *bi = XA_NEW(MemTag::Default, BitImage);
+ bi->resize(resolution, resolution, true);
+ m_bitImages.push_back(bi);
+ firstChartInBitImage = true;
+ if (createImage)
+ m_atlasImages.push_back(XA_NEW(MemTag::Default, AtlasImage, resolution, resolution));
+ // Start positions are per-atlas, so create a new one of those too.
+ chartStartPositions.push_back(Vector2i(0, 0));
}
- int best_x, best_y;
- int best_cw, best_ch; // Includes padding now.
- int best_r;
- findChartLocation(options.quality, &chart_bitmap, chartExtents[c], w, h, &best_x, &best_y, &best_cw, &best_ch, &best_r, chart->blockAligned);
- /*if (w < best_x + best_cw || h < best_y + best_ch)
- {
- xaPrint("Resize extents to (%d, %d).\n", best_x + best_cw, best_y + best_ch);
- }*/
- // Update parametric extents.
- w = std::max(w, best_x + best_cw);
- h = std::max(h, best_y + best_ch);
- w = align(w, 4);
- h = align(h, 4);
- // Resize bitmap if necessary.
- if (uint32_t(w) > m_bitmap.width() || uint32_t(h) > m_bitmap.height()) {
- //xaPrint("Resize bitmap (%d, %d).\n", nextPowerOfTwo(w), nextPowerOfTwo(h));
- m_bitmap.resize(nextPowerOfTwo(uint32_t(w)), nextPowerOfTwo(uint32_t(h)), false);
+ XA_PROFILE_START(packChartsFindLocation)
+ const bool foundLocation = findChartLocation(taskScheduler, chartStartPositions[currentAtlas], options.bruteForce, m_bitImages[currentAtlas], &chartBitImage, &chartBitImageRotated, atlasWidth, atlasHeight, &best_x, &best_y, &best_cw, &best_ch, &best_r, options.blockAlign, resizableAtlas, chart->allowRotate);
+ XA_PROFILE_END(packChartsFindLocation)
+ if (firstChartInBitImage && !foundLocation) {
+ // Chart doesn't fit in an empty, newly allocated bitImage. texelsPerUnit must be too large for the resolution.
+ XA_ASSERT(true && "chart doesn't fit");
+ break;
+ }
+ if (resizableAtlas) {
+ XA_DEBUG_ASSERT(foundLocation);
+ break;
+ }
+ if (foundLocation)
+ break;
+ // Chart doesn't fit in the current bitImage, try the next one.
+ currentAtlas++;
+ }
+ // Update brute force start location.
+ if (options.bruteForce) {
+ // Reset start location if the chart expanded the atlas.
+ if (best_x + best_cw > atlasWidth || best_y + best_ch > atlasHeight) {
+ for (uint32_t j = 0; j < chartStartPositions.size(); j++)
+ chartStartPositions[j] = Vector2i(0, 0);
}
- //xaPrint("Add chart at (%d, %d).\n", best_x, best_y);
- addChart(&chart_bitmap, w, h, best_x, best_y, best_r);
- //float best_angle = 2 * PI * best_r;
- // Translate and rotate chart texture coordinates.
- halfedge::Mesh *mesh = chart->chartMesh();
- const uint32_t vertexCount = mesh->vertexCount();
- for (uint32_t v = 0; v < vertexCount; v++) {
- halfedge::Vertex *vertex = mesh->vertexAt(v);
- Vector2 t = vertex->tex;
- if (best_r) std::swap(t.x, t.y);
- //vertex->tex.x = best_x + t.x * cosf(best_angle) - t.y * sinf(best_angle);
- //vertex->tex.y = best_y + t.x * sinf(best_angle) + t.y * cosf(best_angle);
- vertex->tex.x = best_x + t.x + 0.5f;
- vertex->tex.y = best_y + t.y + 0.5f;
- xaAssert(vertex->tex.x >= 0 && vertex->tex.y >= 0);
- xaAssert(std::isfinite(vertex->tex.x) && std::isfinite(vertex->tex.y));
+ else {
+ chartStartPositions[currentAtlas] = Vector2i(best_x, best_y);
}
}
- //w -= padding - 1; // Leave one pixel border!
- //h -= padding - 1;
- m_width = std::max(0, w);
- m_height = std::max(0, h);
- xaAssert(isAligned(m_width, 4));
- xaAssert(isAligned(m_height, 4));
- if (options.method == PackMethod::ExactResolution) {
- texelsPerUnit *= sqrt((options.resolution * options.resolution) / (float)(m_width * m_height));
- if (iteration > 1 && m_width <= options.resolution && m_height <= options.resolution) {
- m_width = m_height = options.resolution;
- return;
+ // Update parametric extents.
+ atlasWidth = max(atlasWidth, best_x + best_cw);
+ atlasHeight = max(atlasHeight, best_y + best_ch);
+ if (resizableAtlas) {
+ // Resize bitImage if necessary.
+ if (uint32_t(atlasWidth) > m_bitImages[0]->width() || uint32_t(atlasHeight) > m_bitImages[0]->height()) {
+ m_bitImages[0]->resize(nextPowerOfTwo(uint32_t(atlasWidth)), nextPowerOfTwo(uint32_t(atlasHeight)), false);
+ if (createImage)
+ m_atlasImages[0]->resize(m_bitImages[0]->width(), m_bitImages[0]->height());
}
- resetUvs();
} else {
- return;
+ atlasWidth = min((int)options.resolution, atlasWidth);
+ atlasHeight = min((int)options.resolution, atlasHeight);
+ }
+ XA_PROFILE_START(packChartsBlit)
+ addChart(m_bitImages[currentAtlas], &chartBitImage, &chartBitImageRotated, atlasWidth, atlasHeight, best_x, best_y, best_r);
+ XA_PROFILE_END(packChartsBlit)
+ if (createImage) {
+ m_atlasImages[currentAtlas]->addChart(c, best_r == 0 ? &chartBitImageNoPadding : &chartBitImageNoPaddingRotated, false, atlasWidth, atlasHeight, best_x, best_y);
+ m_atlasImages[currentAtlas]->addChart(c, best_r == 0 ? &chartBitImage : &chartBitImageRotated, true, atlasWidth, atlasHeight, best_x, best_y);
+ }
+ chart->atlasIndex = (int32_t)currentAtlas;
+ // Translate and rotate chart texture coordinates.
+ for (uint32_t v = 0; v < chart->uniqueVertexCount(); v++) {
+ Vector2 &texcoord = chart->uniqueVertexAt(v);
+ Vector2 t = texcoord;
+ if (best_r) {
+ XA_DEBUG_ASSERT(chart->allowRotate);
+ swap(t.x, t.y);
+ }
+ texcoord.x = best_x + t.x + 0.5f;
+ texcoord.y = best_y + t.y + 0.5f;
+ XA_ASSERT(texcoord.x >= 0 && texcoord.y >= 0);
+ XA_ASSERT(isFinite(texcoord.x) && isFinite(texcoord.y));
+ }
+ if (progressFunc) {
+ const int newProgress = int((i + 1) / (float)chartCount * 100.0f);
+ if (newProgress != progress) {
+ progress = newProgress;
+ if (!progressFunc(ProgressCategory::PackCharts, progress, progressUserData))
+ return false;
+ }
}
}
- }
-
- float computeAtlasUtilization() const
- {
- const uint32_t w = m_width;
- const uint32_t h = m_height;
- xaDebugAssert(w <= m_bitmap.width());
- xaDebugAssert(h <= m_bitmap.height());
- uint32_t count = 0;
- for (uint32_t y = 0; y < h; y++) {
- for (uint32_t x = 0; x < w; x++) {
- count += m_bitmap.bitAt(x, y);
+ if (resizableAtlas) {
+ m_width = max(0, atlasWidth - (int)options.padding * 2);
+ m_height = max(0, atlasHeight - (int)options.padding * 2);
+ } else {
+ m_width = m_height = options.resolution;
+ }
+ XA_PRINT(" %dx%d resolution\n", m_width, m_height);
+ m_utilization.resize(m_bitImages.size());
+ for (uint32_t i = 0; i < m_utilization.size(); i++) {
+ uint32_t count = 0;
+ for (uint32_t y = 0; y < m_height; y++) {
+ for (uint32_t x = 0; x < m_width; x++)
+ count += m_bitImages[i]->bitAt(x, y);
+ }
+ m_utilization[i] = float(count) / (m_width * m_height);
+ if (m_utilization.size() > 1) {
+ XA_PRINT(" %u: %f%% utilization\n", i, m_utilization[i] * 100.0f);
+ }
+ else {
+ XA_PRINT(" %f%% utilization\n", m_utilization[i] * 100.0f);
}
}
- return float(count) / (w * h);
- }
-
-private:
- void resetUvs()
- {
- for (uint32_t i = 0; i < m_atlas->chartCount(); i++) {
- halfedge::Mesh *mesh = m_atlas->chartAt(i)->chartMesh();
- for (uint32_t j = 0; j < mesh->vertexCount(); j++)
- mesh->vertexAt(j)->tex = m_originalChartUvs[i][j];
+#if XA_DEBUG_EXPORT_ATLAS_IMAGES
+ for (uint32_t i = 0; i < m_atlasImages.size(); i++) {
+ char filename[256];
+ XA_SPRINTF(filename, sizeof(filename), "debug_atlas_image%02u.tga", i);
+ m_atlasImages[i]->writeTga(filename, m_width, m_height);
+ }
+#endif
+ if (progressFunc && progress != 100) {
+ if (!progressFunc(ProgressCategory::PackCharts, 100, progressUserData))
+ return false;
}
+ return true;
}
+private:
// IC: Brute force is slow, and random may take too much time to converge. We start inserting large charts in a small atlas. Using brute force is lame, because most of the space
// is occupied at this point. At the end we have many small charts and a large atlas with sparse holes. Finding those holes randomly is slow. A better approach would be to
// start stacking large charts as if they were tetris pieces. Once charts get small try to place them randomly. It may be interesting to try a intermediate strategy, first try
// along one axis and then try exhaustively along that axis.
- void findChartLocation(int quality, const BitMap *bitmap, Vector2::Arg extents, int w, int h, int *best_x, int *best_y, int *best_w, int *best_h, int *best_r, bool blockAligned)
- {
- int attempts = 256;
- if (quality == 1) attempts = 4096;
- if (quality == 2) attempts = 2048;
- if (quality == 3) attempts = 1024;
- if (quality == 4) attempts = 512;
- if (quality == 0 || w * h < attempts) {
- findChartLocation_bruteForce(bitmap, extents, w, h, best_x, best_y, best_w, best_h, best_r, blockAligned);
- } else {
- findChartLocation_random(bitmap, extents, w, h, best_x, best_y, best_w, best_h, best_r, attempts, blockAligned);
- }
+ bool findChartLocation(TaskScheduler *taskScheduler, const Vector2i &startPosition, bool bruteForce, const BitImage *atlasBitImage, const BitImage *chartBitImage, const BitImage *chartBitImageRotated, int w, int h, int *best_x, int *best_y, int *best_w, int *best_h, int *best_r, bool blockAligned, bool resizableAtlas, bool allowRotate)
+ {
+ const int attempts = 4096;
+ if (bruteForce || attempts >= w * h)
+ return findChartLocation_bruteForce(taskScheduler, startPosition, atlasBitImage, chartBitImage, chartBitImageRotated, w, h, best_x, best_y, best_w, best_h, best_r, blockAligned, resizableAtlas, allowRotate);
+ return findChartLocation_random(atlasBitImage, chartBitImage, chartBitImageRotated, w, h, best_x, best_y, best_w, best_h, best_r, attempts, blockAligned, resizableAtlas, allowRotate);
}
- void findChartLocation_bruteForce(const BitMap *bitmap, Vector2::Arg /*extents*/, int w, int h, int *best_x, int *best_y, int *best_w, int *best_h, int *best_r, bool blockAligned)
+ bool findChartLocation_bruteForce(TaskScheduler *taskScheduler, const Vector2i &startPosition, const BitImage *atlasBitImage, const BitImage *chartBitImage, const BitImage *chartBitImageRotated, int w, int h, int *best_x, int *best_y, int *best_w, int *best_h, int *best_r, bool blockAligned, bool resizableAtlas, bool allowRotate)
{
- const int BLOCK_SIZE = 4;
+ const int stepSize = blockAligned ? 4 : 1;
+ uint32_t taskCount = 0;
+ for (int y = startPosition.y; y <= h + stepSize; y += stepSize)
+ taskCount++;
+ Array<FindChartLocationBruteForceTaskArgs> taskArgs;
+ taskArgs.resize(taskCount);
+ TaskGroupHandle taskGroup = taskScheduler->createTaskGroup(taskCount);
+ std::atomic<bool> finished(false); // One of the tasks found a location that doesn't expand the atlas.
+ uint32_t i = 0;
+ for (int y = startPosition.y; y <= h + stepSize; y += stepSize) {
+ FindChartLocationBruteForceTaskArgs &args = taskArgs[i];
+ args.finished = &finished;
+ args.startPosition = Vector2i(y == startPosition.y ? startPosition.x : 0, y);
+ args.atlasBitImage = atlasBitImage;
+ args.chartBitImage = chartBitImage;
+ args.chartBitImageRotated = chartBitImageRotated;
+ args.w = w;
+ args.h = h;
+ args.blockAligned = blockAligned;
+ args.resizableAtlas = resizableAtlas;
+ args.allowRotate = allowRotate;
+ Task task;
+ task.userData = &taskArgs[i];
+ task.func = runFindChartLocationBruteForceTask;
+ taskScheduler->run(taskGroup, task);
+ i++;
+ }
+ taskScheduler->wait(&taskGroup);
+ // Find the task result with the best metric.
int best_metric = INT_MAX;
- int step_size = blockAligned ? BLOCK_SIZE : 1;
- // Try two different orientations.
- for (int r = 0; r < 2; r++) {
- int cw = bitmap->width();
- int ch = bitmap->height();
- if (r & 1) std::swap(cw, ch);
- for (int y = 0; y <= h + 1; y += step_size) { // + 1 to extend atlas in case atlas full.
- for (int x = 0; x <= w + 1; x += step_size) { // + 1 not really necessary here.
- // Early out.
- int area = std::max(w, x + cw) * std::max(h, y + ch);
- //int perimeter = max(w, x+cw) + max(h, y+ch);
- int extents = std::max(std::max(w, x + cw), std::max(h, y + ch));
- int metric = extents * extents + area;
- if (metric > best_metric) {
- continue;
- }
- if (metric == best_metric && std::max(x, y) >= std::max(*best_x, *best_y)) {
- // If metric is the same, pick the one closest to the origin.
- continue;
- }
- if (canAddChart(bitmap, w, h, x, y, r)) {
- best_metric = metric;
- *best_x = x;
- *best_y = y;
- *best_w = cw;
- *best_h = ch;
- *best_r = r;
- if (area == w * h) {
- // Chart is completely inside, do not look at any other location.
- goto done;
- }
- }
- }
- }
+ bool best_insideAtlas = false;
+ for (i = 0; i < taskCount; i++) {
+ FindChartLocationBruteForceTaskArgs &args = taskArgs[i];
+ if (args.best_metric > best_metric)
+ continue;
+ // A location that doesn't expand the atlas is always preferred.
+ if (!args.best_insideAtlas && best_insideAtlas)
+ continue;
+ // If metric is the same, pick the one closest to the origin.
+ if (args.best_insideAtlas == best_insideAtlas && args.best_metric == best_metric && max(args.best_x, args.best_y) >= max(*best_x, *best_y))
+ continue;
+ best_metric = args.best_metric;
+ best_insideAtlas = args.best_insideAtlas;
+ *best_x = args.best_x;
+ *best_y = args.best_y;
+ *best_w = args.best_w;
+ *best_h = args.best_h;
+ *best_r = args.best_r;
}
- done:
- xaDebugAssert (best_metric != INT_MAX);
+ return best_metric != INT_MAX;
}
- void findChartLocation_random(const BitMap *bitmap, Vector2::Arg /*extents*/, int w, int h, int *best_x, int *best_y, int *best_w, int *best_h, int *best_r, int minTrialCount, bool blockAligned)
+ bool findChartLocation_random(const BitImage *atlasBitImage, const BitImage *chartBitImage, const BitImage *chartBitImageRotated, int w, int h, int *best_x, int *best_y, int *best_w, int *best_h, int *best_r, int minTrialCount, bool blockAligned, bool resizableAtlas, bool allowRotate)
{
+ bool result = false;
const int BLOCK_SIZE = 4;
int best_metric = INT_MAX;
- for (int i = 0; i < minTrialCount || best_metric == INT_MAX; i++) {
- int r = m_rand.getRange(1);
- int x = m_rand.getRange(w + 1); // + 1 to extend atlas in case atlas full. We may want to use a higher number to increase probability of extending atlas.
- int y = m_rand.getRange(h + 1); // + 1 to extend atlas in case atlas full.
+ for (int i = 0; i < minTrialCount; i++) {
+ int cw = chartBitImage->width();
+ int ch = chartBitImage->height();
+ int r = allowRotate ? m_rand.getRange(1) : 0;
+ if (r == 1)
+ swap(cw, ch);
+ // + 1 to extend atlas in case atlas full. We may want to use a higher number to increase probability of extending atlas.
+ int xRange = w + 1;
+ int yRange = h + 1;
+ if (!resizableAtlas) {
+ xRange = min(xRange, (int)atlasBitImage->width() - cw);
+ yRange = min(yRange, (int)atlasBitImage->height() - ch);
+ }
+ int x = m_rand.getRange(xRange);
+ int y = m_rand.getRange(yRange);
if (blockAligned) {
x = align(x, BLOCK_SIZE);
y = align(y, BLOCK_SIZE);
+ if (!resizableAtlas && (x > (int)atlasBitImage->width() - cw || y > (int)atlasBitImage->height() - ch))
+ continue; // Block alignment pushed the chart outside the atlas.
}
- int cw = bitmap->width();
- int ch = bitmap->height();
- if (r & 1) std::swap(cw, ch);
// Early out.
- int area = std::max(w, x + cw) * std::max(h, y + ch);
+ int area = max(w, x + cw) * max(h, y + ch);
//int perimeter = max(w, x+cw) + max(h, y+ch);
- int extents = std::max(std::max(w, x + cw), std::max(h, y + ch));
+ int extents = max(max(w, x + cw), max(h, y + ch));
int metric = extents * extents + area;
if (metric > best_metric) {
continue;
}
- if (metric == best_metric && std::min(x, y) > std::min(*best_x, *best_y)) {
+ if (metric == best_metric && min(x, y) > min(*best_x, *best_y)) {
// If metric is the same, pick the one closest to the origin.
continue;
}
- if (canAddChart(bitmap, w, h, x, y, r)) {
+ if (atlasBitImage->canBlit(r == 1 ? *chartBitImageRotated : *chartBitImage, x, y)) {
+ result = true;
best_metric = metric;
*best_x = x;
*best_y = y;
*best_w = cw;
*best_h = ch;
- *best_r = r;
+ *best_r = allowRotate ? r : 0;
if (area == w * h) {
// Chart is completely inside, do not look at any other location.
break;
}
}
}
+ return result;
}
- void drawChartBitmapDilate(const Chart *chart, BitMap *bitmap, int padding)
- {
- const int w = bitmap->width();
- const int h = bitmap->height();
- const Vector2 extents = Vector2(float(w), float(h));
- // Rasterize chart faces, check that all bits are not set.
- const uint32_t faceCount = chart->faceCount();
- for (uint32_t f = 0; f < faceCount; f++) {
- const halfedge::Face *face = chart->chartMesh()->faceAt(f);
- Vector2 vertices[4];
- uint32_t edgeCount = 0;
- for (halfedge::Face::ConstEdgeIterator it(face->edges()); !it.isDone(); it.advance()) {
- if (edgeCount < 4) {
- vertices[edgeCount] = it.vertex()->tex + Vector2(0.5) + Vector2(float(padding), float(padding));
- }
- edgeCount++;
- }
- if (edgeCount == 3) {
- raster::drawTriangle(raster::Mode_Antialiased, extents, true, vertices, AtlasPacker::setBitsCallback, bitmap);
- } else {
- raster::drawQuad(raster::Mode_Antialiased, extents, true, vertices, AtlasPacker::setBitsCallback, bitmap);
- }
- }
- // Expand chart by padding pixels. (dilation)
- BitMap tmp(w, h);
- for (int i = 0; i < padding; i++) {
- tmp.clearAll();
- for (int y = 0; y < h; y++) {
- for (int x = 0; x < w; x++) {
- bool b = bitmap->bitAt(x, y);
- if (!b) {
- if (x > 0) {
- b |= bitmap->bitAt(x - 1, y);
- if (y > 0) b |= bitmap->bitAt(x - 1, y - 1);
- if (y < h - 1) b |= bitmap->bitAt(x - 1, y + 1);
- }
- if (y > 0) b |= bitmap->bitAt(x, y - 1);
- if (y < h - 1) b |= bitmap->bitAt(x, y + 1);
- if (x < w - 1) {
- b |= bitmap->bitAt(x + 1, y);
- if (y > 0) b |= bitmap->bitAt(x + 1, y - 1);
- if (y < h - 1) b |= bitmap->bitAt(x + 1, y + 1);
- }
- }
- if (b) tmp.setBitAt(x, y);
- }
- }
- std::swap(tmp, *bitmap);
- }
- }
-
- void drawChartBitmap(const Chart *chart, BitMap *bitmap, const Vector2 &scale, const Vector2 &offset)
+ void addChart(BitImage *atlasBitImage, const BitImage *chartBitImage, const BitImage *chartBitImageRotated, int atlas_w, int atlas_h, int offset_x, int offset_y, int r)
{
- const int w = bitmap->width();
- const int h = bitmap->height();
- const Vector2 extents = Vector2(float(w), float(h));
- static const Vector2 pad[4] = {
- Vector2(-0.5, -0.5),
- Vector2(0.5, -0.5),
- Vector2(-0.5, 0.5),
- Vector2(0.5, 0.5)
- };
- // Rasterize 4 times to add proper padding.
- for (int i = 0; i < 4; i++) {
- // Rasterize chart faces, check that all bits are not set.
- const uint32_t faceCount = chart->chartMesh()->faceCount();
- for (uint32_t f = 0; f < faceCount; f++) {
- const halfedge::Face *face = chart->chartMesh()->faceAt(f);
- Vector2 vertices[4];
- uint32_t edgeCount = 0;
- for (halfedge::Face::ConstEdgeIterator it(face->edges()); !it.isDone(); it.advance()) {
- if (edgeCount < 4) {
- vertices[edgeCount] = it.vertex()->tex * scale + offset + pad[i];
- xaAssert(ftoi_ceil(vertices[edgeCount].x) >= 0);
- xaAssert(ftoi_ceil(vertices[edgeCount].y) >= 0);
- xaAssert(ftoi_ceil(vertices[edgeCount].x) <= w);
- xaAssert(ftoi_ceil(vertices[edgeCount].y) <= h);
- }
- edgeCount++;
- }
- if (edgeCount == 3) {
- raster::drawTriangle(raster::Mode_Antialiased, extents, /*enableScissors=*/true, vertices, AtlasPacker::setBitsCallback, bitmap);
- } else {
- raster::drawQuad(raster::Mode_Antialiased, extents, /*enableScissors=*/true, vertices, AtlasPacker::setBitsCallback, bitmap);
- }
- }
- }
- // Expand chart by padding pixels. (dilation)
- BitMap tmp(w, h);
- tmp.clearAll();
+ XA_DEBUG_ASSERT(r == 0 || r == 1);
+ const BitImage *image = r == 0 ? chartBitImage : chartBitImageRotated;
+ const int w = image->width();
+ const int h = image->height();
for (int y = 0; y < h; y++) {
- for (int x = 0; x < w; x++) {
- bool b = bitmap->bitAt(x, y);
- if (!b) {
- if (x > 0) {
- b |= bitmap->bitAt(x - 1, y);
- if (y > 0) b |= bitmap->bitAt(x - 1, y - 1);
- if (y < h - 1) b |= bitmap->bitAt(x - 1, y + 1);
- }
- if (y > 0) b |= bitmap->bitAt(x, y - 1);
- if (y < h - 1) b |= bitmap->bitAt(x, y + 1);
- if (x < w - 1) {
- b |= bitmap->bitAt(x + 1, y);
- if (y > 0) b |= bitmap->bitAt(x + 1, y - 1);
- if (y < h - 1) b |= bitmap->bitAt(x + 1, y + 1);
- }
- }
- if (b) tmp.setBitAt(x, y);
- }
- }
- std::swap(tmp, *bitmap);
- }
-
- bool canAddChart(const BitMap *bitmap, int atlas_w, int atlas_h, int offset_x, int offset_y, int r)
- {
- xaDebugAssert(r == 0 || r == 1);
- // Check whether the two bitmaps overlap.
- const int w = bitmap->width();
- const int h = bitmap->height();
- if (r == 0) {
- for (int y = 0; y < h; y++) {
- int yy = y + offset_y;
- if (yy >= 0) {
- for (int x = 0; x < w; x++) {
- int xx = x + offset_x;
- if (xx >= 0) {
- if (bitmap->bitAt(x, y)) {
- if (xx < atlas_w && yy < atlas_h) {
- if (m_bitmap.bitAt(xx, yy)) return false;
- }
- }
- }
- }
- }
- }
- } else if (r == 1) {
- for (int y = 0; y < h; y++) {
- int xx = y + offset_x;
- if (xx >= 0) {
- for (int x = 0; x < w; x++) {
- int yy = x + offset_y;
- if (yy >= 0) {
- if (bitmap->bitAt(x, y)) {
- if (xx < atlas_w && yy < atlas_h) {
- if (m_bitmap.bitAt(xx, yy)) return false;
- }
- }
- }
- }
- }
- }
- }
- return true;
- }
-
- void addChart(const BitMap *bitmap, int atlas_w, int atlas_h, int offset_x, int offset_y, int r)
- {
- xaDebugAssert(r == 0 || r == 1);
- // Check whether the two bitmaps overlap.
- const int w = bitmap->width();
- const int h = bitmap->height();
- if (r == 0) {
- for (int y = 0; y < h; y++) {
- int yy = y + offset_y;
- if (yy >= 0) {
- for (int x = 0; x < w; x++) {
- int xx = x + offset_x;
- if (xx >= 0) {
- if (bitmap->bitAt(x, y)) {
- if (xx < atlas_w && yy < atlas_h) {
- xaDebugAssert(m_bitmap.bitAt(xx, yy) == false);
- m_bitmap.setBitAt(xx, yy);
- }
- }
- }
- }
- }
- }
- } else if (r == 1) {
- for (int y = 0; y < h; y++) {
- int xx = y + offset_x;
- if (xx >= 0) {
- for (int x = 0; x < w; x++) {
- int yy = x + offset_y;
- if (yy >= 0) {
- if (bitmap->bitAt(x, y)) {
- if (xx < atlas_w && yy < atlas_h) {
- xaDebugAssert(m_bitmap.bitAt(xx, yy) == false);
- m_bitmap.setBitAt(xx, yy);
- }
+ int yy = y + offset_y;
+ if (yy >= 0) {
+ for (int x = 0; x < w; x++) {
+ int xx = x + offset_x;
+ if (xx >= 0) {
+ if (image->bitAt(x, y)) {
+ if (xx < atlas_w && yy < atlas_h) {
+ XA_DEBUG_ASSERT(atlasBitImage->bitAt(xx, yy) == false);
+ atlasBitImage->setBitAt(xx, yy);
}
}
}
@@ -7350,458 +7475,996 @@ private:
}
}
- static bool setBitsCallback(void *param, int x, int y, Vector3::Arg, Vector3::Arg, Vector3::Arg, float area)
+ struct DrawTriangleCallbackArgs
{
- BitMap *bitmap = (BitMap * )param;
- if (area > 0.0) {
- bitmap->setBitAt(x, y);
- }
- return true;
- }
+ BitImage *chartBitImage;
+ BitImage *chartBitImageRotated;
+ };
- // Compute the convex hull using Graham Scan.
- static void convexHull(const std::vector<Vector2> &input, std::vector<Vector2> &output, float epsilon)
+ static bool drawTriangleCallback(void *param, int x, int y)
{
- const uint32_t inputCount = input.size();
- std::vector<float> coords(inputCount);
- for (uint32_t i = 0; i < inputCount; i++) {
- coords[i] = input[i].x;
- }
- RadixSort radix;
- radix.sort(coords);
- const uint32_t *ranks = radix.ranks();
- std::vector<Vector2> top;
- top.reserve(inputCount);
- std::vector<Vector2> bottom;
- bottom.reserve(inputCount);
- Vector2 P = input[ranks[0]];
- Vector2 Q = input[ranks[inputCount - 1]];
- float topy = std::max(P.y, Q.y);
- float boty = std::min(P.y, Q.y);
- for (uint32_t i = 0; i < inputCount; i++) {
- Vector2 p = input[ranks[i]];
- if (p.y >= boty) top.push_back(p);
- }
- for (uint32_t i = 0; i < inputCount; i++) {
- Vector2 p = input[ranks[inputCount - 1 - i]];
- if (p.y <= topy) bottom.push_back(p);
- }
- // Filter top list.
- output.clear();
- output.push_back(top[0]);
- output.push_back(top[1]);
- for (uint32_t i = 2; i < top.size(); ) {
- Vector2 a = output[output.size() - 2];
- Vector2 b = output[output.size() - 1];
- Vector2 c = top[i];
- float area = triangleArea(a, b, c);
- if (area >= -epsilon) {
- output.pop_back();
- }
- if (area < -epsilon || output.size() == 1) {
- output.push_back(c);
- i++;
- }
- }
- uint32_t top_count = output.size();
- output.push_back(bottom[1]);
- // Filter bottom list.
- for (uint32_t i = 2; i < bottom.size(); ) {
- Vector2 a = output[output.size() - 2];
- Vector2 b = output[output.size() - 1];
- Vector2 c = bottom[i];
- float area = triangleArea(a, b, c);
- if (area >= -epsilon) {
- output.pop_back();
- }
- if (area < -epsilon || output.size() == top_count) {
- output.push_back(c);
- i++;
- }
- }
- // Remove duplicate element.
- xaDebugAssert(output.front() == output.back());
- output.pop_back();
+ auto args = (DrawTriangleCallbackArgs *)param;
+ args->chartBitImage->setBitAt(x, y);
+ if (args->chartBitImageRotated)
+ args->chartBitImageRotated->setBitAt(y, x);
+ return true;
}
- // This should compute convex hull and use rotating calipers to find the best box. Currently it uses a brute force method.
- static void computeBoundingBox(Chart *chart, Vector2 *majorAxis, Vector2 *minorAxis, Vector2 *minCorner, Vector2 *maxCorner)
- {
- // Compute list of boundary points.
- std::vector<Vector2> points;
- points.reserve(16);
- halfedge::Mesh *mesh = chart->chartMesh();
- const uint32_t vertexCount = mesh->vertexCount();
- for (uint32_t i = 0; i < vertexCount; i++) {
- halfedge::Vertex *vertex = mesh->vertexAt(i);
- if (vertex->isBoundary()) {
- points.push_back(vertex->tex);
- }
- }
- xaDebugAssert(points.size() > 0);
- std::vector<Vector2> hull;
- convexHull(points, hull, 0.00001f);
- // @@ Ideally I should use rotating calipers to find the best box. Using brute force for now.
- float best_area = FLT_MAX;
- Vector2 best_min;
- Vector2 best_max;
- Vector2 best_axis;
- const uint32_t hullCount = hull.size();
- for (uint32_t i = 0, j = hullCount - 1; i < hullCount; j = i, i++) {
- if (equal(hull[i], hull[j])) {
- continue;
- }
- Vector2 axis = normalize(hull[i] - hull[j], 0.0f);
- xaDebugAssert(isFinite(axis));
- // Compute bounding box.
- Vector2 box_min(FLT_MAX, FLT_MAX);
- Vector2 box_max(-FLT_MAX, -FLT_MAX);
- for (uint32_t v = 0; v < hullCount; v++) {
- Vector2 point = hull[v];
- float x = dot(axis, point);
- if (x < box_min.x) box_min.x = x;
- if (x > box_max.x) box_max.x = x;
- float y = dot(Vector2(-axis.y, axis.x), point);
- if (y < box_min.y) box_min.y = y;
- if (y > box_max.y) box_max.y = y;
- }
- // Compute box area.
- float area = (box_max.x - box_min.x) * (box_max.y - box_min.y);
- if (area < best_area) {
- best_area = area;
- best_min = box_min;
- best_max = box_max;
- best_axis = axis;
- }
- }
- // Consider all points, not only boundary points, in case the input chart is malformed.
- for (uint32_t i = 0; i < vertexCount; i++) {
- halfedge::Vertex *vertex = mesh->vertexAt(i);
- Vector2 point = vertex->tex;
- float x = dot(best_axis, point);
- if (x < best_min.x) best_min.x = x;
- if (x > best_max.x) best_max.x = x;
- float y = dot(Vector2(-best_axis.y, best_axis.x), point);
- if (y < best_min.y) best_min.y = y;
- if (y > best_max.y) best_max.y = y;
- }
- *majorAxis = best_axis;
- *minorAxis = Vector2(-best_axis.y, best_axis.x);
- *minCorner = best_min;
- *maxCorner = best_max;
- }
-
- Atlas *m_atlas;
- BitMap m_bitmap;
+ Array<AtlasImage *> m_atlasImages;
+ Array<float> m_utilization;
+ Array<BitImage *> m_bitImages;
+ BoundingBox2D m_boundingBox;
+ Array<Chart *> m_charts;
RadixSort m_radix;
- uint32_t m_width;
- uint32_t m_height;
- MTRand m_rand;
- std::vector<std::vector<Vector2> > m_originalChartUvs;
+ uint32_t m_width = 0;
+ uint32_t m_height = 0;
+ float m_texelsPerUnit = 0.0f;
+ KISSRng m_rand;
};
-} // namespace param
+} // namespace pack
} // namespace internal
-struct Atlas
-{
- internal::param::Atlas atlas;
- std::vector<internal::halfedge::Mesh *> heMeshes;
- uint32_t width = 0;
- uint32_t height = 0;
- OutputMesh **outputMeshes = NULL;
+struct Context
+{
+ Atlas atlas;
+ uint32_t meshCount = 0;
+ internal::Progress *addMeshProgress = nullptr;
+ internal::TaskGroupHandle addMeshTaskGroup;
+ internal::param::Atlas paramAtlas;
+ ProgressFunc progressFunc = nullptr;
+ void *progressUserData = nullptr;
+ internal::TaskScheduler *taskScheduler;
+ internal::Array<internal::UvMesh *> uvMeshes;
+ internal::Array<internal::UvMeshInstance *> uvMeshInstances;
};
-void SetPrint(PrintFunc print)
+Atlas *Create()
{
- internal::s_print = print;
+ Context *ctx = XA_NEW(internal::MemTag::Default, Context);
+ memset(&ctx->atlas, 0, sizeof(Atlas));
+ ctx->taskScheduler = XA_NEW(internal::MemTag::Default, internal::TaskScheduler);
+ return &ctx->atlas;
}
-Atlas *Create()
-{
- Atlas *atlas = new Atlas();
- return atlas;
+static void DestroyOutputMeshes(Context *ctx)
+{
+ if (!ctx->atlas.meshes)
+ return;
+ for (int i = 0; i < (int)ctx->atlas.meshCount; i++) {
+ Mesh &mesh = ctx->atlas.meshes[i];
+ for (uint32_t j = 0; j < mesh.chartCount; j++) {
+ if (mesh.chartArray[j].indexArray)
+ XA_FREE(mesh.chartArray[j].indexArray);
+ }
+ if (mesh.chartArray)
+ XA_FREE(mesh.chartArray);
+ if (mesh.vertexArray)
+ XA_FREE(mesh.vertexArray);
+ if (mesh.indexArray)
+ XA_FREE(mesh.indexArray);
+ }
+ if (ctx->atlas.meshes)
+ XA_FREE(ctx->atlas.meshes);
+ ctx->atlas.meshes = nullptr;
}
void Destroy(Atlas *atlas)
{
- xaAssert(atlas);
- for (int i = 0; i < (int)atlas->heMeshes.size(); i++) {
- delete atlas->heMeshes[i];
- if (atlas->outputMeshes) {
- OutputMesh *outputMesh = atlas->outputMeshes[i];
- for (uint32_t j = 0; j < outputMesh->chartCount; j++)
- delete [] outputMesh->chartArray[j].indexArray;
- delete [] outputMesh->chartArray;
- delete [] outputMesh->vertexArray;
- delete [] outputMesh->indexArray;
- delete outputMesh;
- }
- }
- delete [] atlas->outputMeshes;
- delete atlas;
+ XA_DEBUG_ASSERT(atlas);
+ Context *ctx = (Context *)atlas;
+ if (atlas->utilization)
+ XA_FREE(atlas->utilization);
+ if (atlas->image)
+ XA_FREE(atlas->image);
+ DestroyOutputMeshes(ctx);
+ if (ctx->addMeshProgress) {
+ ctx->addMeshProgress->cancel = true;
+ AddMeshJoin(atlas); // frees addMeshProgress
+ }
+ ctx->taskScheduler->~TaskScheduler();
+ XA_FREE(ctx->taskScheduler);
+ for (uint32_t i = 0; i < ctx->uvMeshes.size(); i++) {
+ internal::UvMesh *mesh = ctx->uvMeshes[i];
+ for (uint32_t j = 0; j < mesh->charts.size(); j++) {
+ mesh->charts[j]->~UvMeshChart();
+ XA_FREE(mesh->charts[j]);
+ }
+ mesh->~UvMesh();
+ XA_FREE(mesh);
+ }
+ for (uint32_t i = 0; i < ctx->uvMeshInstances.size(); i++) {
+ internal::UvMeshInstance *mesh = ctx->uvMeshInstances[i];
+ mesh->~UvMeshInstance();
+ XA_FREE(mesh);
+ }
+ ctx->~Context();
+ XA_FREE(ctx);
+#if XA_DEBUG_HEAP
+ internal::ReportLeaks();
+#endif
}
-static internal::Vector3 DecodePosition(const InputMesh &mesh, uint32_t index)
+struct AddMeshTaskArgs
{
- xaAssert(mesh.vertexPositionData);
- return *((const internal::Vector3 *)&((const uint8_t *)mesh.vertexPositionData)[mesh.vertexPositionStride * index]);
+ Context *ctx;
+ internal::Mesh *mesh;
+};
+
+static void runAddMeshTask(void *userData)
+{
+ XA_PROFILE_START(addMeshThread)
+ auto args = (AddMeshTaskArgs *)userData; // Responsible for freeing this.
+ internal::Mesh *mesh = args->mesh;
+ internal::Progress *progress = args->ctx->addMeshProgress;
+ if (progress->cancel)
+ goto cleanup;
+ {
+ XA_PROFILE_START(addMeshCreateColocals)
+ mesh->createColocals();
+ XA_PROFILE_END(addMeshCreateColocals)
+ }
+ if (progress->cancel)
+ goto cleanup;
+ {
+ XA_PROFILE_START(addMeshCreateFaceGroups)
+ mesh->createFaceGroups();
+ XA_PROFILE_END(addMeshCreateFaceGroups)
+ }
+ if (progress->cancel)
+ goto cleanup;
+ {
+ XA_PROFILE_START(addMeshCreateBoundaries)
+ mesh->createBoundaries();
+ XA_PROFILE_END(addMeshCreateBoundaries)
+ }
+ if (progress->cancel)
+ goto cleanup;
+#if XA_DEBUG_EXPORT_OBJ_SOURCE_MESHES
+ char filename[256];
+ XA_SPRINTF(filename, sizeof(filename), "debug_mesh_%03u.obj", mesh->id());
+ FILE *file;
+ XA_FOPEN(file, filename, "w");
+ if (file) {
+ mesh->writeObjVertices(file);
+ // groups
+ uint32_t numGroups = 0;
+ for (uint32_t i = 0; i < mesh->faceGroupCount(); i++) {
+ if (mesh->faceGroupAt(i) != UINT32_MAX)
+ numGroups = internal::max(numGroups, mesh->faceGroupAt(i) + 1);
+ }
+ for (uint32_t i = 0; i < numGroups; i++) {
+ fprintf(file, "o group_%04d\n", i);
+ fprintf(file, "s off\n");
+ for (uint32_t f = 0; f < mesh->faceGroupCount(); f++) {
+ if (mesh->faceGroupAt(f) == i)
+ mesh->writeObjFace(file, f);
+ }
+ }
+ fprintf(file, "o group_ignored\n");
+ fprintf(file, "s off\n");
+ for (uint32_t f = 0; f < mesh->faceGroupCount(); f++) {
+ if (mesh->faceGroupAt(f) == UINT32_MAX)
+ mesh->writeObjFace(file, f);
+ }
+ mesh->writeObjBoundaryEges(file);
+ fclose(file);
+ }
+#endif
+ {
+ XA_PROFILE_START(addMeshCreateChartGroupsReal)
+ args->ctx->paramAtlas.addMesh(args->ctx->taskScheduler, mesh); // addMesh is thread safe
+ XA_PROFILE_END(addMeshCreateChartGroupsReal)
+ }
+ if (progress->cancel)
+ goto cleanup;
+ progress->value++;
+ progress->update();
+cleanup:
+ mesh->~Mesh();
+ XA_FREE(mesh);
+ args->~AddMeshTaskArgs();
+ XA_FREE(args);
+ XA_PROFILE_END(addMeshThread)
}
-static internal::Vector3 DecodeNormal(const InputMesh &mesh, uint32_t index)
+static internal::Vector3 DecodePosition(const MeshDecl &meshDecl, uint32_t index)
{
- xaAssert(mesh.vertexNormalData);
- return *((const internal::Vector3 *)&((const uint8_t *)mesh.vertexNormalData)[mesh.vertexNormalStride * index]);
+ XA_DEBUG_ASSERT(meshDecl.vertexPositionData);
+ XA_DEBUG_ASSERT(meshDecl.vertexPositionStride > 0);
+ return *((const internal::Vector3 *)&((const uint8_t *)meshDecl.vertexPositionData)[meshDecl.vertexPositionStride * index]);
}
-static internal::Vector2 DecodeUv(const InputMesh &mesh, uint32_t index)
+static internal::Vector3 DecodeNormal(const MeshDecl &meshDecl, uint32_t index)
{
- xaAssert(mesh.vertexUvData);
- return *((const internal::Vector2 *)&((const uint8_t *)mesh.vertexUvData)[mesh.vertexUvStride * index]);
+ XA_DEBUG_ASSERT(meshDecl.vertexNormalData);
+ XA_DEBUG_ASSERT(meshDecl.vertexNormalStride > 0);
+ return *((const internal::Vector3 *)&((const uint8_t *)meshDecl.vertexNormalData)[meshDecl.vertexNormalStride * index]);
}
-static uint32_t DecodeIndex(IndexFormat::Enum format, const void *indexData, uint32_t i)
+static internal::Vector2 DecodeUv(const MeshDecl &meshDecl, uint32_t index)
{
- if (format == IndexFormat::HalfFloat)
- return (uint32_t)((const uint16_t *)indexData)[i];
- return ((const uint32_t *)indexData)[i];
+ XA_DEBUG_ASSERT(meshDecl.vertexUvData);
+ XA_DEBUG_ASSERT(meshDecl.vertexUvStride > 0);
+ return *((const internal::Vector2 *)&((const uint8_t *)meshDecl.vertexUvData)[meshDecl.vertexUvStride * index]);
}
-static float EdgeLength(internal::Vector3 pos1, internal::Vector3 pos2)
+static uint32_t DecodeIndex(IndexFormat::Enum format, const void *indexData, int32_t offset, uint32_t i)
{
- return internal::length(pos2 - pos1);
+ XA_DEBUG_ASSERT(indexData);
+ if (format == IndexFormat::UInt16)
+ return uint16_t((int32_t)((const uint16_t *)indexData)[i] + offset);
+ return uint32_t((int32_t)((const uint32_t *)indexData)[i] + offset);
}
-AddMeshError AddMesh(Atlas *atlas, const InputMesh &mesh, bool useColocalVertices)
+AddMeshError::Enum AddMesh(Atlas *atlas, const MeshDecl &meshDecl, uint32_t meshCountHint)
{
- xaAssert(atlas);
- AddMeshError error;
- error.code = AddMeshErrorCode::Success;
- error.face = error.index0 = error.index1 = UINT32_MAX;
- // Expecting triangle faces.
- if ((mesh.indexCount % 3) != 0)
- {
- error.code = AddMeshErrorCode::InvalidIndexCount;
- return error;
- }
- // Check if any index is out of range.
- for (uint32_t j = 0; j < mesh.indexCount; j++) {
- const uint32_t index = DecodeIndex(mesh.indexFormat, mesh.indexData, j);
- if (index < 0 || index >= mesh.vertexCount) {
- error.code = AddMeshErrorCode::IndexOutOfRange;
- error.index0 = index;
- return error;
- }
- }
- // Build half edge mesh.
- internal::halfedge::Mesh *heMesh = new internal::halfedge::Mesh;
- std::vector<uint32_t> canonicalMap;
- canonicalMap.reserve(mesh.vertexCount);
- for (uint32_t i = 0; i < mesh.vertexCount; i++) {
- internal::halfedge::Vertex *vertex = heMesh->addVertex(DecodePosition(mesh, i));
- if (mesh.vertexNormalData)
- vertex->nor = DecodeNormal(mesh, i);
- if (mesh.vertexUvData)
- vertex->tex = DecodeUv(mesh, i);
- // Link colocals. You probably want to do this more efficiently! Sort by one axis or use a hash or grid.
- uint32_t firstColocal = i;
- if (useColocalVertices) {
- for (uint32_t j = 0; j < i; j++) {
- if (vertex->pos != DecodePosition(mesh, j))
- continue;
-#if 0
- if (mesh.vertexNormalData && vertex->nor != DecodeNormal(mesh, j))
- continue;
+ XA_DEBUG_ASSERT(atlas);
+ if (!atlas) {
+ XA_PRINT_WARNING("AddMesh: atlas is null.\n");
+ return AddMeshError::Error;
+ }
+ Context *ctx = (Context *)atlas;
+ if (!ctx->uvMeshes.isEmpty()) {
+ XA_PRINT_WARNING("AddMesh: Meshes and UV meshes cannot be added to the same atlas.\n");
+ return AddMeshError::Error;
+ }
+#if XA_PROFILE
+ if (ctx->meshCount == 0)
+ internal::s_profile.addMeshReal = clock();
#endif
- if (mesh.vertexUvData && vertex->tex != DecodeUv(mesh, j))
- continue;
- firstColocal = j;
- break;
- }
- }
- canonicalMap.push_back(firstColocal);
+ // Don't know how many times AddMesh will be called, so progress needs to adjusted each time.
+ if (!ctx->addMeshProgress) {
+ ctx->addMeshProgress = XA_NEW(internal::MemTag::Default, internal::Progress, ProgressCategory::AddMesh, ctx->progressFunc, ctx->progressUserData, 1);
+ }
+ else {
+ ctx->addMeshProgress->setMaxValue(internal::max(ctx->meshCount + 1, meshCountHint));
}
- heMesh->linkColocalsWithCanonicalMap(canonicalMap);
- for (uint32_t i = 0; i < mesh.indexCount / 3; i++) {
+ bool decoded = (meshDecl.indexCount <= 0);
+ uint32_t indexCount = decoded ? meshDecl.vertexCount : meshDecl.indexCount;
+ XA_PRINT("Adding mesh %d: %u vertices, %u triangles\n", ctx->meshCount, meshDecl.vertexCount, indexCount / 3);
+ // Expecting triangle faces.
+ if ((indexCount % 3) != 0)
+ return AddMeshError::InvalidIndexCount;
+ if (!decoded) {
+ // Check if any index is out of range.
+ for (uint32_t i = 0; i < indexCount; i++) {
+ const uint32_t index = DecodeIndex(meshDecl.indexFormat, meshDecl.indexData, meshDecl.indexOffset, i);
+ if (index >= meshDecl.vertexCount)
+ return AddMeshError::IndexOutOfRange;
+ }
+ }
+ uint32_t meshFlags = internal::MeshFlags::HasFaceGroups | internal::MeshFlags::HasIgnoredFaces;
+ if (meshDecl.vertexNormalData)
+ meshFlags |= internal::MeshFlags::HasNormals;
+ internal::Mesh *mesh = XA_NEW(internal::MemTag::Mesh, internal::Mesh, meshDecl.epsilon, meshDecl.vertexCount, indexCount / 3, meshFlags, ctx->meshCount);
+ for (uint32_t i = 0; i < meshDecl.vertexCount; i++) {
+ internal::Vector3 normal(0.0f);
+ internal::Vector2 texcoord(0.0f);
+ if (meshDecl.vertexNormalData)
+ normal = DecodeNormal(meshDecl, i);
+ if (meshDecl.vertexUvData)
+ texcoord = DecodeUv(meshDecl, i);
+ mesh->addVertex(DecodePosition(meshDecl, i), normal, texcoord);
+ }
+ for (uint32_t i = 0; i < indexCount / 3; i++) {
uint32_t tri[3];
for (int j = 0; j < 3; j++)
- tri[j] = DecodeIndex(mesh.indexFormat, mesh.indexData, i * 3 + j);
- // Check for zero length edges.
+ tri[j] = decoded ? i * 3 + j : DecodeIndex(meshDecl.indexFormat, meshDecl.indexData, meshDecl.indexOffset, i * 3 + j);
+ bool ignore = false;
+ // Check for degenerate or zero length edges.
for (int j = 0; j < 3; j++) {
- const uint32_t edges[6] = { 0, 1, 1, 2, 2, 0 };
- const uint32_t index1 = tri[edges[j * 2 + 0]];
- const uint32_t index2 = tri[edges[j * 2 + 1]];
- const internal::Vector3 pos1 = DecodePosition(mesh, index1);
- const internal::Vector3 pos2 = DecodePosition(mesh, index2);
- if (EdgeLength(pos1, pos2) <= 0.0f) {
- delete heMesh;
- error.code = AddMeshErrorCode::ZeroLengthEdge;
- error.face = i;
- error.index0 = index1;
- error.index1 = index2;
- return error;
- }
- }
- // Check for zero area faces.
- {
- const internal::Vector3 a = DecodePosition(mesh, tri[0]);
- const internal::Vector3 b = DecodePosition(mesh, tri[1]);
- const internal::Vector3 c = DecodePosition(mesh, tri[2]);
- const float area = internal::length(internal::cross(b - a, c - a)) * 0.5f;
- if (area <= 0.0f) {
- delete heMesh;
- error.code = AddMeshErrorCode::ZeroAreaFace;
- error.face = i;
- return error;
- }
- }
- internal::halfedge::Face *face = heMesh->addFace(tri[0], tri[1], tri[2]);
-
- // -- GODOT start --
- if (!face && heMesh->errorCode == internal::halfedge::Mesh::ErrorCode::AlreadyAddedEdge) {
- //there is still hope for this, no reason to not add, at least add as separate
- face = heMesh->addUniqueFace(tri[0], tri[1], tri[2]);
- }
- // -- GODOT end --
-
- if (!face) {
- if (heMesh->errorCode == internal::halfedge::Mesh::ErrorCode::AlreadyAddedEdge)
- error.code = AddMeshErrorCode::AlreadyAddedEdge;
- else if (heMesh->errorCode == internal::halfedge::Mesh::ErrorCode::DegenerateColocalEdge)
- error.code = AddMeshErrorCode::DegenerateColocalEdge;
- else if (heMesh->errorCode == internal::halfedge::Mesh::ErrorCode::DegenerateEdge)
- error.code = AddMeshErrorCode::DegenerateEdge;
- else if (heMesh->errorCode == internal::halfedge::Mesh::ErrorCode::DuplicateEdge)
- error.code = AddMeshErrorCode::DuplicateEdge;
- error.face = i;
- error.index0 = heMesh->errorIndex0;
- error.index1 = heMesh->errorIndex1;
- delete heMesh;
- return error;
- }
- if (mesh.faceMaterialData)
- face->material = mesh.faceMaterialData[i];
- }
- heMesh->linkBoundary();
- atlas->heMeshes.push_back(heMesh);
- return error;
+ const uint32_t index1 = tri[j];
+ const uint32_t index2 = tri[(j + 1) % 3];
+ if (index1 == index2) {
+ ignore = true;
+ XA_PRINT(" Degenerate edge: index %d, index %d\n", index1, index2);
+ break;
+ }
+ const internal::Vector3 &pos1 = mesh->position(index1);
+ const internal::Vector3 &pos2 = mesh->position(index2);
+ if (internal::length(pos2 - pos1) <= 0.0f) {
+ ignore = true;
+ XA_PRINT(" Zero length edge: index %d position (%g %g %g), index %d position (%g %g %g)\n", index1, pos1.x, pos1.y, pos1.z, index2, pos2.x, pos2.y, pos2.z);
+ break;
+ }
+ }
+ const internal::Vector3 &a = mesh->position(tri[0]);
+ const internal::Vector3 &b = mesh->position(tri[1]);
+ const internal::Vector3 &c = mesh->position(tri[2]);
+ // Check for zero area faces. Don't bother if a degenerate or zero length edge was already detected.
+ float area = 0.0f;
+ if (!ignore) {
+ area = internal::length(internal::cross(b - a, c - a)) * 0.5f;
+ if (area <= internal::kAreaEpsilon) {
+ ignore = true;
+ XA_PRINT(" Zero area face: %d, indices (%d %d %d), area is %f\n", i, tri[0], tri[1], tri[2], area);
+ }
+ }
+ if (!ignore) {
+ if (internal::equal(a, b, meshDecl.epsilon) || internal::equal(a, c, meshDecl.epsilon) || internal::equal(b, c, meshDecl.epsilon)) {
+ ignore = true;
+ XA_PRINT(" Degenerate face: %d, area is %f\n", i, area);
+ }
+ }
+ if (meshDecl.faceIgnoreData && meshDecl.faceIgnoreData[i])
+ ignore = true;
+ mesh->addFace(tri[0], tri[1], tri[2], ignore);
+ }
+ if (ctx->addMeshTaskGroup.value == UINT32_MAX)
+ ctx->addMeshTaskGroup = ctx->taskScheduler->createTaskGroup();
+ AddMeshTaskArgs *taskArgs = XA_NEW(internal::MemTag::Default, AddMeshTaskArgs); // The task frees this.
+ taskArgs->ctx = ctx;
+ taskArgs->mesh = mesh;
+ internal::Task task;
+ task.userData = taskArgs;
+ task.func = runAddMeshTask;
+ ctx->taskScheduler->run(ctx->addMeshTaskGroup, task);
+ ctx->meshCount++;
+ return AddMeshError::Success;
}
-void Generate(Atlas *atlas, CharterOptions charterOptions, PackerOptions packerOptions)
-{
- xaAssert(atlas);
- xaAssert(packerOptions.texelArea > 0);
- // Chart meshes.
- for (int i = 0; i < (int)atlas->heMeshes.size(); i++) {
- std::vector<uint32_t> uncharted_materials;
- atlas->atlas.computeCharts(atlas->heMeshes[i], charterOptions, uncharted_materials);
- }
- atlas->atlas.parameterizeCharts();
- internal::param::AtlasPacker packer(&atlas->atlas);
- packer.packCharts(packerOptions);
- //float utilization = return packer.computeAtlasUtilization();
- atlas->width = packer.getWidth();
- atlas->height = packer.getHeight();
- // Build output meshes.
- atlas->outputMeshes = new OutputMesh*[atlas->heMeshes.size()];
- for (int i = 0; i < (int)atlas->heMeshes.size(); i++) {
- const internal::halfedge::Mesh *heMesh = atlas->heMeshes[i];
- OutputMesh *outputMesh = atlas->outputMeshes[i] = new OutputMesh;
- const internal::param::MeshCharts *charts = atlas->atlas.meshAt(i);
- // Vertices.
- outputMesh->vertexCount = charts->vertexCount();
- outputMesh->vertexArray = new OutputVertex[outputMesh->vertexCount];
- for (uint32_t i = 0; i < charts->chartCount(); i++) {
- const internal::param::Chart *chart = charts->chartAt(i);
- const uint32_t vertexOffset = charts->vertexCountBeforeChartAt(i);
- for (uint32_t v = 0; v < chart->vertexCount(); v++) {
- OutputVertex &output_vertex = outputMesh->vertexArray[vertexOffset + v];
- output_vertex.xref = chart->mapChartVertexToOriginalVertex(v);
- internal::Vector2 uv = chart->chartMesh()->vertexAt(v)->tex;
- output_vertex.uv[0] = uv.x;
- output_vertex.uv[1] = uv.y;
- }
- }
- // Indices.
- outputMesh->indexCount = heMesh->faceCount() * 3;
- outputMesh->indexArray = new uint32_t[outputMesh->indexCount];
- for (uint32_t f = 0; f < heMesh->faceCount(); f++) {
- const uint32_t c = charts->faceChartAt(f);
- const uint32_t i = charts->faceIndexWithinChartAt(f);
- const uint32_t vertexOffset = charts->vertexCountBeforeChartAt(c);
- const internal::param::Chart *chart = charts->chartAt(c);
- xaDebugAssert(i < chart->chartMesh()->faceCount());
- xaDebugAssert(chart->faceAt(i) == f);
- const internal::halfedge::Face *face = chart->chartMesh()->faceAt(i);
- const internal::halfedge::Edge *edge = face->edge;
- outputMesh->indexArray[3 * f + 0] = vertexOffset + edge->vertex->id;
- outputMesh->indexArray[3 * f + 1] = vertexOffset + edge->next->vertex->id;
- outputMesh->indexArray[3 * f + 2] = vertexOffset + edge->next->next->vertex->id;
- }
- // Charts.
- outputMesh->chartCount = charts->chartCount();
- outputMesh->chartArray = new OutputChart[outputMesh->chartCount];
- for (uint32_t i = 0; i < charts->chartCount(); i++) {
- OutputChart *outputChart = &outputMesh->chartArray[i];
- const internal::param::Chart *chart = charts->chartAt(i);
- const uint32_t vertexOffset = charts->vertexCountBeforeChartAt(i);
- const internal::halfedge::Mesh *mesh = chart->chartMesh();
- outputChart->indexCount = mesh->faceCount() * 3;
- outputChart->indexArray = new uint32_t[outputChart->indexCount];
- for (uint32_t j = 0; j < mesh->faceCount(); j++) {
- const internal::halfedge::Face *face = mesh->faceAt(j);
- const internal::halfedge::Edge *edge = face->edge;
- outputChart->indexArray[3 * j + 0] = vertexOffset + edge->vertex->id;
- outputChart->indexArray[3 * j + 1] = vertexOffset + edge->next->vertex->id;
- outputChart->indexArray[3 * j + 2] = vertexOffset + edge->next->next->vertex->id;
+void AddMeshJoin(Atlas *atlas)
+{
+ XA_DEBUG_ASSERT(atlas);
+ if (!atlas) {
+ XA_PRINT_WARNING("AddMeshJoin: atlas is null.\n");
+ return;
+ }
+ Context *ctx = (Context *)atlas;
+ if (!ctx->addMeshProgress)
+ return;
+ ctx->taskScheduler->wait(&ctx->addMeshTaskGroup);
+ ctx->addMeshProgress->~Progress();
+ XA_FREE(ctx->addMeshProgress);
+ ctx->addMeshProgress = nullptr;
+#if XA_PROFILE
+ XA_PRINT("Added %u meshes\n", ctx->meshCount);
+ internal::s_profile.addMeshReal = clock() - internal::s_profile.addMeshReal;
+#endif
+ XA_PROFILE_PRINT_AND_RESET(" Total (real): ", addMeshReal)
+ XA_PROFILE_PRINT_AND_RESET(" Total (thread): ", addMeshThread)
+ XA_PROFILE_PRINT_AND_RESET(" Create colocals: ", addMeshCreateColocals)
+ XA_PROFILE_PRINT_AND_RESET(" Create face groups: ", addMeshCreateFaceGroups)
+ XA_PROFILE_PRINT_AND_RESET(" Create boundaries: ", addMeshCreateBoundaries)
+ XA_PROFILE_PRINT_AND_RESET(" Create chart groups (real): ", addMeshCreateChartGroupsReal)
+ XA_PROFILE_PRINT_AND_RESET(" Create chart groups (thread): ", addMeshCreateChartGroupsThread)
+ XA_PRINT_MEM_USAGE
+}
+
+struct EdgeKey
+{
+ EdgeKey() {}
+ EdgeKey(const EdgeKey &k) : v0(k.v0), v1(k.v1) {}
+ EdgeKey(uint32_t v0, uint32_t v1) : v0(v0), v1(v1) {}
+
+ void operator=(const EdgeKey &k)
+ {
+ v0 = k.v0;
+ v1 = k.v1;
+ }
+ bool operator==(const EdgeKey &k) const
+ {
+ return v0 == k.v0 && v1 == k.v1;
+ }
+
+ uint32_t v0;
+ uint32_t v1;
+};
+
+AddMeshError::Enum AddUvMesh(Atlas *atlas, const UvMeshDecl &decl)
+{
+ XA_DEBUG_ASSERT(atlas);
+ if (!atlas) {
+ XA_PRINT_WARNING("AddUvMesh: atlas is null.\n");
+ return AddMeshError::Error;
+ }
+ Context *ctx = (Context *)atlas;
+ if (ctx->meshCount > 0) {
+ XA_PRINT_WARNING("AddUvMesh: Meshes and UV meshes cannot be added to the same atlas.\n");
+ return AddMeshError::Error;
+ }
+ const bool decoded = (decl.indexCount <= 0);
+ const uint32_t indexCount = decoded ? decl.vertexCount : decl.indexCount;
+ XA_PRINT("Adding UV mesh %d: %u vertices, %u triangles\n", ctx->uvMeshes.size(), decl.vertexCount, indexCount / 3);
+ // Expecting triangle faces.
+ if ((indexCount % 3) != 0)
+ return AddMeshError::InvalidIndexCount;
+ if (!decoded) {
+ // Check if any index is out of range.
+ for (uint32_t i = 0; i < indexCount; i++) {
+ const uint32_t index = DecodeIndex(decl.indexFormat, decl.indexData, decl.indexOffset, i);
+ if (index >= decl.vertexCount)
+ return AddMeshError::IndexOutOfRange;
+ }
+ }
+ internal::UvMeshInstance *meshInstance = XA_NEW(internal::MemTag::Default, internal::UvMeshInstance);
+ meshInstance->texcoords.resize(decl.vertexCount);
+ for (uint32_t i = 0; i < decl.vertexCount; i++)
+ meshInstance->texcoords[i] = *((const internal::Vector2 *)&((const uint8_t *)decl.vertexUvData)[decl.vertexStride * i]);
+ meshInstance->rotateCharts = decl.rotateCharts;
+ // See if this is an instance of an already existing mesh.
+ internal::UvMesh *mesh = nullptr;
+ for (uint32_t m = 0; m < ctx->uvMeshes.size(); m++) {
+ if (memcmp(&ctx->uvMeshes[m]->decl, &decl, sizeof(UvMeshDecl)) == 0) {
+ meshInstance->mesh = mesh = ctx->uvMeshes[m];
+ break;
+ }
+ }
+ if (!mesh) {
+ // Copy geometry to mesh.
+ meshInstance->mesh = mesh = XA_NEW(internal::MemTag::Default, internal::UvMesh);
+ mesh->decl = decl;
+ mesh->indices.resize(decl.indexCount);
+ for (uint32_t i = 0; i < indexCount; i++)
+ mesh->indices[i] = decoded ? i : DecodeIndex(decl.indexFormat, decl.indexData, decl.indexOffset, i);
+ mesh->vertexToChartMap.resize(decl.vertexCount);
+ for (uint32_t i = 0; i < mesh->vertexToChartMap.size(); i++)
+ mesh->vertexToChartMap[i] = UINT32_MAX;
+ // Calculate charts (incident faces).
+ internal::HashMap<internal::Vector2, uint32_t> vertexToFaceMap(internal::MemTag::Default, indexCount);
+ const uint32_t faceCount = indexCount / 3;
+ for (uint32_t i = 0; i < indexCount; i++)
+ vertexToFaceMap.add(meshInstance->texcoords[mesh->indices[i]], i / 3);
+ internal::BitArray faceAssigned(faceCount);
+ faceAssigned.clearAll();
+ internal::Array<uint32_t> chartFaces;
+ for (uint32_t f = 0; f < faceCount; f++) {
+ if (faceAssigned.bitAt(f))
+ continue;
+ // Found an unassigned face, create a new chart.
+ internal::UvMeshChart *chart = XA_NEW(internal::MemTag::Default, internal::UvMeshChart);
+ chart->material = decl.faceMaterialData ? decl.faceMaterialData[f] : 0;
+ // Walk incident faces and assign them to the chart.
+ faceAssigned.setBitAt(f);
+ chartFaces.clear();
+ chartFaces.push_back(f);
+ for (;;) {
+ bool newFaceAssigned = false;
+ const uint32_t faceCount2 = chartFaces.size();
+ for (uint32_t f2 = 0; f2 < faceCount2; f2++) {
+ const uint32_t face = chartFaces[f2];
+ for (uint32_t i = 0; i < 3; i++) {
+ const internal::Vector2 &texcoord = meshInstance->texcoords[meshInstance->mesh->indices[face * 3 + i]];
+ uint32_t mapFaceIndex = vertexToFaceMap.get(texcoord);
+ while (mapFaceIndex != UINT32_MAX) {
+ const uint32_t face2 = vertexToFaceMap.value(mapFaceIndex);
+ // Materials must match.
+ if (!faceAssigned.bitAt(face2) && (!decl.faceMaterialData || decl.faceMaterialData[face] == decl.faceMaterialData[face2])) {
+ faceAssigned.setBitAt(face2);
+ chartFaces.push_back(face2);
+ newFaceAssigned = true;
+ }
+ mapFaceIndex = vertexToFaceMap.getNext(mapFaceIndex);
+ }
+ }
+ }
+ if (!newFaceAssigned)
+ break;
+ }
+ for (uint32_t i = 0; i < chartFaces.size(); i++) {
+ for (uint32_t j = 0; j < 3; j++) {
+ const uint32_t vertex = meshInstance->mesh->indices[chartFaces[i] * 3 + j];
+ chart->indices.push_back(vertex);
+ mesh->vertexToChartMap[vertex] = mesh->charts.size();
+ }
+ }
+ mesh->charts.push_back(chart);
+ }
+ ctx->uvMeshes.push_back(mesh);
+ } else {
+ XA_PRINT(" instance of a previous UV mesh\n");
+ }
+ XA_PRINT(" %u charts\n", meshInstance->mesh->charts.size());
+ ctx->uvMeshInstances.push_back(meshInstance);
+ return AddMeshError::Success;
+}
+
+void ComputeCharts(Atlas *atlas, ChartOptions chartOptions)
+{
+ if (!atlas) {
+ XA_PRINT_WARNING("ComputeCharts: atlas is null.\n");
+ return;
+ }
+ Context *ctx = (Context *)atlas;
+ if (!ctx->uvMeshInstances.isEmpty()) {
+ XA_PRINT_WARNING("ComputeCharts: This function should not be called with UV meshes.\n");
+ return;
+ }
+ AddMeshJoin(atlas);
+ if (ctx->meshCount == 0) {
+ XA_PRINT_WARNING("ComputeCharts: No meshes. Call AddMesh first.\n");
+ return;
+ }
+ XA_PRINT("Computing charts\n");
+ uint32_t chartCount = 0, chartsWithHolesCount = 0, holesCount = 0, chartsWithTJunctionsCount = 0, tJunctionsCount = 0;
+ XA_PROFILE_START(computeChartsReal)
+ if (!ctx->paramAtlas.computeCharts(ctx->taskScheduler, chartOptions, ctx->progressFunc, ctx->progressUserData)) {
+ XA_PRINT(" Cancelled by user\n");
+ return;
+ }
+ XA_PROFILE_END(computeChartsReal)
+ // Count charts and print warnings.
+ for (uint32_t i = 0; i < ctx->meshCount; i++) {
+ for (uint32_t j = 0; j < ctx->paramAtlas.chartGroupCount(i); j++) {
+ const internal::param::ChartGroup *chartGroup = ctx->paramAtlas.chartGroupAt(i, j);
+ if (chartGroup->isVertexMap())
+ continue;
+ for (uint32_t k = 0; k < chartGroup->chartCount(); k++) {
+ const internal::param::Chart *chart = chartGroup->chartAt(k);
+ if (chart->warningFlags() & internal::param::ChartWarningFlags::CloseHolesFailed)
+ XA_PRINT_WARNING(" Chart %u (mesh %u, group %u, id %u): failed to close holes\n", chartCount, i, j, k);
+ if (chart->warningFlags() & internal::param::ChartWarningFlags::FixTJunctionsDuplicatedEdge)
+ XA_PRINT_WARNING(" Chart %u (mesh %u, group %u, id %u): fixing t-junctions created non-manifold geometry\n", chartCount, i, j, k);
+ if (chart->warningFlags() & internal::param::ChartWarningFlags::FixTJunctionsFailed)
+ XA_PRINT_WARNING(" Chart %u (mesh %u, group %u, id %u): fixing t-junctions failed\n", chartCount, i, j, k);
+ if (chart->warningFlags() & internal::param::ChartWarningFlags::TriangulateDuplicatedEdge)
+ XA_PRINT_WARNING(" Chart %u (mesh %u, group %u, id %u): triangulation created non-manifold geometry\n", chartCount, i, j, k);
+ if (!chart->isDisk())
+ XA_PRINT_WARNING(" Chart %u (mesh %u, group %u, id %u): doesn't have disk topology\n", chartCount, i, j, k);
+ holesCount += chart->closedHolesCount();
+ if (chart->closedHolesCount() > 0)
+ chartsWithHolesCount++;
+ tJunctionsCount += chart->fixedTJunctionsCount();
+ if (chart->fixedTJunctionsCount() > 0)
+ chartsWithTJunctionsCount++;
+ chartCount++;
+ }
+ }
+ }
+ if (holesCount > 0)
+ XA_PRINT(" Closed %u holes in %u charts\n", holesCount, chartsWithHolesCount);
+ if (tJunctionsCount > 0)
+ XA_PRINT(" Fixed %u t-junctions in %u charts\n", tJunctionsCount, chartsWithTJunctionsCount);
+ XA_PRINT(" %u charts\n", chartCount);
+ XA_PROFILE_PRINT_AND_RESET(" Total (real): ", computeChartsReal)
+ XA_PROFILE_PRINT_AND_RESET(" Total (thread): ", computeChartsThread)
+ XA_PROFILE_PRINT_AND_RESET(" Atlas builder: ", atlasBuilder)
+ XA_PROFILE_PRINT_AND_RESET(" Init: ", atlasBuilderInit)
+ XA_PROFILE_PRINT_AND_RESET(" Create initial charts: ", atlasBuilderCreateInitialCharts)
+ XA_PROFILE_PRINT_AND_RESET(" Grow charts: ", atlasBuilderGrowCharts)
+ XA_PROFILE_PRINT_AND_RESET(" Merge charts: ", atlasBuilderMergeCharts)
+ XA_PROFILE_PRINT_AND_RESET(" Create chart meshes (real): ", createChartMeshesReal)
+ XA_PROFILE_PRINT_AND_RESET(" Create chart meshes (thread): ", createChartMeshesThread)
+ XA_PROFILE_PRINT_AND_RESET(" Fix t-junctions: ", fixChartMeshTJunctions)
+ XA_PROFILE_PRINT_AND_RESET(" Close holes: ", closeChartMeshHoles)
+ XA_PRINT_MEM_USAGE
+}
+
+void ParameterizeCharts(Atlas *atlas, ParameterizeFunc func)
+{
+ if (!atlas) {
+ XA_PRINT_WARNING("ParameterizeCharts: atlas is null.\n");
+ return;
+ }
+ Context *ctx = (Context *)atlas;
+ if (!ctx->uvMeshInstances.isEmpty()) {
+ XA_PRINT_WARNING("ParameterizeCharts: This function should not be called with UV meshes.\n");
+ return;
+ }
+ if (!ctx->paramAtlas.chartsComputed()) {
+ XA_PRINT_WARNING("ParameterizeCharts: ComputeCharts must be called first.\n");
+ return;
+ }
+ atlas->atlasCount = 0;
+ atlas->height = 0;
+ atlas->texelsPerUnit = 0;
+ atlas->width = 0;
+ if (atlas->utilization) {
+ XA_FREE(atlas->utilization);
+ atlas->utilization = nullptr;
+ }
+ if (atlas->image) {
+ XA_FREE(atlas->image);
+ atlas->image = nullptr;
+ }
+ DestroyOutputMeshes(ctx);
+ XA_PRINT("Parameterizing charts\n");
+ XA_PROFILE_START(parameterizeChartsReal)
+ if (!ctx->paramAtlas.parameterizeCharts(ctx->taskScheduler, func, ctx->progressFunc, ctx->progressUserData)) {
+ XA_PRINT(" Cancelled by user\n");
+ return;
+ }
+ XA_PROFILE_END(parameterizeChartsReal)
+ uint32_t chartCount = 0, orthoChartsCount = 0, planarChartsCount = 0, chartsAddedCount = 0, chartsDeletedCount = 0;
+ for (uint32_t i = 0; i < ctx->meshCount; i++) {
+ for (uint32_t j = 0; j < ctx->paramAtlas.chartGroupCount(i); j++) {
+ const internal::param::ChartGroup *chartGroup = ctx->paramAtlas.chartGroupAt(i, j);
+ if (chartGroup->isVertexMap())
+ continue;
+ for (uint32_t k = 0; k < chartGroup->chartCount(); k++) {
+ const internal::param::Chart *chart = chartGroup->chartAt(k);
+ if (chart->isPlanar())
+ planarChartsCount++;
+ else if (chart->isOrtho())
+ orthoChartsCount++;
+ }
+ chartCount += chartGroup->chartCount();
+ chartsAddedCount += chartGroup->paramAddedChartsCount();
+ chartsDeletedCount += chartGroup->paramDeletedChartsCount();
+ }
+ }
+ XA_PRINT(" %u planar charts, %u ortho charts, %u other\n", planarChartsCount, orthoChartsCount, chartCount - (planarChartsCount + orthoChartsCount));
+ if (chartsDeletedCount > 0) {
+ XA_PRINT(" %u charts deleted due to invalid parameterizations, %u new charts added\n", chartsDeletedCount, chartsAddedCount);
+ XA_PRINT(" %u charts\n", ctx->paramAtlas.chartCount());
+ }
+ uint32_t chartIndex = 0, invalidParamCount = 0;
+ for (uint32_t i = 0; i < ctx->meshCount; i++) {
+ for (uint32_t j = 0; j < ctx->paramAtlas.chartGroupCount(i); j++) {
+ const internal::param::ChartGroup *chartGroup = ctx->paramAtlas.chartGroupAt(i, j);
+ if (chartGroup->isVertexMap())
+ continue;
+ for (uint32_t k = 0; k < chartGroup->chartCount(); k++) {
+ const internal::param::Chart *chart = chartGroup->chartAt(k);
+ const internal::param::ParameterizationQuality &quality = chart->paramQuality();
+#if XA_DEBUG_EXPORT_OBJ_CHARTS_AFTER_PARAMETERIZATION
+ {
+ char filename[256];
+ XA_SPRINTF(filename, sizeof(filename), "debug_chart_%03u_after_parameterization.obj", chartIndex);
+ chart->unifiedMesh()->writeObjFile(filename);
+ }
+#endif
+ bool invalid = false;
+ if (quality.boundaryIntersection) {
+ invalid = true;
+ XA_PRINT_WARNING(" Chart %u (mesh %u, group %u, id %u) (%s): invalid parameterization, self-intersecting boundary.\n", chartIndex, i, j, k, chart->isPlanar() ? "planar" : chart->isOrtho() ? "ortho" : "other");
+ }
+ if (quality.flippedTriangleCount > 0) {
+ invalid = true;
+ XA_PRINT_WARNING(" Chart %u (mesh %u, group %u, id %u) (%s): invalid parameterization, %u / %u flipped triangles.\n", chartIndex, i, j, k, chart->isPlanar() ? "planar" : chart->isOrtho() ? "ortho" : "other", quality.flippedTriangleCount, quality.totalTriangleCount);
+ }
+ if (invalid)
+ invalidParamCount++;
+#if XA_DEBUG_EXPORT_OBJ_INVALID_PARAMETERIZATION
+ if (invalid) {
+ char filename[256];
+ XA_SPRINTF(filename, sizeof(filename), "debug_chart_%03u_invalid_parameterization.obj", chartIndex);
+ const internal::Mesh *mesh = chart->unifiedMesh();
+ FILE *file;
+ XA_FOPEN(file, filename, "w");
+ if (file) {
+ mesh->writeObjVertices(file);
+ fprintf(file, "s off\n");
+ fprintf(file, "o object\n");
+ for (uint32_t f = 0; f < mesh->faceCount(); f++)
+ mesh->writeObjFace(file, f);
+ if (!chart->paramFlippedFaces().isEmpty()) {
+ fprintf(file, "o flipped_faces\n");
+ for (uint32_t f = 0; f < chart->paramFlippedFaces().size(); f++)
+ mesh->writeObjFace(file, chart->paramFlippedFaces()[f]);
+ }
+ mesh->writeObjBoundaryEges(file);
+ mesh->writeObjLinkedBoundaries(file);
+ fclose(file);
+ }
+ }
+#endif
+ chartIndex++;
}
}
}
+ if (invalidParamCount > 0)
+ XA_PRINT_WARNING(" %u charts with invalid parameterizations\n", invalidParamCount);
+ XA_PROFILE_PRINT_AND_RESET(" Total (real): ", parameterizeChartsReal)
+ XA_PROFILE_PRINT_AND_RESET(" Total (thread): ", parameterizeChartsThread)
+ XA_PROFILE_PRINT_AND_RESET(" Orthogonal: ", parameterizeChartsOrthogonal)
+ XA_PROFILE_PRINT_AND_RESET(" LSCM: ", parameterizeChartsLSCM)
+ XA_PROFILE_PRINT_AND_RESET(" Evaluate quality: ", parameterizeChartsEvaluateQuality)
+ XA_PRINT_MEM_USAGE
}
-uint32_t GetWidth(const Atlas *atlas)
+void PackCharts(Atlas *atlas, PackOptions packOptions)
{
- xaAssert(atlas);
- return atlas->width;
+ // Validate arguments and context state.
+ if (!atlas) {
+ XA_PRINT_WARNING("PackCharts: atlas is null.\n");
+ return;
+ }
+ Context *ctx = (Context *)atlas;
+ if (ctx->meshCount == 0 && ctx->uvMeshInstances.isEmpty()) {
+ XA_PRINT_WARNING("PackCharts: No meshes. Call AddMesh or AddUvMesh first.\n");
+ return;
+ }
+ if (ctx->uvMeshInstances.isEmpty()) {
+ if (!ctx->paramAtlas.chartsComputed()) {
+ XA_PRINT_WARNING("PackCharts: ComputeCharts must be called first.\n");
+ return;
+ }
+ if (!ctx->paramAtlas.chartsParameterized()) {
+ XA_PRINT_WARNING("PackCharts: ParameterizeCharts must be called first.\n");
+ return;
+ }
+ }
+ if (packOptions.texelsPerUnit < 0.0f) {
+ XA_PRINT_WARNING("PackCharts: PackOptions::texelsPerUnit is negative.\n");
+ packOptions.texelsPerUnit = 0.0f;
+ }
+ // Cleanup atlas.
+ DestroyOutputMeshes(ctx);
+ if (atlas->utilization) {
+ XA_FREE(atlas->utilization);
+ atlas->utilization = nullptr;
+ }
+ if (atlas->image) {
+ XA_FREE(atlas->image);
+ atlas->image = nullptr;
+ }
+ atlas->meshCount = 0;
+ // Pack charts.
+ internal::pack::Atlas packAtlas;
+ if (!ctx->uvMeshInstances.isEmpty()) {
+ for (uint32_t i = 0; i < ctx->uvMeshInstances.size(); i++)
+ packAtlas.addUvMeshCharts(ctx->uvMeshInstances[i]);
+ }
+ else if (ctx->paramAtlas.chartCount() > 0) {
+ ctx->paramAtlas.restoreOriginalChartTexcoords();
+ for (uint32_t i = 0; i < ctx->paramAtlas.chartCount(); i++)
+ packAtlas.addChart(ctx->paramAtlas.chartAt(i));
+ }
+ XA_PROFILE_START(packCharts)
+ if (!packAtlas.packCharts(ctx->taskScheduler, packOptions, ctx->progressFunc, ctx->progressUserData))
+ return;
+ XA_PROFILE_END(packCharts)
+ // Populate atlas object with pack results.
+ atlas->atlasCount = packAtlas.getNumAtlases();
+ atlas->chartCount = packAtlas.getChartCount();
+ atlas->width = packAtlas.getWidth();
+ atlas->height = packAtlas.getHeight();
+ atlas->texelsPerUnit = packAtlas.getTexelsPerUnit();
+ if (atlas->atlasCount > 0) {
+ atlas->utilization = XA_ALLOC_ARRAY(internal::MemTag::Default, float, atlas->atlasCount);
+ for (uint32_t i = 0; i < atlas->atlasCount; i++)
+ atlas->utilization[i] = packAtlas.getUtilization(i);
+ }
+ if (packOptions.createImage) {
+ atlas->image = XA_ALLOC_ARRAY(internal::MemTag::Default, uint32_t, atlas->atlasCount * atlas->width * atlas->height);
+ for (uint32_t i = 0; i < atlas->atlasCount; i++)
+ packAtlas.getImages()[i]->copyTo(&atlas->image[atlas->width * atlas->height * i], atlas->width, atlas->height);
+ }
+ XA_PROFILE_PRINT_AND_RESET(" Total: ", packCharts)
+ XA_PROFILE_PRINT_AND_RESET(" Rasterize: ", packChartsRasterize)
+ XA_PROFILE_PRINT_AND_RESET(" Dilate (padding): ", packChartsDilate)
+ XA_PROFILE_PRINT_AND_RESET(" Find location (real): ", packChartsFindLocation)
+ XA_PROFILE_PRINT_AND_RESET(" Find location (thread): ", packChartsFindLocationThread)
+ XA_PROFILE_PRINT_AND_RESET(" Blit: ", packChartsBlit)
+ XA_PRINT_MEM_USAGE
+ XA_PRINT("Building output meshes\n");
+ int progress = 0;
+ if (ctx->progressFunc) {
+ if (!ctx->progressFunc(ProgressCategory::BuildOutputMeshes, 0, ctx->progressUserData))
+ return;
+ }
+ if (ctx->uvMeshInstances.isEmpty())
+ atlas->meshCount = ctx->meshCount;
+ else
+ atlas->meshCount = ctx->uvMeshInstances.size();
+ atlas->meshes = XA_ALLOC_ARRAY(internal::MemTag::Default, Mesh, atlas->meshCount);
+ memset(atlas->meshes, 0, sizeof(Mesh) * atlas->meshCount);
+ if (ctx->uvMeshInstances.isEmpty()) {
+ uint32_t chartIndex = 0;
+ for (uint32_t i = 0; i < ctx->meshCount; i++) {
+ Mesh &outputMesh = atlas->meshes[i];
+ // Count and alloc arrays. Ignore vertex mapped chart groups in Mesh::chartCount, since they're ignored faces.
+ for (uint32_t cg = 0; cg < ctx->paramAtlas.chartGroupCount(i); cg++) {
+ const internal::param::ChartGroup *chartGroup = ctx->paramAtlas.chartGroupAt(i, cg);
+ if (chartGroup->isVertexMap()) {
+ outputMesh.vertexCount += chartGroup->mesh()->vertexCount();
+ outputMesh.indexCount += chartGroup->mesh()->faceCount() * 3;
+ } else {
+ for (uint32_t c = 0; c < chartGroup->chartCount(); c++) {
+ const internal::param::Chart *chart = chartGroup->chartAt(c);
+ outputMesh.vertexCount += chart->mesh()->vertexCount();
+ outputMesh.indexCount += chart->mesh()->faceCount() * 3;
+ outputMesh.chartCount++;
+ }
+ }
+ }
+ outputMesh.vertexArray = XA_ALLOC_ARRAY(internal::MemTag::Default, Vertex, outputMesh.vertexCount);
+ outputMesh.indexArray = XA_ALLOC_ARRAY(internal::MemTag::Default, uint32_t, outputMesh.indexCount);
+ outputMesh.chartArray = XA_ALLOC_ARRAY(internal::MemTag::Default, Chart, outputMesh.chartCount);
+ XA_PRINT(" mesh %u: %u vertices, %u triangles, %u charts\n", i, outputMesh.vertexCount, outputMesh.indexCount / 3, outputMesh.chartCount);
+ // Copy mesh data.
+ uint32_t firstVertex = 0;
+ uint32_t meshChartIndex = 0;
+ for (uint32_t cg = 0; cg < ctx->paramAtlas.chartGroupCount(i); cg++) {
+ const internal::param::ChartGroup *chartGroup = ctx->paramAtlas.chartGroupAt(i, cg);
+ if (chartGroup->isVertexMap()) {
+ const internal::Mesh *mesh = chartGroup->mesh();
+ // Vertices.
+ for (uint32_t v = 0; v < mesh->vertexCount(); v++) {
+ Vertex &vertex = outputMesh.vertexArray[firstVertex + v];
+ vertex.atlasIndex = -1;
+ vertex.chartIndex = -1;
+ vertex.uv[0] = vertex.uv[1] = 0.0f;
+ vertex.xref = chartGroup->mapVertexToSourceVertex(v);
+ }
+ // Indices.
+ for (uint32_t f = 0; f < mesh->faceCount(); f++) {
+ const uint32_t indexOffset = chartGroup->mapFaceToSourceFace(f) * 3;
+ for (uint32_t j = 0; j < 3; j++)
+ outputMesh.indexArray[indexOffset + j] = firstVertex + mesh->vertexAt(f * 3 + j);
+ }
+ firstVertex += mesh->vertexCount();
+ } else {
+ for (uint32_t c = 0; c < chartGroup->chartCount(); c++) {
+ const internal::param::Chart *chart = chartGroup->chartAt(c);
+ const internal::Mesh *mesh = chart->mesh();
+ // Vertices.
+ for (uint32_t v = 0; v < mesh->vertexCount(); v++) {
+ Vertex &vertex = outputMesh.vertexArray[firstVertex + v];
+ vertex.atlasIndex = packAtlas.getChart(chartIndex)->atlasIndex;
+ XA_DEBUG_ASSERT(vertex.atlasIndex >= 0);
+ vertex.chartIndex = (int32_t)chartIndex;
+ const internal::Vector2 &uv = mesh->texcoord(v);
+ vertex.uv[0] = internal::max(0.0f, uv.x);
+ vertex.uv[1] = internal::max(0.0f, uv.y);
+ vertex.xref = chartGroup->mapVertexToSourceVertex(chart->mapChartVertexToOriginalVertex(v));
+ }
+ // Indices.
+ for (uint32_t f = 0; f < mesh->faceCount(); f++) {
+ const uint32_t indexOffset = chartGroup->mapFaceToSourceFace(chart->mapFaceToSourceFace(f)) * 3;
+ for (uint32_t j = 0; j < 3; j++)
+ outputMesh.indexArray[indexOffset + j] = firstVertex + mesh->vertexAt(f * 3 + j);
+ }
+ // Charts.
+ Chart *outputChart = &outputMesh.chartArray[meshChartIndex];
+ const int32_t atlasIndex = packAtlas.getChart(chartIndex)->atlasIndex;
+ XA_DEBUG_ASSERT(atlasIndex >= 0);
+ outputChart->atlasIndex = (uint32_t)atlasIndex;
+ outputChart->flags = 0;
+ if (chart->paramQuality().boundaryIntersection || chart->paramQuality().flippedTriangleCount > 0)
+ outputChart->flags |= ChartFlags::Invalid;
+ outputChart->indexCount = mesh->faceCount() * 3;
+ outputChart->indexArray = XA_ALLOC_ARRAY(internal::MemTag::Default, uint32_t, outputChart->indexCount);
+ for (uint32_t f = 0; f < mesh->faceCount(); f++) {
+ for (uint32_t j = 0; j < 3; j++)
+ outputChart->indexArray[3 * f + j] = firstVertex + mesh->vertexAt(f * 3 + j);
+ }
+ outputChart->material = 0;
+ meshChartIndex++;
+ chartIndex++;
+ firstVertex += chart->mesh()->vertexCount();
+ }
+ }
+ }
+ XA_DEBUG_ASSERT(outputMesh.vertexCount == firstVertex);
+ XA_DEBUG_ASSERT(outputMesh.chartCount == meshChartIndex);
+ if (ctx->progressFunc) {
+ const int newProgress = int((i + 1) / (float)atlas->meshCount * 100.0f);
+ if (newProgress != progress) {
+ progress = newProgress;
+ if (!ctx->progressFunc(ProgressCategory::BuildOutputMeshes, progress, ctx->progressUserData))
+ return;
+ }
+ }
+ }
+ } else {
+ uint32_t chartIndex = 0;
+ for (uint32_t m = 0; m < ctx->uvMeshInstances.size(); m++) {
+ Mesh &outputMesh = atlas->meshes[m];
+ const internal::UvMeshInstance *mesh = ctx->uvMeshInstances[m];
+ // Alloc arrays.
+ outputMesh.vertexCount = mesh->texcoords.size();
+ outputMesh.indexCount = mesh->mesh->indices.size();
+ outputMesh.chartCount = mesh->mesh->charts.size();
+ outputMesh.vertexArray = XA_ALLOC_ARRAY(internal::MemTag::Default, Vertex, outputMesh.vertexCount);
+ outputMesh.indexArray = XA_ALLOC_ARRAY(internal::MemTag::Default, uint32_t, outputMesh.indexCount);
+ outputMesh.chartArray = XA_ALLOC_ARRAY(internal::MemTag::Default, Chart, outputMesh.chartCount);
+ XA_PRINT(" UV mesh %u: %u vertices, %u triangles, %u charts\n", m, outputMesh.vertexCount, outputMesh.indexCount / 3, outputMesh.chartCount);
+ // Copy mesh data.
+ // Vertices.
+ for (uint32_t v = 0; v < mesh->texcoords.size(); v++) {
+ Vertex &vertex = outputMesh.vertexArray[v];
+ vertex.uv[0] = mesh->texcoords[v].x;
+ vertex.uv[1] = mesh->texcoords[v].y;
+ vertex.xref = v;
+ const uint32_t meshChartIndex = mesh->mesh->vertexToChartMap[v];
+ if (meshChartIndex == UINT32_MAX) {
+ // Vertex doesn't exist in any chart.
+ vertex.atlasIndex = -1;
+ vertex.chartIndex = -1;
+ } else {
+ const internal::pack::Chart *chart = packAtlas.getChart(chartIndex + meshChartIndex);
+ vertex.atlasIndex = chart->atlasIndex;
+ vertex.chartIndex = (int32_t)chartIndex + meshChartIndex;
+ }
+ }
+ // Indices.
+ memcpy(outputMesh.indexArray, mesh->mesh->indices.data(), mesh->mesh->indices.size() * sizeof(uint32_t));
+ // Charts.
+ for (uint32_t c = 0; c < mesh->mesh->charts.size(); c++) {
+ Chart *outputChart = &outputMesh.chartArray[c];
+ const internal::pack::Chart *chart = packAtlas.getChart(chartIndex);
+ XA_DEBUG_ASSERT(chart->atlasIndex >= 0);
+ outputChart->atlasIndex = (uint32_t)chart->atlasIndex;
+ outputChart->indexCount = chart->indexCount;
+ outputChart->indexArray = XA_ALLOC_ARRAY(internal::MemTag::Default, uint32_t, outputChart->indexCount);
+ outputChart->material = chart->material;
+ memcpy(outputChart->indexArray, chart->indices, chart->indexCount * sizeof(uint32_t));
+ chartIndex++;
+ }
+ if (ctx->progressFunc) {
+ const int newProgress = int((m + 1) / (float)atlas->meshCount * 100.0f);
+ if (newProgress != progress) {
+ progress = newProgress;
+ if (!ctx->progressFunc(ProgressCategory::BuildOutputMeshes, progress, ctx->progressUserData))
+ return;
+ }
+ }
+ }
+ }
+ if (ctx->progressFunc && progress != 100)
+ ctx->progressFunc(ProgressCategory::BuildOutputMeshes, 100, ctx->progressUserData);
+ XA_PRINT_MEM_USAGE
+}
+
+void Generate(Atlas *atlas, ChartOptions chartOptions, ParameterizeFunc paramFunc, PackOptions packOptions)
+{
+ if (!atlas) {
+ XA_PRINT_WARNING("Generate: atlas is null.\n");
+ return;
+ }
+ Context *ctx = (Context *)atlas;
+ if (!ctx->uvMeshInstances.isEmpty()) {
+ XA_PRINT_WARNING("Generate: This function should not be called with UV meshes.\n");
+ return;
+ }
+ if (ctx->meshCount == 0) {
+ XA_PRINT_WARNING("Generate: No meshes. Call AddMesh first.\n");
+ return;
+ }
+ ComputeCharts(atlas, chartOptions);
+ ParameterizeCharts(atlas, paramFunc);
+ PackCharts(atlas, packOptions);
}
-uint32_t GetHeight(const Atlas *atlas)
+void SetProgressCallback(Atlas *atlas, ProgressFunc progressFunc, void *progressUserData)
{
- xaAssert(atlas);
- return atlas->height;
+ if (!atlas) {
+ XA_PRINT_WARNING("SetProgressCallback: atlas is null.\n");
+ return;
+ }
+ Context *ctx = (Context *)atlas;
+ ctx->progressFunc = progressFunc;
+ ctx->progressUserData = progressUserData;
}
-uint32_t GetNumCharts(const Atlas *atlas)
+void SetRealloc(ReallocFunc reallocFunc)
{
- xaAssert(atlas);
- return atlas->atlas.chartCount();
+ internal::s_realloc = reallocFunc;
+}
+
+void SetPrint(PrintFunc print, bool verbose)
+{
+ internal::s_print = print;
+ internal::s_printVerbose = verbose;
}
-const OutputMesh * const *GetOutputMeshes(const Atlas *atlas)
+const char *StringForEnum(AddMeshError::Enum error)
{
- xaAssert(atlas);
- return atlas->outputMeshes;
+ if (error == AddMeshError::Error)
+ return "Unspecified error";
+ if (error == AddMeshError::IndexOutOfRange)
+ return "Index out of range";
+ if (error == AddMeshError::InvalidIndexCount)
+ return "Invalid index count";
+ return "Success";
}
-const char *StringForEnum(AddMeshErrorCode::Enum error)
-{
- if (error == AddMeshErrorCode::AlreadyAddedEdge)
- return "already added edge";
- if (error == AddMeshErrorCode::DegenerateColocalEdge)
- return "degenerate colocal edge";
- if (error == AddMeshErrorCode::DegenerateEdge)
- return "degenerate edge";
- if (error == AddMeshErrorCode::DuplicateEdge)
- return "duplicate edge";
- if (error == AddMeshErrorCode::IndexOutOfRange)
- return "index out of range";
- if (error == AddMeshErrorCode::InvalidIndexCount)
- return "invalid index count";
- if (error == AddMeshErrorCode::ZeroAreaFace)
- return "zero area face";
- if (error == AddMeshErrorCode::ZeroLengthEdge)
- return "zero length edge";
- return "success";
+const char *StringForEnum(ProgressCategory::Enum category)
+{
+ if (category == ProgressCategory::AddMesh)
+ return "Adding mesh(es)";
+ if (category == ProgressCategory::ComputeCharts)
+ return "Computing charts";
+ if (category == ProgressCategory::ParameterizeCharts)
+ return "Parameterizing charts";
+ if (category == ProgressCategory::PackCharts)
+ return "Packing charts";
+ if (category == ProgressCategory::BuildOutputMeshes)
+ return "Building output meshes";
+ return "";
}
} // namespace xatlas
diff --git a/thirdparty/xatlas/xatlas.h b/thirdparty/xatlas/xatlas.h
index dbf8ca08c7..c123e800b4 100644
--- a/thirdparty/xatlas/xatlas.h
+++ b/thirdparty/xatlas/xatlas.h
@@ -1,176 +1,254 @@
-// This code is in the public domain -- castanyo@yahoo.es
+/*
+MIT License
+
+Copyright (c) 2018-2019 Jonathan Young
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+/*
+thekla_atlas
+MIT License
+https://github.com/Thekla/thekla_atlas
+Copyright (c) 2013 Thekla, Inc
+Copyright NVIDIA Corporation 2006 -- Ignacio Castano <icastano@nvidia.com>
+*/
#pragma once
#ifndef XATLAS_H
#define XATLAS_H
-#include <float.h> // FLT_MAX
-// -- GODOT start --
-#include <limits.h> // INT_MAX, UINT_MAX
-// -- GODOT end --
+#include <stdint.h>
namespace xatlas {
-typedef void (*PrintFunc)(const char *, ...);
+struct ChartFlags
+{
+ enum
+ {
+ Invalid = 1 << 0
+ };
+};
-struct Atlas;
+// A group of connected faces, belonging to a single atlas.
+struct Chart
+{
+ uint32_t atlasIndex; // Sub-atlas index.
+ uint32_t flags;
+ uint32_t *indexArray;
+ uint32_t indexCount;
+ uint32_t material;
+};
-struct CharterOptions
+// Output vertex.
+struct Vertex
{
- float proxyFitMetricWeight;
- float roundnessMetricWeight;
- float straightnessMetricWeight;
- float normalSeamMetricWeight;
- float textureSeamMetricWeight;
- float maxChartArea;
- float maxBoundaryLength;
-
- CharterOptions()
- {
- // These are the default values we use on The Witness.
- proxyFitMetricWeight = 2.0f;
- roundnessMetricWeight = 0.01f;
- straightnessMetricWeight = 6.0f;
- normalSeamMetricWeight = 4.0f;
- textureSeamMetricWeight = 0.5f;
- /*
- proxyFitMetricWeight = 1.0f;
- roundnessMetricWeight = 0.1f;
- straightnessMetricWeight = 0.25f;
- normalSeamMetricWeight = 1.0f;
- textureSeamMetricWeight = 0.1f;
- */
- maxChartArea = FLT_MAX;
- maxBoundaryLength = FLT_MAX;
- }
+ int32_t atlasIndex; // Sub-atlas index. -1 if the vertex doesn't exist in any atlas.
+ int32_t chartIndex; // -1 if the vertex doesn't exist in any chart.
+ float uv[2]; // Not normalized - values are in Atlas width and height range.
+ uint32_t xref; // Index of input vertex from which this output vertex originated.
};
-struct PackMethod
+// Output mesh.
+struct Mesh
{
- enum Enum
- {
- TexelArea, // texel_area determines resolution
- ApproximateResolution, // guess texel_area to approximately match desired resolution
- ExactResolution // run the packer multiple times to exactly match the desired resolution (slow)
- };
+ Chart *chartArray;
+ uint32_t chartCount;
+ uint32_t *indexArray;
+ uint32_t indexCount;
+ Vertex *vertexArray;
+ uint32_t vertexCount;
};
-struct PackerOptions
+static const uint32_t kImageChartIndexMask = 0x3FFFFFFF;
+static const uint32_t kImageHasChartIndexBit = 0x40000000;
+static const uint32_t kImageIsPaddingBit = 0x80000000;
+
+// Empty on creation. Populated after charts are packed.
+struct Atlas
{
- PackMethod::Enum method;
-
- // 0 - brute force
- // 1 - 4096 attempts
- // 2 - 2048
- // 3 - 1024
- // 4 - 512
- // other - 256
- // Avoid brute force packing, since it can be unusably slow in some situations.
- int quality;
-
- float texelArea; // This is not really texel area, but 1 / texel width?
- uint32_t resolution;
- bool blockAlign; // Align charts to 4x4 blocks.
- bool conservative; // Pack charts with extra padding.
- int padding;
-
- PackerOptions()
- {
- method = PackMethod::ApproximateResolution;
- quality = 1;
- texelArea = 8;
- resolution = 512;
- blockAlign = false;
- conservative = false;
- padding = 0;
- }
+ uint32_t width; // Atlas width in texels.
+ uint32_t height; // Atlas height in texels.
+ uint32_t atlasCount; // Number of sub-atlases. Equal to 0 unless PackOptions resolution is changed from default (0).
+ uint32_t chartCount; // Total number of charts in all meshes.
+ uint32_t meshCount; // Number of output meshes. Equal to the number of times AddMesh was called.
+ Mesh *meshes; // The output meshes, corresponding to each AddMesh call.
+ float *utilization; // Normalized atlas texel utilization array. E.g. a value of 0.8 means 20% empty space. atlasCount in length.
+ float texelsPerUnit; // Equal to PackOptions texelsPerUnit if texelsPerUnit > 0, otherwise an estimated value to match PackOptions resolution.
+ uint32_t *image;
};
-struct AddMeshErrorCode
+// Create an empty atlas.
+Atlas *Create();
+
+void Destroy(Atlas *atlas);
+
+struct IndexFormat
{
enum Enum
{
- Success,
- AlreadyAddedEdge, // index0 and index1 are the edge indices
- DegenerateColocalEdge, // index0 and index1 are the edge indices
- DegenerateEdge, // index0 and index1 are the edge indices
- DuplicateEdge, // index0 and index1 are the edge indices
- IndexOutOfRange, // index0 is the index
- InvalidIndexCount, // not evenly divisible by 3 - expecting triangles
- ZeroAreaFace,
- ZeroLengthEdge // index0 and index1 are the edge indices
+ UInt16,
+ UInt32
};
};
-struct AddMeshError
+// Input mesh declaration.
+struct MeshDecl
{
- AddMeshErrorCode::Enum code;
- uint32_t face;
- uint32_t index0, index1;
+ uint32_t vertexCount = 0;
+ const void *vertexPositionData = nullptr;
+ uint32_t vertexPositionStride = 0;
+ const void *vertexNormalData = nullptr; // optional
+ uint32_t vertexNormalStride = 0; // optional
+ const void *vertexUvData = nullptr; // optional. The input UVs are provided as a hint to the chart generator.
+ uint32_t vertexUvStride = 0; // optional
+ uint32_t indexCount = 0;
+ const void *indexData = nullptr; // optional
+ int32_t indexOffset = 0; // optional. Add this offset to all indices.
+ IndexFormat::Enum indexFormat = IndexFormat::UInt16;
+
+ // Optional. indexCount / 3 (triangle count) in length.
+ // Don't atlas faces set to true. Ignored faces still exist in the output meshes, Vertex uv is set to (0, 0) and Vertex atlasIndex to -1.
+ const bool *faceIgnoreData = nullptr;
+
+ // Vertex positions within epsilon distance of each other are considered colocal.
+ float epsilon = 1.192092896e-07F;
};
-struct IndexFormat
+struct AddMeshError
{
enum Enum
{
- HalfFloat,
- Float
+ Success, // No error.
+ Error, // Unspecified error.
+ IndexOutOfRange, // An index is >= MeshDecl vertexCount.
+ InvalidIndexCount // Not evenly divisible by 3 - expecting triangles.
};
};
-struct InputMesh
-{
- uint32_t vertexCount;
- const void *vertexPositionData;
- uint32_t vertexPositionStride;
- const void *vertexNormalData; // optional
- uint32_t vertexNormalStride; // optional
-
- // optional
- // The input UVs are provided as a hint to the chart generator.
- const void *vertexUvData;
- uint32_t vertexUvStride;
+// Add a mesh to the atlas. MeshDecl data is copied, so it can be freed after AddMesh returns.
+AddMeshError::Enum AddMesh(Atlas *atlas, const MeshDecl &meshDecl, uint32_t meshCountHint = 0);
- uint32_t indexCount;
- const void *indexData;
- IndexFormat::Enum indexFormat;
+// Wait for AddMesh async processing to finish. ComputeCharts / Generate call this internally.
+void AddMeshJoin(Atlas *atlas);
- // optional. indexCount / 3 in length.
- // Charter also uses material boundaries as a hint to cut charts.
- const uint16_t *faceMaterialData;
+struct UvMeshDecl
+{
+ uint32_t vertexCount = 0;
+ uint32_t vertexStride = 0;
+ const void *vertexUvData = nullptr;
+ uint32_t indexCount = 0;
+ const void *indexData = nullptr; // optional
+ int32_t indexOffset = 0; // optional. Add this offset to all indices.
+ IndexFormat::Enum indexFormat = IndexFormat::UInt16;
+ const uint32_t *faceMaterialData = nullptr; // Optional. Faces with different materials won't be assigned to the same chart. Must be indexCount / 3 in length.
+ bool rotateCharts = true;
};
-struct OutputChart
+AddMeshError::Enum AddUvMesh(Atlas *atlas, const UvMeshDecl &decl);
+
+struct ChartOptions
{
- uint32_t *indexArray;
- uint32_t indexCount;
+ float maxChartArea = 0.0f; // Don't grow charts to be larger than this. 0 means no limit.
+ float maxBoundaryLength = 0.0f; // Don't grow charts to have a longer boundary than this. 0 means no limit.
+
+ // Weights determine chart growth. Higher weights mean higher cost for that metric.
+ float proxyFitMetricWeight = 2.0f; // Angle between face and average chart normal.
+ float roundnessMetricWeight = 0.01f;
+ float straightnessMetricWeight = 6.0f;
+ float normalSeamMetricWeight = 4.0f; // If > 1000, normal seams are fully respected.
+ float textureSeamMetricWeight = 0.5f;
+
+ float maxThreshold = 2.0f; // If total of all metrics * weights > maxThreshold, don't grow chart. Lower values result in more charts.
+ uint32_t growFaceCount = 32; // Grow this many faces at a time.
+ uint32_t maxIterations = 1; // Number of iterations of the chart growing and seeding phases. Higher values result in better charts.
};
-struct OutputVertex
+// Call after all AddMesh calls. Can be called multiple times to recompute charts with different options.
+void ComputeCharts(Atlas *atlas, ChartOptions chartOptions = ChartOptions());
+
+// Custom parameterization function. texcoords initial values are an orthogonal parameterization.
+typedef void (*ParameterizeFunc)(const float *positions, float *texcoords, uint32_t vertexCount, const uint32_t *indices, uint32_t indexCount);
+
+// Call after ComputeCharts. Can be called multiple times to re-parameterize charts with a different ParameterizeFunc.
+void ParameterizeCharts(Atlas *atlas, ParameterizeFunc func = nullptr);
+
+struct PackOptions
{
- float uv[2];
- uint32_t xref; // Index of input vertex from which this output vertex originated.
+ // Slower, but gives the best result. If false, use random chart placement.
+ bool bruteForce = false;
+
+ // Create Atlas::image
+ bool createImage = false;
+
+ // Unit to texel scale. e.g. a 1x1 quad with texelsPerUnit of 32 will take up approximately 32x32 texels in the atlas.
+ // If 0, an estimated value will be calculated to approximately match the given resolution.
+ // If resolution is also 0, the estimated value will approximately match a 1024x1024 atlas.
+ float texelsPerUnit = 0.0f;
+
+ // If 0, generate a single atlas with texelsPerUnit determining the final resolution.
+ // If not 0, and texelsPerUnit is not 0, generate one or more atlases with that exact resolution.
+ // If not 0, and texelsPerUnit is 0, texelsPerUnit is estimated to approximately match the resolution.
+ uint32_t resolution = 0;
+
+ // Charts larger than this will be scaled down.
+ uint32_t maxChartSize = 1024;
+
+ // Align charts to 4x4 blocks. Also improves packing speed, since there are fewer possible chart locations to consider.
+ bool blockAlign = false;
+
+ // Number of pixels to pad charts with.
+ uint32_t padding = 0;
};
-struct OutputMesh
+// Call after ParameterizeCharts. Can be called multiple times to re-pack charts with different options.
+void PackCharts(Atlas *atlas, PackOptions packOptions = PackOptions());
+
+// Equivalent to calling ComputeCharts, ParameterizeCharts and PackCharts in sequence. Can be called multiple times to regenerate with different options.
+void Generate(Atlas *atlas, ChartOptions chartOptions = ChartOptions(), ParameterizeFunc paramFunc = nullptr, PackOptions packOptions = PackOptions());
+
+// Progress tracking.
+struct ProgressCategory
{
- OutputChart *chartArray;
- uint32_t chartCount;
- uint32_t *indexArray;
- uint32_t indexCount;
- OutputVertex *vertexArray;
- uint32_t vertexCount;
+ enum Enum
+ {
+ AddMesh,
+ ComputeCharts,
+ ParameterizeCharts,
+ PackCharts,
+ BuildOutputMeshes
+ };
};
-void SetPrint(PrintFunc print);
-Atlas *Create();
-void Destroy(Atlas *atlas);
-// useColocalVertices - generates fewer charts (good), but is more sensitive to bad geometry.
-AddMeshError AddMesh(Atlas *atlas, const InputMesh &mesh, bool useColocalVertices = true);
-void Generate(Atlas *atlas, CharterOptions charterOptions = CharterOptions(), PackerOptions packerOptions = PackerOptions());
-uint32_t GetWidth(const Atlas *atlas);
-uint32_t GetHeight(const Atlas *atlas);
-uint32_t GetNumCharts(const Atlas *atlas);
-const OutputMesh * const *GetOutputMeshes(const Atlas *atlas);
-const char *StringForEnum(AddMeshErrorCode::Enum error);
+// May be called from any thread. Return false to cancel.
+typedef bool (*ProgressFunc)(ProgressCategory::Enum category, int progress, void *userData);
+
+void SetProgressCallback(Atlas *atlas, ProgressFunc progressFunc = nullptr, void *progressUserData = nullptr);
+
+// Custom memory allocation.
+typedef void *(*ReallocFunc)(void *, size_t);
+void SetRealloc(ReallocFunc reallocFunc);
+
+// Custom print function.
+typedef int (*PrintFunc)(const char *, ...);
+void SetPrint(PrintFunc print, bool verbose);
+
+// Helper functions for error messages.
+const char *StringForEnum(AddMeshError::Enum error);
+const char *StringForEnum(ProgressCategory::Enum category);
} // namespace xatlas
diff --git a/thirdparty/zstd/common/compiler.h b/thirdparty/zstd/common/compiler.h
index 0836e3ed27..87bf51ae8c 100644
--- a/thirdparty/zstd/common/compiler.h
+++ b/thirdparty/zstd/common/compiler.h
@@ -127,6 +127,13 @@
} \
}
+/* vectorization */
+#if !defined(__clang__) && defined(__GNUC__)
+# define DONT_VECTORIZE __attribute__((optimize("no-tree-vectorize")))
+#else
+# define DONT_VECTORIZE
+#endif
+
/* disable warnings */
#ifdef _MSC_VER /* Visual Studio */
# include <intrin.h> /* For Visual 2005 */
diff --git a/thirdparty/zstd/common/zstd_internal.h b/thirdparty/zstd/common/zstd_internal.h
index 31f756ab58..81b16eac2e 100644
--- a/thirdparty/zstd/common/zstd_internal.h
+++ b/thirdparty/zstd/common/zstd_internal.h
@@ -34,7 +34,6 @@
#endif
#include "xxhash.h" /* XXH_reset, update, digest */
-
#if defined (__cplusplus)
extern "C" {
#endif
@@ -193,19 +192,72 @@ static const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG;
* Shared functions to include for inlining
*********************************************/
static void ZSTD_copy8(void* dst, const void* src) { memcpy(dst, src, 8); }
+
#define COPY8(d,s) { ZSTD_copy8(d,s); d+=8; s+=8; }
+static void ZSTD_copy16(void* dst, const void* src) { memcpy(dst, src, 16); }
+#define COPY16(d,s) { ZSTD_copy16(d,s); d+=16; s+=16; }
+
+#define WILDCOPY_OVERLENGTH 8
+#define VECLEN 16
+
+typedef enum {
+ ZSTD_no_overlap,
+ ZSTD_overlap_src_before_dst,
+ /* ZSTD_overlap_dst_before_src, */
+} ZSTD_overlap_e;
/*! ZSTD_wildcopy() :
* custom version of memcpy(), can overwrite up to WILDCOPY_OVERLENGTH bytes (if length==0) */
-#define WILDCOPY_OVERLENGTH 8
-MEM_STATIC void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length)
+MEM_STATIC FORCE_INLINE_ATTR DONT_VECTORIZE
+void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e ovtype)
{
+ ptrdiff_t diff = (BYTE*)dst - (const BYTE*)src;
const BYTE* ip = (const BYTE*)src;
BYTE* op = (BYTE*)dst;
BYTE* const oend = op + length;
- do
- COPY8(op, ip)
- while (op < oend);
+
+ assert(diff >= 8 || (ovtype == ZSTD_no_overlap && diff < -8));
+ if (length < VECLEN || (ovtype == ZSTD_overlap_src_before_dst && diff < VECLEN)) {
+ do
+ COPY8(op, ip)
+ while (op < oend);
+ }
+ else {
+ if ((length & 8) == 0)
+ COPY8(op, ip);
+ do {
+ COPY16(op, ip);
+ }
+ while (op < oend);
+ }
+}
+
+/*! ZSTD_wildcopy_16min() :
+ * same semantics as ZSTD_wilcopy() except guaranteed to be able to copy 16 bytes at the start */
+MEM_STATIC FORCE_INLINE_ATTR DONT_VECTORIZE
+void ZSTD_wildcopy_16min(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e ovtype)
+{
+ ptrdiff_t diff = (BYTE*)dst - (const BYTE*)src;
+ const BYTE* ip = (const BYTE*)src;
+ BYTE* op = (BYTE*)dst;
+ BYTE* const oend = op + length;
+
+ assert(length >= 8);
+ assert(diff >= 8 || (ovtype == ZSTD_no_overlap && diff < -8));
+
+ if (ovtype == ZSTD_overlap_src_before_dst && diff < VECLEN) {
+ do
+ COPY8(op, ip)
+ while (op < oend);
+ }
+ else {
+ if ((length & 8) == 0)
+ COPY8(op, ip);
+ do {
+ COPY16(op, ip);
+ }
+ while (op < oend);
+ }
}
MEM_STATIC void ZSTD_wildcopy_e(void* dst, const void* src, void* dstEnd) /* should be faster for decoding, but strangely, not verified on all platform */
diff --git a/thirdparty/zstd/compress/zstd_compress.c b/thirdparty/zstd/compress/zstd_compress.c
index 2e163c8bf3..1476512580 100644
--- a/thirdparty/zstd/compress/zstd_compress.c
+++ b/thirdparty/zstd/compress/zstd_compress.c
@@ -385,6 +385,11 @@ ZSTD_bounds ZSTD_cParam_getBounds(ZSTD_cParameter param)
bounds.upperBound = ZSTD_lcm_uncompressed;
return bounds;
+ case ZSTD_c_targetCBlockSize:
+ bounds.lowerBound = ZSTD_TARGETCBLOCKSIZE_MIN;
+ bounds.upperBound = ZSTD_TARGETCBLOCKSIZE_MAX;
+ return bounds;
+
default:
{ ZSTD_bounds const boundError = { ERROR(parameter_unsupported), 0, 0 };
return boundError;
@@ -452,6 +457,7 @@ static int ZSTD_isUpdateAuthorized(ZSTD_cParameter param)
case ZSTD_c_ldmHashRateLog:
case ZSTD_c_forceAttachDict:
case ZSTD_c_literalCompressionMode:
+ case ZSTD_c_targetCBlockSize:
default:
return 0;
}
@@ -497,6 +503,7 @@ size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value)
case ZSTD_c_ldmHashLog:
case ZSTD_c_ldmMinMatch:
case ZSTD_c_ldmBucketSizeLog:
+ case ZSTD_c_targetCBlockSize:
break;
default: RETURN_ERROR(parameter_unsupported);
@@ -671,6 +678,12 @@ size_t ZSTD_CCtxParams_setParameter(ZSTD_CCtx_params* CCtxParams,
CCtxParams->ldmParams.hashRateLog = value;
return CCtxParams->ldmParams.hashRateLog;
+ case ZSTD_c_targetCBlockSize :
+ if (value!=0) /* 0 ==> default */
+ BOUNDCHECK(ZSTD_c_targetCBlockSize, value);
+ CCtxParams->targetCBlockSize = value;
+ return CCtxParams->targetCBlockSize;
+
default: RETURN_ERROR(parameter_unsupported, "unknown parameter");
}
}
@@ -692,13 +705,13 @@ size_t ZSTD_CCtxParams_getParameter(
*value = CCtxParams->compressionLevel;
break;
case ZSTD_c_windowLog :
- *value = CCtxParams->cParams.windowLog;
+ *value = (int)CCtxParams->cParams.windowLog;
break;
case ZSTD_c_hashLog :
- *value = CCtxParams->cParams.hashLog;
+ *value = (int)CCtxParams->cParams.hashLog;
break;
case ZSTD_c_chainLog :
- *value = CCtxParams->cParams.chainLog;
+ *value = (int)CCtxParams->cParams.chainLog;
break;
case ZSTD_c_searchLog :
*value = CCtxParams->cParams.searchLog;
@@ -773,6 +786,9 @@ size_t ZSTD_CCtxParams_getParameter(
case ZSTD_c_ldmHashRateLog :
*value = CCtxParams->ldmParams.hashRateLog;
break;
+ case ZSTD_c_targetCBlockSize :
+ *value = (int)CCtxParams->targetCBlockSize;
+ break;
default: RETURN_ERROR(parameter_unsupported, "unknown parameter");
}
return 0;
@@ -930,12 +946,12 @@ size_t ZSTD_CCtx_reset(ZSTD_CCtx* cctx, ZSTD_ResetDirective reset)
@return : 0, or an error code if one value is beyond authorized range */
size_t ZSTD_checkCParams(ZSTD_compressionParameters cParams)
{
- BOUNDCHECK(ZSTD_c_windowLog, cParams.windowLog);
- BOUNDCHECK(ZSTD_c_chainLog, cParams.chainLog);
- BOUNDCHECK(ZSTD_c_hashLog, cParams.hashLog);
- BOUNDCHECK(ZSTD_c_searchLog, cParams.searchLog);
- BOUNDCHECK(ZSTD_c_minMatch, cParams.minMatch);
- BOUNDCHECK(ZSTD_c_targetLength,cParams.targetLength);
+ BOUNDCHECK(ZSTD_c_windowLog, (int)cParams.windowLog);
+ BOUNDCHECK(ZSTD_c_chainLog, (int)cParams.chainLog);
+ BOUNDCHECK(ZSTD_c_hashLog, (int)cParams.hashLog);
+ BOUNDCHECK(ZSTD_c_searchLog, (int)cParams.searchLog);
+ BOUNDCHECK(ZSTD_c_minMatch, (int)cParams.minMatch);
+ BOUNDCHECK(ZSTD_c_targetLength,(int)cParams.targetLength);
BOUNDCHECK(ZSTD_c_strategy, cParams.strategy);
return 0;
}
@@ -951,7 +967,7 @@ ZSTD_clampCParams(ZSTD_compressionParameters cParams)
if ((int)val<bounds.lowerBound) val=(type)bounds.lowerBound; \
else if ((int)val>bounds.upperBound) val=(type)bounds.upperBound; \
}
-# define CLAMP(cParam, val) CLAMP_TYPE(cParam, val, int)
+# define CLAMP(cParam, val) CLAMP_TYPE(cParam, val, unsigned)
CLAMP(ZSTD_c_windowLog, cParams.windowLog);
CLAMP(ZSTD_c_chainLog, cParams.chainLog);
CLAMP(ZSTD_c_hashLog, cParams.hashLog);
@@ -1282,15 +1298,14 @@ static void ZSTD_reset_compressedBlockState(ZSTD_compressedBlockState_t* bs)
}
/*! ZSTD_invalidateMatchState()
- * Invalidate all the matches in the match finder tables.
- * Requires nextSrc and base to be set (can be NULL).
+ * Invalidate all the matches in the match finder tables.
+ * Requires nextSrc and base to be set (can be NULL).
*/
static void ZSTD_invalidateMatchState(ZSTD_matchState_t* ms)
{
ZSTD_window_clear(&ms->window);
ms->nextToUpdate = ms->window.dictLimit;
- ms->nextToUpdate3 = ms->window.dictLimit;
ms->loadedDictEnd = 0;
ms->opt.litLengthSum = 0; /* force reset of btopt stats */
ms->dictMatchState = NULL;
@@ -1327,15 +1342,17 @@ static size_t ZSTD_continueCCtx(ZSTD_CCtx* cctx, ZSTD_CCtx_params params, U64 pl
typedef enum { ZSTDcrp_continue, ZSTDcrp_noMemset } ZSTD_compResetPolicy_e;
+typedef enum { ZSTD_resetTarget_CDict, ZSTD_resetTarget_CCtx } ZSTD_resetTarget_e;
+
static void*
ZSTD_reset_matchState(ZSTD_matchState_t* ms,
void* ptr,
const ZSTD_compressionParameters* cParams,
- ZSTD_compResetPolicy_e const crp, U32 const forCCtx)
+ ZSTD_compResetPolicy_e const crp, ZSTD_resetTarget_e const forWho)
{
size_t const chainSize = (cParams->strategy == ZSTD_fast) ? 0 : ((size_t)1 << cParams->chainLog);
size_t const hSize = ((size_t)1) << cParams->hashLog;
- U32 const hashLog3 = (forCCtx && cParams->minMatch==3) ? MIN(ZSTD_HASHLOG3_MAX, cParams->windowLog) : 0;
+ U32 const hashLog3 = ((forWho == ZSTD_resetTarget_CCtx) && cParams->minMatch==3) ? MIN(ZSTD_HASHLOG3_MAX, cParams->windowLog) : 0;
size_t const h3Size = ((size_t)1) << hashLog3;
size_t const tableSpace = (chainSize + hSize + h3Size) * sizeof(U32);
@@ -1349,7 +1366,7 @@ ZSTD_reset_matchState(ZSTD_matchState_t* ms,
ZSTD_invalidateMatchState(ms);
/* opt parser space */
- if (forCCtx && (cParams->strategy >= ZSTD_btopt)) {
+ if ((forWho == ZSTD_resetTarget_CCtx) && (cParams->strategy >= ZSTD_btopt)) {
DEBUGLOG(4, "reserving optimal parser space");
ms->opt.litFreq = (unsigned*)ptr;
ms->opt.litLengthFreq = ms->opt.litFreq + (1<<Litbits);
@@ -1377,6 +1394,19 @@ ZSTD_reset_matchState(ZSTD_matchState_t* ms,
return ptr;
}
+/* ZSTD_indexTooCloseToMax() :
+ * minor optimization : prefer memset() rather than reduceIndex()
+ * which is measurably slow in some circumstances (reported for Visual Studio).
+ * Works when re-using a context for a lot of smallish inputs :
+ * if all inputs are smaller than ZSTD_INDEXOVERFLOW_MARGIN,
+ * memset() will be triggered before reduceIndex().
+ */
+#define ZSTD_INDEXOVERFLOW_MARGIN (16 MB)
+static int ZSTD_indexTooCloseToMax(ZSTD_window_t w)
+{
+ return (size_t)(w.nextSrc - w.base) > (ZSTD_CURRENT_MAX - ZSTD_INDEXOVERFLOW_MARGIN);
+}
+
#define ZSTD_WORKSPACETOOLARGE_FACTOR 3 /* define "workspace is too large" as this number of times larger than needed */
#define ZSTD_WORKSPACETOOLARGE_MAXDURATION 128 /* when workspace is continuously too large
* during at least this number of times,
@@ -1388,7 +1418,7 @@ ZSTD_reset_matchState(ZSTD_matchState_t* ms,
note : `params` are assumed fully validated at this stage */
static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc,
ZSTD_CCtx_params params,
- U64 pledgedSrcSize,
+ U64 const pledgedSrcSize,
ZSTD_compResetPolicy_e const crp,
ZSTD_buffered_policy_e const zbuff)
{
@@ -1400,13 +1430,21 @@ static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc,
if (ZSTD_equivalentParams(zc->appliedParams, params,
zc->inBuffSize,
zc->seqStore.maxNbSeq, zc->seqStore.maxNbLit,
- zbuff, pledgedSrcSize)) {
- DEBUGLOG(4, "ZSTD_equivalentParams()==1 -> continue mode (wLog1=%u, blockSize1=%zu)",
- zc->appliedParams.cParams.windowLog, zc->blockSize);
+ zbuff, pledgedSrcSize) ) {
+ DEBUGLOG(4, "ZSTD_equivalentParams()==1 -> consider continue mode");
zc->workSpaceOversizedDuration += (zc->workSpaceOversizedDuration > 0); /* if it was too large, it still is */
- if (zc->workSpaceOversizedDuration <= ZSTD_WORKSPACETOOLARGE_MAXDURATION)
+ if (zc->workSpaceOversizedDuration <= ZSTD_WORKSPACETOOLARGE_MAXDURATION) {
+ DEBUGLOG(4, "continue mode confirmed (wLog1=%u, blockSize1=%zu)",
+ zc->appliedParams.cParams.windowLog, zc->blockSize);
+ if (ZSTD_indexTooCloseToMax(zc->blockState.matchState.window)) {
+ /* prefer a reset, faster than a rescale */
+ ZSTD_reset_matchState(&zc->blockState.matchState,
+ zc->entropyWorkspace + HUF_WORKSPACE_SIZE_U32,
+ &params.cParams,
+ crp, ZSTD_resetTarget_CCtx);
+ }
return ZSTD_continueCCtx(zc, params, pledgedSrcSize);
- } }
+ } } }
DEBUGLOG(4, "ZSTD_equivalentParams()==0 -> reset CCtx");
if (params.ldmParams.enableLdm) {
@@ -1449,7 +1487,7 @@ static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc,
DEBUGLOG(4, "windowSize: %zu - blockSize: %zu", windowSize, blockSize);
if (workSpaceTooSmall || workSpaceWasteful) {
- DEBUGLOG(4, "Need to resize workSpaceSize from %zuKB to %zuKB",
+ DEBUGLOG(4, "Resize workSpaceSize from %zuKB to %zuKB",
zc->workSpaceSize >> 10,
neededSpace >> 10);
@@ -1491,7 +1529,10 @@ static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc,
ZSTD_reset_compressedBlockState(zc->blockState.prevCBlock);
- ptr = zc->entropyWorkspace + HUF_WORKSPACE_SIZE_U32;
+ ptr = ZSTD_reset_matchState(&zc->blockState.matchState,
+ zc->entropyWorkspace + HUF_WORKSPACE_SIZE_U32,
+ &params.cParams,
+ crp, ZSTD_resetTarget_CCtx);
/* ldm hash table */
/* initialize bucketOffsets table later for pointer alignment */
@@ -1509,8 +1550,6 @@ static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc,
}
assert(((size_t)ptr & 3) == 0); /* ensure ptr is properly aligned */
- ptr = ZSTD_reset_matchState(&zc->blockState.matchState, ptr, &params.cParams, crp, /* forCCtx */ 1);
-
/* sequences storage */
zc->seqStore.maxNbSeq = maxNbSeq;
zc->seqStore.sequencesStart = (seqDef*)ptr;
@@ -1587,15 +1626,14 @@ static int ZSTD_shouldAttachDict(const ZSTD_CDict* cdict,
* handled in _enforceMaxDist */
}
-static size_t ZSTD_resetCCtx_byAttachingCDict(
- ZSTD_CCtx* cctx,
- const ZSTD_CDict* cdict,
- ZSTD_CCtx_params params,
- U64 pledgedSrcSize,
- ZSTD_buffered_policy_e zbuff)
+static size_t
+ZSTD_resetCCtx_byAttachingCDict(ZSTD_CCtx* cctx,
+ const ZSTD_CDict* cdict,
+ ZSTD_CCtx_params params,
+ U64 pledgedSrcSize,
+ ZSTD_buffered_policy_e zbuff)
{
- {
- const ZSTD_compressionParameters *cdict_cParams = &cdict->matchState.cParams;
+ { const ZSTD_compressionParameters* const cdict_cParams = &cdict->matchState.cParams;
unsigned const windowLog = params.cParams.windowLog;
assert(windowLog != 0);
/* Resize working context table params for input only, since the dict
@@ -1607,8 +1645,7 @@ static size_t ZSTD_resetCCtx_byAttachingCDict(
assert(cctx->appliedParams.cParams.strategy == cdict_cParams->strategy);
}
- {
- const U32 cdictEnd = (U32)( cdict->matchState.window.nextSrc
+ { const U32 cdictEnd = (U32)( cdict->matchState.window.nextSrc
- cdict->matchState.window.base);
const U32 cdictLen = cdictEnd - cdict->matchState.window.dictLimit;
if (cdictLen == 0) {
@@ -1625,9 +1662,9 @@ static size_t ZSTD_resetCCtx_byAttachingCDict(
cctx->blockState.matchState.window.base + cdictEnd;
ZSTD_window_clear(&cctx->blockState.matchState.window);
}
+ /* loadedDictEnd is expressed within the referential of the active context */
cctx->blockState.matchState.loadedDictEnd = cctx->blockState.matchState.window.dictLimit;
- }
- }
+ } }
cctx->dictID = cdict->dictID;
@@ -1681,7 +1718,6 @@ static size_t ZSTD_resetCCtx_byCopyingCDict(ZSTD_CCtx* cctx,
ZSTD_matchState_t* dstMatchState = &cctx->blockState.matchState;
dstMatchState->window = srcMatchState->window;
dstMatchState->nextToUpdate = srcMatchState->nextToUpdate;
- dstMatchState->nextToUpdate3= srcMatchState->nextToUpdate3;
dstMatchState->loadedDictEnd= srcMatchState->loadedDictEnd;
}
@@ -1761,7 +1797,6 @@ static size_t ZSTD_copyCCtx_internal(ZSTD_CCtx* dstCCtx,
ZSTD_matchState_t* dstMatchState = &dstCCtx->blockState.matchState;
dstMatchState->window = srcMatchState->window;
dstMatchState->nextToUpdate = srcMatchState->nextToUpdate;
- dstMatchState->nextToUpdate3= srcMatchState->nextToUpdate3;
dstMatchState->loadedDictEnd= srcMatchState->loadedDictEnd;
}
dstCCtx->dictID = srcCCtx->dictID;
@@ -1831,16 +1866,15 @@ static void ZSTD_reduceTable_btlazy2(U32* const table, U32 const size, U32 const
/*! ZSTD_reduceIndex() :
* rescale all indexes to avoid future overflow (indexes are U32) */
-static void ZSTD_reduceIndex (ZSTD_CCtx* zc, const U32 reducerValue)
+static void ZSTD_reduceIndex (ZSTD_matchState_t* ms, ZSTD_CCtx_params const* params, const U32 reducerValue)
{
- ZSTD_matchState_t* const ms = &zc->blockState.matchState;
- { U32 const hSize = (U32)1 << zc->appliedParams.cParams.hashLog;
+ { U32 const hSize = (U32)1 << params->cParams.hashLog;
ZSTD_reduceTable(ms->hashTable, hSize, reducerValue);
}
- if (zc->appliedParams.cParams.strategy != ZSTD_fast) {
- U32 const chainSize = (U32)1 << zc->appliedParams.cParams.chainLog;
- if (zc->appliedParams.cParams.strategy == ZSTD_btlazy2)
+ if (params->cParams.strategy != ZSTD_fast) {
+ U32 const chainSize = (U32)1 << params->cParams.chainLog;
+ if (params->cParams.strategy == ZSTD_btlazy2)
ZSTD_reduceTable_btlazy2(ms->chainTable, chainSize, reducerValue);
else
ZSTD_reduceTable(ms->chainTable, chainSize, reducerValue);
@@ -2524,6 +2558,7 @@ ZSTD_compressSequences_internal(seqStore_t* seqStorePtr,
op[0] = (BYTE)((nbSeq>>8) + 0x80), op[1] = (BYTE)nbSeq, op+=2;
else
op[0]=0xFF, MEM_writeLE16(op+1, (U16)(nbSeq - LONGNBSEQ)), op+=3;
+ assert(op <= oend);
if (nbSeq==0) {
/* Copy the old tables over as if we repeated them */
memcpy(&nextEntropy->fse, &prevEntropy->fse, sizeof(prevEntropy->fse));
@@ -2532,6 +2567,7 @@ ZSTD_compressSequences_internal(seqStore_t* seqStorePtr,
/* seqHead : flags for FSE encoding type */
seqHead = op++;
+ assert(op <= oend);
/* convert length/distances into codes */
ZSTD_seqToCodes(seqStorePtr);
@@ -2555,6 +2591,7 @@ ZSTD_compressSequences_internal(seqStore_t* seqStorePtr,
if (LLtype == set_compressed)
lastNCount = op;
op += countSize;
+ assert(op <= oend);
} }
/* build CTable for Offsets */
{ unsigned max = MaxOff;
@@ -2577,6 +2614,7 @@ ZSTD_compressSequences_internal(seqStore_t* seqStorePtr,
if (Offtype == set_compressed)
lastNCount = op;
op += countSize;
+ assert(op <= oend);
} }
/* build CTable for MatchLengths */
{ unsigned max = MaxML;
@@ -2597,6 +2635,7 @@ ZSTD_compressSequences_internal(seqStore_t* seqStorePtr,
if (MLtype == set_compressed)
lastNCount = op;
op += countSize;
+ assert(op <= oend);
} }
*seqHead = (BYTE)((LLtype<<6) + (Offtype<<4) + (MLtype<<2));
@@ -2610,6 +2649,7 @@ ZSTD_compressSequences_internal(seqStore_t* seqStorePtr,
longOffsets, bmi2);
FORWARD_IF_ERROR(bitstreamSize);
op += bitstreamSize;
+ assert(op <= oend);
/* zstd versions <= 1.3.4 mistakenly report corruption when
* FSE_readNCount() receives a buffer < 4 bytes.
* Fixed by https://github.com/facebook/zstd/pull/1146.
@@ -2721,30 +2761,24 @@ void ZSTD_resetSeqStore(seqStore_t* ssPtr)
ssPtr->longLengthID = 0;
}
-static size_t ZSTD_compressBlock_internal(ZSTD_CCtx* zc,
- void* dst, size_t dstCapacity,
- const void* src, size_t srcSize)
+typedef enum { ZSTDbss_compress, ZSTDbss_noCompress } ZSTD_buildSeqStore_e;
+
+static size_t ZSTD_buildSeqStore(ZSTD_CCtx* zc, const void* src, size_t srcSize)
{
ZSTD_matchState_t* const ms = &zc->blockState.matchState;
- size_t cSize;
- DEBUGLOG(5, "ZSTD_compressBlock_internal (dstCapacity=%u, dictLimit=%u, nextToUpdate=%u)",
- (unsigned)dstCapacity, (unsigned)ms->window.dictLimit, (unsigned)ms->nextToUpdate);
+ DEBUGLOG(5, "ZSTD_buildSeqStore (srcSize=%zu)", srcSize);
assert(srcSize <= ZSTD_BLOCKSIZE_MAX);
-
/* Assert that we have correctly flushed the ctx params into the ms's copy */
ZSTD_assertEqualCParams(zc->appliedParams.cParams, ms->cParams);
-
if (srcSize < MIN_CBLOCK_SIZE+ZSTD_blockHeaderSize+1) {
ZSTD_ldm_skipSequences(&zc->externSeqStore, srcSize, zc->appliedParams.cParams.minMatch);
- cSize = 0;
- goto out; /* don't even attempt compression below a certain srcSize */
+ return ZSTDbss_noCompress; /* don't even attempt compression below a certain srcSize */
}
ZSTD_resetSeqStore(&(zc->seqStore));
/* required for optimal parser to read stats from dictionary */
ms->opt.symbolCosts = &zc->blockState.prevCBlock->entropy;
/* tell the optimal parser how we expect to compress literals */
ms->opt.literalCompressionMode = zc->appliedParams.literalCompressionMode;
-
/* a gap between an attached dict and the current window is not safe,
* they must remain adjacent,
* and when that stops being the case, the dict must be unset */
@@ -2798,6 +2832,21 @@ static size_t ZSTD_compressBlock_internal(ZSTD_CCtx* zc,
{ const BYTE* const lastLiterals = (const BYTE*)src + srcSize - lastLLSize;
ZSTD_storeLastLiterals(&zc->seqStore, lastLiterals, lastLLSize);
} }
+ return ZSTDbss_compress;
+}
+
+static size_t ZSTD_compressBlock_internal(ZSTD_CCtx* zc,
+ void* dst, size_t dstCapacity,
+ const void* src, size_t srcSize)
+{
+ size_t cSize;
+ DEBUGLOG(5, "ZSTD_compressBlock_internal (dstCapacity=%u, dictLimit=%u, nextToUpdate=%u)",
+ (unsigned)dstCapacity, (unsigned)zc->blockState.matchState.window.dictLimit, (unsigned)zc->blockState.matchState.nextToUpdate);
+
+ { const size_t bss = ZSTD_buildSeqStore(zc, src, srcSize);
+ FORWARD_IF_ERROR(bss);
+ if (bss == ZSTDbss_noCompress) { cSize = 0; goto out; }
+ }
/* encode sequences and literals */
cSize = ZSTD_compressSequences(&zc->seqStore,
@@ -2826,6 +2875,25 @@ out:
}
+static void ZSTD_overflowCorrectIfNeeded(ZSTD_matchState_t* ms, ZSTD_CCtx_params const* params, void const* ip, void const* iend)
+{
+ if (ZSTD_window_needOverflowCorrection(ms->window, iend)) {
+ U32 const maxDist = (U32)1 << params->cParams.windowLog;
+ U32 const cycleLog = ZSTD_cycleLog(params->cParams.chainLog, params->cParams.strategy);
+ U32 const correction = ZSTD_window_correctOverflow(&ms->window, cycleLog, maxDist, ip);
+ ZSTD_STATIC_ASSERT(ZSTD_CHAINLOG_MAX <= 30);
+ ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX_32 <= 30);
+ ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX <= 31);
+ ZSTD_reduceIndex(ms, params, correction);
+ if (ms->nextToUpdate < correction) ms->nextToUpdate = 0;
+ else ms->nextToUpdate -= correction;
+ /* invalidate dictionaries on overflow correction */
+ ms->loadedDictEnd = 0;
+ ms->dictMatchState = NULL;
+ }
+}
+
+
/*! ZSTD_compress_frameChunk() :
* Compress a chunk of data into one or multiple blocks.
* All blocks will be terminated, all input will be consumed.
@@ -2844,7 +2912,7 @@ static size_t ZSTD_compress_frameChunk (ZSTD_CCtx* cctx,
BYTE* const ostart = (BYTE*)dst;
BYTE* op = ostart;
U32 const maxDist = (U32)1 << cctx->appliedParams.cParams.windowLog;
- assert(cctx->appliedParams.cParams.windowLog <= 31);
+ assert(cctx->appliedParams.cParams.windowLog <= ZSTD_WINDOWLOG_MAX);
DEBUGLOG(5, "ZSTD_compress_frameChunk (blockSize=%u)", (unsigned)blockSize);
if (cctx->appliedParams.fParams.checksumFlag && srcSize)
@@ -2859,19 +2927,10 @@ static size_t ZSTD_compress_frameChunk (ZSTD_CCtx* cctx,
"not enough space to store compressed block");
if (remaining < blockSize) blockSize = remaining;
- if (ZSTD_window_needOverflowCorrection(ms->window, ip + blockSize)) {
- U32 const cycleLog = ZSTD_cycleLog(cctx->appliedParams.cParams.chainLog, cctx->appliedParams.cParams.strategy);
- U32 const correction = ZSTD_window_correctOverflow(&ms->window, cycleLog, maxDist, ip);
- ZSTD_STATIC_ASSERT(ZSTD_CHAINLOG_MAX <= 30);
- ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX_32 <= 30);
- ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX <= 31);
- ZSTD_reduceIndex(cctx, correction);
- if (ms->nextToUpdate < correction) ms->nextToUpdate = 0;
- else ms->nextToUpdate -= correction;
- ms->loadedDictEnd = 0;
- ms->dictMatchState = NULL;
- }
- ZSTD_window_enforceMaxDist(&ms->window, ip + blockSize, maxDist, &ms->loadedDictEnd, &ms->dictMatchState);
+ ZSTD_overflowCorrectIfNeeded(ms, &cctx->appliedParams, ip, ip + blockSize);
+ ZSTD_checkDictValidity(&ms->window, ip + blockSize, maxDist, &ms->loadedDictEnd, &ms->dictMatchState);
+
+ /* Ensure hash/chain table insertion resumes no sooner than lowlimit */
if (ms->nextToUpdate < ms->window.lowLimit) ms->nextToUpdate = ms->window.lowLimit;
{ size_t cSize = ZSTD_compressBlock_internal(cctx,
@@ -2899,7 +2958,7 @@ static size_t ZSTD_compress_frameChunk (ZSTD_CCtx* cctx,
} }
if (lastFrameChunk && (op>ostart)) cctx->stage = ZSTDcs_ending;
- return op-ostart;
+ return (size_t)(op-ostart);
}
@@ -2991,6 +3050,7 @@ static size_t ZSTD_compressContinue_internal (ZSTD_CCtx* cctx,
fhSize = ZSTD_writeFrameHeader(dst, dstCapacity, cctx->appliedParams,
cctx->pledgedSrcSizePlusOne-1, cctx->dictID);
FORWARD_IF_ERROR(fhSize);
+ assert(fhSize <= dstCapacity);
dstCapacity -= fhSize;
dst = (char*)dst + fhSize;
cctx->stage = ZSTDcs_ongoing;
@@ -3007,18 +3067,7 @@ static size_t ZSTD_compressContinue_internal (ZSTD_CCtx* cctx,
if (!frame) {
/* overflow check and correction for block mode */
- if (ZSTD_window_needOverflowCorrection(ms->window, (const char*)src + srcSize)) {
- U32 const cycleLog = ZSTD_cycleLog(cctx->appliedParams.cParams.chainLog, cctx->appliedParams.cParams.strategy);
- U32 const correction = ZSTD_window_correctOverflow(&ms->window, cycleLog, 1 << cctx->appliedParams.cParams.windowLog, src);
- ZSTD_STATIC_ASSERT(ZSTD_CHAINLOG_MAX <= 30);
- ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX_32 <= 30);
- ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX <= 31);
- ZSTD_reduceIndex(cctx, correction);
- if (ms->nextToUpdate < correction) ms->nextToUpdate = 0;
- else ms->nextToUpdate -= correction;
- ms->loadedDictEnd = 0;
- ms->dictMatchState = NULL;
- }
+ ZSTD_overflowCorrectIfNeeded(ms, &cctx->appliedParams, src, (BYTE const*)src + srcSize);
}
DEBUGLOG(5, "ZSTD_compressContinue_internal (blockSize=%u)", (unsigned)cctx->blockSize);
@@ -3074,7 +3123,7 @@ static size_t ZSTD_loadDictionaryContent(ZSTD_matchState_t* ms,
const void* src, size_t srcSize,
ZSTD_dictTableLoadMethod_e dtlm)
{
- const BYTE* const ip = (const BYTE*) src;
+ const BYTE* ip = (const BYTE*) src;
const BYTE* const iend = ip + srcSize;
ZSTD_window_update(&ms->window, src, srcSize);
@@ -3085,32 +3134,42 @@ static size_t ZSTD_loadDictionaryContent(ZSTD_matchState_t* ms,
if (srcSize <= HASH_READ_SIZE) return 0;
- switch(params->cParams.strategy)
- {
- case ZSTD_fast:
- ZSTD_fillHashTable(ms, iend, dtlm);
- break;
- case ZSTD_dfast:
- ZSTD_fillDoubleHashTable(ms, iend, dtlm);
- break;
+ while (iend - ip > HASH_READ_SIZE) {
+ size_t const remaining = iend - ip;
+ size_t const chunk = MIN(remaining, ZSTD_CHUNKSIZE_MAX);
+ const BYTE* const ichunk = ip + chunk;
- case ZSTD_greedy:
- case ZSTD_lazy:
- case ZSTD_lazy2:
- if (srcSize >= HASH_READ_SIZE)
- ZSTD_insertAndFindFirstIndex(ms, iend-HASH_READ_SIZE);
- break;
+ ZSTD_overflowCorrectIfNeeded(ms, params, ip, ichunk);
- case ZSTD_btlazy2: /* we want the dictionary table fully sorted */
- case ZSTD_btopt:
- case ZSTD_btultra:
- case ZSTD_btultra2:
- if (srcSize >= HASH_READ_SIZE)
- ZSTD_updateTree(ms, iend-HASH_READ_SIZE, iend);
- break;
+ switch(params->cParams.strategy)
+ {
+ case ZSTD_fast:
+ ZSTD_fillHashTable(ms, ichunk, dtlm);
+ break;
+ case ZSTD_dfast:
+ ZSTD_fillDoubleHashTable(ms, ichunk, dtlm);
+ break;
- default:
- assert(0); /* not possible : not a valid strategy id */
+ case ZSTD_greedy:
+ case ZSTD_lazy:
+ case ZSTD_lazy2:
+ if (chunk >= HASH_READ_SIZE)
+ ZSTD_insertAndFindFirstIndex(ms, ichunk-HASH_READ_SIZE);
+ break;
+
+ case ZSTD_btlazy2: /* we want the dictionary table fully sorted */
+ case ZSTD_btopt:
+ case ZSTD_btultra:
+ case ZSTD_btultra2:
+ if (chunk >= HASH_READ_SIZE)
+ ZSTD_updateTree(ms, ichunk-HASH_READ_SIZE, ichunk);
+ break;
+
+ default:
+ assert(0); /* not possible : not a valid strategy id */
+ }
+
+ ip = ichunk;
}
ms->nextToUpdate = (U32)(iend - ms->window.base);
@@ -3297,12 +3356,11 @@ static size_t ZSTD_compressBegin_internal(ZSTD_CCtx* cctx,
FORWARD_IF_ERROR( ZSTD_resetCCtx_internal(cctx, params, pledgedSrcSize,
ZSTDcrp_continue, zbuff) );
- {
- size_t const dictID = ZSTD_compress_insertDictionary(
+ { size_t const dictID = ZSTD_compress_insertDictionary(
cctx->blockState.prevCBlock, &cctx->blockState.matchState,
&params, dict, dictSize, dictContentType, dtlm, cctx->entropyWorkspace);
FORWARD_IF_ERROR(dictID);
- assert(dictID <= (size_t)(U32)-1);
+ assert(dictID <= UINT_MAX);
cctx->dictID = (U32)dictID;
}
return 0;
@@ -3555,10 +3613,10 @@ static size_t ZSTD_initCDict_internal(
/* Reset the state to no dictionary */
ZSTD_reset_compressedBlockState(&cdict->cBlockState);
- { void* const end = ZSTD_reset_matchState(
- &cdict->matchState,
- (U32*)cdict->workspace + HUF_WORKSPACE_SIZE_U32,
- &cParams, ZSTDcrp_continue, /* forCCtx */ 0);
+ { void* const end = ZSTD_reset_matchState(&cdict->matchState,
+ (U32*)cdict->workspace + HUF_WORKSPACE_SIZE_U32,
+ &cParams,
+ ZSTDcrp_continue, ZSTD_resetTarget_CDict);
assert(end == (char*)cdict->workspace + cdict->workspaceSize);
(void)end;
}
@@ -4068,7 +4126,7 @@ static size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs,
case zcss_flush:
DEBUGLOG(5, "flush stage");
{ size_t const toFlush = zcs->outBuffContentSize - zcs->outBuffFlushedSize;
- size_t const flushed = ZSTD_limitCopy(op, oend-op,
+ size_t const flushed = ZSTD_limitCopy(op, (size_t)(oend-op),
zcs->outBuff + zcs->outBuffFlushedSize, toFlush);
DEBUGLOG(5, "toFlush: %u into %u ==> flushed: %u",
(unsigned)toFlush, (unsigned)(oend-op), (unsigned)flushed);
@@ -4262,7 +4320,7 @@ size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output)
if (zcs->appliedParams.nbWorkers > 0) return remainingToFlush; /* minimal estimation */
/* single thread mode : attempt to calculate remaining to flush more precisely */
{ size_t const lastBlockSize = zcs->frameEnded ? 0 : ZSTD_BLOCKHEADERSIZE;
- size_t const checksumSize = zcs->frameEnded ? 0 : zcs->appliedParams.fParams.checksumFlag * 4;
+ size_t const checksumSize = (size_t)(zcs->frameEnded ? 0 : zcs->appliedParams.fParams.checksumFlag * 4);
size_t const toFlush = remainingToFlush + lastBlockSize + checksumSize;
DEBUGLOG(4, "ZSTD_endStream : remaining to flush : %u", (unsigned)toFlush);
return toFlush;
diff --git a/thirdparty/zstd/compress/zstd_compress_internal.h b/thirdparty/zstd/compress/zstd_compress_internal.h
index cc3cbb9da9..5495899be3 100644
--- a/thirdparty/zstd/compress/zstd_compress_internal.h
+++ b/thirdparty/zstd/compress/zstd_compress_internal.h
@@ -33,13 +33,13 @@ extern "C" {
***************************************/
#define kSearchStrength 8
#define HASH_READ_SIZE 8
-#define ZSTD_DUBT_UNSORTED_MARK 1 /* For btlazy2 strategy, index 1 now means "unsorted".
+#define ZSTD_DUBT_UNSORTED_MARK 1 /* For btlazy2 strategy, index ZSTD_DUBT_UNSORTED_MARK==1 means "unsorted".
It could be confused for a real successor at index "1", if sorted as larger than its predecessor.
It's not a big deal though : candidate will just be sorted again.
Additionally, candidate position 1 will be lost.
But candidate 1 cannot hide a large tree of candidates, so it's a minimal loss.
- The benefit is that ZSTD_DUBT_UNSORTED_MARK cannot be mishandled after table re-use with a different strategy
- Constant required by ZSTD_compressBlock_btlazy2() and ZSTD_reduceTable_internal() */
+ The benefit is that ZSTD_DUBT_UNSORTED_MARK cannot be mishandled after table re-use with a different strategy.
+ This constant is required by ZSTD_compressBlock_btlazy2() and ZSTD_reduceTable_internal() */
/*-*************************************
@@ -128,21 +128,20 @@ typedef struct {
BYTE const* base; /* All regular indexes relative to this position */
BYTE const* dictBase; /* extDict indexes relative to this position */
U32 dictLimit; /* below that point, need extDict */
- U32 lowLimit; /* below that point, no more data */
+ U32 lowLimit; /* below that point, no more valid data */
} ZSTD_window_t;
typedef struct ZSTD_matchState_t ZSTD_matchState_t;
struct ZSTD_matchState_t {
ZSTD_window_t window; /* State for window round buffer management */
- U32 loadedDictEnd; /* index of end of dictionary */
+ U32 loadedDictEnd; /* index of end of dictionary, within context's referential. When dict referential is copied into active context (i.e. not attached), effectively same value as dictSize, since referential starts from zero */
U32 nextToUpdate; /* index from which to continue table update */
- U32 nextToUpdate3; /* index from which to continue table update */
U32 hashLog3; /* dispatch table : larger == faster, more memory */
U32* hashTable;
U32* hashTable3;
U32* chainTable;
optState_t opt; /* optimal parser state */
- const ZSTD_matchState_t * dictMatchState;
+ const ZSTD_matchState_t* dictMatchState;
ZSTD_compressionParameters cParams;
};
@@ -195,6 +194,9 @@ struct ZSTD_CCtx_params_s {
int compressionLevel;
int forceWindow; /* force back-references to respect limit of
* 1<<wLog, even for dictionary */
+ size_t targetCBlockSize; /* Tries to fit compressed block size to be around targetCBlockSize.
+ * No target when targetCBlockSize == 0.
+ * There is no guarantee on compressed block size */
ZSTD_dictAttachPref_e attachDictPref;
ZSTD_literalCompressionMode_e literalCompressionMode;
@@ -324,7 +326,7 @@ MEM_STATIC void ZSTD_storeSeq(seqStore_t* seqStorePtr, size_t litLength, const v
/* copy Literals */
assert(seqStorePtr->maxNbLit <= 128 KB);
assert(seqStorePtr->lit + litLength <= seqStorePtr->litStart + seqStorePtr->maxNbLit);
- ZSTD_wildcopy(seqStorePtr->lit, literals, litLength);
+ ZSTD_wildcopy(seqStorePtr->lit, literals, litLength, ZSTD_no_overlap);
seqStorePtr->lit += litLength;
/* literal Length */
@@ -564,6 +566,9 @@ MEM_STATIC U64 ZSTD_rollingHash_rotate(U64 hash, BYTE toRemove, BYTE toAdd, U64
/*-*************************************
* Round buffer management
***************************************/
+#if (ZSTD_WINDOWLOG_MAX_64 > 31)
+# error "ZSTD_WINDOWLOG_MAX is too large : would overflow ZSTD_CURRENT_MAX"
+#endif
/* Max current allowed */
#define ZSTD_CURRENT_MAX ((3U << 29) + (1U << ZSTD_WINDOWLOG_MAX))
/* Maximum chunk size before overflow correction needs to be called again */
@@ -675,31 +680,49 @@ MEM_STATIC U32 ZSTD_window_correctOverflow(ZSTD_window_t* window, U32 cycleLog,
* Updates lowLimit so that:
* (srcEnd - base) - lowLimit == maxDist + loadedDictEnd
*
- * This allows a simple check that index >= lowLimit to see if index is valid.
- * This must be called before a block compression call, with srcEnd as the block
- * source end.
+ * It ensures index is valid as long as index >= lowLimit.
+ * This must be called before a block compression call.
+ *
+ * loadedDictEnd is only defined if a dictionary is in use for current compression.
+ * As the name implies, loadedDictEnd represents the index at end of dictionary.
+ * The value lies within context's referential, it can be directly compared to blockEndIdx.
*
- * If loadedDictEndPtr is not NULL, we set it to zero once we update lowLimit.
- * This is because dictionaries are allowed to be referenced as long as the last
- * byte of the dictionary is in the window, but once they are out of range,
- * they cannot be referenced. If loadedDictEndPtr is NULL, we use
- * loadedDictEnd == 0.
+ * If loadedDictEndPtr is NULL, no dictionary is in use, and we use loadedDictEnd == 0.
+ * If loadedDictEndPtr is not NULL, we set it to zero after updating lowLimit.
+ * This is because dictionaries are allowed to be referenced fully
+ * as long as the last byte of the dictionary is in the window.
+ * Once input has progressed beyond window size, dictionary cannot be referenced anymore.
*
- * In normal dict mode, the dict is between lowLimit and dictLimit. In
- * dictMatchState mode, lowLimit and dictLimit are the same, and the dictionary
- * is below them. forceWindow and dictMatchState are therefore incompatible.
+ * In normal dict mode, the dictionary lies between lowLimit and dictLimit.
+ * In dictMatchState mode, lowLimit and dictLimit are the same,
+ * and the dictionary is below them.
+ * forceWindow and dictMatchState are therefore incompatible.
*/
MEM_STATIC void
ZSTD_window_enforceMaxDist(ZSTD_window_t* window,
- void const* srcEnd,
- U32 maxDist,
- U32* loadedDictEndPtr,
+ const void* blockEnd,
+ U32 maxDist,
+ U32* loadedDictEndPtr,
const ZSTD_matchState_t** dictMatchStatePtr)
{
- U32 const blockEndIdx = (U32)((BYTE const*)srcEnd - window->base);
- U32 loadedDictEnd = (loadedDictEndPtr != NULL) ? *loadedDictEndPtr : 0;
- DEBUGLOG(5, "ZSTD_window_enforceMaxDist: blockEndIdx=%u, maxDist=%u",
- (unsigned)blockEndIdx, (unsigned)maxDist);
+ U32 const blockEndIdx = (U32)((BYTE const*)blockEnd - window->base);
+ U32 const loadedDictEnd = (loadedDictEndPtr != NULL) ? *loadedDictEndPtr : 0;
+ DEBUGLOG(5, "ZSTD_window_enforceMaxDist: blockEndIdx=%u, maxDist=%u, loadedDictEnd=%u",
+ (unsigned)blockEndIdx, (unsigned)maxDist, (unsigned)loadedDictEnd);
+
+ /* - When there is no dictionary : loadedDictEnd == 0.
+ In which case, the test (blockEndIdx > maxDist) is merely to avoid
+ overflowing next operation `newLowLimit = blockEndIdx - maxDist`.
+ - When there is a standard dictionary :
+ Index referential is copied from the dictionary,
+ which means it starts from 0.
+ In which case, loadedDictEnd == dictSize,
+ and it makes sense to compare `blockEndIdx > maxDist + dictSize`
+ since `blockEndIdx` also starts from zero.
+ - When there is an attached dictionary :
+ loadedDictEnd is expressed within the referential of the context,
+ so it can be directly compared against blockEndIdx.
+ */
if (blockEndIdx > maxDist + loadedDictEnd) {
U32 const newLowLimit = blockEndIdx - maxDist;
if (window->lowLimit < newLowLimit) window->lowLimit = newLowLimit;
@@ -708,10 +731,31 @@ ZSTD_window_enforceMaxDist(ZSTD_window_t* window,
(unsigned)window->dictLimit, (unsigned)window->lowLimit);
window->dictLimit = window->lowLimit;
}
- if (loadedDictEndPtr)
- *loadedDictEndPtr = 0;
- if (dictMatchStatePtr)
- *dictMatchStatePtr = NULL;
+ /* On reaching window size, dictionaries are invalidated */
+ if (loadedDictEndPtr) *loadedDictEndPtr = 0;
+ if (dictMatchStatePtr) *dictMatchStatePtr = NULL;
+ }
+}
+
+/* Similar to ZSTD_window_enforceMaxDist(),
+ * but only invalidates dictionary
+ * when input progresses beyond window size. */
+MEM_STATIC void
+ZSTD_checkDictValidity(ZSTD_window_t* window,
+ const void* blockEnd,
+ U32 maxDist,
+ U32* loadedDictEndPtr,
+ const ZSTD_matchState_t** dictMatchStatePtr)
+{
+ U32 const blockEndIdx = (U32)((BYTE const*)blockEnd - window->base);
+ U32 const loadedDictEnd = (loadedDictEndPtr != NULL) ? *loadedDictEndPtr : 0;
+ DEBUGLOG(5, "ZSTD_checkDictValidity: blockEndIdx=%u, maxDist=%u, loadedDictEnd=%u",
+ (unsigned)blockEndIdx, (unsigned)maxDist, (unsigned)loadedDictEnd);
+
+ if (loadedDictEnd && (blockEndIdx > maxDist + loadedDictEnd)) {
+ /* On reaching window size, dictionaries are invalidated */
+ if (loadedDictEndPtr) *loadedDictEndPtr = 0;
+ if (dictMatchStatePtr) *dictMatchStatePtr = NULL;
}
}
diff --git a/thirdparty/zstd/compress/zstd_double_fast.c b/thirdparty/zstd/compress/zstd_double_fast.c
index 47faf6d641..5957255d90 100644
--- a/thirdparty/zstd/compress/zstd_double_fast.c
+++ b/thirdparty/zstd/compress/zstd_double_fast.c
@@ -43,8 +43,7 @@ void ZSTD_fillDoubleHashTable(ZSTD_matchState_t* ms,
/* Only load extra positions for ZSTD_dtlm_full */
if (dtlm == ZSTD_dtlm_fast)
break;
- }
- }
+ } }
}
@@ -63,7 +62,10 @@ size_t ZSTD_compressBlock_doubleFast_generic(
const BYTE* const istart = (const BYTE*)src;
const BYTE* ip = istart;
const BYTE* anchor = istart;
- const U32 prefixLowestIndex = ms->window.dictLimit;
+ const U32 endIndex = (U32)((size_t)(istart - base) + srcSize);
+ const U32 lowestValid = ms->window.dictLimit;
+ const U32 maxDistance = 1U << cParams->windowLog;
+ const U32 prefixLowestIndex = (endIndex - lowestValid > maxDistance) ? endIndex - maxDistance : lowestValid;
const BYTE* const prefixLowest = base + prefixLowestIndex;
const BYTE* const iend = istart + srcSize;
const BYTE* const ilimit = iend - HASH_READ_SIZE;
@@ -95,8 +97,15 @@ size_t ZSTD_compressBlock_doubleFast_generic(
dictCParams->chainLog : hBitsS;
const U32 dictAndPrefixLength = (U32)(ip - prefixLowest + dictEnd - dictStart);
+ DEBUGLOG(5, "ZSTD_compressBlock_doubleFast_generic");
+
assert(dictMode == ZSTD_noDict || dictMode == ZSTD_dictMatchState);
+ /* if a dictionary is attached, it must be within window range */
+ if (dictMode == ZSTD_dictMatchState) {
+ assert(lowestValid + maxDistance >= endIndex);
+ }
+
/* init */
ip += (dictAndPrefixLength == 0);
if (dictMode == ZSTD_noDict) {
@@ -138,7 +147,7 @@ size_t ZSTD_compressBlock_doubleFast_generic(
const BYTE* repMatchEnd = repIndex < prefixLowestIndex ? dictEnd : iend;
mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixLowest) + 4;
ip++;
- ZSTD_storeSeq(seqStore, ip-anchor, anchor, 0, mLength-MINMATCH);
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, 0, mLength-MINMATCH);
goto _match_stored;
}
@@ -147,7 +156,7 @@ size_t ZSTD_compressBlock_doubleFast_generic(
&& ((offset_1 > 0) & (MEM_read32(ip+1-offset_1) == MEM_read32(ip+1)))) {
mLength = ZSTD_count(ip+1+4, ip+1+4-offset_1, iend) + 4;
ip++;
- ZSTD_storeSeq(seqStore, ip-anchor, anchor, 0, mLength-MINMATCH);
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, 0, mLength-MINMATCH);
goto _match_stored;
}
@@ -170,8 +179,7 @@ size_t ZSTD_compressBlock_doubleFast_generic(
offset = (U32)(current - dictMatchIndexL - dictIndexDelta);
while (((ip>anchor) & (dictMatchL>dictStart)) && (ip[-1] == dictMatchL[-1])) { ip--; dictMatchL--; mLength++; } /* catch up */
goto _match_found;
- }
- }
+ } }
if (matchIndexS > prefixLowestIndex) {
/* check prefix short match */
@@ -186,16 +194,14 @@ size_t ZSTD_compressBlock_doubleFast_generic(
if (match > dictStart && MEM_read32(match) == MEM_read32(ip)) {
goto _search_next_long;
- }
- }
+ } }
ip += ((ip-anchor) >> kSearchStrength) + 1;
continue;
_search_next_long:
- {
- size_t const hl3 = ZSTD_hashPtr(ip+1, hBitsL, 8);
+ { size_t const hl3 = ZSTD_hashPtr(ip+1, hBitsL, 8);
size_t const dictHLNext = ZSTD_hashPtr(ip+1, dictHBitsL, 8);
U32 const matchIndexL3 = hashLong[hl3];
const BYTE* matchL3 = base + matchIndexL3;
@@ -221,9 +227,7 @@ _search_next_long:
offset = (U32)(current + 1 - dictMatchIndexL3 - dictIndexDelta);
while (((ip>anchor) & (dictMatchL3>dictStart)) && (ip[-1] == dictMatchL3[-1])) { ip--; dictMatchL3--; mLength++; } /* catch up */
goto _match_found;
- }
- }
- }
+ } } }
/* if no long +1 match, explore the short match we found */
if (dictMode == ZSTD_dictMatchState && matchIndexS < prefixLowestIndex) {
@@ -242,7 +246,7 @@ _match_found:
offset_2 = offset_1;
offset_1 = offset;
- ZSTD_storeSeq(seqStore, ip-anchor, anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
_match_stored:
/* match found */
@@ -250,11 +254,14 @@ _match_stored:
anchor = ip;
if (ip <= ilimit) {
- /* Fill Table */
- hashLong[ZSTD_hashPtr(base+current+2, hBitsL, 8)] =
- hashSmall[ZSTD_hashPtr(base+current+2, hBitsS, mls)] = current+2; /* here because current+2 could be > iend-8 */
- hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] =
- hashSmall[ZSTD_hashPtr(ip-2, hBitsS, mls)] = (U32)(ip-2-base);
+ /* Complementary insertion */
+ /* done after iLimit test, as candidates could be > iend-8 */
+ { U32 const indexToInsert = current+2;
+ hashLong[ZSTD_hashPtr(base+indexToInsert, hBitsL, 8)] = indexToInsert;
+ hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] = (U32)(ip-2-base);
+ hashSmall[ZSTD_hashPtr(base+indexToInsert, hBitsS, mls)] = indexToInsert;
+ hashSmall[ZSTD_hashPtr(ip-1, hBitsS, mls)] = (U32)(ip-1-base);
+ }
/* check immediate repcode */
if (dictMode == ZSTD_dictMatchState) {
@@ -278,8 +285,7 @@ _match_stored:
continue;
}
break;
- }
- }
+ } }
if (dictMode == ZSTD_noDict) {
while ( (ip <= ilimit)
@@ -294,14 +300,15 @@ _match_stored:
ip += rLength;
anchor = ip;
continue; /* faster when present ... (?) */
- } } } }
+ } } }
+ } /* while (ip < ilimit) */
/* save reps for next block */
rep[0] = offset_1 ? offset_1 : offsetSaved;
rep[1] = offset_2 ? offset_2 : offsetSaved;
/* Return the last literals size */
- return iend - anchor;
+ return (size_t)(iend - anchor);
}
@@ -360,10 +367,15 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
const BYTE* anchor = istart;
const BYTE* const iend = istart + srcSize;
const BYTE* const ilimit = iend - 8;
- const U32 prefixStartIndex = ms->window.dictLimit;
const BYTE* const base = ms->window.base;
+ const U32 endIndex = (U32)((size_t)(istart - base) + srcSize);
+ const U32 maxDistance = 1U << cParams->windowLog;
+ const U32 lowestValid = ms->window.lowLimit;
+ const U32 lowLimit = (endIndex - lowestValid > maxDistance) ? endIndex - maxDistance : lowestValid;
+ const U32 dictStartIndex = lowLimit;
+ const U32 dictLimit = ms->window.dictLimit;
+ const U32 prefixStartIndex = (dictLimit > lowLimit) ? dictLimit : lowLimit;
const BYTE* const prefixStart = base + prefixStartIndex;
- const U32 dictStartIndex = ms->window.lowLimit;
const BYTE* const dictBase = ms->window.dictBase;
const BYTE* const dictStart = dictBase + dictStartIndex;
const BYTE* const dictEnd = dictBase + prefixStartIndex;
@@ -371,6 +383,10 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
DEBUGLOG(5, "ZSTD_compressBlock_doubleFast_extDict_generic (srcSize=%zu)", srcSize);
+ /* if extDict is invalidated due to maxDistance, switch to "regular" variant */
+ if (prefixStartIndex == dictStartIndex)
+ return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, mls, ZSTD_noDict);
+
/* Search Loop */
while (ip < ilimit) { /* < instead of <=, because (ip+1) */
const size_t hSmall = ZSTD_hashPtr(ip, hBitsS, mls);
@@ -396,7 +412,7 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
const BYTE* repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixStart) + 4;
ip++;
- ZSTD_storeSeq(seqStore, ip-anchor, anchor, 0, mLength-MINMATCH);
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, 0, mLength-MINMATCH);
} else {
if ((matchLongIndex > dictStartIndex) && (MEM_read64(matchLong) == MEM_read64(ip))) {
const BYTE* const matchEnd = matchLongIndex < prefixStartIndex ? dictEnd : iend;
@@ -407,7 +423,7 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
while (((ip>anchor) & (matchLong>lowMatchPtr)) && (ip[-1] == matchLong[-1])) { ip--; matchLong--; mLength++; } /* catch up */
offset_2 = offset_1;
offset_1 = offset;
- ZSTD_storeSeq(seqStore, ip-anchor, anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
} else if ((matchIndex > dictStartIndex) && (MEM_read32(match) == MEM_read32(ip))) {
size_t const h3 = ZSTD_hashPtr(ip+1, hBitsL, 8);
@@ -432,23 +448,27 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
}
offset_2 = offset_1;
offset_1 = offset;
- ZSTD_storeSeq(seqStore, ip-anchor, anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
} else {
ip += ((ip-anchor) >> kSearchStrength) + 1;
continue;
} }
- /* found a match : store it */
+ /* move to next sequence start */
ip += mLength;
anchor = ip;
if (ip <= ilimit) {
- /* Fill Table */
- hashSmall[ZSTD_hashPtr(base+current+2, hBitsS, mls)] = current+2;
- hashLong[ZSTD_hashPtr(base+current+2, hBitsL, 8)] = current+2;
- hashSmall[ZSTD_hashPtr(ip-2, hBitsS, mls)] = (U32)(ip-2-base);
- hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] = (U32)(ip-2-base);
+ /* Complementary insertion */
+ /* done after iLimit test, as candidates could be > iend-8 */
+ { U32 const indexToInsert = current+2;
+ hashLong[ZSTD_hashPtr(base+indexToInsert, hBitsL, 8)] = indexToInsert;
+ hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] = (U32)(ip-2-base);
+ hashSmall[ZSTD_hashPtr(base+indexToInsert, hBitsS, mls)] = indexToInsert;
+ hashSmall[ZSTD_hashPtr(ip-1, hBitsS, mls)] = (U32)(ip-1-base);
+ }
+
/* check immediate repcode */
while (ip <= ilimit) {
U32 const current2 = (U32)(ip-base);
@@ -475,7 +495,7 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
rep[1] = offset_2;
/* Return the last literals size */
- return iend - anchor;
+ return (size_t)(iend - anchor);
}
diff --git a/thirdparty/zstd/compress/zstd_fast.c b/thirdparty/zstd/compress/zstd_fast.c
index ed997b441c..a05b8a47f1 100644
--- a/thirdparty/zstd/compress/zstd_fast.c
+++ b/thirdparty/zstd/compress/zstd_fast.c
@@ -13,7 +13,8 @@
void ZSTD_fillHashTable(ZSTD_matchState_t* ms,
- void const* end, ZSTD_dictTableLoadMethod_e dtlm)
+ const void* const end,
+ ZSTD_dictTableLoadMethod_e dtlm)
{
const ZSTD_compressionParameters* const cParams = &ms->cParams;
U32* const hashTable = ms->hashTable;
@@ -41,6 +42,7 @@ void ZSTD_fillHashTable(ZSTD_matchState_t* ms,
} } } }
}
+
FORCE_INLINE_TEMPLATE
size_t ZSTD_compressBlock_fast_generic(
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
@@ -58,7 +60,10 @@ size_t ZSTD_compressBlock_fast_generic(
const BYTE* ip0 = istart;
const BYTE* ip1;
const BYTE* anchor = istart;
- const U32 prefixStartIndex = ms->window.dictLimit;
+ const U32 endIndex = (U32)((size_t)(istart - base) + srcSize);
+ const U32 maxDistance = 1U << cParams->windowLog;
+ const U32 validStartIndex = ms->window.dictLimit;
+ const U32 prefixStartIndex = (endIndex - validStartIndex > maxDistance) ? endIndex - maxDistance : validStartIndex;
const BYTE* const prefixStart = base + prefixStartIndex;
const BYTE* const iend = istart + srcSize;
const BYTE* const ilimit = iend - HASH_READ_SIZE;
@@ -165,7 +170,7 @@ _match: /* Requires: ip0, match0, offcode */
rep[1] = offset_2 ? offset_2 : offsetSaved;
/* Return the last literals size */
- return iend - anchor;
+ return (size_t)(iend - anchor);
}
@@ -222,8 +227,15 @@ size_t ZSTD_compressBlock_fast_dictMatchState_generic(
const U32 dictAndPrefixLength = (U32)(ip - prefixStart + dictEnd - dictStart);
const U32 dictHLog = dictCParams->hashLog;
- /* otherwise, we would get index underflow when translating a dict index
- * into a local index */
+ /* if a dictionary is still attached, it necessarily means that
+ * it is within window size. So we just check it. */
+ const U32 maxDistance = 1U << cParams->windowLog;
+ const U32 endIndex = (U32)((size_t)(ip - base) + srcSize);
+ assert(endIndex - prefixStartIndex <= maxDistance);
+ (void)maxDistance; (void)endIndex; /* these variables are not used when assert() is disabled */
+
+ /* ensure there will be no no underflow
+ * when translating a dict index into a local index */
assert(prefixStartIndex >= (U32)(dictEnd - dictBase));
/* init */
@@ -251,7 +263,7 @@ size_t ZSTD_compressBlock_fast_dictMatchState_generic(
const BYTE* const repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixStart) + 4;
ip++;
- ZSTD_storeSeq(seqStore, ip-anchor, anchor, 0, mLength-MINMATCH);
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, 0, mLength-MINMATCH);
} else if ( (matchIndex <= prefixStartIndex) ) {
size_t const dictHash = ZSTD_hashPtr(ip, dictHLog, mls);
U32 const dictMatchIndex = dictHashTable[dictHash];
@@ -271,7 +283,7 @@ size_t ZSTD_compressBlock_fast_dictMatchState_generic(
} /* catch up */
offset_2 = offset_1;
offset_1 = offset;
- ZSTD_storeSeq(seqStore, ip-anchor, anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
}
} else if (MEM_read32(match) != MEM_read32(ip)) {
/* it's not a match, and we're not going to check the dictionary */
@@ -286,7 +298,7 @@ size_t ZSTD_compressBlock_fast_dictMatchState_generic(
&& (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */
offset_2 = offset_1;
offset_1 = offset;
- ZSTD_storeSeq(seqStore, ip-anchor, anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
}
/* match found */
@@ -327,7 +339,7 @@ size_t ZSTD_compressBlock_fast_dictMatchState_generic(
rep[1] = offset_2 ? offset_2 : offsetSaved;
/* Return the last literals size */
- return iend - anchor;
+ return (size_t)(iend - anchor);
}
size_t ZSTD_compressBlock_fast_dictMatchState(
@@ -366,15 +378,24 @@ static size_t ZSTD_compressBlock_fast_extDict_generic(
const BYTE* const istart = (const BYTE*)src;
const BYTE* ip = istart;
const BYTE* anchor = istart;
- const U32 dictStartIndex = ms->window.lowLimit;
+ const U32 endIndex = (U32)((size_t)(istart - base) + srcSize);
+ const U32 maxDistance = 1U << cParams->windowLog;
+ const U32 validLow = ms->window.lowLimit;
+ const U32 lowLimit = (endIndex - validLow > maxDistance) ? endIndex - maxDistance : validLow;
+ const U32 dictStartIndex = lowLimit;
const BYTE* const dictStart = dictBase + dictStartIndex;
- const U32 prefixStartIndex = ms->window.dictLimit;
+ const U32 dictLimit = ms->window.dictLimit;
+ const U32 prefixStartIndex = dictLimit < lowLimit ? lowLimit : dictLimit;
const BYTE* const prefixStart = base + prefixStartIndex;
const BYTE* const dictEnd = dictBase + prefixStartIndex;
const BYTE* const iend = istart + srcSize;
const BYTE* const ilimit = iend - 8;
U32 offset_1=rep[0], offset_2=rep[1];
+ /* switch to "regular" variant if extDict is invalidated due to maxDistance */
+ if (prefixStartIndex == dictStartIndex)
+ return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, mls);
+
/* Search Loop */
while (ip < ilimit) { /* < instead of <=, because (ip+1) */
const size_t h = ZSTD_hashPtr(ip, hlog, mls);
@@ -394,7 +415,7 @@ static size_t ZSTD_compressBlock_fast_extDict_generic(
const BYTE* repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixStart) + 4;
ip++;
- ZSTD_storeSeq(seqStore, ip-anchor, anchor, 0, mLength-MINMATCH);
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, 0, mLength-MINMATCH);
} else {
if ( (matchIndex < dictStartIndex) ||
(MEM_read32(match) != MEM_read32(ip)) ) {
@@ -410,7 +431,7 @@ static size_t ZSTD_compressBlock_fast_extDict_generic(
offset = current - matchIndex;
offset_2 = offset_1;
offset_1 = offset;
- ZSTD_storeSeq(seqStore, ip-anchor, anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
} }
/* found a match : store it */
@@ -445,7 +466,7 @@ static size_t ZSTD_compressBlock_fast_extDict_generic(
rep[1] = offset_2;
/* Return the last literals size */
- return iend - anchor;
+ return (size_t)(iend - anchor);
}
diff --git a/thirdparty/zstd/compress/zstd_lazy.c b/thirdparty/zstd/compress/zstd_lazy.c
index 53f998a437..94d906c01f 100644
--- a/thirdparty/zstd/compress/zstd_lazy.c
+++ b/thirdparty/zstd/compress/zstd_lazy.c
@@ -83,7 +83,10 @@ ZSTD_insertDUBT1(ZSTD_matchState_t* ms,
U32* largerPtr = smallerPtr + 1;
U32 matchIndex = *smallerPtr; /* this candidate is unsorted : next sorted candidate is reached through *smallerPtr, while *largerPtr contains previous unsorted candidate (which is already saved and can be overwritten) */
U32 dummy32; /* to be nullified at the end */
- U32 const windowLow = ms->window.lowLimit;
+ U32 const windowValid = ms->window.lowLimit;
+ U32 const maxDistance = 1U << cParams->windowLog;
+ U32 const windowLow = (current - windowValid > maxDistance) ? current - maxDistance : windowValid;
+
DEBUGLOG(8, "ZSTD_insertDUBT1(%u) (dictLimit=%u, lowLimit=%u)",
current, dictLimit, windowLow);
@@ -239,7 +242,9 @@ ZSTD_DUBT_findBestMatch(ZSTD_matchState_t* ms,
const BYTE* const base = ms->window.base;
U32 const current = (U32)(ip-base);
- U32 const windowLow = ms->window.lowLimit;
+ U32 const maxDistance = 1U << cParams->windowLog;
+ U32 const windowValid = ms->window.lowLimit;
+ U32 const windowLow = (current - windowValid > maxDistance) ? current - maxDistance : windowValid;
U32* const bt = ms->chainTable;
U32 const btLog = cParams->chainLog - 1;
@@ -490,8 +495,10 @@ size_t ZSTD_HcFindBestMatch_generic (
const U32 dictLimit = ms->window.dictLimit;
const BYTE* const prefixStart = base + dictLimit;
const BYTE* const dictEnd = dictBase + dictLimit;
- const U32 lowLimit = ms->window.lowLimit;
const U32 current = (U32)(ip-base);
+ const U32 maxDistance = 1U << cParams->windowLog;
+ const U32 lowValid = ms->window.lowLimit;
+ const U32 lowLimit = (current - lowValid > maxDistance) ? current - maxDistance : lowValid;
const U32 minChain = current > chainSize ? current - chainSize : 0;
U32 nbAttempts = 1U << cParams->searchLog;
size_t ml=4-1;
@@ -653,7 +660,6 @@ size_t ZSTD_compressBlock_lazy_generic(
/* init */
ip += (dictAndPrefixLength == 0);
- ms->nextToUpdate3 = ms->nextToUpdate;
if (dictMode == ZSTD_noDict) {
U32 const maxRep = (U32)(ip - prefixLowest);
if (offset_2 > maxRep) savedOffset = offset_2, offset_2 = 0;
@@ -933,7 +939,6 @@ size_t ZSTD_compressBlock_lazy_extDict_generic(
U32 offset_1 = rep[0], offset_2 = rep[1];
/* init */
- ms->nextToUpdate3 = ms->nextToUpdate;
ip += (ip == prefixStart);
/* Match Loop */
diff --git a/thirdparty/zstd/compress/zstd_ldm.c b/thirdparty/zstd/compress/zstd_ldm.c
index 784d20f3ab..3dcf86e6e8 100644
--- a/thirdparty/zstd/compress/zstd_ldm.c
+++ b/thirdparty/zstd/compress/zstd_ldm.c
@@ -447,7 +447,7 @@ size_t ZSTD_ldm_generateSequences(
if (ZSTD_window_needOverflowCorrection(ldmState->window, chunkEnd)) {
U32 const ldmHSize = 1U << params->hashLog;
U32 const correction = ZSTD_window_correctOverflow(
- &ldmState->window, /* cycleLog */ 0, maxDist, src);
+ &ldmState->window, /* cycleLog */ 0, maxDist, chunkStart);
ZSTD_ldm_reduceTable(ldmState->hashTable, ldmHSize, correction);
}
/* 2. We enforce the maximum offset allowed.
diff --git a/thirdparty/zstd/compress/zstd_opt.c b/thirdparty/zstd/compress/zstd_opt.c
index efb69d3267..e32e542e02 100644
--- a/thirdparty/zstd/compress/zstd_opt.c
+++ b/thirdparty/zstd/compress/zstd_opt.c
@@ -255,13 +255,13 @@ static U32 ZSTD_litLengthPrice(U32 const litLength, const optState_t* const optP
* to provide a cost which is directly comparable to a match ending at same position */
static int ZSTD_litLengthContribution(U32 const litLength, const optState_t* const optPtr, int optLevel)
{
- if (optPtr->priceType >= zop_predef) return WEIGHT(litLength, optLevel);
+ if (optPtr->priceType >= zop_predef) return (int)WEIGHT(litLength, optLevel);
/* dynamic statistics */
{ U32 const llCode = ZSTD_LLcode(litLength);
- int const contribution = (LL_bits[llCode] * BITCOST_MULTIPLIER)
- + WEIGHT(optPtr->litLengthFreq[0], optLevel) /* note: log2litLengthSum cancel out */
- - WEIGHT(optPtr->litLengthFreq[llCode], optLevel);
+ int const contribution = (int)(LL_bits[llCode] * BITCOST_MULTIPLIER)
+ + (int)WEIGHT(optPtr->litLengthFreq[0], optLevel) /* note: log2litLengthSum cancel out */
+ - (int)WEIGHT(optPtr->litLengthFreq[llCode], optLevel);
#if 1
return contribution;
#else
@@ -278,7 +278,7 @@ static int ZSTD_literalsContribution(const BYTE* const literals, U32 const litLe
const optState_t* const optPtr,
int optLevel)
{
- int const contribution = ZSTD_rawLiteralsCost(literals, litLength, optPtr, optLevel)
+ int const contribution = (int)ZSTD_rawLiteralsCost(literals, litLength, optPtr, optLevel)
+ ZSTD_litLengthContribution(litLength, optPtr, optLevel);
return contribution;
}
@@ -372,13 +372,15 @@ MEM_STATIC U32 ZSTD_readMINMATCH(const void* memPtr, U32 length)
/* Update hashTable3 up to ip (excluded)
Assumption : always within prefix (i.e. not within extDict) */
-static U32 ZSTD_insertAndFindFirstIndexHash3 (ZSTD_matchState_t* ms, const BYTE* const ip)
+static U32 ZSTD_insertAndFindFirstIndexHash3 (ZSTD_matchState_t* ms,
+ U32* nextToUpdate3,
+ const BYTE* const ip)
{
U32* const hashTable3 = ms->hashTable3;
U32 const hashLog3 = ms->hashLog3;
const BYTE* const base = ms->window.base;
- U32 idx = ms->nextToUpdate3;
- U32 const target = ms->nextToUpdate3 = (U32)(ip - base);
+ U32 idx = *nextToUpdate3;
+ U32 const target = (U32)(ip - base);
size_t const hash3 = ZSTD_hash3Ptr(ip, hashLog3);
assert(hashLog3 > 0);
@@ -387,6 +389,7 @@ static U32 ZSTD_insertAndFindFirstIndexHash3 (ZSTD_matchState_t* ms, const BYTE*
idx++;
}
+ *nextToUpdate3 = target;
return hashTable3[hash3];
}
@@ -503,9 +506,11 @@ static U32 ZSTD_insertBt1(
} }
*smallerPtr = *largerPtr = 0;
- if (bestLength > 384) return MIN(192, (U32)(bestLength - 384)); /* speed optimization */
- assert(matchEndIdx > current + 8);
- return matchEndIdx - (current + 8);
+ { U32 positions = 0;
+ if (bestLength > 384) positions = MIN(192, (U32)(bestLength - 384)); /* speed optimization */
+ assert(matchEndIdx > current + 8);
+ return MAX(positions, matchEndIdx - (current + 8));
+ }
}
FORCE_INLINE_TEMPLATE
@@ -520,8 +525,13 @@ void ZSTD_updateTree_internal(
DEBUGLOG(6, "ZSTD_updateTree_internal, from %u to %u (dictMode:%u)",
idx, target, dictMode);
- while(idx < target)
- idx += ZSTD_insertBt1(ms, base+idx, iend, mls, dictMode == ZSTD_extDict);
+ while(idx < target) {
+ U32 const forward = ZSTD_insertBt1(ms, base+idx, iend, mls, dictMode == ZSTD_extDict);
+ assert(idx < (U32)(idx + forward));
+ idx += forward;
+ }
+ assert((size_t)(ip - base) <= (size_t)(U32)(-1));
+ assert((size_t)(iend - base) <= (size_t)(U32)(-1));
ms->nextToUpdate = target;
}
@@ -531,16 +541,18 @@ void ZSTD_updateTree(ZSTD_matchState_t* ms, const BYTE* ip, const BYTE* iend) {
FORCE_INLINE_TEMPLATE
U32 ZSTD_insertBtAndGetAllMatches (
+ ZSTD_match_t* matches, /* store result (found matches) in this table (presumed large enough) */
ZSTD_matchState_t* ms,
+ U32* nextToUpdate3,
const BYTE* const ip, const BYTE* const iLimit, const ZSTD_dictMode_e dictMode,
- U32 rep[ZSTD_REP_NUM],
+ const U32 rep[ZSTD_REP_NUM],
U32 const ll0, /* tells if associated literal length is 0 or not. This value must be 0 or 1 */
- ZSTD_match_t* matches,
const U32 lengthToBeat,
U32 const mls /* template */)
{
const ZSTD_compressionParameters* const cParams = &ms->cParams;
U32 const sufficient_len = MIN(cParams->targetLength, ZSTD_OPT_NUM -1);
+ U32 const maxDistance = 1U << cParams->windowLog;
const BYTE* const base = ms->window.base;
U32 const current = (U32)(ip-base);
U32 const hashLog = cParams->hashLog;
@@ -556,8 +568,9 @@ U32 ZSTD_insertBtAndGetAllMatches (
U32 const dictLimit = ms->window.dictLimit;
const BYTE* const dictEnd = dictBase + dictLimit;
const BYTE* const prefixStart = base + dictLimit;
- U32 const btLow = btMask >= current ? 0 : current - btMask;
- U32 const windowLow = ms->window.lowLimit;
+ U32 const btLow = (btMask >= current) ? 0 : current - btMask;
+ U32 const windowValid = ms->window.lowLimit;
+ U32 const windowLow = ((current - windowValid) > maxDistance) ? current - maxDistance : windowValid;
U32 const matchLow = windowLow ? windowLow : 1;
U32* smallerPtr = bt + 2*(current&btMask);
U32* largerPtr = bt + 2*(current&btMask) + 1;
@@ -627,7 +640,7 @@ U32 ZSTD_insertBtAndGetAllMatches (
/* HC3 match finder */
if ((mls == 3) /*static*/ && (bestLength < mls)) {
- U32 const matchIndex3 = ZSTD_insertAndFindFirstIndexHash3(ms, ip);
+ U32 const matchIndex3 = ZSTD_insertAndFindFirstIndexHash3(ms, nextToUpdate3, ip);
if ((matchIndex3 >= matchLow)
& (current - matchIndex3 < (1<<18)) /*heuristic : longer distance likely too expensive*/ ) {
size_t mlen;
@@ -653,9 +666,7 @@ U32 ZSTD_insertBtAndGetAllMatches (
(ip+mlen == iLimit) ) { /* best possible length */
ms->nextToUpdate = current+1; /* skip insertion */
return 1;
- }
- }
- }
+ } } }
/* no dictMatchState lookup: dicts don't have a populated HC3 table */
}
@@ -760,10 +771,13 @@ U32 ZSTD_insertBtAndGetAllMatches (
FORCE_INLINE_TEMPLATE U32 ZSTD_BtGetAllMatches (
+ ZSTD_match_t* matches, /* store result (match found, increasing size) in this table */
ZSTD_matchState_t* ms,
+ U32* nextToUpdate3,
const BYTE* ip, const BYTE* const iHighLimit, const ZSTD_dictMode_e dictMode,
- U32 rep[ZSTD_REP_NUM], U32 const ll0,
- ZSTD_match_t* matches, U32 const lengthToBeat)
+ const U32 rep[ZSTD_REP_NUM],
+ U32 const ll0,
+ U32 const lengthToBeat)
{
const ZSTD_compressionParameters* const cParams = &ms->cParams;
U32 const matchLengthSearch = cParams->minMatch;
@@ -772,12 +786,12 @@ FORCE_INLINE_TEMPLATE U32 ZSTD_BtGetAllMatches (
ZSTD_updateTree_internal(ms, ip, iHighLimit, matchLengthSearch, dictMode);
switch(matchLengthSearch)
{
- case 3 : return ZSTD_insertBtAndGetAllMatches(ms, ip, iHighLimit, dictMode, rep, ll0, matches, lengthToBeat, 3);
+ case 3 : return ZSTD_insertBtAndGetAllMatches(matches, ms, nextToUpdate3, ip, iHighLimit, dictMode, rep, ll0, lengthToBeat, 3);
default :
- case 4 : return ZSTD_insertBtAndGetAllMatches(ms, ip, iHighLimit, dictMode, rep, ll0, matches, lengthToBeat, 4);
- case 5 : return ZSTD_insertBtAndGetAllMatches(ms, ip, iHighLimit, dictMode, rep, ll0, matches, lengthToBeat, 5);
+ case 4 : return ZSTD_insertBtAndGetAllMatches(matches, ms, nextToUpdate3, ip, iHighLimit, dictMode, rep, ll0, lengthToBeat, 4);
+ case 5 : return ZSTD_insertBtAndGetAllMatches(matches, ms, nextToUpdate3, ip, iHighLimit, dictMode, rep, ll0, lengthToBeat, 5);
case 7 :
- case 6 : return ZSTD_insertBtAndGetAllMatches(ms, ip, iHighLimit, dictMode, rep, ll0, matches, lengthToBeat, 6);
+ case 6 : return ZSTD_insertBtAndGetAllMatches(matches, ms, nextToUpdate3, ip, iHighLimit, dictMode, rep, ll0, lengthToBeat, 6);
}
}
@@ -853,6 +867,7 @@ ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms,
U32 const sufficient_len = MIN(cParams->targetLength, ZSTD_OPT_NUM -1);
U32 const minMatch = (cParams->minMatch == 3) ? 3 : 4;
+ U32 nextToUpdate3 = ms->nextToUpdate;
ZSTD_optimal_t* const opt = optStatePtr->priceTable;
ZSTD_match_t* const matches = optStatePtr->matchTable;
@@ -862,7 +877,6 @@ ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms,
DEBUGLOG(5, "ZSTD_compressBlock_opt_generic: current=%u, prefix=%u, nextToUpdate=%u",
(U32)(ip - base), ms->window.dictLimit, ms->nextToUpdate);
assert(optLevel <= 2);
- ms->nextToUpdate3 = ms->nextToUpdate;
ZSTD_rescaleFreqs(optStatePtr, (const BYTE*)src, srcSize, optLevel);
ip += (ip==prefixStart);
@@ -873,7 +887,7 @@ ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms,
/* find first match */
{ U32 const litlen = (U32)(ip - anchor);
U32 const ll0 = !litlen;
- U32 const nbMatches = ZSTD_BtGetAllMatches(ms, ip, iend, dictMode, rep, ll0, matches, minMatch);
+ U32 const nbMatches = ZSTD_BtGetAllMatches(matches, ms, &nextToUpdate3, ip, iend, dictMode, rep, ll0, minMatch);
if (!nbMatches) { ip++; continue; }
/* initialize opt[0] */
@@ -970,7 +984,7 @@ ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms,
U32 const litlen = (opt[cur].mlen == 0) ? opt[cur].litlen : 0;
U32 const previousPrice = opt[cur].price;
U32 const basePrice = previousPrice + ZSTD_litLengthPrice(0, optStatePtr, optLevel);
- U32 const nbMatches = ZSTD_BtGetAllMatches(ms, inr, iend, dictMode, opt[cur].rep, ll0, matches, minMatch);
+ U32 const nbMatches = ZSTD_BtGetAllMatches(matches, ms, &nextToUpdate3, inr, iend, dictMode, opt[cur].rep, ll0, minMatch);
U32 matchNb;
if (!nbMatches) {
DEBUGLOG(7, "rPos:%u : no match found", cur);
@@ -1094,7 +1108,7 @@ _shortestPath: /* cur, last_pos, best_mlen, best_off have to be set */
} /* while (ip < ilimit) */
/* Return the last literals size */
- return iend - anchor;
+ return (size_t)(iend - anchor);
}
@@ -1158,7 +1172,6 @@ ZSTD_initStats_ultra(ZSTD_matchState_t* ms,
ms->window.dictLimit += (U32)srcSize;
ms->window.lowLimit = ms->window.dictLimit;
ms->nextToUpdate = ms->window.dictLimit;
- ms->nextToUpdate3 = ms->window.dictLimit;
/* re-inforce weight of collected statistics */
ZSTD_upscaleStats(&ms->opt);
diff --git a/thirdparty/zstd/compress/zstdmt_compress.c b/thirdparty/zstd/compress/zstdmt_compress.c
index 38fbb90768..9e537b8848 100644
--- a/thirdparty/zstd/compress/zstdmt_compress.c
+++ b/thirdparty/zstd/compress/zstdmt_compress.c
@@ -1129,9 +1129,14 @@ size_t ZSTDMT_toFlushNow(ZSTDMT_CCtx* mtctx)
size_t const produced = ZSTD_isError(cResult) ? 0 : cResult;
size_t const flushed = ZSTD_isError(cResult) ? 0 : jobPtr->dstFlushed;
assert(flushed <= produced);
+ assert(jobPtr->consumed <= jobPtr->src.size);
toFlush = produced - flushed;
- if (toFlush==0 && (jobPtr->consumed >= jobPtr->src.size)) {
- /* doneJobID is not-fully-flushed, but toFlush==0 : doneJobID should be compressing some more data */
+ /* if toFlush==0, nothing is available to flush.
+ * However, jobID is expected to still be active:
+ * if jobID was already completed and fully flushed,
+ * ZSTDMT_flushProduced() should have already moved onto next job.
+ * Therefore, some input has not yet been consumed. */
+ if (toFlush==0) {
assert(jobPtr->consumed < jobPtr->src.size);
}
}
@@ -1148,12 +1153,16 @@ size_t ZSTDMT_toFlushNow(ZSTDMT_CCtx* mtctx)
static unsigned ZSTDMT_computeTargetJobLog(ZSTD_CCtx_params const params)
{
- if (params.ldmParams.enableLdm)
+ unsigned jobLog;
+ if (params.ldmParams.enableLdm) {
/* In Long Range Mode, the windowLog is typically oversized.
* In which case, it's preferable to determine the jobSize
* based on chainLog instead. */
- return MAX(21, params.cParams.chainLog + 4);
- return MAX(20, params.cParams.windowLog + 2);
+ jobLog = MAX(21, params.cParams.chainLog + 4);
+ } else {
+ jobLog = MAX(20, params.cParams.windowLog + 2);
+ }
+ return MIN(jobLog, (unsigned)ZSTDMT_JOBLOG_MAX);
}
static int ZSTDMT_overlapLog_default(ZSTD_strategy strat)
@@ -1197,7 +1206,7 @@ static size_t ZSTDMT_computeOverlapSize(ZSTD_CCtx_params const params)
ovLog = MIN(params.cParams.windowLog, ZSTDMT_computeTargetJobLog(params) - 2)
- overlapRLog;
}
- assert(0 <= ovLog && ovLog <= 30);
+ assert(0 <= ovLog && ovLog <= ZSTD_WINDOWLOG_MAX);
DEBUGLOG(4, "overlapLog : %i", params.overlapLog);
DEBUGLOG(4, "overlap size : %i", 1 << ovLog);
return (ovLog==0) ? 0 : (size_t)1 << ovLog;
@@ -1391,7 +1400,7 @@ size_t ZSTDMT_initCStream_internal(
FORWARD_IF_ERROR( ZSTDMT_resize(mtctx, params.nbWorkers) );
if (params.jobSize != 0 && params.jobSize < ZSTDMT_JOBSIZE_MIN) params.jobSize = ZSTDMT_JOBSIZE_MIN;
- if (params.jobSize > (size_t)ZSTDMT_JOBSIZE_MAX) params.jobSize = ZSTDMT_JOBSIZE_MAX;
+ if (params.jobSize > (size_t)ZSTDMT_JOBSIZE_MAX) params.jobSize = (size_t)ZSTDMT_JOBSIZE_MAX;
mtctx->singleBlockingThread = (pledgedSrcSize <= ZSTDMT_JOBSIZE_MIN); /* do not trigger multi-threading when srcSize is too small */
if (mtctx->singleBlockingThread) {
@@ -1432,6 +1441,8 @@ size_t ZSTDMT_initCStream_internal(
if (mtctx->targetSectionSize == 0) {
mtctx->targetSectionSize = 1ULL << ZSTDMT_computeTargetJobLog(params);
}
+ assert(mtctx->targetSectionSize <= (size_t)ZSTDMT_JOBSIZE_MAX);
+
if (params.rsyncable) {
/* Aim for the targetsectionSize as the average job size. */
U32 const jobSizeMB = (U32)(mtctx->targetSectionSize >> 20);
diff --git a/thirdparty/zstd/compress/zstdmt_compress.h b/thirdparty/zstd/compress/zstdmt_compress.h
index 12e6bcb3a3..12a526087d 100644
--- a/thirdparty/zstd/compress/zstdmt_compress.h
+++ b/thirdparty/zstd/compress/zstdmt_compress.h
@@ -50,6 +50,7 @@
#ifndef ZSTDMT_JOBSIZE_MIN
# define ZSTDMT_JOBSIZE_MIN (1 MB)
#endif
+#define ZSTDMT_JOBLOG_MAX (MEM_32bits() ? 29 : 30)
#define ZSTDMT_JOBSIZE_MAX (MEM_32bits() ? (512 MB) : (1024 MB))
diff --git a/thirdparty/zstd/decompress/zstd_decompress.c b/thirdparty/zstd/decompress/zstd_decompress.c
index 675596f5aa..e42872ad96 100644
--- a/thirdparty/zstd/decompress/zstd_decompress.c
+++ b/thirdparty/zstd/decompress/zstd_decompress.c
@@ -360,8 +360,11 @@ static size_t readSkippableFrameSize(void const* src, size_t srcSize)
sizeU32 = MEM_readLE32((BYTE const*)src + ZSTD_FRAMEIDSIZE);
RETURN_ERROR_IF((U32)(sizeU32 + ZSTD_SKIPPABLEHEADERSIZE) < sizeU32,
frameParameter_unsupported);
-
- return skippableHeaderSize + sizeU32;
+ {
+ size_t const skippableSize = skippableHeaderSize + sizeU32;
+ RETURN_ERROR_IF(skippableSize > srcSize, srcSize_wrong);
+ return skippableSize;
+ }
}
/** ZSTD_findDecompressedSize() :
@@ -378,11 +381,10 @@ unsigned long long ZSTD_findDecompressedSize(const void* src, size_t srcSize)
if ((magicNumber & ZSTD_MAGIC_SKIPPABLE_MASK) == ZSTD_MAGIC_SKIPPABLE_START) {
size_t const skippableSize = readSkippableFrameSize(src, srcSize);
- if (ZSTD_isError(skippableSize))
- return skippableSize;
- if (srcSize < skippableSize) {
+ if (ZSTD_isError(skippableSize)) {
return ZSTD_CONTENTSIZE_ERROR;
}
+ assert(skippableSize <= srcSize);
src = (const BYTE *)src + skippableSize;
srcSize -= skippableSize;
@@ -467,6 +469,8 @@ static ZSTD_frameSizeInfo ZSTD_findFrameSizeInfo(const void* src, size_t srcSize
if ((srcSize >= ZSTD_SKIPPABLEHEADERSIZE)
&& (MEM_readLE32(src) & ZSTD_MAGIC_SKIPPABLE_MASK) == ZSTD_MAGIC_SKIPPABLE_START) {
frameSizeInfo.compressedSize = readSkippableFrameSize(src, srcSize);
+ assert(ZSTD_isError(frameSizeInfo.compressedSize) ||
+ frameSizeInfo.compressedSize <= srcSize);
return frameSizeInfo;
} else {
const BYTE* ip = (const BYTE*)src;
@@ -529,7 +533,6 @@ size_t ZSTD_findFrameCompressedSize(const void *src, size_t srcSize)
return frameSizeInfo.compressedSize;
}
-
/** ZSTD_decompressBound() :
* compatible with legacy mode
* `src` must point to the start of a ZSTD frame or a skippeable frame
@@ -546,6 +549,7 @@ unsigned long long ZSTD_decompressBound(const void* src, size_t srcSize)
unsigned long long const decompressedBound = frameSizeInfo.decompressedBound;
if (ZSTD_isError(compressedSize) || decompressedBound == ZSTD_CONTENTSIZE_ERROR)
return ZSTD_CONTENTSIZE_ERROR;
+ assert(srcSize >= compressedSize);
src = (const BYTE*)src + compressedSize;
srcSize -= compressedSize;
bound += decompressedBound;
@@ -738,9 +742,8 @@ static size_t ZSTD_decompressMultiFrame(ZSTD_DCtx* dctx,
(unsigned)magicNumber, ZSTD_MAGICNUMBER);
if ((magicNumber & ZSTD_MAGIC_SKIPPABLE_MASK) == ZSTD_MAGIC_SKIPPABLE_START) {
size_t const skippableSize = readSkippableFrameSize(src, srcSize);
- if (ZSTD_isError(skippableSize))
- return skippableSize;
- RETURN_ERROR_IF(srcSize < skippableSize, srcSize_wrong);
+ FORWARD_IF_ERROR(skippableSize);
+ assert(skippableSize <= srcSize);
src = (const BYTE *)src + skippableSize;
srcSize -= skippableSize;
diff --git a/thirdparty/zstd/decompress/zstd_decompress_block.c b/thirdparty/zstd/decompress/zstd_decompress_block.c
index a2a7eedcf2..24f4859c56 100644
--- a/thirdparty/zstd/decompress/zstd_decompress_block.c
+++ b/thirdparty/zstd/decompress/zstd_decompress_block.c
@@ -505,7 +505,7 @@ size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr,
*nbSeqPtr = nbSeq;
/* FSE table descriptors */
- RETURN_ERROR_IF(ip+4 > iend, srcSize_wrong); /* minimum possible size */
+ RETURN_ERROR_IF(ip+1 > iend, srcSize_wrong); /* minimum possible size: 1 byte for symbol encoding types */
{ symbolEncodingType_e const LLtype = (symbolEncodingType_e)(*ip >> 6);
symbolEncodingType_e const OFtype = (symbolEncodingType_e)((*ip >> 4) & 3);
symbolEncodingType_e const MLtype = (symbolEncodingType_e)((*ip >> 2) & 3);
@@ -637,9 +637,10 @@ size_t ZSTD_execSequence(BYTE* op,
if (oLitEnd>oend_w) return ZSTD_execSequenceLast7(op, oend, sequence, litPtr, litLimit, prefixStart, virtualStart, dictEnd);
/* copy Literals */
- ZSTD_copy8(op, *litPtr);
if (sequence.litLength > 8)
- ZSTD_wildcopy(op+8, (*litPtr)+8, sequence.litLength - 8); /* note : since oLitEnd <= oend-WILDCOPY_OVERLENGTH, no risk of overwrite beyond oend */
+ ZSTD_wildcopy_16min(op, (*litPtr), sequence.litLength, ZSTD_no_overlap); /* note : since oLitEnd <= oend-WILDCOPY_OVERLENGTH, no risk of overwrite beyond oend */
+ else
+ ZSTD_copy8(op, *litPtr);
op = oLitEnd;
*litPtr = iLitEnd; /* update for next sequence */
@@ -686,13 +687,13 @@ size_t ZSTD_execSequence(BYTE* op,
if (oMatchEnd > oend-(16-MINMATCH)) {
if (op < oend_w) {
- ZSTD_wildcopy(op, match, oend_w - op);
+ ZSTD_wildcopy(op, match, oend_w - op, ZSTD_overlap_src_before_dst);
match += oend_w - op;
op = oend_w;
}
while (op < oMatchEnd) *op++ = *match++;
} else {
- ZSTD_wildcopy(op, match, (ptrdiff_t)sequence.matchLength-8); /* works even if matchLength < 8 */
+ ZSTD_wildcopy(op, match, (ptrdiff_t)sequence.matchLength-8, ZSTD_overlap_src_before_dst); /* works even if matchLength < 8 */
}
return sequenceLength;
}
@@ -717,9 +718,11 @@ size_t ZSTD_execSequenceLong(BYTE* op,
if (oLitEnd > oend_w) return ZSTD_execSequenceLast7(op, oend, sequence, litPtr, litLimit, prefixStart, dictStart, dictEnd);
/* copy Literals */
- ZSTD_copy8(op, *litPtr); /* note : op <= oLitEnd <= oend_w == oend - 8 */
if (sequence.litLength > 8)
- ZSTD_wildcopy(op+8, (*litPtr)+8, sequence.litLength - 8); /* note : since oLitEnd <= oend-WILDCOPY_OVERLENGTH, no risk of overwrite beyond oend */
+ ZSTD_wildcopy_16min(op, *litPtr, sequence.litLength, ZSTD_no_overlap); /* note : since oLitEnd <= oend-WILDCOPY_OVERLENGTH, no risk of overwrite beyond oend */
+ else
+ ZSTD_copy8(op, *litPtr); /* note : op <= oLitEnd <= oend_w == oend - 8 */
+
op = oLitEnd;
*litPtr = iLitEnd; /* update for next sequence */
@@ -766,13 +769,13 @@ size_t ZSTD_execSequenceLong(BYTE* op,
if (oMatchEnd > oend-(16-MINMATCH)) {
if (op < oend_w) {
- ZSTD_wildcopy(op, match, oend_w - op);
+ ZSTD_wildcopy(op, match, oend_w - op, ZSTD_overlap_src_before_dst);
match += oend_w - op;
op = oend_w;
}
while (op < oMatchEnd) *op++ = *match++;
} else {
- ZSTD_wildcopy(op, match, (ptrdiff_t)sequence.matchLength-8); /* works even if matchLength < 8 */
+ ZSTD_wildcopy(op, match, (ptrdiff_t)sequence.matchLength-8, ZSTD_overlap_src_before_dst); /* works even if matchLength < 8 */
}
return sequenceLength;
}
@@ -889,6 +892,7 @@ ZSTD_decodeSequence(seqState_t* seqState, const ZSTD_longOffset_e longOffsets)
}
FORCE_INLINE_TEMPLATE size_t
+DONT_VECTORIZE
ZSTD_decompressSequences_body( ZSTD_DCtx* dctx,
void* dst, size_t maxDstSize,
const void* seqStart, size_t seqSize, int nbSeq,
@@ -918,6 +922,11 @@ ZSTD_decompressSequences_body( ZSTD_DCtx* dctx,
ZSTD_initFseState(&seqState.stateOffb, &seqState.DStream, dctx->OFTptr);
ZSTD_initFseState(&seqState.stateML, &seqState.DStream, dctx->MLTptr);
+ ZSTD_STATIC_ASSERT(
+ BIT_DStream_unfinished < BIT_DStream_completed &&
+ BIT_DStream_endOfBuffer < BIT_DStream_completed &&
+ BIT_DStream_completed < BIT_DStream_overflow);
+
for ( ; (BIT_reloadDStream(&(seqState.DStream)) <= BIT_DStream_completed) && nbSeq ; ) {
nbSeq--;
{ seq_t const sequence = ZSTD_decodeSequence(&seqState, isLongOffset);
@@ -930,6 +939,7 @@ ZSTD_decompressSequences_body( ZSTD_DCtx* dctx,
/* check if reached exact end */
DEBUGLOG(5, "ZSTD_decompressSequences_body: after decode loop, remaining nbSeq : %i", nbSeq);
RETURN_ERROR_IF(nbSeq, corruption_detected);
+ RETURN_ERROR_IF(BIT_reloadDStream(&seqState.DStream) < BIT_DStream_completed, corruption_detected);
/* save reps for next block */
{ U32 i; for (i=0; i<ZSTD_REP_NUM; i++) dctx->entropy.rep[i] = (U32)(seqState.prevOffset[i]); }
}
@@ -1131,6 +1141,7 @@ ZSTD_decompressSequencesLong_default(ZSTD_DCtx* dctx,
#ifndef ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG
static TARGET_ATTRIBUTE("bmi2") size_t
+DONT_VECTORIZE
ZSTD_decompressSequences_bmi2(ZSTD_DCtx* dctx,
void* dst, size_t maxDstSize,
const void* seqStart, size_t seqSize, int nbSeq,
diff --git a/thirdparty/zstd/zstd.h b/thirdparty/zstd/zstd.h
index 53470c18f3..a1910ee223 100644
--- a/thirdparty/zstd/zstd.h
+++ b/thirdparty/zstd/zstd.h
@@ -71,7 +71,7 @@ extern "C" {
/*------ Version ------*/
#define ZSTD_VERSION_MAJOR 1
#define ZSTD_VERSION_MINOR 4
-#define ZSTD_VERSION_RELEASE 0
+#define ZSTD_VERSION_RELEASE 1
#define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE)
ZSTDLIB_API unsigned ZSTD_versionNumber(void); /**< to check runtime library version */
@@ -82,16 +82,16 @@ ZSTDLIB_API unsigned ZSTD_versionNumber(void); /**< to check runtime library v
#define ZSTD_VERSION_STRING ZSTD_EXPAND_AND_QUOTE(ZSTD_LIB_VERSION)
ZSTDLIB_API const char* ZSTD_versionString(void); /* requires v1.3.0+ */
-/***************************************
-* Default constant
-***************************************/
+/* *************************************
+ * Default constant
+ ***************************************/
#ifndef ZSTD_CLEVEL_DEFAULT
# define ZSTD_CLEVEL_DEFAULT 3
#endif
-/***************************************
-* Constants
-***************************************/
+/* *************************************
+ * Constants
+ ***************************************/
/* All magic numbers are supposed read/written to/from files/memory using little-endian convention */
#define ZSTD_MAGICNUMBER 0xFD2FB528 /* valid since v0.8.0 */
@@ -183,9 +183,14 @@ ZSTDLIB_API int ZSTD_maxCLevel(void); /*!< maximum compres
***************************************/
/*= Compression context
* When compressing many times,
- * it is recommended to allocate a context just once, and re-use it for each successive compression operation.
+ * it is recommended to allocate a context just once,
+ * and re-use it for each successive compression operation.
* This will make workload friendlier for system's memory.
- * Use one context per thread for parallel execution in multi-threaded environments. */
+ * Note : re-using context is just a speed / resource optimization.
+ * It doesn't change the compression ratio, which remains identical.
+ * Note 2 : In multi-threaded environments,
+ * use one different context per thread for parallel execution.
+ */
typedef struct ZSTD_CCtx_s ZSTD_CCtx;
ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void);
ZSTDLIB_API size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx);
@@ -380,6 +385,7 @@ typedef enum {
* ZSTD_c_forceMaxWindow
* ZSTD_c_forceAttachDict
* ZSTD_c_literalCompressionMode
+ * ZSTD_c_targetCBlockSize
* Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
* note : never ever use experimentalParam? names directly;
* also, the enums values themselves are unstable and can still change.
@@ -389,6 +395,7 @@ typedef enum {
ZSTD_c_experimentalParam3=1000,
ZSTD_c_experimentalParam4=1001,
ZSTD_c_experimentalParam5=1002,
+ ZSTD_c_experimentalParam6=1003,
} ZSTD_cParameter;
typedef struct {
@@ -657,17 +664,33 @@ ZSTDLIB_API size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
ZSTD_inBuffer* input,
ZSTD_EndDirective endOp);
+
+/* These buffer sizes are softly recommended.
+ * They are not required : ZSTD_compressStream*() happily accepts any buffer size, for both input and output.
+ * Respecting the recommended size just makes it a bit easier for ZSTD_compressStream*(),
+ * reducing the amount of memory shuffling and buffering, resulting in minor performance savings.
+ *
+ * However, note that these recommendations are from the perspective of a C caller program.
+ * If the streaming interface is invoked from some other language,
+ * especially managed ones such as Java or Go, through a foreign function interface such as jni or cgo,
+ * a major performance rule is to reduce crossing such interface to an absolute minimum.
+ * It's not rare that performance ends being spent more into the interface, rather than compression itself.
+ * In which cases, prefer using large buffers, as large as practical,
+ * for both input and output, to reduce the nb of roundtrips.
+ */
ZSTDLIB_API size_t ZSTD_CStreamInSize(void); /**< recommended size for input buffer */
-ZSTDLIB_API size_t ZSTD_CStreamOutSize(void); /**< recommended size for output buffer. Guarantee to successfully flush at least one complete compressed block in all circumstances. */
+ZSTDLIB_API size_t ZSTD_CStreamOutSize(void); /**< recommended size for output buffer. Guarantee to successfully flush at least one complete compressed block. */
-/*******************************************************************************
- * This is a legacy streaming API, and can be replaced by ZSTD_CCtx_reset() and
- * ZSTD_compressStream2(). It is redundant, but is still fully supported.
+
+/* *****************************************************************************
+ * This following is a legacy streaming API.
+ * It can be replaced by ZSTD_CCtx_reset() and ZSTD_compressStream2().
+ * It is redundant, but remains fully supported.
* Advanced parameters and dictionary compression can only be used through the
* new API.
******************************************************************************/
-/**
+/*!
* Equivalent to:
*
* ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
@@ -675,16 +698,16 @@ ZSTDLIB_API size_t ZSTD_CStreamOutSize(void); /**< recommended size for output
* ZSTD_CCtx_setParameter(zcs, ZSTD_c_compressionLevel, compressionLevel);
*/
ZSTDLIB_API size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel);
-/**
+/*!
* Alternative for ZSTD_compressStream2(zcs, output, input, ZSTD_e_continue).
* NOTE: The return value is different. ZSTD_compressStream() returns a hint for
* the next read size (if non-zero and not an error). ZSTD_compressStream2()
- * returns the number of bytes left to flush (if non-zero and not an error).
+ * returns the minimum nb of bytes left to flush (if non-zero and not an error).
*/
ZSTDLIB_API size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
-/** Equivalent to ZSTD_compressStream2(zcs, output, &emptyInput, ZSTD_e_flush). */
+/*! Equivalent to ZSTD_compressStream2(zcs, output, &emptyInput, ZSTD_e_flush). */
ZSTDLIB_API size_t ZSTD_flushStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
-/** Equivalent to ZSTD_compressStream2(zcs, output, &emptyInput, ZSTD_e_end). */
+/*! Equivalent to ZSTD_compressStream2(zcs, output, &emptyInput, ZSTD_e_end). */
ZSTDLIB_API size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
@@ -969,7 +992,7 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
#endif /* ZSTD_H_235446 */
-/****************************************************************************************
+/* **************************************************************************************
* ADVANCED AND EXPERIMENTAL FUNCTIONS
****************************************************************************************
* The definitions in the following section are considered experimental.
@@ -1037,6 +1060,10 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
#define ZSTD_LDM_HASHRATELOG_MIN 0
#define ZSTD_LDM_HASHRATELOG_MAX (ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN)
+/* Advanced parameter bounds */
+#define ZSTD_TARGETCBLOCKSIZE_MIN 64
+#define ZSTD_TARGETCBLOCKSIZE_MAX ZSTD_BLOCKSIZE_MAX
+
/* internal */
#define ZSTD_HASHLOG3_MAX 17
@@ -1162,7 +1189,7 @@ typedef enum {
* however it does mean that all frame data must be present and valid. */
ZSTDLIB_API unsigned long long ZSTD_findDecompressedSize(const void* src, size_t srcSize);
-/** ZSTD_decompressBound() :
+/*! ZSTD_decompressBound() :
* `src` should point to the start of a series of ZSTD encoded and/or skippable frames
* `srcSize` must be the _exact_ size of this series
* (i.e. there should be a frame boundary at `src + srcSize`)
@@ -1409,6 +1436,11 @@ ZSTDLIB_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const void* pre
*/
#define ZSTD_c_literalCompressionMode ZSTD_c_experimentalParam5
+/* Tries to fit compressed block size to be around targetCBlockSize.
+ * No target when targetCBlockSize == 0.
+ * There is no guarantee on compressed block size (default:0) */
+#define ZSTD_c_targetCBlockSize ZSTD_c_experimentalParam6
+
/*! ZSTD_CCtx_getParameter() :
* Get the requested compression parameter value, selected by enum ZSTD_cParameter,
* and store it into int* value.
@@ -1843,7 +1875,7 @@ typedef struct {
unsigned checksumFlag;
} ZSTD_frameHeader;
-/** ZSTD_getFrameHeader() :
+/*! ZSTD_getFrameHeader() :
* decode Frame Header, or requires larger `srcSize`.
* @return : 0, `zfhPtr` is correctly filled,
* >0, `srcSize` is too small, value is wanted `srcSize` amount,