1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 08:13:04 +04:00

Compare commits

..

5 Commits

Author SHA1 Message Date
Alexander Smorkalov 5199850039 Version update to 4.8.1. 2023-09-27 13:18:31 +03:00
Alexander Smorkalov 4ddd1181df Use proper branch for CI pipelines. 2023-09-27 12:22:37 +03:00
Alexander Smorkalov f11c74d52a CI update for 4.8.x branch. 2023-09-27 10:48:19 +03:00
Vincent Rabaud 5d591b2a17 Merge pull request #24274 from vrabaud:webp_1.3.2
Merge pull request #24274 from vrabaud:webp_1.3.2
 
Bump libwebp to 1.3.2 #24274

This is version [c1ffd9a](https://chromium.googlesource.com/webm/libwebp/+/c1ffd9ac7593894c40a1de99d03f0b7af8af2577)
It is 1.3.2 with a few patches that were made right after to help compilation.
No need for patches on the OpenCV side!

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
2023-09-27 10:10:12 +03:00
Zihao Mu 31c803d15e Merge pull request #23952 from zihaomu:fix_depth_conv_5x5
DNN: optimize the speed of general Depth-wise #23952

Try to solve the issue: https://github.com/opencv/opencv/issues/23941

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
2023-09-27 10:08:16 +03:00
949 changed files with 23412 additions and 44694 deletions
+2 -2
View File
@@ -15,12 +15,12 @@ body:
Please provide the following system information to help us diagnose the bug. For example: Please provide the following system information to help us diagnose the bug. For example:
// example for c++ user // example for c++ user
OpenCV version: 4.8.0 OpenCV version: 4.6.0
Operating System / Platform: Ubuntu 20.04 Operating System / Platform: Ubuntu 20.04
Compiler & compiler version: GCC 9.3.0 Compiler & compiler version: GCC 9.3.0
// example for python user // example for python user
OpenCV python version: 4.8.0.74 OpenCV python version: 4.6.0.66
Operating System / Platform: Ubuntu 20.04 Operating System / Platform: Ubuntu 20.04
Python version: 3.9.6 Python version: 3.9.6
validations: validations:
+1 -1
View File
@@ -12,7 +12,7 @@ body:
attributes: attributes:
label: Describe the doc issue label: Describe the doc issue
description: > description: >
Please provide a clear and concise description of what content in https://docs.opencv.org/ is an issue. Note that there are multiple active branches, such as 4.x and 5.x, so please specify the branch with the problem. Please provide a clear and concise description of what content in https://docs.opencv.org/ is an issue. Note that there are multiple active branches, such as 3.4, 4.x and 5.x, so please specify the branch with the problem.
placeholder: | placeholder: |
A clear and concise description of what content in https://docs.opencv.org/ is an issue. A clear and concise description of what content in https://docs.opencv.org/ is an issue.
+15 -24
View File
@@ -1,56 +1,47 @@
name: PR:4.x name: PR:4.8.x
on: on:
pull_request: pull_request:
branches: branches:
- 4.x - 4.8.x
jobs: jobs:
Ubuntu2004-ARM64: Ubuntu2004-ARM64:
uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-ARM64.yaml@main uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-ARM64.yaml@release_4.8.x
Ubuntu2004-ARM64-Debug: Ubuntu2004-ARM64-Debug:
uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-ARM64-Debug.yaml@main uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-ARM64-Debug.yaml@release_4.8.x
Ubuntu2004-x64: Ubuntu2004-x64:
uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-U20.yaml@main uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-U20.yaml@release_4.8.x
Ubuntu2004-x64-OpenVINO:
uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-U20-OpenVINO.yaml@main
Ubuntu2204-x64:
uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-U22.yaml@main
Ubuntu2004-x64-CUDA: Ubuntu2004-x64-CUDA:
if: "${{ contains(github.event.pull_request.labels.*.name, 'category: dnn') }} || ${{ contains(github.event.pull_request.labels.*.name, 'category: dnn (onnx)') }}" if: "${{ contains(github.event.pull_request.labels.*.name, 'category: dnn') }} || ${{ contains(github.event.pull_request.labels.*.name, 'category: dnn (onnx)') }}"
uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-U20-Cuda.yaml@main uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-U20-Cuda.yaml@release_4.8.x
Windows10-x64: Windows10-x64:
uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-W10.yaml@main uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-W10.yaml@release_4.8.x
Windows10-x64-Vulkan: Windows10-x64-Vulkan:
uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-W10-Vulkan.yaml@main uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-W10-Vulkan.yaml@release_4.8.x
macOS-ARM64: macOS-ARM64:
uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-macOS-ARM64.yaml@main uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-macOS-ARM64.yaml@release_4.8.x
macOS-x64: macOS-x64:
uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-macOS-x86_64.yaml@main uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-macOS-x86_64.yaml@release_4.8.x
macOS-ARM64-Vulkan: macOS-ARM64-Vulkan:
uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-macOS-ARM64-Vulkan.yaml@main uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-macOS-ARM64-Vulkan.yaml@release_4.8.x
iOS: iOS:
uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-iOS.yaml@main uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-iOS.yaml@release_4.8.x
Android: Android:
uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-Android.yaml@main uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-Android.yaml@release_4.8.x
TIM-VX: TIM-VX:
uses: opencv/ci-gha-workflow/.github/workflows/OCV-timvx-backend-tests-4.x.yml@main uses: opencv/ci-gha-workflow/.github/workflows/OCV-timvx-backend-tests-4.x.yml@release_4.8.x
docs: docs:
uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-docs.yaml@main uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-docs.yaml@release_4.8.x
Linux-RISC-V-Clang:
uses: opencv/ci-gha-workflow/.github/workflows/OCV-PR-4.x-RISCV.yaml@main
-8
View File
@@ -42,14 +42,6 @@ endif()
if(WITH_NEON) if(WITH_NEON)
target_compile_definitions(carotene_objs PRIVATE "-DWITH_NEON") target_compile_definitions(carotene_objs PRIVATE "-DWITH_NEON")
if(NOT DEFINED CAROTENE_NEON_ARCH )
elseif(CAROTENE_NEON_ARCH EQUAL 8)
target_compile_definitions(carotene_objs PRIVATE "-DCAROTENE_NEON_ARCH=8")
elseif(CAROTENE_NEON_ARCH EQUAL 7)
target_compile_definitions(carotene_objs PRIVATE "-DCAROTENE_NEON_ARCH=7")
else()
target_compile_definitions(carotene_objs PRIVATE "-DCAROTENE_NEON_ARCH=0")
endif()
endif() endif()
# we add dummy file to fix XCode build # we add dummy file to fix XCode build
+6 -7
View File
@@ -39,7 +39,6 @@
#include "common.hpp" #include "common.hpp"
#include "vtransform.hpp" #include "vtransform.hpp"
#include "vround_helper.hpp"
namespace CAROTENE_NS { namespace CAROTENE_NS {
@@ -107,7 +106,7 @@ template <> struct wAdd<s32>
{ {
valpha = vdupq_n_f32(_alpha); valpha = vdupq_n_f32(_alpha);
vbeta = vdupq_n_f32(_beta); vbeta = vdupq_n_f32(_beta);
vgamma = vdupq_n_f32(_gamma); vgamma = vdupq_n_f32(_gamma + 0.5);
} }
void operator() (const VecTraits<s32>::vec128 & v_src0, void operator() (const VecTraits<s32>::vec128 & v_src0,
@@ -119,7 +118,7 @@ template <> struct wAdd<s32>
vs1 = vmlaq_f32(vgamma, vs1, valpha); vs1 = vmlaq_f32(vgamma, vs1, valpha);
vs1 = vmlaq_f32(vs1, vs2, vbeta); vs1 = vmlaq_f32(vs1, vs2, vbeta);
v_dst = vroundq_s32_f32(vs1); v_dst = vcvtq_s32_f32(vs1);
} }
void operator() (const VecTraits<s32>::vec64 & v_src0, void operator() (const VecTraits<s32>::vec64 & v_src0,
@@ -131,7 +130,7 @@ template <> struct wAdd<s32>
vs1 = vmla_f32(vget_low(vgamma), vs1, vget_low(valpha)); vs1 = vmla_f32(vget_low(vgamma), vs1, vget_low(valpha));
vs1 = vmla_f32(vs1, vs2, vget_low(vbeta)); vs1 = vmla_f32(vs1, vs2, vget_low(vbeta));
v_dst = vround_s32_f32(vs1); v_dst = vcvt_s32_f32(vs1);
} }
void operator() (const s32 * src0, const s32 * src1, s32 * dst) const void operator() (const s32 * src0, const s32 * src1, s32 * dst) const
@@ -151,7 +150,7 @@ template <> struct wAdd<u32>
{ {
valpha = vdupq_n_f32(_alpha); valpha = vdupq_n_f32(_alpha);
vbeta = vdupq_n_f32(_beta); vbeta = vdupq_n_f32(_beta);
vgamma = vdupq_n_f32(_gamma); vgamma = vdupq_n_f32(_gamma + 0.5);
} }
void operator() (const VecTraits<u32>::vec128 & v_src0, void operator() (const VecTraits<u32>::vec128 & v_src0,
@@ -163,7 +162,7 @@ template <> struct wAdd<u32>
vs1 = vmlaq_f32(vgamma, vs1, valpha); vs1 = vmlaq_f32(vgamma, vs1, valpha);
vs1 = vmlaq_f32(vs1, vs2, vbeta); vs1 = vmlaq_f32(vs1, vs2, vbeta);
v_dst = vroundq_u32_f32(vs1); v_dst = vcvtq_u32_f32(vs1);
} }
void operator() (const VecTraits<u32>::vec64 & v_src0, void operator() (const VecTraits<u32>::vec64 & v_src0,
@@ -175,7 +174,7 @@ template <> struct wAdd<u32>
vs1 = vmla_f32(vget_low(vgamma), vs1, vget_low(valpha)); vs1 = vmla_f32(vget_low(vgamma), vs1, vget_low(valpha));
vs1 = vmla_f32(vs1, vs2, vget_low(vbeta)); vs1 = vmla_f32(vs1, vs2, vget_low(vbeta));
v_dst = vround_u32_f32(vs1); v_dst = vcvt_u32_f32(vs1);
} }
void operator() (const u32 * src0, const u32 * src1, u32 * dst) const void operator() (const u32 * src0, const u32 * src1, u32 * dst) const
+8 -7
View File
@@ -41,7 +41,6 @@
#include "common.hpp" #include "common.hpp"
#include "saturate_cast.hpp" #include "saturate_cast.hpp"
#include "vround_helper.hpp"
namespace CAROTENE_NS { namespace CAROTENE_NS {
@@ -199,6 +198,7 @@ void blur3x3(const Size2D &size, s32 cn,
//#define FLOAT_VARIANT_1_9 //#define FLOAT_VARIANT_1_9
#ifdef FLOAT_VARIANT_1_9 #ifdef FLOAT_VARIANT_1_9
float32x4_t v1_9 = vdupq_n_f32 (1.0/9.0); float32x4_t v1_9 = vdupq_n_f32 (1.0/9.0);
float32x4_t v0_5 = vdupq_n_f32 (.5);
#else #else
const int16x8_t vScale = vmovq_n_s16(3640); const int16x8_t vScale = vmovq_n_s16(3640);
#endif #endif
@@ -283,8 +283,8 @@ void blur3x3(const Size2D &size, s32 cn,
uint32x4_t tres2 = vmovl_u16(vget_high_u16(t0)); uint32x4_t tres2 = vmovl_u16(vget_high_u16(t0));
float32x4_t vf1 = vmulq_f32(v1_9, vcvtq_f32_u32(tres1)); float32x4_t vf1 = vmulq_f32(v1_9, vcvtq_f32_u32(tres1));
float32x4_t vf2 = vmulq_f32(v1_9, vcvtq_f32_u32(tres2)); float32x4_t vf2 = vmulq_f32(v1_9, vcvtq_f32_u32(tres2));
tres1 = internal::vroundq_u32_f32(vf1); tres1 = vcvtq_u32_f32(vaddq_f32(vf1, v0_5));
tres2 = internal::vroundq_u32_f32(vf2); tres2 = vcvtq_u32_f32(vaddq_f32(vf2, v0_5));
t0 = vcombine_u16(vmovn_u32(tres1),vmovn_u32(tres2)); t0 = vcombine_u16(vmovn_u32(tres1),vmovn_u32(tres2));
vst1_u8(drow + x - 8, vmovn_u16(t0)); vst1_u8(drow + x - 8, vmovn_u16(t0));
#else #else
@@ -445,8 +445,8 @@ void blur3x3(const Size2D &size, s32 cn,
uint32x4_t tres2 = vmovl_u16(vget_high_u16(t0)); uint32x4_t tres2 = vmovl_u16(vget_high_u16(t0));
float32x4_t vf1 = vmulq_f32(v1_9, vcvtq_f32_u32(tres1)); float32x4_t vf1 = vmulq_f32(v1_9, vcvtq_f32_u32(tres1));
float32x4_t vf2 = vmulq_f32(v1_9, vcvtq_f32_u32(tres2)); float32x4_t vf2 = vmulq_f32(v1_9, vcvtq_f32_u32(tres2));
tres1 = internal::vroundq_u32_f32(vf1); tres1 = vcvtq_u32_f32(vaddq_f32(vf1, v0_5));
tres2 = internal::vroundq_u32_f32(vf2); tres2 = vcvtq_u32_f32(vaddq_f32(vf2, v0_5));
t0 = vcombine_u16(vmovn_u32(tres1),vmovn_u32(tres2)); t0 = vcombine_u16(vmovn_u32(tres1),vmovn_u32(tres2));
vst1_u8(drow + x - 8, vmovn_u16(t0)); vst1_u8(drow + x - 8, vmovn_u16(t0));
#else #else
@@ -508,6 +508,7 @@ void blur5x5(const Size2D &size, s32 cn,
#define FLOAT_VARIANT_1_25 #define FLOAT_VARIANT_1_25
#ifdef FLOAT_VARIANT_1_25 #ifdef FLOAT_VARIANT_1_25
float32x4_t v1_25 = vdupq_n_f32 (1.0f/25.0f); float32x4_t v1_25 = vdupq_n_f32 (1.0f/25.0f);
float32x4_t v0_5 = vdupq_n_f32 (.5f);
#else #else
const int16x8_t vScale = vmovq_n_s16(1310); const int16x8_t vScale = vmovq_n_s16(1310);
#endif #endif
@@ -751,8 +752,8 @@ void blur5x5(const Size2D &size, s32 cn,
uint32x4_t tres2 = vmovl_u16(vget_high_u16(t0)); uint32x4_t tres2 = vmovl_u16(vget_high_u16(t0));
float32x4_t vf1 = vmulq_f32(v1_25, vcvtq_f32_u32(tres1)); float32x4_t vf1 = vmulq_f32(v1_25, vcvtq_f32_u32(tres1));
float32x4_t vf2 = vmulq_f32(v1_25, vcvtq_f32_u32(tres2)); float32x4_t vf2 = vmulq_f32(v1_25, vcvtq_f32_u32(tres2));
tres1 = internal::vroundq_u32_f32(vf1); tres1 = vcvtq_u32_f32(vaddq_f32(vf1, v0_5));
tres2 = internal::vroundq_u32_f32(vf2); tres2 = vcvtq_u32_f32(vaddq_f32(vf2, v0_5));
t0 = vcombine_u16(vmovn_u32(tres1),vmovn_u32(tres2)); t0 = vcombine_u16(vmovn_u32(tres1),vmovn_u32(tres2));
vst1_u8(drow + x - 8, vmovn_u16(t0)); vst1_u8(drow + x - 8, vmovn_u16(t0));
#else #else
+11 -5
View File
@@ -40,7 +40,6 @@
#include "common.hpp" #include "common.hpp"
#include "saturate_cast.hpp" #include "saturate_cast.hpp"
#include "vround_helper.hpp"
namespace CAROTENE_NS { namespace CAROTENE_NS {
@@ -1167,10 +1166,17 @@ inline uint8x8x3_t convertToHSV(const uint8x8_t vR, const uint8x8_t vG, const ui
vSt3 = vmulq_f32(vHF1, vDivTab); vSt3 = vmulq_f32(vHF1, vDivTab);
vSt4 = vmulq_f32(vHF2, vDivTab); vSt4 = vmulq_f32(vHF2, vDivTab);
uint32x4_t vRes1 = internal::vroundq_u32_f32(vSt1); float32x4_t bias = vdupq_n_f32(0.5f);
uint32x4_t vRes2 = internal::vroundq_u32_f32(vSt2);
uint32x4_t vRes3 = internal::vroundq_u32_f32(vSt3); vSt1 = vaddq_f32(vSt1, bias);
uint32x4_t vRes4 = internal::vroundq_u32_f32(vSt4); vSt2 = vaddq_f32(vSt2, bias);
vSt3 = vaddq_f32(vSt3, bias);
vSt4 = vaddq_f32(vSt4, bias);
uint32x4_t vRes1 = vcvtq_u32_f32(vSt1);
uint32x4_t vRes2 = vcvtq_u32_f32(vSt2);
uint32x4_t vRes3 = vcvtq_u32_f32(vSt3);
uint32x4_t vRes4 = vcvtq_u32_f32(vSt4);
int32x4_t vH_L = vmovl_s16(vget_low_s16(vDiff4)); int32x4_t vH_L = vmovl_s16(vget_low_s16(vDiff4));
int32x4_t vH_H = vmovl_s16(vget_high_s16(vDiff4)); int32x4_t vH_H = vmovl_s16(vget_high_s16(vDiff4));
-11
View File
@@ -58,17 +58,6 @@
namespace CAROTENE_NS { namespace internal { namespace CAROTENE_NS { namespace internal {
#ifndef CAROTENE_NEON_ARCH
# if defined(__aarch64__) || defined(__aarch32__)
# define CAROTENE_NEON_ARCH 8
# else
# define CAROTENE_NEON_ARCH 7
# endif
#endif
#if ( !defined(__aarch64__) && !defined(__aarch32__) ) && (CAROTENE_NEON_ARCH == 8 )
# error("ARMv7 doen't support A32/A64 Neon instructions")
#endif
inline void prefetch(const void *ptr, size_t offset = 32*10) inline void prefetch(const void *ptr, size_t offset = 32*10)
{ {
#if defined __GNUC__ #if defined __GNUC__
+107 -108
View File
@@ -38,7 +38,6 @@
*/ */
#include "common.hpp" #include "common.hpp"
#include "vround_helper.hpp"
namespace CAROTENE_NS { namespace CAROTENE_NS {
@@ -186,7 +185,7 @@ CVTS_FUNC1(u8, 16,
#else #else
CVTS_FUNC1(u8, 16, CVTS_FUNC1(u8, 16,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 16) for (size_t i = 0; i < w; i += 16)
{ {
@@ -210,10 +209,10 @@ CVTS_FUNC1(u8, 16,
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
vline3_f32 = vaddq_f32(vline3_f32, vshift); vline3_f32 = vaddq_f32(vline3_f32, vshift);
vline4_f32 = vaddq_f32(vline4_f32, vshift); vline4_f32 = vaddq_f32(vline4_f32, vshift);
int32x4_t vline1_s32 = internal::vroundq_s32_f32(vline1_f32); int32x4_t vline1_s32 = vcvtq_s32_f32(vline1_f32);
int32x4_t vline2_s32 = internal::vroundq_s32_f32(vline2_f32); int32x4_t vline2_s32 = vcvtq_s32_f32(vline2_f32);
int32x4_t vline3_s32 = internal::vroundq_s32_f32(vline3_f32); int32x4_t vline3_s32 = vcvtq_s32_f32(vline3_f32);
int32x4_t vline4_s32 = internal::vroundq_s32_f32(vline4_f32); int32x4_t vline4_s32 = vcvtq_s32_f32(vline4_f32);
uint16x8_t vRes1_u16 = vcombine_u16(vqmovun_s32(vline1_s32), vqmovun_s32(vline2_s32)); uint16x8_t vRes1_u16 = vcombine_u16(vqmovun_s32(vline1_s32), vqmovun_s32(vline2_s32));
uint16x8_t vRes2_u16 = vcombine_u16(vqmovun_s32(vline3_s32), vqmovun_s32(vline4_s32)); uint16x8_t vRes2_u16 = vcombine_u16(vqmovun_s32(vline3_s32), vqmovun_s32(vline4_s32));
vst1q_u8(_dst + i, vcombine_u8(vqmovn_u16(vRes1_u16), vqmovn_u16(vRes2_u16))); vst1q_u8(_dst + i, vcombine_u8(vqmovn_u16(vRes1_u16), vqmovn_u16(vRes2_u16)));
@@ -271,7 +270,7 @@ CVTS_FUNC(u8, s8, 16,
#else #else
CVTS_FUNC(u8, s8, 16, CVTS_FUNC(u8, s8, 16,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 16) for (size_t i = 0; i < w; i += 16)
{ {
@@ -295,10 +294,10 @@ CVTS_FUNC(u8, s8, 16,
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
vline3_f32 = vaddq_f32(vline3_f32, vshift); vline3_f32 = vaddq_f32(vline3_f32, vshift);
vline4_f32 = vaddq_f32(vline4_f32, vshift); vline4_f32 = vaddq_f32(vline4_f32, vshift);
int32x4_t vline1_s32 = internal::vroundq_s32_f32(vline1_f32); int32x4_t vline1_s32 = vcvtq_s32_f32(vline1_f32);
int32x4_t vline2_s32 = internal::vroundq_s32_f32(vline2_f32); int32x4_t vline2_s32 = vcvtq_s32_f32(vline2_f32);
int32x4_t vline3_s32 = internal::vroundq_s32_f32(vline3_f32); int32x4_t vline3_s32 = vcvtq_s32_f32(vline3_f32);
int32x4_t vline4_s32 = internal::vroundq_s32_f32(vline4_f32); int32x4_t vline4_s32 = vcvtq_s32_f32(vline4_f32);
int16x8_t vRes1_u16 = vcombine_s16(vqmovn_s32(vline1_s32), vqmovn_s32(vline2_s32)); int16x8_t vRes1_u16 = vcombine_s16(vqmovn_s32(vline1_s32), vqmovn_s32(vline2_s32));
int16x8_t vRes2_u16 = vcombine_s16(vqmovn_s32(vline3_s32), vqmovn_s32(vline4_s32)); int16x8_t vRes2_u16 = vcombine_s16(vqmovn_s32(vline3_s32), vqmovn_s32(vline4_s32));
vst1q_s8(_dst + i, vcombine_s8(vqmovn_s16(vRes1_u16), vqmovn_s16(vRes2_u16))); vst1q_s8(_dst + i, vcombine_s8(vqmovn_s16(vRes1_u16), vqmovn_s16(vRes2_u16)));
@@ -356,7 +355,7 @@ CVTS_FUNC(u8, u16, 16,
#else #else
CVTS_FUNC(u8, u16, 16, CVTS_FUNC(u8, u16, 16,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 16) for (size_t i = 0; i < w; i += 16)
{ {
@@ -380,10 +379,10 @@ CVTS_FUNC(u8, u16, 16,
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
vline3_f32 = vaddq_f32(vline3_f32, vshift); vline3_f32 = vaddq_f32(vline3_f32, vshift);
vline4_f32 = vaddq_f32(vline4_f32, vshift); vline4_f32 = vaddq_f32(vline4_f32, vshift);
int32x4_t vline1_s32 = internal::vroundq_s32_f32(vline1_f32); int32x4_t vline1_s32 = vcvtq_s32_f32(vline1_f32);
int32x4_t vline2_s32 = internal::vroundq_s32_f32(vline2_f32); int32x4_t vline2_s32 = vcvtq_s32_f32(vline2_f32);
int32x4_t vline3_s32 = internal::vroundq_s32_f32(vline3_f32); int32x4_t vline3_s32 = vcvtq_s32_f32(vline3_f32);
int32x4_t vline4_s32 = internal::vroundq_s32_f32(vline4_f32); int32x4_t vline4_s32 = vcvtq_s32_f32(vline4_f32);
vst1q_u16(_dst + i + 0, vcombine_u16(vqmovun_s32(vline1_s32), vqmovun_s32(vline2_s32))); vst1q_u16(_dst + i + 0, vcombine_u16(vqmovun_s32(vline1_s32), vqmovun_s32(vline2_s32)));
vst1q_u16(_dst + i + 8, vcombine_u16(vqmovun_s32(vline3_s32), vqmovun_s32(vline4_s32))); vst1q_u16(_dst + i + 8, vcombine_u16(vqmovun_s32(vline3_s32), vqmovun_s32(vline4_s32)));
} }
@@ -440,7 +439,7 @@ CVTS_FUNC(u8, s16, 16,
#else #else
CVTS_FUNC(u8, s16, 16, CVTS_FUNC(u8, s16, 16,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 16) for (size_t i = 0; i < w; i += 16)
{ {
@@ -464,10 +463,10 @@ CVTS_FUNC(u8, s16, 16,
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
vline3_f32 = vaddq_f32(vline3_f32, vshift); vline3_f32 = vaddq_f32(vline3_f32, vshift);
vline4_f32 = vaddq_f32(vline4_f32, vshift); vline4_f32 = vaddq_f32(vline4_f32, vshift);
int32x4_t vline1_s32 = internal::vroundq_s32_f32(vline1_f32); int32x4_t vline1_s32 = vcvtq_s32_f32(vline1_f32);
int32x4_t vline2_s32 = internal::vroundq_s32_f32(vline2_f32); int32x4_t vline2_s32 = vcvtq_s32_f32(vline2_f32);
int32x4_t vline3_s32 = internal::vroundq_s32_f32(vline3_f32); int32x4_t vline3_s32 = vcvtq_s32_f32(vline3_f32);
int32x4_t vline4_s32 = internal::vroundq_s32_f32(vline4_f32); int32x4_t vline4_s32 = vcvtq_s32_f32(vline4_f32);
vst1q_s16(_dst + i + 0, vcombine_s16(vqmovn_s32(vline1_s32), vqmovn_s32(vline2_s32))); vst1q_s16(_dst + i + 0, vcombine_s16(vqmovn_s32(vline1_s32), vqmovn_s32(vline2_s32)));
vst1q_s16(_dst + i + 8, vcombine_s16(vqmovn_s32(vline3_s32), vqmovn_s32(vline4_s32))); vst1q_s16(_dst + i + 8, vcombine_s16(vqmovn_s32(vline3_s32), vqmovn_s32(vline4_s32)));
} }
@@ -527,7 +526,7 @@ CVTS_FUNC(u8, s32, 16,
#else #else
CVTS_FUNC(u8, s32, 16, CVTS_FUNC(u8, s32, 16,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 16) for (size_t i = 0; i < w; i += 16)
{ {
@@ -551,10 +550,10 @@ CVTS_FUNC(u8, s32, 16,
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
vline3_f32 = vaddq_f32(vline3_f32, vshift); vline3_f32 = vaddq_f32(vline3_f32, vshift);
vline4_f32 = vaddq_f32(vline4_f32, vshift); vline4_f32 = vaddq_f32(vline4_f32, vshift);
int32x4_t vline1_s32 = internal::vroundq_s32_f32(vline1_f32); int32x4_t vline1_s32 = vcvtq_s32_f32(vline1_f32);
int32x4_t vline2_s32 = internal::vroundq_s32_f32(vline2_f32); int32x4_t vline2_s32 = vcvtq_s32_f32(vline2_f32);
int32x4_t vline3_s32 = internal::vroundq_s32_f32(vline3_f32); int32x4_t vline3_s32 = vcvtq_s32_f32(vline3_f32);
int32x4_t vline4_s32 = internal::vroundq_s32_f32(vline4_f32); int32x4_t vline4_s32 = vcvtq_s32_f32(vline4_f32);
vst1q_s32(_dst + i + 0, vline1_s32); vst1q_s32(_dst + i + 0, vline1_s32);
vst1q_s32(_dst + i + 4, vline2_s32); vst1q_s32(_dst + i + 4, vline2_s32);
vst1q_s32(_dst + i + 8, vline3_s32); vst1q_s32(_dst + i + 8, vline3_s32);
@@ -694,7 +693,7 @@ CVTS_FUNC(s8, u8, 16,
#else #else
CVTS_FUNC(s8, u8, 16, CVTS_FUNC(s8, u8, 16,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 16) for (size_t i = 0; i < w; i += 16)
{ {
@@ -718,10 +717,10 @@ CVTS_FUNC(s8, u8, 16,
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
vline3_f32 = vaddq_f32(vline3_f32, vshift); vline3_f32 = vaddq_f32(vline3_f32, vshift);
vline4_f32 = vaddq_f32(vline4_f32, vshift); vline4_f32 = vaddq_f32(vline4_f32, vshift);
vline1_s32 = internal::vroundq_s32_f32(vline1_f32); vline1_s32 = vcvtq_s32_f32(vline1_f32);
vline2_s32 = internal::vroundq_s32_f32(vline2_f32); vline2_s32 = vcvtq_s32_f32(vline2_f32);
vline3_s32 = internal::vroundq_s32_f32(vline3_f32); vline3_s32 = vcvtq_s32_f32(vline3_f32);
vline4_s32 = internal::vroundq_s32_f32(vline4_f32); vline4_s32 = vcvtq_s32_f32(vline4_f32);
uint16x8_t vRes1_u16 = vcombine_u16(vqmovun_s32(vline1_s32), vqmovun_s32(vline2_s32)); uint16x8_t vRes1_u16 = vcombine_u16(vqmovun_s32(vline1_s32), vqmovun_s32(vline2_s32));
uint16x8_t vRes2_u16 = vcombine_u16(vqmovun_s32(vline3_s32), vqmovun_s32(vline4_s32)); uint16x8_t vRes2_u16 = vcombine_u16(vqmovun_s32(vline3_s32), vqmovun_s32(vline4_s32));
vst1q_u8(_dst + i, vcombine_u8(vqmovn_u16(vRes1_u16), vqmovn_u16(vRes2_u16))); vst1q_u8(_dst + i, vcombine_u8(vqmovn_u16(vRes1_u16), vqmovn_u16(vRes2_u16)));
@@ -779,7 +778,7 @@ CVTS_FUNC1(s8, 16,
#else #else
CVTS_FUNC1(s8, 16, CVTS_FUNC1(s8, 16,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 16) for (size_t i = 0; i < w; i += 16)
{ {
@@ -803,10 +802,10 @@ CVTS_FUNC1(s8, 16,
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
vline3_f32 = vaddq_f32(vline3_f32, vshift); vline3_f32 = vaddq_f32(vline3_f32, vshift);
vline4_f32 = vaddq_f32(vline4_f32, vshift); vline4_f32 = vaddq_f32(vline4_f32, vshift);
vline1_s32 = internal::vroundq_s32_f32(vline1_f32); vline1_s32 = vcvtq_s32_f32(vline1_f32);
vline2_s32 = internal::vroundq_s32_f32(vline2_f32); vline2_s32 = vcvtq_s32_f32(vline2_f32);
vline3_s32 = internal::vroundq_s32_f32(vline3_f32); vline3_s32 = vcvtq_s32_f32(vline3_f32);
vline4_s32 = internal::vroundq_s32_f32(vline4_f32); vline4_s32 = vcvtq_s32_f32(vline4_f32);
int16x8_t vRes1_s16 = vcombine_s16(vqmovn_s32(vline1_s32), vqmovn_s32(vline2_s32)); int16x8_t vRes1_s16 = vcombine_s16(vqmovn_s32(vline1_s32), vqmovn_s32(vline2_s32));
int16x8_t vRes2_s16 = vcombine_s16(vqmovn_s32(vline3_s32), vqmovn_s32(vline4_s32)); int16x8_t vRes2_s16 = vcombine_s16(vqmovn_s32(vline3_s32), vqmovn_s32(vline4_s32));
vst1q_s8(_dst + i, vcombine_s8(vqmovn_s16(vRes1_s16), vqmovn_s16(vRes2_s16))); vst1q_s8(_dst + i, vcombine_s8(vqmovn_s16(vRes1_s16), vqmovn_s16(vRes2_s16)));
@@ -864,7 +863,7 @@ CVTS_FUNC(s8, u16, 16,
#else #else
CVTS_FUNC(s8, u16, 16, CVTS_FUNC(s8, u16, 16,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 16) for (size_t i = 0; i < w; i += 16)
{ {
@@ -888,10 +887,10 @@ CVTS_FUNC(s8, u16, 16,
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
vline3_f32 = vaddq_f32(vline3_f32, vshift); vline3_f32 = vaddq_f32(vline3_f32, vshift);
vline4_f32 = vaddq_f32(vline4_f32, vshift); vline4_f32 = vaddq_f32(vline4_f32, vshift);
vline1_s32 = internal::vroundq_s32_f32(vline1_f32); vline1_s32 = vcvtq_s32_f32(vline1_f32);
vline2_s32 = internal::vroundq_s32_f32(vline2_f32); vline2_s32 = vcvtq_s32_f32(vline2_f32);
vline3_s32 = internal::vroundq_s32_f32(vline3_f32); vline3_s32 = vcvtq_s32_f32(vline3_f32);
vline4_s32 = internal::vroundq_s32_f32(vline4_f32); vline4_s32 = vcvtq_s32_f32(vline4_f32);
uint16x8_t vRes1_u16 = vcombine_u16(vqmovun_s32(vline1_s32), vqmovun_s32(vline2_s32)); uint16x8_t vRes1_u16 = vcombine_u16(vqmovun_s32(vline1_s32), vqmovun_s32(vline2_s32));
uint16x8_t vRes2_u16 = vcombine_u16(vqmovun_s32(vline3_s32), vqmovun_s32(vline4_s32)); uint16x8_t vRes2_u16 = vcombine_u16(vqmovun_s32(vline3_s32), vqmovun_s32(vline4_s32));
vst1q_u16(_dst + i + 0, vRes1_u16); vst1q_u16(_dst + i + 0, vRes1_u16);
@@ -950,7 +949,7 @@ CVTS_FUNC(s8, s16, 16,
#else #else
CVTS_FUNC(s8, s16, 16, CVTS_FUNC(s8, s16, 16,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 16) for (size_t i = 0; i < w; i += 16)
{ {
@@ -974,10 +973,10 @@ CVTS_FUNC(s8, s16, 16,
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
vline3_f32 = vaddq_f32(vline3_f32, vshift); vline3_f32 = vaddq_f32(vline3_f32, vshift);
vline4_f32 = vaddq_f32(vline4_f32, vshift); vline4_f32 = vaddq_f32(vline4_f32, vshift);
vline1_s32 = internal::vroundq_s32_f32(vline1_f32); vline1_s32 = vcvtq_s32_f32(vline1_f32);
vline2_s32 = internal::vroundq_s32_f32(vline2_f32); vline2_s32 = vcvtq_s32_f32(vline2_f32);
vline3_s32 = internal::vroundq_s32_f32(vline3_f32); vline3_s32 = vcvtq_s32_f32(vline3_f32);
vline4_s32 = internal::vroundq_s32_f32(vline4_f32); vline4_s32 = vcvtq_s32_f32(vline4_f32);
int16x8_t vRes1_s16 = vcombine_s16(vqmovn_s32(vline1_s32), vqmovn_s32(vline2_s32)); int16x8_t vRes1_s16 = vcombine_s16(vqmovn_s32(vline1_s32), vqmovn_s32(vline2_s32));
int16x8_t vRes2_s16 = vcombine_s16(vqmovn_s32(vline3_s32), vqmovn_s32(vline4_s32)); int16x8_t vRes2_s16 = vcombine_s16(vqmovn_s32(vline3_s32), vqmovn_s32(vline4_s32));
vst1q_s16(_dst + i + 0, vRes1_s16); vst1q_s16(_dst + i + 0, vRes1_s16);
@@ -1039,7 +1038,7 @@ CVTS_FUNC(s8, s32, 16,
#else #else
CVTS_FUNC(s8, s32, 16, CVTS_FUNC(s8, s32, 16,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 16) for (size_t i = 0; i < w; i += 16)
{ {
@@ -1063,10 +1062,10 @@ CVTS_FUNC(s8, s32, 16,
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
vline3_f32 = vaddq_f32(vline3_f32, vshift); vline3_f32 = vaddq_f32(vline3_f32, vshift);
vline4_f32 = vaddq_f32(vline4_f32, vshift); vline4_f32 = vaddq_f32(vline4_f32, vshift);
vline1_s32 = internal::vroundq_s32_f32(vline1_f32); vline1_s32 = vcvtq_s32_f32(vline1_f32);
vline2_s32 = internal::vroundq_s32_f32(vline2_f32); vline2_s32 = vcvtq_s32_f32(vline2_f32);
vline3_s32 = internal::vroundq_s32_f32(vline3_f32); vline3_s32 = vcvtq_s32_f32(vline3_f32);
vline4_s32 = internal::vroundq_s32_f32(vline4_f32); vline4_s32 = vcvtq_s32_f32(vline4_f32);
vst1q_s32(_dst + i + 0, vline1_s32); vst1q_s32(_dst + i + 0, vline1_s32);
vst1q_s32(_dst + i + 4, vline2_s32); vst1q_s32(_dst + i + 4, vline2_s32);
vst1q_s32(_dst + i + 8, vline3_s32); vst1q_s32(_dst + i + 8, vline3_s32);
@@ -1191,7 +1190,7 @@ CVTS_FUNC(u16, u8, 16,
#else #else
CVTS_FUNC(u16, u8, 16, CVTS_FUNC(u16, u8, 16,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 8) for (size_t i = 0; i < w; i += 8)
{ {
@@ -1205,8 +1204,8 @@ CVTS_FUNC(u16, u8, 16,
vline2_f32 = vmulq_f32(vline2_f32, vscale); vline2_f32 = vmulq_f32(vline2_f32, vscale);
vline1_f32 = vaddq_f32(vline1_f32, vshift); vline1_f32 = vaddq_f32(vline1_f32, vshift);
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
int32x4_t vline1_s32 = internal::vroundq_s32_f32(vline1_f32); int32x4_t vline1_s32 = vcvtq_s32_f32(vline1_f32);
int32x4_t vline2_s32 = internal::vroundq_s32_f32(vline2_f32); int32x4_t vline2_s32 = vcvtq_s32_f32(vline2_f32);
int16x4_t vRes1 = vqmovn_s32(vline1_s32); int16x4_t vRes1 = vqmovn_s32(vline1_s32);
int16x4_t vRes2 = vqmovn_s32(vline2_s32); int16x4_t vRes2 = vqmovn_s32(vline2_s32);
uint8x8_t vRes = vqmovun_s16(vcombine_s16(vRes1, vRes2)); uint8x8_t vRes = vqmovun_s16(vcombine_s16(vRes1, vRes2));
@@ -1250,7 +1249,7 @@ CVTS_FUNC(u16, s8, 16,
#else #else
CVTS_FUNC(u16, s8, 16, CVTS_FUNC(u16, s8, 16,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 8) for (size_t i = 0; i < w; i += 8)
{ {
@@ -1264,8 +1263,8 @@ CVTS_FUNC(u16, s8, 16,
vline2_f32 = vmulq_f32(vline2_f32, vscale); vline2_f32 = vmulq_f32(vline2_f32, vscale);
vline1_f32 = vaddq_f32(vline1_f32, vshift); vline1_f32 = vaddq_f32(vline1_f32, vshift);
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
int32x4_t vline1_s32 = internal::vroundq_s32_f32(vline1_f32); int32x4_t vline1_s32 = vcvtq_s32_f32(vline1_f32);
int32x4_t vline2_s32 = internal::vroundq_s32_f32(vline2_f32); int32x4_t vline2_s32 = vcvtq_s32_f32(vline2_f32);
int16x4_t vRes1 = vqmovn_s32(vline1_s32); int16x4_t vRes1 = vqmovn_s32(vline1_s32);
int16x4_t vRes2 = vqmovn_s32(vline2_s32); int16x4_t vRes2 = vqmovn_s32(vline2_s32);
int8x8_t vRes = vqmovn_s16(vcombine_s16(vRes1, vRes2)); int8x8_t vRes = vqmovn_s16(vcombine_s16(vRes1, vRes2));
@@ -1308,7 +1307,7 @@ CVTS_FUNC1(u16, 16,
#else #else
CVTS_FUNC1(u16, 16, CVTS_FUNC1(u16, 16,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 8) for (size_t i = 0; i < w; i += 8)
{ {
@@ -1322,8 +1321,8 @@ CVTS_FUNC1(u16, 16,
vline2_f32 = vmulq_f32(vline2_f32, vscale); vline2_f32 = vmulq_f32(vline2_f32, vscale);
vline1_f32 = vaddq_f32(vline1_f32, vshift); vline1_f32 = vaddq_f32(vline1_f32, vshift);
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
int32x4_t vline1_s32 = internal::vroundq_s32_f32(vline1_f32); int32x4_t vline1_s32 = vcvtq_s32_f32(vline1_f32);
int32x4_t vline2_s32 = internal::vroundq_s32_f32(vline2_f32); int32x4_t vline2_s32 = vcvtq_s32_f32(vline2_f32);
uint16x4_t vRes1 = vqmovun_s32(vline1_s32); uint16x4_t vRes1 = vqmovun_s32(vline1_s32);
uint16x4_t vRes2 = vqmovun_s32(vline2_s32); uint16x4_t vRes2 = vqmovun_s32(vline2_s32);
vst1q_u16(_dst + i, vcombine_u16(vRes1, vRes2)); vst1q_u16(_dst + i, vcombine_u16(vRes1, vRes2));
@@ -1365,7 +1364,7 @@ CVTS_FUNC(u16, s16, 8,
#else #else
CVTS_FUNC(u16, s16, 8, CVTS_FUNC(u16, s16, 8,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 8) for (size_t i = 0; i < w; i += 8)
{ {
@@ -1379,8 +1378,8 @@ CVTS_FUNC(u16, s16, 8,
vline2_f32 = vmulq_f32(vline2_f32, vscale); vline2_f32 = vmulq_f32(vline2_f32, vscale);
vline1_f32 = vaddq_f32(vline1_f32, vshift); vline1_f32 = vaddq_f32(vline1_f32, vshift);
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
int32x4_t vline1_s32 = internal::vroundq_s32_f32(vline1_f32); int32x4_t vline1_s32 = vcvtq_s32_f32(vline1_f32);
int32x4_t vline2_s32 = internal::vroundq_s32_f32(vline2_f32); int32x4_t vline2_s32 = vcvtq_s32_f32(vline2_f32);
int16x4_t vRes1 = vqmovn_s32(vline1_s32); int16x4_t vRes1 = vqmovn_s32(vline1_s32);
int16x4_t vRes2 = vqmovn_s32(vline2_s32); int16x4_t vRes2 = vqmovn_s32(vline2_s32);
vst1q_s16(_dst + i, vcombine_s16(vRes1, vRes2)); vst1q_s16(_dst + i, vcombine_s16(vRes1, vRes2));
@@ -1422,7 +1421,7 @@ CVTS_FUNC(u16, s32, 8,
#else #else
CVTS_FUNC(u16, s32, 8, CVTS_FUNC(u16, s32, 8,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 8) for (size_t i = 0; i < w; i += 8)
{ {
@@ -1436,8 +1435,8 @@ CVTS_FUNC(u16, s32, 8,
vline2_f32 = vmulq_f32(vline2_f32, vscale); vline2_f32 = vmulq_f32(vline2_f32, vscale);
vline1_f32 = vaddq_f32(vline1_f32, vshift); vline1_f32 = vaddq_f32(vline1_f32, vshift);
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
int32x4_t vline1_s32 = internal::vroundq_s32_f32(vline1_f32); int32x4_t vline1_s32 = vcvtq_s32_f32(vline1_f32);
int32x4_t vline2_s32 = internal::vroundq_s32_f32(vline2_f32); int32x4_t vline2_s32 = vcvtq_s32_f32(vline2_f32);
vst1q_s32(_dst + i + 0, vline1_s32); vst1q_s32(_dst + i + 0, vline1_s32);
vst1q_s32(_dst + i + 4, vline2_s32); vst1q_s32(_dst + i + 4, vline2_s32);
} }
@@ -1531,7 +1530,7 @@ CVTS_FUNC(s16, u8, 16,
#else #else
CVTS_FUNC(s16, u8, 16, CVTS_FUNC(s16, u8, 16,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 8) for (size_t i = 0; i < w; i += 8)
{ {
@@ -1545,8 +1544,8 @@ CVTS_FUNC(s16, u8, 16,
vline2_f32 = vmulq_f32(vline2_f32, vscale); vline2_f32 = vmulq_f32(vline2_f32, vscale);
vline1_f32 = vaddq_f32(vline1_f32, vshift); vline1_f32 = vaddq_f32(vline1_f32, vshift);
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
vline1_s32 = internal::vroundq_s32_f32(vline1_f32); vline1_s32 = vcvtq_s32_f32(vline1_f32);
vline2_s32 = internal::vroundq_s32_f32(vline2_f32); vline2_s32 = vcvtq_s32_f32(vline2_f32);
int16x4_t vRes1 = vqmovn_s32(vline1_s32); int16x4_t vRes1 = vqmovn_s32(vline1_s32);
int16x4_t vRes2 = vqmovn_s32(vline2_s32); int16x4_t vRes2 = vqmovn_s32(vline2_s32);
uint8x8_t vRes = vqmovun_s16(vcombine_s16(vRes1, vRes2)); uint8x8_t vRes = vqmovun_s16(vcombine_s16(vRes1, vRes2));
@@ -1590,7 +1589,7 @@ CVTS_FUNC(s16, s8, 16,
#else #else
CVTS_FUNC(s16, s8, 16, CVTS_FUNC(s16, s8, 16,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 8) for (size_t i = 0; i < w; i += 8)
{ {
@@ -1604,8 +1603,8 @@ CVTS_FUNC(s16, s8, 16,
vline2_f32 = vmulq_f32(vline2_f32, vscale); vline2_f32 = vmulq_f32(vline2_f32, vscale);
vline1_f32 = vaddq_f32(vline1_f32, vshift); vline1_f32 = vaddq_f32(vline1_f32, vshift);
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
vline1_s32 = internal::vroundq_s32_f32(vline1_f32); vline1_s32 = vcvtq_s32_f32(vline1_f32);
vline2_s32 = internal::vroundq_s32_f32(vline2_f32); vline2_s32 = vcvtq_s32_f32(vline2_f32);
int16x4_t vRes1 = vqmovn_s32(vline1_s32); int16x4_t vRes1 = vqmovn_s32(vline1_s32);
int16x4_t vRes2 = vqmovn_s32(vline2_s32); int16x4_t vRes2 = vqmovn_s32(vline2_s32);
int8x8_t vRes = vqmovn_s16(vcombine_s16(vRes1, vRes2)); int8x8_t vRes = vqmovn_s16(vcombine_s16(vRes1, vRes2));
@@ -1648,7 +1647,7 @@ CVTS_FUNC(s16, u16, 8,
#else #else
CVTS_FUNC(s16, u16, 8, CVTS_FUNC(s16, u16, 8,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 8) for (size_t i = 0; i < w; i += 8)
{ {
@@ -1662,8 +1661,8 @@ CVTS_FUNC(s16, u16, 8,
vline2_f32 = vmulq_f32(vline2_f32, vscale); vline2_f32 = vmulq_f32(vline2_f32, vscale);
vline1_f32 = vaddq_f32(vline1_f32, vshift); vline1_f32 = vaddq_f32(vline1_f32, vshift);
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
vline1_s32 = internal::vroundq_s32_f32(vline1_f32); vline1_s32 = vcvtq_s32_f32(vline1_f32);
vline2_s32 = internal::vroundq_s32_f32(vline2_f32); vline2_s32 = vcvtq_s32_f32(vline2_f32);
uint16x4_t vRes1 = vqmovun_s32(vline1_s32); uint16x4_t vRes1 = vqmovun_s32(vline1_s32);
uint16x4_t vRes2 = vqmovun_s32(vline2_s32); uint16x4_t vRes2 = vqmovun_s32(vline2_s32);
vst1q_u16(_dst + i, vcombine_u16(vRes1, vRes2)); vst1q_u16(_dst + i, vcombine_u16(vRes1, vRes2));
@@ -1705,7 +1704,7 @@ CVTS_FUNC1(s16, 16,
#else #else
CVTS_FUNC1(s16, 16, CVTS_FUNC1(s16, 16,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 8) for (size_t i = 0; i < w; i += 8)
{ {
@@ -1719,8 +1718,8 @@ CVTS_FUNC1(s16, 16,
vline2_f32 = vmulq_f32(vline2_f32, vscale); vline2_f32 = vmulq_f32(vline2_f32, vscale);
vline1_f32 = vaddq_f32(vline1_f32, vshift); vline1_f32 = vaddq_f32(vline1_f32, vshift);
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
vline1_s32 = internal::vroundq_s32_f32(vline1_f32); vline1_s32 = vcvtq_s32_f32(vline1_f32);
vline2_s32 = internal::vroundq_s32_f32(vline2_f32); vline2_s32 = vcvtq_s32_f32(vline2_f32);
int16x4_t vRes1 = vqmovn_s32(vline1_s32); int16x4_t vRes1 = vqmovn_s32(vline1_s32);
int16x4_t vRes2 = vqmovn_s32(vline2_s32); int16x4_t vRes2 = vqmovn_s32(vline2_s32);
vst1q_s16(_dst + i, vcombine_s16(vRes1, vRes2)); vst1q_s16(_dst + i, vcombine_s16(vRes1, vRes2));
@@ -1762,7 +1761,7 @@ CVTS_FUNC(s16, s32, 8,
#else #else
CVTS_FUNC(s16, s32, 8, CVTS_FUNC(s16, s32, 8,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 8) for (size_t i = 0; i < w; i += 8)
{ {
@@ -1776,8 +1775,8 @@ CVTS_FUNC(s16, s32, 8,
vline2_f32 = vmulq_f32(vline2_f32, vscale); vline2_f32 = vmulq_f32(vline2_f32, vscale);
vline1_f32 = vaddq_f32(vline1_f32, vshift); vline1_f32 = vaddq_f32(vline1_f32, vshift);
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
vline1_s32 = internal::vroundq_s32_f32(vline1_f32); vline1_s32 = vcvtq_s32_f32(vline1_f32);
vline2_s32 = internal::vroundq_s32_f32(vline2_f32); vline2_s32 = vcvtq_s32_f32(vline2_f32);
vst1q_s32(_dst + i + 0, vline1_s32); vst1q_s32(_dst + i + 0, vline1_s32);
vst1q_s32(_dst + i + 4, vline2_s32); vst1q_s32(_dst + i + 4, vline2_s32);
} }
@@ -1871,7 +1870,7 @@ CVTS_FUNC(s32, u8, 8,
#else #else
CVTS_FUNC(s32, u8, 8, CVTS_FUNC(s32, u8, 8,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 8) for (size_t i = 0; i < w; i += 8)
{ {
@@ -1884,8 +1883,8 @@ CVTS_FUNC(s32, u8, 8,
vline2_f32 = vmulq_f32(vline2_f32, vscale); vline2_f32 = vmulq_f32(vline2_f32, vscale);
vline1_f32 = vaddq_f32(vline1_f32, vshift); vline1_f32 = vaddq_f32(vline1_f32, vshift);
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
vline1_s32 = internal::vroundq_s32_f32(vline1_f32); vline1_s32 = vcvtq_s32_f32(vline1_f32);
vline2_s32 = internal::vroundq_s32_f32(vline2_f32); vline2_s32 = vcvtq_s32_f32(vline2_f32);
uint16x4_t vRes1 = vqmovun_s32(vline1_s32); uint16x4_t vRes1 = vqmovun_s32(vline1_s32);
uint16x4_t vRes2 = vqmovun_s32(vline2_s32); uint16x4_t vRes2 = vqmovun_s32(vline2_s32);
uint8x8_t vRes = vqmovn_u16(vcombine_u16(vRes1, vRes2)); uint8x8_t vRes = vqmovn_u16(vcombine_u16(vRes1, vRes2));
@@ -1929,7 +1928,7 @@ CVTS_FUNC(s32, s8, 8,
#else #else
CVTS_FUNC(s32, s8, 8, CVTS_FUNC(s32, s8, 8,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 8) for (size_t i = 0; i < w; i += 8)
{ {
@@ -1942,8 +1941,8 @@ CVTS_FUNC(s32, s8, 8,
vline2_f32 = vmulq_f32(vline2_f32, vscale); vline2_f32 = vmulq_f32(vline2_f32, vscale);
vline1_f32 = vaddq_f32(vline1_f32, vshift); vline1_f32 = vaddq_f32(vline1_f32, vshift);
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
vline1_s32 = internal::vroundq_s32_f32(vline1_f32); vline1_s32 = vcvtq_s32_f32(vline1_f32);
vline2_s32 = internal::vroundq_s32_f32(vline2_f32); vline2_s32 = vcvtq_s32_f32(vline2_f32);
int16x4_t vRes1 = vqmovn_s32(vline1_s32); int16x4_t vRes1 = vqmovn_s32(vline1_s32);
int16x4_t vRes2 = vqmovn_s32(vline2_s32); int16x4_t vRes2 = vqmovn_s32(vline2_s32);
int8x8_t vRes = vqmovn_s16(vcombine_s16(vRes1, vRes2)); int8x8_t vRes = vqmovn_s16(vcombine_s16(vRes1, vRes2));
@@ -1986,7 +1985,7 @@ CVTS_FUNC(s32, u16, 8,
#else #else
CVTS_FUNC(s32, u16, 8, CVTS_FUNC(s32, u16, 8,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 8) for (size_t i = 0; i < w; i += 8)
{ {
@@ -1999,8 +1998,8 @@ CVTS_FUNC(s32, u16, 8,
vline2_f32 = vmulq_f32(vline2_f32, vscale); vline2_f32 = vmulq_f32(vline2_f32, vscale);
vline1_f32 = vaddq_f32(vline1_f32, vshift); vline1_f32 = vaddq_f32(vline1_f32, vshift);
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
vline1_s32 = internal::vroundq_s32_f32(vline1_f32); vline1_s32 = vcvtq_s32_f32(vline1_f32);
vline2_s32 = internal::vroundq_s32_f32(vline2_f32); vline2_s32 = vcvtq_s32_f32(vline2_f32);
uint16x4_t vRes1 = vqmovun_s32(vline1_s32); uint16x4_t vRes1 = vqmovun_s32(vline1_s32);
uint16x4_t vRes2 = vqmovun_s32(vline2_s32); uint16x4_t vRes2 = vqmovun_s32(vline2_s32);
vst1q_u16(_dst + i, vcombine_u16(vRes1, vRes2)); vst1q_u16(_dst + i, vcombine_u16(vRes1, vRes2));
@@ -2042,7 +2041,7 @@ CVTS_FUNC(s32, s16, 8,
#else #else
CVTS_FUNC(s32, s16, 8, CVTS_FUNC(s32, s16, 8,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 8) for (size_t i = 0; i < w; i += 8)
{ {
@@ -2055,8 +2054,8 @@ CVTS_FUNC(s32, s16, 8,
vline2_f32 = vmulq_f32(vline2_f32, vscale); vline2_f32 = vmulq_f32(vline2_f32, vscale);
vline1_f32 = vaddq_f32(vline1_f32, vshift); vline1_f32 = vaddq_f32(vline1_f32, vshift);
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
vline1_s32 = internal::vroundq_s32_f32(vline1_f32); vline1_s32 = vcvtq_s32_f32(vline1_f32);
vline2_s32 = internal::vroundq_s32_f32(vline2_f32); vline2_s32 = vcvtq_s32_f32(vline2_f32);
int16x4_t vRes1 = vqmovn_s32(vline1_s32); int16x4_t vRes1 = vqmovn_s32(vline1_s32);
int16x4_t vRes2 = vqmovn_s32(vline2_s32); int16x4_t vRes2 = vqmovn_s32(vline2_s32);
vst1q_s16(_dst + i, vcombine_s16(vRes1, vRes2)); vst1q_s16(_dst + i, vcombine_s16(vRes1, vRes2));
@@ -2098,7 +2097,7 @@ CVTS_FUNC1(s32, 8,
#else #else
CVTS_FUNC1(s32, 8, CVTS_FUNC1(s32, 8,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 8) for (size_t i = 0; i < w; i += 8)
{ {
@@ -2111,8 +2110,8 @@ CVTS_FUNC1(s32, 8,
vline2_f32 = vmulq_f32(vline2_f32, vscale); vline2_f32 = vmulq_f32(vline2_f32, vscale);
vline1_f32 = vaddq_f32(vline1_f32, vshift); vline1_f32 = vaddq_f32(vline1_f32, vshift);
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
vline1_s32 = internal::vroundq_s32_f32(vline1_f32); vline1_s32 = vcvtq_s32_f32(vline1_f32);
vline2_s32 = internal::vroundq_s32_f32(vline2_f32); vline2_s32 = vcvtq_s32_f32(vline2_f32);
vst1q_s32(_dst + i + 0, vline1_s32); vst1q_s32(_dst + i + 0, vline1_s32);
vst1q_s32(_dst + i + 4, vline2_s32); vst1q_s32(_dst + i + 4, vline2_s32);
} }
@@ -2273,7 +2272,7 @@ CVTS_FUNC(f32, s8, 8,
#else #else
CVTS_FUNC(f32, s8, 8, CVTS_FUNC(f32, s8, 8,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 8) for (size_t i = 0; i < w; i += 8)
{ {
@@ -2284,8 +2283,8 @@ CVTS_FUNC(f32, s8, 8,
vline2_f32 = vmulq_f32(vline2_f32, vscale); vline2_f32 = vmulq_f32(vline2_f32, vscale);
vline1_f32 = vaddq_f32(vline1_f32, vshift); vline1_f32 = vaddq_f32(vline1_f32, vshift);
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
int32x4_t vline1_s32 = internal::vroundq_s32_f32(vline1_f32); int32x4_t vline1_s32 = vcvtq_s32_f32(vline1_f32);
int32x4_t vline2_s32 = internal::vroundq_s32_f32(vline2_f32); int32x4_t vline2_s32 = vcvtq_s32_f32(vline2_f32);
int16x4_t vRes1 = vqmovn_s32(vline1_s32); int16x4_t vRes1 = vqmovn_s32(vline1_s32);
int16x4_t vRes2 = vqmovn_s32(vline2_s32); int16x4_t vRes2 = vqmovn_s32(vline2_s32);
int8x8_t vRes = vqmovn_s16(vcombine_s16(vRes1, vRes2)); int8x8_t vRes = vqmovn_s16(vcombine_s16(vRes1, vRes2));
@@ -2326,7 +2325,7 @@ CVTS_FUNC(f32, u16, 8,
#else #else
CVTS_FUNC(f32, u16, 8, CVTS_FUNC(f32, u16, 8,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 8) for (size_t i = 0; i < w; i += 8)
{ {
@@ -2337,8 +2336,8 @@ CVTS_FUNC(f32, u16, 8,
vline2_f32 = vmulq_f32(vline2_f32, vscale); vline2_f32 = vmulq_f32(vline2_f32, vscale);
vline1_f32 = vaddq_f32(vline1_f32, vshift); vline1_f32 = vaddq_f32(vline1_f32, vshift);
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
uint32x4_t vline1_u32 = internal::vroundq_u32_f32(vline1_f32); uint32x4_t vline1_u32 = vcvtq_u32_f32(vline1_f32);
uint32x4_t vline2_u32 = internal::vroundq_u32_f32(vline2_f32); uint32x4_t vline2_u32 = vcvtq_u32_f32(vline2_f32);
uint16x4_t vRes1 = vqmovn_u32(vline1_u32); uint16x4_t vRes1 = vqmovn_u32(vline1_u32);
uint16x4_t vRes2 = vqmovn_u32(vline2_u32); uint16x4_t vRes2 = vqmovn_u32(vline2_u32);
vst1q_u16(_dst + i, vcombine_u16(vRes1, vRes2)); vst1q_u16(_dst + i, vcombine_u16(vRes1, vRes2));
@@ -2378,7 +2377,7 @@ CVTS_FUNC(f32, s16, 8,
#else #else
CVTS_FUNC(f32, s16, 8, CVTS_FUNC(f32, s16, 8,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 8) for (size_t i = 0; i < w; i += 8)
{ {
@@ -2389,8 +2388,8 @@ CVTS_FUNC(f32, s16, 8,
vline2_f32 = vmulq_f32(vline2_f32, vscale); vline2_f32 = vmulq_f32(vline2_f32, vscale);
vline1_f32 = vaddq_f32(vline1_f32, vshift); vline1_f32 = vaddq_f32(vline1_f32, vshift);
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
int32x4_t vline1_s32 = internal::vroundq_s32_f32(vline1_f32); int32x4_t vline1_s32 = vcvtq_s32_f32(vline1_f32);
int32x4_t vline2_s32 = internal::vroundq_s32_f32(vline2_f32); int32x4_t vline2_s32 = vcvtq_s32_f32(vline2_f32);
int16x4_t vRes1 = vqmovn_s32(vline1_s32); int16x4_t vRes1 = vqmovn_s32(vline1_s32);
int16x4_t vRes2 = vqmovn_s32(vline2_s32); int16x4_t vRes2 = vqmovn_s32(vline2_s32);
vst1q_s16(_dst + i, vcombine_s16(vRes1, vRes2)); vst1q_s16(_dst + i, vcombine_s16(vRes1, vRes2));
@@ -2430,7 +2429,7 @@ CVTS_FUNC(f32, s32, 8,
#else #else
CVTS_FUNC(f32, s32, 8, CVTS_FUNC(f32, s32, 8,
float32x4_t vscale = vdupq_n_f32((f32)alpha); float32x4_t vscale = vdupq_n_f32((f32)alpha);
float32x4_t vshift = vdupq_n_f32((f32)beta);, float32x4_t vshift = vdupq_n_f32((f32)beta + 0.5f);,
{ {
for (size_t i = 0; i < w; i += 8) for (size_t i = 0; i < w; i += 8)
{ {
@@ -2441,8 +2440,8 @@ CVTS_FUNC(f32, s32, 8,
vline2_f32 = vmulq_f32(vline2_f32, vscale); vline2_f32 = vmulq_f32(vline2_f32, vscale);
vline1_f32 = vaddq_f32(vline1_f32, vshift); vline1_f32 = vaddq_f32(vline1_f32, vshift);
vline2_f32 = vaddq_f32(vline2_f32, vshift); vline2_f32 = vaddq_f32(vline2_f32, vshift);
int32x4_t vline1_s32 = internal::vroundq_s32_f32(vline1_f32); int32x4_t vline1_s32 = vcvtq_s32_f32(vline1_f32);
int32x4_t vline2_s32 = internal::vroundq_s32_f32(vline2_f32); int32x4_t vline2_s32 = vcvtq_s32_f32(vline2_f32);
vst1q_s32(_dst + i + 0, vline1_s32); vst1q_s32(_dst + i + 0, vline1_s32);
vst1q_s32(_dst + i + 4, vline2_s32); vst1q_s32(_dst + i + 4, vline2_s32);
} }
+20 -7
View File
@@ -39,7 +39,6 @@
#include "common.hpp" #include "common.hpp"
#include "vtransform.hpp" #include "vtransform.hpp"
#include "vround_helper.hpp"
#include <cstring> #include <cstring>
#include <cfloat> #include <cfloat>
@@ -52,6 +51,13 @@ namespace {
#ifdef CAROTENE_NEON #ifdef CAROTENE_NEON
inline float32x4_t vroundq(const float32x4_t& v)
{
const int32x4_t signMask = vdupq_n_s32(1 << 31), half = vreinterpretq_s32_f32(vdupq_n_f32(0.5f));
float32x4_t v_addition = vreinterpretq_f32_s32(vorrq_s32(half, vandq_s32(signMask, vreinterpretq_s32_f32(v))));
return vaddq_f32(v, v_addition);
}
template <typename T> template <typename T>
inline T divSaturateQ(const T &v1, const T &v2, const float scale) inline T divSaturateQ(const T &v1, const T &v2, const float scale)
{ {
@@ -63,10 +69,17 @@ inline T divSaturateQ(const T &v1, const T &v2, const float scale)
} }
template <> template <>
inline int32x4_t divSaturateQ<int32x4_t>(const int32x4_t &v1, const int32x4_t &v2, const float scale) inline int32x4_t divSaturateQ<int32x4_t>(const int32x4_t &v1, const int32x4_t &v2, const float scale)
{ return internal::vroundq_s32_f32(vmulq_f32(vmulq_n_f32(vcvtq_f32_s32(v1), scale), internal::vrecpq_f32(vcvtq_f32_s32(v2)))); } { return vcvtq_s32_f32(vroundq(vmulq_f32(vmulq_n_f32(vcvtq_f32_s32(v1), scale), internal::vrecpq_f32(vcvtq_f32_s32(v2))))); }
template <> template <>
inline uint32x4_t divSaturateQ<uint32x4_t>(const uint32x4_t &v1, const uint32x4_t &v2, const float scale) inline uint32x4_t divSaturateQ<uint32x4_t>(const uint32x4_t &v1, const uint32x4_t &v2, const float scale)
{ return internal::vroundq_u32_f32(vmulq_f32(vmulq_n_f32(vcvtq_f32_u32(v1), scale), internal::vrecpq_f32(vcvtq_f32_u32(v2)))); } { return vcvtq_u32_f32(vroundq(vmulq_f32(vmulq_n_f32(vcvtq_f32_u32(v1), scale), internal::vrecpq_f32(vcvtq_f32_u32(v2))))); }
inline float32x2_t vround(const float32x2_t& v)
{
const int32x2_t signMask = vdup_n_s32(1 << 31), half = vreinterpret_s32_f32(vdup_n_f32(0.5f));
float32x2_t v_addition = vreinterpret_f32_s32(vorr_s32(half, vand_s32(signMask, vreinterpret_s32_f32(v))));
return vadd_f32(v, v_addition);
}
template <typename T> template <typename T>
inline T divSaturate(const T &v1, const T &v2, const float scale) inline T divSaturate(const T &v1, const T &v2, const float scale)
@@ -75,10 +88,10 @@ inline T divSaturate(const T &v1, const T &v2, const float scale)
} }
template <> template <>
inline int32x2_t divSaturate<int32x2_t>(const int32x2_t &v1, const int32x2_t &v2, const float scale) inline int32x2_t divSaturate<int32x2_t>(const int32x2_t &v1, const int32x2_t &v2, const float scale)
{ return internal::vround_s32_f32(vmul_f32(vmul_n_f32(vcvt_f32_s32(v1), scale), internal::vrecp_f32(vcvt_f32_s32(v2)))); } { return vcvt_s32_f32(vround(vmul_f32(vmul_n_f32(vcvt_f32_s32(v1), scale), internal::vrecp_f32(vcvt_f32_s32(v2))))); }
template <> template <>
inline uint32x2_t divSaturate<uint32x2_t>(const uint32x2_t &v1, const uint32x2_t &v2, const float scale) inline uint32x2_t divSaturate<uint32x2_t>(const uint32x2_t &v1, const uint32x2_t &v2, const float scale)
{ return internal::vround_u32_f32(vmul_f32(vmul_n_f32(vcvt_f32_u32(v1), scale), internal::vrecp_f32(vcvt_f32_u32(v2)))); } { return vcvt_u32_f32(vround(vmul_f32(vmul_n_f32(vcvt_f32_u32(v1), scale), internal::vrecp_f32(vcvt_f32_u32(v2))))); }
template <typename T> template <typename T>
@@ -144,8 +157,8 @@ void div(const Size2D &size,
if (scale == 0.0f || if (scale == 0.0f ||
(std::numeric_limits<T>::is_integer && (std::numeric_limits<T>::is_integer &&
(scale * static_cast<float>(std::numeric_limits<T>::max())) < 1.0f && (scale * std::numeric_limits<T>::max()) < 1.0f &&
(scale * static_cast<float>(std::numeric_limits<T>::max())) > -1.0f)) (scale * std::numeric_limits<T>::max()) > -1.0f))
{ {
for (size_t y = 0; y < size.height; ++y) for (size_t y = 0; y < size.height; ++y)
{ {
+8 -7
View File
@@ -41,7 +41,6 @@
#include <cmath> #include <cmath>
#include "common.hpp" #include "common.hpp"
#include "vround_helper.hpp"
namespace CAROTENE_NS { namespace CAROTENE_NS {
@@ -122,6 +121,8 @@ void phase(const Size2D &size,
size_t roiw16 = size.width >= 15 ? size.width - 15 : 0; size_t roiw16 = size.width >= 15 ? size.width - 15 : 0;
size_t roiw8 = size.width >= 7 ? size.width - 7 : 0; size_t roiw8 = size.width >= 7 ? size.width - 7 : 0;
float32x4_t v_05 = vdupq_n_f32(0.5f);
for (size_t i = 0; i < size.height; ++i) for (size_t i = 0; i < size.height; ++i)
{ {
const s16 * src0 = internal::getRowPtr(src0Base, src0Stride, i); const s16 * src0 = internal::getRowPtr(src0Base, src0Stride, i);
@@ -148,8 +149,8 @@ void phase(const Size2D &size,
float32x4_t v_dst32f1; float32x4_t v_dst32f1;
FASTATAN2VECTOR(v_src1_p, v_src0_p, v_dst32f1) FASTATAN2VECTOR(v_src1_p, v_src0_p, v_dst32f1)
uint16x8_t v_dst16s0 = vcombine_u16(vmovn_u32(internal::vroundq_u32_f32(v_dst32f0)), uint16x8_t v_dst16s0 = vcombine_u16(vmovn_u32(vcvtq_u32_f32(vaddq_f32(v_dst32f0, v_05))),
vmovn_u32(internal::vroundq_u32_f32(v_dst32f1))); vmovn_u32(vcvtq_u32_f32(vaddq_f32(v_dst32f1, v_05))));
// 1 // 1
v_src0_p = vcvtq_f32_s32(vmovl_s16(vget_low_s16(v_src01))); v_src0_p = vcvtq_f32_s32(vmovl_s16(vget_low_s16(v_src01)));
@@ -160,8 +161,8 @@ void phase(const Size2D &size,
v_src1_p = vcvtq_f32_s32(vmovl_s16(vget_high_s16(v_src11))); v_src1_p = vcvtq_f32_s32(vmovl_s16(vget_high_s16(v_src11)));
FASTATAN2VECTOR(v_src1_p, v_src0_p, v_dst32f1) FASTATAN2VECTOR(v_src1_p, v_src0_p, v_dst32f1)
uint16x8_t v_dst16s1 = vcombine_u16(vmovn_u32(internal::vroundq_u32_f32(v_dst32f0)), uint16x8_t v_dst16s1 = vcombine_u16(vmovn_u32(vcvtq_u32_f32(vaddq_f32(v_dst32f0, v_05))),
vmovn_u32(internal::vroundq_u32_f32(v_dst32f1))); vmovn_u32(vcvtq_u32_f32(vaddq_f32(v_dst32f1, v_05))));
vst1q_u8(dst + j, vcombine_u8(vmovn_u16(v_dst16s0), vst1q_u8(dst + j, vcombine_u8(vmovn_u16(v_dst16s0),
vmovn_u16(v_dst16s1))); vmovn_u16(v_dst16s1)));
@@ -181,8 +182,8 @@ void phase(const Size2D &size,
float32x4_t v_dst32f1; float32x4_t v_dst32f1;
FASTATAN2VECTOR(v_src1_p, v_src0_p, v_dst32f1) FASTATAN2VECTOR(v_src1_p, v_src0_p, v_dst32f1)
uint16x8_t v_dst = vcombine_u16(vmovn_u32(internal::vroundq_u32_f32(v_dst32f0)), uint16x8_t v_dst = vcombine_u16(vmovn_u32(vcvtq_u32_f32(vaddq_f32(v_dst32f0, v_05))),
vmovn_u32(internal::vroundq_u32_f32(v_dst32f1))); vmovn_u32(vcvtq_u32_f32(vaddq_f32(v_dst32f1, v_05))));
vst1_u8(dst + j, vmovn_u16(v_dst)); vst1_u8(dst + j, vmovn_u16(v_dst));
} }
-102
View File
@@ -1,102 +0,0 @@
/*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
*
* License Agreement
* For Open Source Computer Vision Library
* (3-clause BSD License)
*
* Copyright (C) 2014-2015, NVIDIA Corporation, all rights reserved.
* Third party copyrights are property of their respective owners.
*
* 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 names of the copyright holders nor the names of the 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 copyright holders or contributors be liable for any direct,
* indirect, incidental, special, exemplary, or consequential damages
* (including, but not limited to, procurement of substitute goods or services;
* loss of use, data, or profits; or business interruption) however caused
* and on any theory of liability, whether in contract, strict liability,
* or tort (including negligence or otherwise) arising in any way out of
* the use of this software, even if advised of the possibility of such damage.
*/
#ifndef CAROTENE_SRC_VROUND_HELPER_HPP
#define CAROTENE_SRC_VROUND_HELPER_HPP
#include "common.hpp"
#include "vtransform.hpp"
#ifdef CAROTENE_NEON
/**
* This helper header is for rounding from float32xN to uin32xN or int32xN to nearest, ties to even.
* See https://en.wikipedia.org/wiki/Rounding#Rounding_half_to_even
*/
// See https://github.com/opencv/opencv/pull/24271#issuecomment-1867318007
#define CAROTENE_ROUND_DELTA (12582912.0f)
namespace CAROTENE_NS { namespace internal {
inline uint32x4_t vroundq_u32_f32(const float32x4_t val)
{
#if CAROTENE_NEON_ARCH >= 8 /* get ready for ARMv9 */
return vcvtnq_u32_f32(val);
#else
const float32x4_t delta = vdupq_n_f32(CAROTENE_ROUND_DELTA);
return vcvtq_u32_f32(vsubq_f32(vaddq_f32(val, delta), delta));
#endif
}
inline uint32x2_t vround_u32_f32(const float32x2_t val)
{
#if CAROTENE_NEON_ARCH >= 8 /* get ready for ARMv9 */
return vcvtn_u32_f32(val);
#else
const float32x2_t delta = vdup_n_f32(CAROTENE_ROUND_DELTA);
return vcvt_u32_f32(vsub_f32(vadd_f32(val, delta), delta));
#endif
}
inline int32x4_t vroundq_s32_f32(const float32x4_t val)
{
#if CAROTENE_NEON_ARCH >= 8 /* get ready for ARMv9 */
return vcvtnq_s32_f32(val);
#else
const float32x4_t delta = vdupq_n_f32(CAROTENE_ROUND_DELTA);
return vcvtq_s32_f32(vsubq_f32(vaddq_f32(val, delta), delta));
#endif
}
inline int32x2_t vround_s32_f32(const float32x2_t val)
{
#if CAROTENE_NEON_ARCH >= 8 /* get ready for ARMv9 */
return vcvtn_s32_f32(val);
#else
const float32x2_t delta = vdup_n_f32(CAROTENE_ROUND_DELTA);
return vcvt_s32_f32(vsub_f32(vadd_f32(val, delta), delta));
#endif
}
} }
#endif // CAROTENE_NEON
#endif
+5 -5
View File
@@ -1,8 +1,8 @@
# Binaries branch name: ffmpeg/4.x_20231225 # Binaries branch name: ffmpeg/4.x_20230622
# Binaries were created for OpenCV: 62f1a7410d5e5e03d6cee5c95549bf61d5ee98db # Binaries were created for OpenCV: 61d48dd0f8d1cc1a115d26998705a61478f64a3c
ocv_update(FFMPEG_BINARIES_COMMIT "fbac408a47977ee4265f39e7659d33f1dfef5216") ocv_update(FFMPEG_BINARIES_COMMIT "7da61f0695eabf8972a2c302bf1632a3d99fb0d5")
ocv_update(FFMPEG_FILE_HASH_BIN32 "9b755ecbbade0a5b78332e9b4ef2dd1b") ocv_update(FFMPEG_FILE_HASH_BIN32 "4aaef1456e282e5ef665d65555f47f56")
ocv_update(FFMPEG_FILE_HASH_BIN64 "cb4db51ee9a423e6168b9d08bee61efc") ocv_update(FFMPEG_FILE_HASH_BIN64 "38a638851e064c591ce812e27ed43f1f")
ocv_update(FFMPEG_FILE_HASH_CMAKE "8862c87496e2e8c375965e1277dee1c7") ocv_update(FFMPEG_FILE_HASH_CMAKE "8862c87496e2e8c375965e1277dee1c7")
function(download_win_ffmpeg script_var) function(download_win_ffmpeg script_var)
+11 -11
View File
@@ -2,32 +2,32 @@ function(download_ippicv root_var)
set(${root_var} "" PARENT_SCOPE) set(${root_var} "" PARENT_SCOPE)
# Commit SHA in the opencv_3rdparty repo # Commit SHA in the opencv_3rdparty repo
set(IPPICV_COMMIT "0cc4aa06bf2bef4b05d237c69a5a96b9cd0cb85a") set(IPPICV_COMMIT "1224f78da6684df04397ac0f40c961ed37f79ccb")
# Define actual ICV versions # Define actual ICV versions
if(APPLE) if(APPLE)
set(OPENCV_ICV_PLATFORM "macosx") set(OPENCV_ICV_PLATFORM "macosx")
set(OPENCV_ICV_PACKAGE_SUBDIR "ippicv_mac") set(OPENCV_ICV_PACKAGE_SUBDIR "ippicv_mac")
set(OPENCV_ICV_NAME "ippicv_2021.9.1_mac_intel64_20230919_general.tgz") set(OPENCV_ICV_NAME "ippicv_2021.8_mac_intel64_20230330_general.tgz")
set(OPENCV_ICV_HASH "14f01c5a4780bfae9dde9b0aaf5e56fc") set(OPENCV_ICV_HASH "d2b234a86af1b616958619a4560356d9")
elseif((UNIX AND NOT ANDROID) OR (UNIX AND ANDROID_ABI MATCHES "x86")) elseif((UNIX AND NOT ANDROID) OR (UNIX AND ANDROID_ABI MATCHES "x86"))
set(OPENCV_ICV_PLATFORM "linux") set(OPENCV_ICV_PLATFORM "linux")
set(OPENCV_ICV_PACKAGE_SUBDIR "ippicv_lnx") set(OPENCV_ICV_PACKAGE_SUBDIR "ippicv_lnx")
if(X86_64) if(X86_64)
set(OPENCV_ICV_NAME "ippicv_2021.10.0_lnx_intel64_20230919_general.tgz") set(OPENCV_ICV_NAME "ippicv_2021.8_lnx_intel64_20230330_general.tgz")
set(OPENCV_ICV_HASH "606a19b207ebedfe42d59fd916cc4850") set(OPENCV_ICV_HASH "43219bdc7e3805adcbe3a1e2f1f3ef3b")
else() else()
set(OPENCV_ICV_NAME "ippicv_2021.10.0_lnx_ia32_20230919_general.tgz") set(OPENCV_ICV_NAME "ippicv_2021.8_lnx_ia32_20230330_general.tgz")
set(OPENCV_ICV_HASH "ea08487b810baad2f68aca87b74a2db9") set(OPENCV_ICV_HASH "165875443d72faa3fd2146869da90d07")
endif() endif()
elseif(WIN32 AND NOT ARM) elseif(WIN32 AND NOT ARM)
set(OPENCV_ICV_PLATFORM "windows") set(OPENCV_ICV_PLATFORM "windows")
set(OPENCV_ICV_PACKAGE_SUBDIR "ippicv_win") set(OPENCV_ICV_PACKAGE_SUBDIR "ippicv_win")
if(X86_64) if(X86_64)
set(OPENCV_ICV_NAME "ippicv_2021.10.0_win_intel64_20230919_general.zip") set(OPENCV_ICV_NAME "ippicv_2021.8_win_intel64_20230330_general.zip")
set(OPENCV_ICV_HASH "538a819ec84193a9c9f3c0f8df0be8b7") set(OPENCV_ICV_HASH "71e4f58de939f0348ec7fb58ffb17dbf")
else() else()
set(OPENCV_ICV_NAME "ippicv_2021.10.0_win_ia32_20230919_general.zip") set(OPENCV_ICV_NAME "ippicv_2021.8_win_ia32_20230330_general.zip")
set(OPENCV_ICV_HASH "8ff93c69415ab0835cc1e94dc5660f5d") set(OPENCV_ICV_HASH "57fd4648cfe64eae9e2ad9d50173a553")
endif() endif()
else() else()
return() return()
+1
View File
@@ -23,6 +23,7 @@ if(MSVC)
endif(MSVC) endif(MSVC)
add_library(${SPNG_LIBRARY} STATIC ${OPENCV_3RDPARTY_EXCLUDE_FROM_ALL} ${spng_headers} ${spng_sources}) add_library(${SPNG_LIBRARY} STATIC ${OPENCV_3RDPARTY_EXCLUDE_FROM_ALL} ${spng_headers} ${spng_sources})
ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-variable)
target_link_libraries(${SPNG_LIBRARY} ${ZLIB_LIBRARIES}) target_link_libraries(${SPNG_LIBRARY} ${ZLIB_LIBRARIES})
set_target_properties(${SPNG_LIBRARY} set_target_properties(${SPNG_LIBRARY}
+1 -1
View File
@@ -1,6 +1,6 @@
BSD 2-Clause License BSD 2-Clause License
Copyright (c) 2018-2023, Randy <randy408@protonmail.com> Copyright (c) 2018-2022, Randy <randy408@protonmail.com>
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
+3 -5
View File
@@ -2691,7 +2691,6 @@ static int read_non_idat_chunks(spng_ctx *ctx)
if(!memcmp(chunk.type, type_exif, 4)) if(!memcmp(chunk.type, type_exif, 4))
{ {
if(ctx->file.exif) return SPNG_EDUP_EXIF; if(ctx->file.exif) return SPNG_EDUP_EXIF;
if(!chunk.length) return SPNG_EEXIF;
ctx->file.exif = 1; ctx->file.exif = 1;
@@ -5000,11 +4999,11 @@ void spng_ctx_free(spng_ctx *ctx)
spng__free(ctx, ctx->prev_scanline_buf); spng__free(ctx, ctx->prev_scanline_buf);
spng__free(ctx, ctx->filtered_scanline_buf); spng__free(ctx, ctx->filtered_scanline_buf);
spng_free_fn *free_fn = ctx->alloc.free_fn; spng_free_fn *free_func = ctx->alloc.free_fn;
memset(ctx, 0, sizeof(spng_ctx)); memset(ctx, 0, sizeof(spng_ctx));
free_fn(ctx); free_func(ctx);
} }
static int buffer_read_fn(spng_ctx *ctx, void *user, void *data, size_t n) static int buffer_read_fn(spng_ctx *ctx, void *user, void *data, size_t n)
@@ -5744,8 +5743,7 @@ int spng_set_iccp(spng_ctx *ctx, struct spng_iccp *iccp)
SPNG_SET_CHUNK_BOILERPLATE(iccp); SPNG_SET_CHUNK_BOILERPLATE(iccp);
if(check_png_keyword(iccp->profile_name)) return SPNG_EICCP_NAME; if(check_png_keyword(iccp->profile_name)) return SPNG_EICCP_NAME;
if(!iccp->profile_len) return SPNG_ECHUNK_SIZE; if(!iccp->profile_len || iccp->profile_len > UINT_MAX) return 1;
if(iccp->profile_len > spng_u32max) return SPNG_ECHUNK_STDLEN;
if(ctx->iccp.profile && !ctx->user.iccp) spng__free(ctx, ctx->iccp.profile); if(ctx->iccp.profile && !ctx->user.iccp) spng__free(ctx, ctx->iccp.profile);
+2 -2
View File
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: BSD-2-Clause */ /* SPDX-License-Identifier: (BSD-2-Clause AND libpng-2.0) */
#ifndef SPNG_H #ifndef SPNG_H
#define SPNG_H #define SPNG_H
@@ -28,7 +28,7 @@ extern "C" {
#define SPNG_VERSION_MAJOR 0 #define SPNG_VERSION_MAJOR 0
#define SPNG_VERSION_MINOR 7 #define SPNG_VERSION_MINOR 7
#define SPNG_VERSION_PATCH 4 #define SPNG_VERSION_PATCH 3
enum spng_errno enum spng_errno
{ {
+80
View File
@@ -0,0 +1,80 @@
# COPYRIGHT
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# License); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# Copyright (c) 2020, OPEN AI LAB
# Author: qtang@openailab.com or https://github.com/BUG1989
# qli@openailab.com
# sqfu@openailab.com
SET(TENGINE_COMMIT_VERSION "e89cf8870de2ff0a80cfe626c0b52b2a16fb302e")
SET(OCV_TENGINE_DIR "${OpenCV_BINARY_DIR}/3rdparty/libtengine")
SET(OCV_TENGINE_SOURCE_PATH "${OCV_TENGINE_DIR}/Tengine-${TENGINE_COMMIT_VERSION}")
IF(EXISTS "${OCV_TENGINE_SOURCE_PATH}")
MESSAGE(STATUS "Tengine is exist already at: ${OCV_TENGINE_SOURCE_PATH}")
SET(Tengine_FOUND ON)
SET(BUILD_TENGINE ON)
ELSE()
SET(OCV_TENGINE_FILENAME "${TENGINE_COMMIT_VERSION}.zip")#name
SET(OCV_TENGINE_URL "https://github.com/OAID/Tengine/archive/") #url
SET(tengine_md5sum 23f61ebb1dd419f1207d8876496289c5) #md5sum
ocv_download(FILENAME ${OCV_TENGINE_FILENAME}
HASH ${tengine_md5sum}
URL
"${OPENCV_TENGINE_URL}"
"$ENV{OPENCV_TENGINE_URL}"
"${OCV_TENGINE_URL}"
DESTINATION_DIR "${OCV_TENGINE_DIR}"
ID TENGINE
STATUS res
UNPACK RELATIVE_URL)
if (NOT res)
MESSAGE(STATUS "TENGINE DOWNLOAD FAILED. Turning Tengine_FOUND off.")
SET(Tengine_FOUND OFF)
else ()
MESSAGE(STATUS "TENGINE DOWNLOAD success . ")
SET(Tengine_FOUND ON)
SET(BUILD_TENGINE ON)
endif()
ENDIF()
if(BUILD_TENGINE)
SET(HAVE_TENGINE 1)
if(NOT ANDROID)
# linux system
if(CMAKE_SYSTEM_PROCESSOR STREQUAL arm)
SET(TENGINE_TOOLCHAIN_FLAG "-march=armv7-a")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64) ## AARCH64
SET(TENGINE_TOOLCHAIN_FLAG "-march=armv8-a")
endif()
endif()
SET(BUILT_IN_OPENCV ON) ## set for tengine compile discern .
SET(Tengine_INCLUDE_DIR "${OCV_TENGINE_SOURCE_PATH}/include" CACHE INTERNAL "")
if(EXISTS "${OCV_TENGINE_SOURCE_PATH}/CMakeLists.txt")
add_subdirectory("${OCV_TENGINE_SOURCE_PATH}" "${OCV_TENGINE_DIR}/build")
else()
message(WARNING "TENGINE: Missing 'CMakeLists.txt' in source code package: ${OCV_TENGINE_SOURCE_PATH}")
endif()
SET(Tengine_LIB "tengine" CACHE INTERNAL "")
endif()
+1 -1
View File
@@ -4371,7 +4371,7 @@ static void
TIFFReadDirectoryCheckOrder(TIFF* tif, TIFFDirEntry* dir, uint16 dircount) TIFFReadDirectoryCheckOrder(TIFF* tif, TIFFDirEntry* dir, uint16 dircount)
{ {
static const char module[] = "TIFFReadDirectoryCheckOrder"; static const char module[] = "TIFFReadDirectoryCheckOrder";
uint32 m; uint16 m;
uint16 n; uint16 n;
TIFFDirEntry* o; TIFFDirEntry* o;
m=0; m=0;
+1 -1
View File
@@ -107,7 +107,7 @@ floatToUint (float f)
if (isNegative (f) || isNan (f)) if (isNegative (f) || isNan (f))
return 0; return 0;
if (isInfinity (f) || f > (float)UINT_MAX) if (isInfinity (f) || f > UINT_MAX)
return UINT_MAX; return UINT_MAX;
return (unsigned int) f; return (unsigned int) f;
-1
View File
@@ -16,7 +16,6 @@ ocv_warnings_disable(CMAKE_C_FLAGS
-Wunused-but-set-variable # clang15 -Wunused-but-set-variable # clang15
-Wmissing-prototypes # clang, function opj_t1_ht_decode_cblk -Wmissing-prototypes # clang, function opj_t1_ht_decode_cblk
-Wmissing-declarations # gcc, function opj_t1_ht_decode_cblk -Wmissing-declarations # gcc, function opj_t1_ht_decode_cblk
-Wdocumentation # clang
) )
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
+1 -8
View File
@@ -55,10 +55,6 @@
#define OPJ_COMPILER_GNUC #define OPJ_COMPILER_GNUC
#endif #endif
#if defined(OPJ_COMPILER_MSVC) && defined(_M_ARM64)
#include <arm64_neon.h>
#endif
//************************************************************************/ //************************************************************************/
/** @brief Displays the error message for disabling the decoding of SPP and /** @brief Displays the error message for disabling the decoding of SPP and
* MRP passes * MRP passes
@@ -73,11 +69,8 @@ static OPJ_BOOL only_cleanup_pass_is_decoded = OPJ_FALSE;
static INLINE static INLINE
OPJ_UINT32 population_count(OPJ_UINT32 val) OPJ_UINT32 population_count(OPJ_UINT32 val)
{ {
#if defined(OPJ_COMPILER_MSVC) && (defined(_M_IX86) || defined(_M_AMD64)) #ifdef OPJ_COMPILER_MSVC
return (OPJ_UINT32)__popcnt(val); return (OPJ_UINT32)__popcnt(val);
#elif defined(OPJ_COMPILER_MSVC) && defined(_M_ARM64)
const __n64 temp = neon_cnt(__uint64ToN64_v(val));
return neon_addv8(temp).n8_i8[0];
#elif (defined OPJ_COMPILER_GNUC) #elif (defined OPJ_COMPILER_GNUC)
return (OPJ_UINT32)__builtin_popcount(val); return (OPJ_UINT32)__builtin_popcount(val);
#else #else
+1 -1
View File
@@ -7796,7 +7796,7 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k,
image->comps[0].h * image->comps[0].prec) / image->comps[0].h * image->comps[0].prec) /
((double)parameters->tcp_rates[parameters->tcp_numlayers - 1] * 8 * ((double)parameters->tcp_rates[parameters->tcp_numlayers - 1] * 8 *
image->comps[0].dx * image->comps[0].dy)); image->comps[0].dx * image->comps[0].dy));
if (temp_size > (OPJ_FLOAT32)INT_MAX) { if (temp_size > INT_MAX) {
parameters->max_cs_size = INT_MAX; parameters->max_cs_size = INT_MAX;
} else { } else {
parameters->max_cs_size = (int) floor(temp_size); parameters->max_cs_size = (int) floor(temp_size);
+1 -1
View File
@@ -2262,7 +2262,7 @@ static OPJ_BOOL opj_tcd_dc_level_shift_decode(opj_tcd_t *p_tcd)
for (j = 0; j < l_height; ++j) { for (j = 0; j < l_height; ++j) {
for (i = 0; i < l_width; ++i) { for (i = 0; i < l_width; ++i) {
OPJ_FLOAT32 l_value = *((OPJ_FLOAT32 *) l_current_ptr); OPJ_FLOAT32 l_value = *((OPJ_FLOAT32 *) l_current_ptr);
if (l_value > (OPJ_FLOAT32)INT_MAX) { if (l_value > INT_MAX) {
*l_current_ptr = l_max; *l_current_ptr = l_max;
} else if (l_value < INT_MIN) { } else if (l_value < INT_MIN) {
*l_current_ptr = l_min; *l_current_ptr = l_min;
-3
View File
@@ -26,9 +26,6 @@ else()
-Wsuggest-override -Winconsistent-missing-override -Wsuggest-override -Winconsistent-missing-override
-Wimplicit-fallthrough -Wimplicit-fallthrough
-Warray-bounds # GCC 9+ -Warray-bounds # GCC 9+
-Wstringop-overflow -Wstringop-overread # GCC 11-12
-Wextra-semi # clang
-Wcomma # clang
) )
endif() endif()
if(CV_ICC) if(CV_ICC)
+2 -3
View File
@@ -31,7 +31,7 @@ libpng Portable Network Graphics library.
libspng Portable Network Graphics library. libspng Portable Network Graphics library.
The license and copyright notes can be found in libspng/LICENSE. The license and copyright notes can be found in libspng/LICENSE.
See libspng home page https://libspng.org See libspng home page https://www.libspng.org
for details and links to the source code for details and links to the source code
WITH_SPNG CMake option must be ON to add libspng support to imgcodecs WITH_SPNG CMake option must be ON to add libspng support to imgcodecs
@@ -39,8 +39,7 @@ libspng Portable Network Graphics library.
libtiff Tag Image File Format (TIFF) Software libtiff Tag Image File Format (TIFF) Software
Copyright (c) 1988-1997 Sam Leffler Copyright (c) 1988-1997 Sam Leffler
Copyright (c) 1991-1997 Silicon Graphics, Inc. Copyright (c) 1991-1997 Silicon Graphics, Inc.
See libtiff home page #1 http://www.simplesystems.org/libtiff/ See libtiff home page http://www.libtiff.org/
#2 https://libtiff.gitlab.io/libtiff/
for details and links to the source code for details and links to the source code
WITH_TIFF CMake option must be ON to add libtiff & zlib support to imgcodecs. WITH_TIFF CMake option must be ON to add libtiff & zlib support to imgcodecs.
+1 -19
View File
@@ -1,24 +1,6 @@
ChangeLog file for zlib ChangeLog file for zlib
Changes in 1.3 (18 Aug 2023)
- Remove K&R function definitions and zlib2ansi
- Fix bug in deflateBound() for level 0 and memLevel 9
- Fix bug when gzungetc() is used immediately after gzopen()
- Fix bug when using gzflush() with a very small buffer
- Fix crash when gzsetparams() attempted for transparent write
- Fix test/example.c to work with FORCE_STORED
- Rewrite of zran in examples (see zran.c version history)
- Fix minizip to allow it to open an empty zip file
- Fix reading disk number start on zip64 files in minizip
- Fix logic error in minizip argument processing
- Add minizip testing to Makefile
- Read multiple bytes instead of byte-by-byte in minizip unzip.c
- Add memory sanitizer to configure (--memory)
- Various portability improvements
- Various documentation improvements
- Various spelling and typo corrections
Changes in 1.2.13 (13 Oct 2022) Changes in 1.2.13 (13 Oct 2022)
- Fix configure issue that discarded provided CC definition - Fix configure issue that discarded provided CC definition
- Correct incorrect inputs provided to the CRC functions - Correct incorrect inputs provided to the CRC functions
@@ -1463,7 +1445,7 @@ Changes in 0.99 (27 Jan 96)
- fix typo in Make_vms.com (f$trnlnm -> f$getsyi) - fix typo in Make_vms.com (f$trnlnm -> f$getsyi)
- in fcalloc, normalize pointer if size > 65520 bytes - in fcalloc, normalize pointer if size > 65520 bytes
- don't use special fcalloc for 32 bit Borland C++ - don't use special fcalloc for 32 bit Borland C++
- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc. - use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc...
- use Z_BINARY instead of BINARY - use Z_BINARY instead of BINARY
- document that gzclose after gzdopen will close the file - document that gzclose after gzdopen will close the file
- allow "a" as mode in gzopen - allow "a" as mode in gzopen
+10 -9
View File
@@ -1,6 +1,6 @@
ZLIB DATA COMPRESSION LIBRARY ZLIB DATA COMPRESSION LIBRARY
zlib 1.3 is a general purpose data compression library. All the code is zlib 1.2.13 is a general purpose data compression library. All the code is
thread safe. The data format used by the zlib library is described by RFCs thread safe. The data format used by the zlib library is described by RFCs
(Request for Comments) 1950 to 1952 in the files (Request for Comments) 1950 to 1952 in the files
http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and
@@ -29,17 +29,18 @@ PLEASE read the zlib FAQ http://zlib.net/zlib_faq.html before asking for help.
Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan. 1997 Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan. 1997
issue of Dr. Dobb's Journal; a copy of the article is available at issue of Dr. Dobb's Journal; a copy of the article is available at
https://marknelson.us/posts/1997/01/01/zlib-engine.html . http://marknelson.us/1997/01/01/zlib-engine/ .
The changes made in version 1.3 are documented in the file ChangeLog. The changes made in version 1.2.13 are documented in the file ChangeLog.
Unsupported third party contributions are provided in directory contrib/ . Unsupported third party contributions are provided in directory contrib/ .
zlib is available in Java using the java.util.zip package. Follow the API zlib is available in Java using the java.util.zip package, documented at
Documentation link at: https://docs.oracle.com/search/?q=java.util.zip . http://java.sun.com/developer/technicalArticles/Programming/compression/ .
A Perl interface to zlib and bzip2 written by Paul Marquess <pmqs@cpan.org> A Perl interface to zlib written by Paul Marquess <pmqs@cpan.org> is available
can be found at https://github.com/pmqs/IO-Compress . at CPAN (Comprehensive Perl Archive Network) sites, including
http://search.cpan.org/~pmqs/IO-Compress-Zlib/ .
A Python interface to zlib written by A.M. Kuchling <amk@amk.ca> is A Python interface to zlib written by A.M. Kuchling <amk@amk.ca> is
available in Python 1.5 and later versions, see available in Python 1.5 and later versions, see
@@ -63,7 +64,7 @@ Notes for some targets:
- zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works - zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works
when compiled with cc. when compiled with cc.
- On Digital Unix 4.0D (formerly OSF/1) on AlphaServer, the cc option -std1 is - On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is
necessary to get gzprintf working correctly. This is done by configure. necessary to get gzprintf working correctly. This is done by configure.
- zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with - zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with
@@ -83,7 +84,7 @@ Acknowledgments:
Copyright notice: Copyright notice:
(C) 1995-2023 Jean-loup Gailly and Mark Adler (C) 1995-2022 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
+27 -5
View File
@@ -7,6 +7,8 @@
#include "zutil.h" #include "zutil.h"
local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
#define BASE 65521U /* largest prime smaller than 65536 */ #define BASE 65521U /* largest prime smaller than 65536 */
#define NMAX 5552 #define NMAX 5552
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
@@ -58,7 +60,11 @@
#endif #endif
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len) { uLong ZEXPORT adler32_z(adler, buf, len)
uLong adler;
const Bytef *buf;
z_size_t len;
{
unsigned long sum2; unsigned long sum2;
unsigned n; unsigned n;
@@ -125,12 +131,20 @@ uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len) {
} }
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) { uLong ZEXPORT adler32(adler, buf, len)
uLong adler;
const Bytef *buf;
uInt len;
{
return adler32_z(adler, buf, len); return adler32_z(adler, buf, len);
} }
/* ========================================================================= */ /* ========================================================================= */
local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2) { local uLong adler32_combine_(adler1, adler2, len2)
uLong adler1;
uLong adler2;
z_off64_t len2;
{
unsigned long sum1; unsigned long sum1;
unsigned long sum2; unsigned long sum2;
unsigned rem; unsigned rem;
@@ -155,10 +169,18 @@ local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2) {
} }
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2) { uLong ZEXPORT adler32_combine(adler1, adler2, len2)
uLong adler1;
uLong adler2;
z_off_t len2;
{
return adler32_combine_(adler1, adler2, len2); return adler32_combine_(adler1, adler2, len2);
} }
uLong ZEXPORT adler32_combine64(uLong adler1, uLong adler2, z_off64_t len2) { uLong ZEXPORT adler32_combine64(adler1, adler2, len2)
uLong adler1;
uLong adler2;
z_off64_t len2;
{
return adler32_combine_(adler1, adler2, len2); return adler32_combine_(adler1, adler2, len2);
} }
+16 -5
View File
@@ -19,8 +19,13 @@
memory, Z_BUF_ERROR if there was not enough room in the output buffer, memory, Z_BUF_ERROR if there was not enough room in the output buffer,
Z_STREAM_ERROR if the level parameter is invalid. Z_STREAM_ERROR if the level parameter is invalid.
*/ */
int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source, int ZEXPORT compress2(dest, destLen, source, sourceLen, level)
uLong sourceLen, int level) { Bytef *dest;
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
int level;
{
z_stream stream; z_stream stream;
int err; int err;
const uInt max = (uInt)-1; const uInt max = (uInt)-1;
@@ -60,8 +65,12 @@ int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source,
/* =========================================================================== /* ===========================================================================
*/ */
int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source, int ZEXPORT compress(dest, destLen, source, sourceLen)
uLong sourceLen) { Bytef *dest;
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
{
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
} }
@@ -69,7 +78,9 @@ int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source,
If the default memLevel or windowBits for deflateInit() is changed, then If the default memLevel or windowBits for deflateInit() is changed, then
this function needs to be updated. this function needs to be updated.
*/ */
uLong ZEXPORT compressBound(uLong sourceLen) { uLong ZEXPORT compressBound(sourceLen)
uLong sourceLen;
{
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
(sourceLen >> 25) + 13; (sourceLen >> 25) + 13;
} }
+162 -86
View File
@@ -103,6 +103,19 @@
# define ARMCRC32 # define ARMCRC32
#endif #endif
/* Local functions. */
local z_crc_t multmodp OF((z_crc_t a, z_crc_t b));
local z_crc_t x2nmodp OF((z_off64_t n, unsigned k));
#if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE))
local z_word_t byte_swap OF((z_word_t word));
#endif
#if defined(W) && !defined(ARMCRC32)
local z_crc_t crc_word OF((z_word_t data));
local z_word_t crc_word_big OF((z_word_t data));
#endif
#if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE)) #if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE))
/* /*
Swap the bytes in a z_word_t to convert between little and big endian. Any Swap the bytes in a z_word_t to convert between little and big endian. Any
@@ -110,7 +123,9 @@
instruction, if one is available. This assumes that word_t is either 32 bits instruction, if one is available. This assumes that word_t is either 32 bits
or 64 bits. or 64 bits.
*/ */
local z_word_t byte_swap(z_word_t word) { local z_word_t byte_swap(word)
z_word_t word;
{
# if W == 8 # if W == 8
return return
(word & 0xff00000000000000) >> 56 | (word & 0xff00000000000000) >> 56 |
@@ -131,77 +146,24 @@ local z_word_t byte_swap(z_word_t word) {
} }
#endif #endif
#ifdef DYNAMIC_CRC_TABLE
/* =========================================================================
* Table of powers of x for combining CRC-32s, filled in by make_crc_table()
* below.
*/
local z_crc_t FAR x2n_table[32];
#else
/* =========================================================================
* Tables for byte-wise and braided CRC-32 calculations, and a table of powers
* of x for combining CRC-32s, all made by make_crc_table().
*/
# include "crc32.h"
#endif
/* CRC polynomial. */ /* CRC polynomial. */
#define POLY 0xedb88320 /* p(x) reflected, with x^32 implied */ #define POLY 0xedb88320 /* p(x) reflected, with x^32 implied */
/*
Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial,
reflected. For speed, this requires that a not be zero.
*/
local z_crc_t multmodp(z_crc_t a, z_crc_t b) {
z_crc_t m, p;
m = (z_crc_t)1 << 31;
p = 0;
for (;;) {
if (a & m) {
p ^= b;
if ((a & (m - 1)) == 0)
break;
}
m >>= 1;
b = b & 1 ? (b >> 1) ^ POLY : b >> 1;
}
return p;
}
/*
Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been
initialized.
*/
local z_crc_t x2nmodp(z_off64_t n, unsigned k) {
z_crc_t p;
p = (z_crc_t)1 << 31; /* x^0 == 1 */
while (n) {
if (n & 1)
p = multmodp(x2n_table[k & 31], p);
n >>= 1;
k++;
}
return p;
}
#ifdef DYNAMIC_CRC_TABLE #ifdef DYNAMIC_CRC_TABLE
/* =========================================================================
* Build the tables for byte-wise and braided CRC-32 calculations, and a table
* of powers of x for combining CRC-32s.
*/
local z_crc_t FAR crc_table[256]; local z_crc_t FAR crc_table[256];
local z_crc_t FAR x2n_table[32];
local void make_crc_table OF((void));
#ifdef W #ifdef W
local z_word_t FAR crc_big_table[256]; local z_word_t FAR crc_big_table[256];
local z_crc_t FAR crc_braid_table[W][256]; local z_crc_t FAR crc_braid_table[W][256];
local z_word_t FAR crc_braid_big_table[W][256]; local z_word_t FAR crc_braid_big_table[W][256];
local void braid(z_crc_t [][256], z_word_t [][256], int, int); local void braid OF((z_crc_t [][256], z_word_t [][256], int, int));
#endif #endif
#ifdef MAKECRCH #ifdef MAKECRCH
local void write_table(FILE *, const z_crc_t FAR *, int); local void write_table OF((FILE *, const z_crc_t FAR *, int));
local void write_table32hi(FILE *, const z_word_t FAR *, int); local void write_table32hi OF((FILE *, const z_word_t FAR *, int));
local void write_table64(FILE *, const z_word_t FAR *, int); local void write_table64 OF((FILE *, const z_word_t FAR *, int));
#endif /* MAKECRCH */ #endif /* MAKECRCH */
/* /*
@@ -214,6 +176,7 @@ local z_crc_t FAR crc_table[256];
/* Definition of once functionality. */ /* Definition of once functionality. */
typedef struct once_s once_t; typedef struct once_s once_t;
local void once OF((once_t *, void (*)(void)));
/* Check for the availability of atomics. */ /* Check for the availability of atomics. */
#if defined(__STDC__) && __STDC_VERSION__ >= 201112L && \ #if defined(__STDC__) && __STDC_VERSION__ >= 201112L && \
@@ -233,7 +196,10 @@ struct once_s {
invoke once() at the same time. The state must be a once_t initialized with invoke once() at the same time. The state must be a once_t initialized with
ONCE_INIT. ONCE_INIT.
*/ */
local void once(once_t *state, void (*init)(void)) { local void once(state, init)
once_t *state;
void (*init)(void);
{
if (!atomic_load(&state->done)) { if (!atomic_load(&state->done)) {
if (atomic_flag_test_and_set(&state->begun)) if (atomic_flag_test_and_set(&state->begun))
while (!atomic_load(&state->done)) while (!atomic_load(&state->done))
@@ -256,7 +222,10 @@ struct once_s {
/* Test and set. Alas, not atomic, but tries to minimize the period of /* Test and set. Alas, not atomic, but tries to minimize the period of
vulnerability. */ vulnerability. */
local int test_and_set(int volatile *flag) { local int test_and_set OF((int volatile *));
local int test_and_set(flag)
int volatile *flag;
{
int was; int was;
was = *flag; was = *flag;
@@ -265,7 +234,10 @@ local int test_and_set(int volatile *flag) {
} }
/* Run the provided init() function once. This is not thread-safe. */ /* Run the provided init() function once. This is not thread-safe. */
local void once(once_t *state, void (*init)(void)) { local void once(state, init)
once_t *state;
void (*init)(void);
{
if (!state->done) { if (!state->done) {
if (test_and_set(&state->begun)) if (test_and_set(&state->begun))
while (!state->done) while (!state->done)
@@ -307,7 +279,8 @@ local once_t made = ONCE_INIT;
combinations of CRC register values and incoming bytes. combinations of CRC register values and incoming bytes.
*/ */
local void make_crc_table(void) { local void make_crc_table()
{
unsigned i, j, n; unsigned i, j, n;
z_crc_t p; z_crc_t p;
@@ -474,7 +447,11 @@ local void make_crc_table(void) {
Write the 32-bit values in table[0..k-1] to out, five per line in Write the 32-bit values in table[0..k-1] to out, five per line in
hexadecimal separated by commas. hexadecimal separated by commas.
*/ */
local void write_table(FILE *out, const z_crc_t FAR *table, int k) { local void write_table(out, table, k)
FILE *out;
const z_crc_t FAR *table;
int k;
{
int n; int n;
for (n = 0; n < k; n++) for (n = 0; n < k; n++)
@@ -487,7 +464,11 @@ local void write_table(FILE *out, const z_crc_t FAR *table, int k) {
Write the high 32-bits of each value in table[0..k-1] to out, five per line Write the high 32-bits of each value in table[0..k-1] to out, five per line
in hexadecimal separated by commas. in hexadecimal separated by commas.
*/ */
local void write_table32hi(FILE *out, const z_word_t FAR *table, int k) { local void write_table32hi(out, table, k)
FILE *out;
const z_word_t FAR *table;
int k;
{
int n; int n;
for (n = 0; n < k; n++) for (n = 0; n < k; n++)
@@ -503,7 +484,11 @@ local void write_table32hi(FILE *out, const z_word_t FAR *table, int k) {
bits. If not, then the type cast and format string can be adjusted bits. If not, then the type cast and format string can be adjusted
accordingly. accordingly.
*/ */
local void write_table64(FILE *out, const z_word_t FAR *table, int k) { local void write_table64(out, table, k)
FILE *out;
const z_word_t FAR *table;
int k;
{
int n; int n;
for (n = 0; n < k; n++) for (n = 0; n < k; n++)
@@ -513,7 +498,8 @@ local void write_table64(FILE *out, const z_word_t FAR *table, int k) {
} }
/* Actually do the deed. */ /* Actually do the deed. */
int main(void) { int main()
{
make_crc_table(); make_crc_table();
return 0; return 0;
} }
@@ -525,7 +511,12 @@ int main(void) {
Generate the little and big-endian braid tables for the given n and z_word_t Generate the little and big-endian braid tables for the given n and z_word_t
size w. Each array must have room for w blocks of 256 elements. size w. Each array must have room for w blocks of 256 elements.
*/ */
local void braid(z_crc_t ltl[][256], z_word_t big[][256], int n, int w) { local void braid(ltl, big, n, w)
z_crc_t ltl[][256];
z_word_t big[][256];
int n;
int w;
{
int k; int k;
z_crc_t i, p, q; z_crc_t i, p, q;
for (k = 0; k < w; k++) { for (k = 0; k < w; k++) {
@@ -540,13 +531,69 @@ local void braid(z_crc_t ltl[][256], z_word_t big[][256], int n, int w) {
} }
#endif #endif
#else /* !DYNAMIC_CRC_TABLE */
/* ========================================================================
* Tables for byte-wise and braided CRC-32 calculations, and a table of powers
* of x for combining CRC-32s, all made by make_crc_table().
*/
#include "crc32.h"
#endif /* DYNAMIC_CRC_TABLE */ #endif /* DYNAMIC_CRC_TABLE */
/* ========================================================================
* Routines used for CRC calculation. Some are also required for the table
* generation above.
*/
/*
Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial,
reflected. For speed, this requires that a not be zero.
*/
local z_crc_t multmodp(a, b)
z_crc_t a;
z_crc_t b;
{
z_crc_t m, p;
m = (z_crc_t)1 << 31;
p = 0;
for (;;) {
if (a & m) {
p ^= b;
if ((a & (m - 1)) == 0)
break;
}
m >>= 1;
b = b & 1 ? (b >> 1) ^ POLY : b >> 1;
}
return p;
}
/*
Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been
initialized.
*/
local z_crc_t x2nmodp(n, k)
z_off64_t n;
unsigned k;
{
z_crc_t p;
p = (z_crc_t)1 << 31; /* x^0 == 1 */
while (n) {
if (n & 1)
p = multmodp(x2n_table[k & 31], p);
n >>= 1;
k++;
}
return p;
}
/* ========================================================================= /* =========================================================================
* This function can be used by asm versions of crc32(), and to force the * This function can be used by asm versions of crc32(), and to force the
* generation of the CRC tables in a threaded application. * generation of the CRC tables in a threaded application.
*/ */
const z_crc_t FAR * ZEXPORT get_crc_table(void) { const z_crc_t FAR * ZEXPORT get_crc_table()
{
#ifdef DYNAMIC_CRC_TABLE #ifdef DYNAMIC_CRC_TABLE
once(&made, make_crc_table); once(&made, make_crc_table);
#endif /* DYNAMIC_CRC_TABLE */ #endif /* DYNAMIC_CRC_TABLE */
@@ -572,8 +619,11 @@ const z_crc_t FAR * ZEXPORT get_crc_table(void) {
#define Z_BATCH_ZEROS 0xa10d3d0c /* computed from Z_BATCH = 3990 */ #define Z_BATCH_ZEROS 0xa10d3d0c /* computed from Z_BATCH = 3990 */
#define Z_BATCH_MIN 800 /* fewest words in a final batch */ #define Z_BATCH_MIN 800 /* fewest words in a final batch */
unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, unsigned long ZEXPORT crc32_z(crc, buf, len)
z_size_t len) { unsigned long crc;
const unsigned char FAR *buf;
z_size_t len;
{
z_crc_t val; z_crc_t val;
z_word_t crc1, crc2; z_word_t crc1, crc2;
const z_word_t *word; const z_word_t *word;
@@ -673,14 +723,18 @@ unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf,
least-significant byte of the word as the first byte of data, without any pre least-significant byte of the word as the first byte of data, without any pre
or post conditioning. This is used to combine the CRCs of each braid. or post conditioning. This is used to combine the CRCs of each braid.
*/ */
local z_crc_t crc_word(z_word_t data) { local z_crc_t crc_word(data)
z_word_t data;
{
int k; int k;
for (k = 0; k < W; k++) for (k = 0; k < W; k++)
data = (data >> 8) ^ crc_table[data & 0xff]; data = (data >> 8) ^ crc_table[data & 0xff];
return (z_crc_t)data; return (z_crc_t)data;
} }
local z_word_t crc_word_big(z_word_t data) { local z_word_t crc_word_big(data)
z_word_t data;
{
int k; int k;
for (k = 0; k < W; k++) for (k = 0; k < W; k++)
data = (data << 8) ^ data = (data << 8) ^
@@ -691,8 +745,11 @@ local z_word_t crc_word_big(z_word_t data) {
#endif #endif
/* ========================================================================= */ /* ========================================================================= */
unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, unsigned long ZEXPORT crc32_z(crc, buf, len)
z_size_t len) { unsigned long crc;
const unsigned char FAR *buf;
z_size_t len;
{
/* Return initial CRC, if requested. */ /* Return initial CRC, if requested. */
if (buf == Z_NULL) return 0; if (buf == Z_NULL) return 0;
@@ -724,8 +781,8 @@ unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf,
words = (z_word_t const *)buf; words = (z_word_t const *)buf;
/* Do endian check at execution time instead of compile time, since ARM /* Do endian check at execution time instead of compile time, since ARM
processors can change the endianness at execution time. If the processors can change the endianess at execution time. If the
compiler knows what the endianness will be, it can optimize out the compiler knows what the endianess will be, it can optimize out the
check and the unused branch. */ check and the unused branch. */
endian = 1; endian = 1;
if (*(unsigned char *)&endian) { if (*(unsigned char *)&endian) {
@@ -1012,13 +1069,20 @@ unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf,
#endif #endif
/* ========================================================================= */ /* ========================================================================= */
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, unsigned long ZEXPORT crc32(crc, buf, len)
uInt len) { unsigned long crc;
const unsigned char FAR *buf;
uInt len;
{
return crc32_z(crc, buf, len); return crc32_z(crc, buf, len);
} }
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT crc32_combine64(uLong crc1, uLong crc2, z_off64_t len2) { uLong ZEXPORT crc32_combine64(crc1, crc2, len2)
uLong crc1;
uLong crc2;
z_off64_t len2;
{
#ifdef DYNAMIC_CRC_TABLE #ifdef DYNAMIC_CRC_TABLE
once(&made, make_crc_table); once(&made, make_crc_table);
#endif /* DYNAMIC_CRC_TABLE */ #endif /* DYNAMIC_CRC_TABLE */
@@ -1026,12 +1090,18 @@ uLong ZEXPORT crc32_combine64(uLong crc1, uLong crc2, z_off64_t len2) {
} }
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2) { uLong ZEXPORT crc32_combine(crc1, crc2, len2)
uLong crc1;
uLong crc2;
z_off_t len2;
{
return crc32_combine64(crc1, crc2, (z_off64_t)len2); return crc32_combine64(crc1, crc2, (z_off64_t)len2);
} }
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT crc32_combine_gen64(z_off64_t len2) { uLong ZEXPORT crc32_combine_gen64(len2)
z_off64_t len2;
{
#ifdef DYNAMIC_CRC_TABLE #ifdef DYNAMIC_CRC_TABLE
once(&made, make_crc_table); once(&made, make_crc_table);
#endif /* DYNAMIC_CRC_TABLE */ #endif /* DYNAMIC_CRC_TABLE */
@@ -1039,11 +1109,17 @@ uLong ZEXPORT crc32_combine_gen64(z_off64_t len2) {
} }
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT crc32_combine_gen(z_off_t len2) { uLong ZEXPORT crc32_combine_gen(len2)
z_off_t len2;
{
return crc32_combine_gen64((z_off64_t)len2); return crc32_combine_gen64((z_off64_t)len2);
} }
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op) { uLong ZEXPORT crc32_combine_op(crc1, crc2, op)
uLong crc1;
uLong crc2;
uLong op;
{
return multmodp(op, crc1) ^ (crc2 & 0xffffffff); return multmodp(op, crc1) ^ (crc2 & 0xffffffff);
} }
+336 -233
View File
@@ -1,5 +1,5 @@
/* deflate.c -- compress data using the deflation algorithm /* deflate.c -- compress data using the deflation algorithm
* Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler * Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@@ -52,7 +52,7 @@
#include "deflate.h" #include "deflate.h"
const char deflate_copyright[] = const char deflate_copyright[] =
" deflate 1.3 Copyright 1995-2023 Jean-loup Gailly and Mark Adler "; " deflate 1.2.13 Copyright 1995-2022 Jean-loup Gailly and Mark Adler ";
/* /*
If you use the zlib library in a product, an acknowledgment is welcome If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot in the documentation of your product. If for some reason you cannot
@@ -60,6 +60,9 @@ const char deflate_copyright[] =
copyright string in the executable of your product. copyright string in the executable of your product.
*/ */
/* ===========================================================================
* Function prototypes.
*/
typedef enum { typedef enum {
need_more, /* block not completed, need more input or more output */ need_more, /* block not completed, need more input or more output */
block_done, /* block flush performed */ block_done, /* block flush performed */
@@ -67,16 +70,29 @@ typedef enum {
finish_done /* finish done, accept no more input or output */ finish_done /* finish done, accept no more input or output */
} block_state; } block_state;
typedef block_state (*compress_func)(deflate_state *s, int flush); typedef block_state (*compress_func) OF((deflate_state *s, int flush));
/* Compression function. Returns the block state after the call. */ /* Compression function. Returns the block state after the call. */
local block_state deflate_stored(deflate_state *s, int flush); local int deflateStateCheck OF((z_streamp strm));
local block_state deflate_fast(deflate_state *s, int flush); local void slide_hash OF((deflate_state *s));
local void fill_window OF((deflate_state *s));
local block_state deflate_stored OF((deflate_state *s, int flush));
local block_state deflate_fast OF((deflate_state *s, int flush));
#ifndef FASTEST #ifndef FASTEST
local block_state deflate_slow(deflate_state *s, int flush); local block_state deflate_slow OF((deflate_state *s, int flush));
#endif
local block_state deflate_rle OF((deflate_state *s, int flush));
local block_state deflate_huff OF((deflate_state *s, int flush));
local void lm_init OF((deflate_state *s));
local void putShortMSB OF((deflate_state *s, uInt b));
local void flush_pending OF((z_streamp strm));
local unsigned read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
local uInt longest_match OF((deflate_state *s, IPos cur_match));
#ifdef ZLIB_DEBUG
local void check_match OF((deflate_state *s, IPos start, IPos match,
int length));
#endif #endif
local block_state deflate_rle(deflate_state *s, int flush);
local block_state deflate_huff(deflate_state *s, int flush);
/* =========================================================================== /* ===========================================================================
* Local data * Local data
@@ -179,12 +195,9 @@ local const config configuration_table[10] = {
* bit values at the expense of memory usage). We slide even when level == 0 to * bit values at the expense of memory usage). We slide even when level == 0 to
* keep the hash table consistent if we switch back to level > 0 later. * keep the hash table consistent if we switch back to level > 0 later.
*/ */
#if defined(__has_feature) local void slide_hash(s)
# if __has_feature(memory_sanitizer) deflate_state *s;
__attribute__((no_sanitize("memory"))) {
# endif
#endif
local void slide_hash(deflate_state *s) {
unsigned n, m; unsigned n, m;
Posf *p; Posf *p;
uInt wsize = s->w_size; uInt wsize = s->w_size;
@@ -208,177 +221,30 @@ local void slide_hash(deflate_state *s) {
#endif #endif
} }
/* ===========================================================================
* Read a new buffer from the current input stream, update the adler32
* and total number of bytes read. All deflate() input goes through
* this function so some applications may wish to modify it to avoid
* allocating a large strm->next_in buffer and copying from it.
* (See also flush_pending()).
*/
local unsigned read_buf(z_streamp strm, Bytef *buf, unsigned size) {
unsigned len = strm->avail_in;
if (len > size) len = size;
if (len == 0) return 0;
strm->avail_in -= len;
zmemcpy(buf, strm->next_in, len);
if (strm->state->wrap == 1) {
strm->adler = adler32(strm->adler, buf, len);
}
#ifdef GZIP
else if (strm->state->wrap == 2) {
strm->adler = crc32(strm->adler, buf, len);
}
#endif
strm->next_in += len;
strm->total_in += len;
return len;
}
/* ===========================================================================
* Fill the window when the lookahead becomes insufficient.
* Updates strstart and lookahead.
*
* IN assertion: lookahead < MIN_LOOKAHEAD
* OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
* At least one byte has been read, or avail_in == 0; reads are
* performed for at least two bytes (required for the zip translate_eol
* option -- not supported here).
*/
local void fill_window(deflate_state *s) {
unsigned n;
unsigned more; /* Amount of free space at the end of the window. */
uInt wsize = s->w_size;
Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
do {
more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
/* Deal with !@#$% 64K limit: */
if (sizeof(int) <= 2) {
if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
more = wsize;
} else if (more == (unsigned)(-1)) {
/* Very unlikely, but possible on 16 bit machine if
* strstart == 0 && lookahead == 1 (input done a byte at time)
*/
more--;
}
}
/* If the window is almost full and there is insufficient lookahead,
* move the upper half to the lower one to make room in the upper half.
*/
if (s->strstart >= wsize + MAX_DIST(s)) {
zmemcpy(s->window, s->window + wsize, (unsigned)wsize - more);
s->match_start -= wsize;
s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
s->block_start -= (long) wsize;
if (s->insert > s->strstart)
s->insert = s->strstart;
slide_hash(s);
more += wsize;
}
if (s->strm->avail_in == 0) break;
/* If there was no sliding:
* strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
* more == window_size - lookahead - strstart
* => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
* => more >= window_size - 2*WSIZE + 2
* In the BIG_MEM or MMAP case (not yet supported),
* window_size == input_size + MIN_LOOKAHEAD &&
* strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
* Otherwise, window_size == 2*WSIZE so more >= 2.
* If there was sliding, more >= WSIZE. So in all cases, more >= 2.
*/
Assert(more >= 2, "more < 2");
n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
s->lookahead += n;
/* Initialize the hash value now that we have some input: */
if (s->lookahead + s->insert >= MIN_MATCH) {
uInt str = s->strstart - s->insert;
s->ins_h = s->window[str];
UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
#if MIN_MATCH != 3
Call UPDATE_HASH() MIN_MATCH-3 more times
#endif
while (s->insert) {
UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
#ifndef FASTEST
s->prev[str & s->w_mask] = s->head[s->ins_h];
#endif
s->head[s->ins_h] = (Pos)str;
str++;
s->insert--;
if (s->lookahead + s->insert < MIN_MATCH)
break;
}
}
/* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
* but this is not important since only literal bytes will be emitted.
*/
} while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
/* If the WIN_INIT bytes after the end of the current data have never been
* written, then zero those bytes in order to avoid memory check reports of
* the use of uninitialized (or uninitialised as Julian writes) bytes by
* the longest match routines. Update the high water mark for the next
* time through here. WIN_INIT is set to MAX_MATCH since the longest match
* routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
*/
if (s->high_water < s->window_size) {
ulg curr = s->strstart + (ulg)(s->lookahead);
ulg init;
if (s->high_water < curr) {
/* Previous high water mark below current data -- zero WIN_INIT
* bytes or up to end of window, whichever is less.
*/
init = s->window_size - curr;
if (init > WIN_INIT)
init = WIN_INIT;
zmemzero(s->window + curr, (unsigned)init);
s->high_water = curr + init;
}
else if (s->high_water < (ulg)curr + WIN_INIT) {
/* High water mark at or above current data, but below current data
* plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
* to end of window, whichever is less.
*/
init = (ulg)curr + WIN_INIT - s->high_water;
if (init > s->window_size - s->high_water)
init = s->window_size - s->high_water;
zmemzero(s->window + s->high_water, (unsigned)init);
s->high_water += init;
}
}
Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
"not enough room for search");
}
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int ZEXPORT deflateInit_(strm, level, version, stream_size)
int stream_size) { z_streamp strm;
int level;
const char *version;
int stream_size;
{
return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
Z_DEFAULT_STRATEGY, version, stream_size); Z_DEFAULT_STRATEGY, version, stream_size);
/* To do: ignore strm->next_in if we use it as window */ /* To do: ignore strm->next_in if we use it as window */
} }
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
int windowBits, int memLevel, int strategy, version, stream_size)
const char *version, int stream_size) { z_streamp strm;
int level;
int method;
int windowBits;
int memLevel;
int strategy;
const char *version;
int stream_size;
{
deflate_state *s; deflate_state *s;
int wrap = 1; int wrap = 1;
static const char my_version[] = ZLIB_VERSION; static const char my_version[] = ZLIB_VERSION;
@@ -520,7 +386,9 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,
/* ========================================================================= /* =========================================================================
* Check for a valid deflate stream state. Return 0 if ok, 1 if not. * Check for a valid deflate stream state. Return 0 if ok, 1 if not.
*/ */
local int deflateStateCheck(z_streamp strm) { local int deflateStateCheck(strm)
z_streamp strm;
{
deflate_state *s; deflate_state *s;
if (strm == Z_NULL || if (strm == Z_NULL ||
strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0)
@@ -541,8 +409,11 @@ local int deflateStateCheck(z_streamp strm) {
} }
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary, int ZEXPORT deflateSetDictionary(strm, dictionary, dictLength)
uInt dictLength) { z_streamp strm;
const Bytef *dictionary;
uInt dictLength;
{
deflate_state *s; deflate_state *s;
uInt str, n; uInt str, n;
int wrap; int wrap;
@@ -607,8 +478,11 @@ int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary,
} }
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflateGetDictionary(z_streamp strm, Bytef *dictionary, int ZEXPORT deflateGetDictionary(strm, dictionary, dictLength)
uInt *dictLength) { z_streamp strm;
Bytef *dictionary;
uInt *dictLength;
{
deflate_state *s; deflate_state *s;
uInt len; uInt len;
@@ -626,7 +500,9 @@ int ZEXPORT deflateGetDictionary(z_streamp strm, Bytef *dictionary,
} }
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflateResetKeep(z_streamp strm) { int ZEXPORT deflateResetKeep(strm)
z_streamp strm;
{
deflate_state *s; deflate_state *s;
if (deflateStateCheck(strm)) { if (deflateStateCheck(strm)) {
@@ -661,32 +537,10 @@ int ZEXPORT deflateResetKeep(z_streamp strm) {
return Z_OK; return Z_OK;
} }
/* ===========================================================================
* Initialize the "longest match" routines for a new zlib stream
*/
local void lm_init(deflate_state *s) {
s->window_size = (ulg)2L*s->w_size;
CLEAR_HASH(s);
/* Set the default configuration parameters:
*/
s->max_lazy_match = configuration_table[s->level].max_lazy;
s->good_match = configuration_table[s->level].good_length;
s->nice_match = configuration_table[s->level].nice_length;
s->max_chain_length = configuration_table[s->level].max_chain;
s->strstart = 0;
s->block_start = 0L;
s->lookahead = 0;
s->insert = 0;
s->match_length = s->prev_length = MIN_MATCH-1;
s->match_available = 0;
s->ins_h = 0;
}
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflateReset(z_streamp strm) { int ZEXPORT deflateReset(strm)
z_streamp strm;
{
int ret; int ret;
ret = deflateResetKeep(strm); ret = deflateResetKeep(strm);
@@ -696,7 +550,10 @@ int ZEXPORT deflateReset(z_streamp strm) {
} }
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflateSetHeader(z_streamp strm, gz_headerp head) { int ZEXPORT deflateSetHeader(strm, head)
z_streamp strm;
gz_headerp head;
{
if (deflateStateCheck(strm) || strm->state->wrap != 2) if (deflateStateCheck(strm) || strm->state->wrap != 2)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
strm->state->gzhead = head; strm->state->gzhead = head;
@@ -704,7 +561,11 @@ int ZEXPORT deflateSetHeader(z_streamp strm, gz_headerp head) {
} }
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflatePending(z_streamp strm, unsigned *pending, int *bits) { int ZEXPORT deflatePending(strm, pending, bits)
unsigned *pending;
int *bits;
z_streamp strm;
{
if (deflateStateCheck(strm)) return Z_STREAM_ERROR; if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
if (pending != Z_NULL) if (pending != Z_NULL)
*pending = strm->state->pending; *pending = strm->state->pending;
@@ -714,7 +575,11 @@ int ZEXPORT deflatePending(z_streamp strm, unsigned *pending, int *bits) {
} }
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) { int ZEXPORT deflatePrime(strm, bits, value)
z_streamp strm;
int bits;
int value;
{
deflate_state *s; deflate_state *s;
int put; int put;
@@ -737,7 +602,11 @@ int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) {
} }
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflateParams(z_streamp strm, int level, int strategy) { int ZEXPORT deflateParams(strm, level, strategy)
z_streamp strm;
int level;
int strategy;
{
deflate_state *s; deflate_state *s;
compress_func func; compress_func func;
@@ -782,8 +651,13 @@ int ZEXPORT deflateParams(z_streamp strm, int level, int strategy) {
} }
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflateTune(z_streamp strm, int good_length, int max_lazy, int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain)
int nice_length, int max_chain) { z_streamp strm;
int good_length;
int max_lazy;
int nice_length;
int max_chain;
{
deflate_state *s; deflate_state *s;
if (deflateStateCheck(strm)) return Z_STREAM_ERROR; if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
@@ -819,7 +693,10 @@ int ZEXPORT deflateTune(z_streamp strm, int good_length, int max_lazy,
* *
* Shifts are used to approximate divisions, for speed. * Shifts are used to approximate divisions, for speed.
*/ */
uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen) { uLong ZEXPORT deflateBound(strm, sourceLen)
z_streamp strm;
uLong sourceLen;
{
deflate_state *s; deflate_state *s;
uLong fixedlen, storelen, wraplen; uLong fixedlen, storelen, wraplen;
@@ -875,8 +752,7 @@ uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen) {
/* if not default parameters, return one of the conservative bounds */ /* if not default parameters, return one of the conservative bounds */
if (s->w_bits != 15 || s->hash_bits != 8 + 7) if (s->w_bits != 15 || s->hash_bits != 8 + 7)
return (s->w_bits <= s->hash_bits && s->level ? fixedlen : storelen) + return (s->w_bits <= s->hash_bits ? fixedlen : storelen) + wraplen;
wraplen;
/* default settings: return tight bound for that case -- ~0.03% overhead /* default settings: return tight bound for that case -- ~0.03% overhead
plus a small constant */ plus a small constant */
@@ -889,7 +765,10 @@ uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen) {
* IN assertion: the stream state is correct and there is enough room in * IN assertion: the stream state is correct and there is enough room in
* pending_buf. * pending_buf.
*/ */
local void putShortMSB(deflate_state *s, uInt b) { local void putShortMSB(s, b)
deflate_state *s;
uInt b;
{
put_byte(s, (Byte)(b >> 8)); put_byte(s, (Byte)(b >> 8));
put_byte(s, (Byte)(b & 0xff)); put_byte(s, (Byte)(b & 0xff));
} }
@@ -900,7 +779,9 @@ local void putShortMSB(deflate_state *s, uInt b) {
* applications may wish to modify it to avoid allocating a large * applications may wish to modify it to avoid allocating a large
* strm->next_out buffer and copying into it. (See also read_buf()). * strm->next_out buffer and copying into it. (See also read_buf()).
*/ */
local void flush_pending(z_streamp strm) { local void flush_pending(strm)
z_streamp strm;
{
unsigned len; unsigned len;
deflate_state *s = strm->state; deflate_state *s = strm->state;
@@ -931,7 +812,10 @@ local void flush_pending(z_streamp strm) {
} while (0) } while (0)
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflate(z_streamp strm, int flush) { int ZEXPORT deflate(strm, flush)
z_streamp strm;
int flush;
{
int old_flush; /* value of flush param for previous deflate call */ int old_flush; /* value of flush param for previous deflate call */
deflate_state *s; deflate_state *s;
@@ -1243,7 +1127,9 @@ int ZEXPORT deflate(z_streamp strm, int flush) {
} }
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflateEnd(z_streamp strm) { int ZEXPORT deflateEnd(strm)
z_streamp strm;
{
int status; int status;
if (deflateStateCheck(strm)) return Z_STREAM_ERROR; if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
@@ -1267,10 +1153,11 @@ int ZEXPORT deflateEnd(z_streamp strm) {
* To simplify the source, this is not supported for 16-bit MSDOS (which * To simplify the source, this is not supported for 16-bit MSDOS (which
* doesn't have enough memory anyway to duplicate compression states). * doesn't have enough memory anyway to duplicate compression states).
*/ */
int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) { int ZEXPORT deflateCopy(dest, source)
z_streamp dest;
z_streamp source;
{
#ifdef MAXSEG_64K #ifdef MAXSEG_64K
(void)dest;
(void)source;
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
#else #else
deflate_state *ds; deflate_state *ds;
@@ -1318,6 +1205,66 @@ int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) {
#endif /* MAXSEG_64K */ #endif /* MAXSEG_64K */
} }
/* ===========================================================================
* Read a new buffer from the current input stream, update the adler32
* and total number of bytes read. All deflate() input goes through
* this function so some applications may wish to modify it to avoid
* allocating a large strm->next_in buffer and copying from it.
* (See also flush_pending()).
*/
local unsigned read_buf(strm, buf, size)
z_streamp strm;
Bytef *buf;
unsigned size;
{
unsigned len = strm->avail_in;
if (len > size) len = size;
if (len == 0) return 0;
strm->avail_in -= len;
zmemcpy(buf, strm->next_in, len);
if (strm->state->wrap == 1) {
strm->adler = adler32(strm->adler, buf, len);
}
#ifdef GZIP
else if (strm->state->wrap == 2) {
strm->adler = crc32(strm->adler, buf, len);
}
#endif
strm->next_in += len;
strm->total_in += len;
return len;
}
/* ===========================================================================
* Initialize the "longest match" routines for a new zlib stream
*/
local void lm_init(s)
deflate_state *s;
{
s->window_size = (ulg)2L*s->w_size;
CLEAR_HASH(s);
/* Set the default configuration parameters:
*/
s->max_lazy_match = configuration_table[s->level].max_lazy;
s->good_match = configuration_table[s->level].good_length;
s->nice_match = configuration_table[s->level].nice_length;
s->max_chain_length = configuration_table[s->level].max_chain;
s->strstart = 0;
s->block_start = 0L;
s->lookahead = 0;
s->insert = 0;
s->match_length = s->prev_length = MIN_MATCH-1;
s->match_available = 0;
s->ins_h = 0;
}
#ifndef FASTEST #ifndef FASTEST
/* =========================================================================== /* ===========================================================================
* Set match_start to the longest match starting at the given string and * Set match_start to the longest match starting at the given string and
@@ -1328,7 +1275,10 @@ int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) {
* string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
* OUT assertion: the match length is not greater than s->lookahead. * OUT assertion: the match length is not greater than s->lookahead.
*/ */
local uInt longest_match(deflate_state *s, IPos cur_match) { local uInt longest_match(s, cur_match)
deflate_state *s;
IPos cur_match; /* current match */
{
unsigned chain_length = s->max_chain_length;/* max hash chain length */ unsigned chain_length = s->max_chain_length;/* max hash chain length */
register Bytef *scan = s->window + s->strstart; /* current string */ register Bytef *scan = s->window + s->strstart; /* current string */
register Bytef *match; /* matched string */ register Bytef *match; /* matched string */
@@ -1476,7 +1426,10 @@ local uInt longest_match(deflate_state *s, IPos cur_match) {
/* --------------------------------------------------------------------------- /* ---------------------------------------------------------------------------
* Optimized version for FASTEST only * Optimized version for FASTEST only
*/ */
local uInt longest_match(deflate_state *s, IPos cur_match) { local uInt longest_match(s, cur_match)
deflate_state *s;
IPos cur_match; /* current match */
{
register Bytef *scan = s->window + s->strstart; /* current string */ register Bytef *scan = s->window + s->strstart; /* current string */
register Bytef *match; /* matched string */ register Bytef *match; /* matched string */
register int len; /* length of current match */ register int len; /* length of current match */
@@ -1537,7 +1490,11 @@ local uInt longest_match(deflate_state *s, IPos cur_match) {
/* =========================================================================== /* ===========================================================================
* Check that the match at match_start is indeed a match. * Check that the match at match_start is indeed a match.
*/ */
local void check_match(deflate_state *s, IPos start, IPos match, int length) { local void check_match(s, start, match, length)
deflate_state *s;
IPos start, match;
int length;
{
/* check that the match is indeed a match */ /* check that the match is indeed a match */
if (zmemcmp(s->window + match, if (zmemcmp(s->window + match,
s->window + start, length) != EQUAL) { s->window + start, length) != EQUAL) {
@@ -1557,6 +1514,137 @@ local void check_match(deflate_state *s, IPos start, IPos match, int length) {
# define check_match(s, start, match, length) # define check_match(s, start, match, length)
#endif /* ZLIB_DEBUG */ #endif /* ZLIB_DEBUG */
/* ===========================================================================
* Fill the window when the lookahead becomes insufficient.
* Updates strstart and lookahead.
*
* IN assertion: lookahead < MIN_LOOKAHEAD
* OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
* At least one byte has been read, or avail_in == 0; reads are
* performed for at least two bytes (required for the zip translate_eol
* option -- not supported here).
*/
local void fill_window(s)
deflate_state *s;
{
unsigned n;
unsigned more; /* Amount of free space at the end of the window. */
uInt wsize = s->w_size;
Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
do {
more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
/* Deal with !@#$% 64K limit: */
if (sizeof(int) <= 2) {
if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
more = wsize;
} else if (more == (unsigned)(-1)) {
/* Very unlikely, but possible on 16 bit machine if
* strstart == 0 && lookahead == 1 (input done a byte at time)
*/
more--;
}
}
/* If the window is almost full and there is insufficient lookahead,
* move the upper half to the lower one to make room in the upper half.
*/
if (s->strstart >= wsize + MAX_DIST(s)) {
zmemcpy(s->window, s->window + wsize, (unsigned)wsize - more);
s->match_start -= wsize;
s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
s->block_start -= (long) wsize;
if (s->insert > s->strstart)
s->insert = s->strstart;
slide_hash(s);
more += wsize;
}
if (s->strm->avail_in == 0) break;
/* If there was no sliding:
* strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
* more == window_size - lookahead - strstart
* => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
* => more >= window_size - 2*WSIZE + 2
* In the BIG_MEM or MMAP case (not yet supported),
* window_size == input_size + MIN_LOOKAHEAD &&
* strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
* Otherwise, window_size == 2*WSIZE so more >= 2.
* If there was sliding, more >= WSIZE. So in all cases, more >= 2.
*/
Assert(more >= 2, "more < 2");
n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
s->lookahead += n;
/* Initialize the hash value now that we have some input: */
if (s->lookahead + s->insert >= MIN_MATCH) {
uInt str = s->strstart - s->insert;
s->ins_h = s->window[str];
UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
#if MIN_MATCH != 3
Call UPDATE_HASH() MIN_MATCH-3 more times
#endif
while (s->insert) {
UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
#ifndef FASTEST
s->prev[str & s->w_mask] = s->head[s->ins_h];
#endif
s->head[s->ins_h] = (Pos)str;
str++;
s->insert--;
if (s->lookahead + s->insert < MIN_MATCH)
break;
}
}
/* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
* but this is not important since only literal bytes will be emitted.
*/
} while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
/* If the WIN_INIT bytes after the end of the current data have never been
* written, then zero those bytes in order to avoid memory check reports of
* the use of uninitialized (or uninitialised as Julian writes) bytes by
* the longest match routines. Update the high water mark for the next
* time through here. WIN_INIT is set to MAX_MATCH since the longest match
* routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
*/
if (s->high_water < s->window_size) {
ulg curr = s->strstart + (ulg)(s->lookahead);
ulg init;
if (s->high_water < curr) {
/* Previous high water mark below current data -- zero WIN_INIT
* bytes or up to end of window, whichever is less.
*/
init = s->window_size - curr;
if (init > WIN_INIT)
init = WIN_INIT;
zmemzero(s->window + curr, (unsigned)init);
s->high_water = curr + init;
}
else if (s->high_water < (ulg)curr + WIN_INIT) {
/* High water mark at or above current data, but below current data
* plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
* to end of window, whichever is less.
*/
init = (ulg)curr + WIN_INIT - s->high_water;
if (init > s->window_size - s->high_water)
init = s->window_size - s->high_water;
zmemzero(s->window + s->high_water, (unsigned)init);
s->high_water += init;
}
}
Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
"not enough room for search");
}
/* =========================================================================== /* ===========================================================================
* Flush the current block, with given end-of-file flag. * Flush the current block, with given end-of-file flag.
* IN assertion: strstart is set to the end of the current match. * IN assertion: strstart is set to the end of the current match.
@@ -1599,7 +1687,10 @@ local void check_match(deflate_state *s, IPos start, IPos match, int length) {
* copied. It is most efficient with large input and output buffers, which * copied. It is most efficient with large input and output buffers, which
* maximizes the opportunities to have a single copy from next_in to next_out. * maximizes the opportunities to have a single copy from next_in to next_out.
*/ */
local block_state deflate_stored(deflate_state *s, int flush) { local block_state deflate_stored(s, flush)
deflate_state *s;
int flush;
{
/* Smallest worthy block size when not flushing or finishing. By default /* Smallest worthy block size when not flushing or finishing. By default
* this is 32K. This can be as small as 507 bytes for memLevel == 1. For * this is 32K. This can be as small as 507 bytes for memLevel == 1. For
* large input and output buffers, the stored block size will be larger. * large input and output buffers, the stored block size will be larger.
@@ -1783,7 +1874,10 @@ local block_state deflate_stored(deflate_state *s, int flush) {
* new strings in the dictionary only for unmatched strings or for short * new strings in the dictionary only for unmatched strings or for short
* matches. It is used only for the fast compression options. * matches. It is used only for the fast compression options.
*/ */
local block_state deflate_fast(deflate_state *s, int flush) { local block_state deflate_fast(s, flush)
deflate_state *s;
int flush;
{
IPos hash_head; /* head of the hash chain */ IPos hash_head; /* head of the hash chain */
int bflush; /* set if current block must be flushed */ int bflush; /* set if current block must be flushed */
@@ -1882,7 +1976,10 @@ local block_state deflate_fast(deflate_state *s, int flush) {
* evaluation for matches: a match is finally adopted only if there is * evaluation for matches: a match is finally adopted only if there is
* no better match at the next window position. * no better match at the next window position.
*/ */
local block_state deflate_slow(deflate_state *s, int flush) { local block_state deflate_slow(s, flush)
deflate_state *s;
int flush;
{
IPos hash_head; /* head of hash chain */ IPos hash_head; /* head of hash chain */
int bflush; /* set if current block must be flushed */ int bflush; /* set if current block must be flushed */
@@ -2010,7 +2107,10 @@ local block_state deflate_slow(deflate_state *s, int flush) {
* one. Do not maintain a hash table. (It will be regenerated if this run of * one. Do not maintain a hash table. (It will be regenerated if this run of
* deflate switches away from Z_RLE.) * deflate switches away from Z_RLE.)
*/ */
local block_state deflate_rle(deflate_state *s, int flush) { local block_state deflate_rle(s, flush)
deflate_state *s;
int flush;
{
int bflush; /* set if current block must be flushed */ int bflush; /* set if current block must be flushed */
uInt prev; /* byte at distance one to match */ uInt prev; /* byte at distance one to match */
Bytef *scan, *strend; /* scan goes up to strend for length of run */ Bytef *scan, *strend; /* scan goes up to strend for length of run */
@@ -2081,7 +2181,10 @@ local block_state deflate_rle(deflate_state *s, int flush) {
* For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table.
* (It will be regenerated if this run of deflate switches away from Huffman.) * (It will be regenerated if this run of deflate switches away from Huffman.)
*/ */
local block_state deflate_huff(deflate_state *s, int flush) { local block_state deflate_huff(s, flush)
deflate_state *s;
int flush;
{
int bflush; /* set if current block must be flushed */ int bflush; /* set if current block must be flushed */
for (;;) { for (;;) {
+8 -8
View File
@@ -291,14 +291,14 @@ typedef struct internal_state {
memory checker errors from longest match routines */ memory checker errors from longest match routines */
/* in trees.c */ /* in trees.c */
void ZLIB_INTERNAL _tr_init(deflate_state *s); void ZLIB_INTERNAL _tr_init OF((deflate_state *s));
int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc); int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf,
ulg stored_len, int last); ulg stored_len, int last));
void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s); void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s));
void ZLIB_INTERNAL _tr_align(deflate_state *s); void ZLIB_INTERNAL _tr_align OF((deflate_state *s));
void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
ulg stored_len, int last); ulg stored_len, int last));
#define d_code(dist) \ #define d_code(dist) \
((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
+3 -1
View File
@@ -8,7 +8,9 @@
/* gzclose() is in a separate file so that it is linked in only if it is used. /* gzclose() is in a separate file so that it is linked in only if it is used.
That way the other gzclose functions can be used instead to avoid linking in That way the other gzclose functions can be used instead to avoid linking in
unneeded compression or decompression routines. */ unneeded compression or decompression routines. */
int ZEXPORT gzclose(gzFile file) { int ZEXPORT gzclose(file)
gzFile file;
{
#ifndef NO_GZCOMPRESS #ifndef NO_GZCOMPRESS
gz_statep state; gz_statep state;
+12 -11
View File
@@ -7,8 +7,9 @@
# ifndef _LARGEFILE_SOURCE # ifndef _LARGEFILE_SOURCE
# define _LARGEFILE_SOURCE 1 # define _LARGEFILE_SOURCE 1
# endif # endif
# undef _FILE_OFFSET_BITS # ifdef _FILE_OFFSET_BITS
# undef _TIME_BITS # undef _FILE_OFFSET_BITS
# endif
#endif #endif
#ifdef HAVE_HIDDEN #ifdef HAVE_HIDDEN
@@ -118,8 +119,8 @@
/* gz* functions always use library allocation functions */ /* gz* functions always use library allocation functions */
#ifndef STDC #ifndef STDC
extern voidp malloc(uInt size); extern voidp malloc OF((uInt size));
extern void free(voidpf ptr); extern void free OF((voidpf ptr));
#endif #endif
/* get errno and strerror definition */ /* get errno and strerror definition */
@@ -137,10 +138,10 @@
/* provide prototypes for these when building zlib without LFS */ /* provide prototypes for these when building zlib without LFS */
#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *); ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int); ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
ZEXTERN z_off64_t ZEXPORT gztell64(gzFile); ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile); ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
#endif #endif
/* default memLevel */ /* default memLevel */
@@ -202,9 +203,9 @@ typedef struct {
typedef gz_state FAR *gz_statep; typedef gz_state FAR *gz_statep;
/* shared functions */ /* shared functions */
void ZLIB_INTERNAL gz_error(gz_statep, int, const char *); void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *));
#if defined UNDER_CE #if defined UNDER_CE
char ZLIB_INTERNAL *gz_strwinerror(DWORD error); char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error));
#endif #endif
/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
@@ -213,6 +214,6 @@ char ZLIB_INTERNAL *gz_strwinerror(DWORD error);
#ifdef INT_MAX #ifdef INT_MAX
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
#else #else
unsigned ZLIB_INTERNAL gz_intmax(void); unsigned ZLIB_INTERNAL gz_intmax OF((void));
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
#endif #endif
+79 -22
View File
@@ -15,6 +15,10 @@
#endif #endif
#endif #endif
/* Local functions */
local void gz_reset OF((gz_statep));
local gzFile gz_open OF((const void *, int, const char *));
#if defined UNDER_CE #if defined UNDER_CE
/* Map the Windows error number in ERROR to a locale-dependent error message /* Map the Windows error number in ERROR to a locale-dependent error message
@@ -26,7 +30,9 @@
The gz_strwinerror function does not change the current setting of The gz_strwinerror function does not change the current setting of
GetLastError. */ GetLastError. */
char ZLIB_INTERNAL *gz_strwinerror(DWORD error) { char ZLIB_INTERNAL *gz_strwinerror(error)
DWORD error;
{
static char buf[1024]; static char buf[1024];
wchar_t *msgbuf; wchar_t *msgbuf;
@@ -66,7 +72,9 @@ char ZLIB_INTERNAL *gz_strwinerror(DWORD error) {
#endif /* UNDER_CE */ #endif /* UNDER_CE */
/* Reset gzip file state */ /* Reset gzip file state */
local void gz_reset(gz_statep state) { local void gz_reset(state)
gz_statep state;
{
state->x.have = 0; /* no output data available */ state->x.have = 0; /* no output data available */
if (state->mode == GZ_READ) { /* for reading ... */ if (state->mode == GZ_READ) { /* for reading ... */
state->eof = 0; /* not at end of file */ state->eof = 0; /* not at end of file */
@@ -82,7 +90,11 @@ local void gz_reset(gz_statep state) {
} }
/* Open a gzip file either by name or file descriptor. */ /* Open a gzip file either by name or file descriptor. */
local gzFile gz_open(const void *path, int fd, const char *mode) { local gzFile gz_open(path, fd, mode)
const void *path;
int fd;
const char *mode;
{
gz_statep state; gz_statep state;
z_size_t len; z_size_t len;
int oflag; int oflag;
@@ -257,17 +269,26 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
gzFile ZEXPORT gzopen(const char *path, const char *mode) { gzFile ZEXPORT gzopen(path, mode)
const char *path;
const char *mode;
{
return gz_open(path, -1, mode); return gz_open(path, -1, mode);
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
gzFile ZEXPORT gzopen64(const char *path, const char *mode) { gzFile ZEXPORT gzopen64(path, mode)
const char *path;
const char *mode;
{
return gz_open(path, -1, mode); return gz_open(path, -1, mode);
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
gzFile ZEXPORT gzdopen(int fd, const char *mode) { gzFile ZEXPORT gzdopen(fd, mode)
int fd;
const char *mode;
{
char *path; /* identifier for error messages */ char *path; /* identifier for error messages */
gzFile gz; gzFile gz;
@@ -285,13 +306,19 @@ gzFile ZEXPORT gzdopen(int fd, const char *mode) {
/* -- see zlib.h -- */ /* -- see zlib.h -- */
#ifdef WIDECHAR #ifdef WIDECHAR
gzFile ZEXPORT gzopen_w(const wchar_t *path, const char *mode) { gzFile ZEXPORT gzopen_w(path, mode)
const wchar_t *path;
const char *mode;
{
return gz_open(path, -2, mode); return gz_open(path, -2, mode);
} }
#endif #endif
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzbuffer(gzFile file, unsigned size) { int ZEXPORT gzbuffer(file, size)
gzFile file;
unsigned size;
{
gz_statep state; gz_statep state;
/* get internal structure and check integrity */ /* get internal structure and check integrity */
@@ -308,14 +335,16 @@ int ZEXPORT gzbuffer(gzFile file, unsigned size) {
/* check and set requested size */ /* check and set requested size */
if ((size << 1) < size) if ((size << 1) < size)
return -1; /* need to be able to double it */ return -1; /* need to be able to double it */
if (size < 8) if (size < 2)
size = 8; /* needed to behave well with flushing */ size = 2; /* need two bytes to check magic header */
state->want = size; state->want = size;
return 0; return 0;
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzrewind(gzFile file) { int ZEXPORT gzrewind(file)
gzFile file;
{
gz_statep state; gz_statep state;
/* get internal structure */ /* get internal structure */
@@ -336,7 +365,11 @@ int ZEXPORT gzrewind(gzFile file) {
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) { z_off64_t ZEXPORT gzseek64(file, offset, whence)
gzFile file;
z_off64_t offset;
int whence;
{
unsigned n; unsigned n;
z_off64_t ret; z_off64_t ret;
gz_statep state; gz_statep state;
@@ -409,7 +442,11 @@ z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence) { z_off_t ZEXPORT gzseek(file, offset, whence)
gzFile file;
z_off_t offset;
int whence;
{
z_off64_t ret; z_off64_t ret;
ret = gzseek64(file, (z_off64_t)offset, whence); ret = gzseek64(file, (z_off64_t)offset, whence);
@@ -417,7 +454,9 @@ z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence) {
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_off64_t ZEXPORT gztell64(gzFile file) { z_off64_t ZEXPORT gztell64(file)
gzFile file;
{
gz_statep state; gz_statep state;
/* get internal structure and check integrity */ /* get internal structure and check integrity */
@@ -432,7 +471,9 @@ z_off64_t ZEXPORT gztell64(gzFile file) {
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_off_t ZEXPORT gztell(gzFile file) { z_off_t ZEXPORT gztell(file)
gzFile file;
{
z_off64_t ret; z_off64_t ret;
ret = gztell64(file); ret = gztell64(file);
@@ -440,7 +481,9 @@ z_off_t ZEXPORT gztell(gzFile file) {
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_off64_t ZEXPORT gzoffset64(gzFile file) { z_off64_t ZEXPORT gzoffset64(file)
gzFile file;
{
z_off64_t offset; z_off64_t offset;
gz_statep state; gz_statep state;
@@ -461,7 +504,9 @@ z_off64_t ZEXPORT gzoffset64(gzFile file) {
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_off_t ZEXPORT gzoffset(gzFile file) { z_off_t ZEXPORT gzoffset(file)
gzFile file;
{
z_off64_t ret; z_off64_t ret;
ret = gzoffset64(file); ret = gzoffset64(file);
@@ -469,7 +514,9 @@ z_off_t ZEXPORT gzoffset(gzFile file) {
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzeof(gzFile file) { int ZEXPORT gzeof(file)
gzFile file;
{
gz_statep state; gz_statep state;
/* get internal structure and check integrity */ /* get internal structure and check integrity */
@@ -484,7 +531,10 @@ int ZEXPORT gzeof(gzFile file) {
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
const char * ZEXPORT gzerror(gzFile file, int *errnum) { const char * ZEXPORT gzerror(file, errnum)
gzFile file;
int *errnum;
{
gz_statep state; gz_statep state;
/* get internal structure and check integrity */ /* get internal structure and check integrity */
@@ -502,7 +552,9 @@ const char * ZEXPORT gzerror(gzFile file, int *errnum) {
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
void ZEXPORT gzclearerr(gzFile file) { void ZEXPORT gzclearerr(file)
gzFile file;
{
gz_statep state; gz_statep state;
/* get internal structure and check integrity */ /* get internal structure and check integrity */
@@ -526,7 +578,11 @@ void ZEXPORT gzclearerr(gzFile file) {
memory). Simply save the error message as a static string. If there is an memory). Simply save the error message as a static string. If there is an
allocation failure constructing the error message, then convert the error to allocation failure constructing the error message, then convert the error to
out of memory. */ out of memory. */
void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) { void ZLIB_INTERNAL gz_error(state, err, msg)
gz_statep state;
int err;
const char *msg;
{
/* free previously allocated message and clear */ /* free previously allocated message and clear */
if (state->msg != NULL) { if (state->msg != NULL) {
if (state->err != Z_MEM_ERROR) if (state->err != Z_MEM_ERROR)
@@ -568,7 +624,8 @@ void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) {
available) -- we need to do this to cover cases where 2's complement not available) -- we need to do this to cover cases where 2's complement not
used, since C standard permits 1's complement and sign-bit representations, used, since C standard permits 1's complement and sign-bit representations,
otherwise we could just use ((unsigned)-1) >> 1 */ otherwise we could just use ((unsigned)-1) >> 1 */
unsigned ZLIB_INTERNAL gz_intmax(void) { unsigned ZLIB_INTERNAL gz_intmax()
{
unsigned p, q; unsigned p, q;
p = 1; p = 1;
+68 -20
View File
@@ -5,12 +5,25 @@
#include "gzguts.h" #include "gzguts.h"
/* Local functions */
local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *));
local int gz_avail OF((gz_statep));
local int gz_look OF((gz_statep));
local int gz_decomp OF((gz_statep));
local int gz_fetch OF((gz_statep));
local int gz_skip OF((gz_statep, z_off64_t));
local z_size_t gz_read OF((gz_statep, voidp, z_size_t));
/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from /* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from
state->fd, and update state->eof, state->err, and state->msg as appropriate. state->fd, and update state->eof, state->err, and state->msg as appropriate.
This function needs to loop on read(), since read() is not guaranteed to This function needs to loop on read(), since read() is not guaranteed to
read the number of bytes requested, depending on the type of descriptor. */ read the number of bytes requested, depending on the type of descriptor. */
local int gz_load(gz_statep state, unsigned char *buf, unsigned len, local int gz_load(state, buf, len, have)
unsigned *have) { gz_statep state;
unsigned char *buf;
unsigned len;
unsigned *have;
{
int ret; int ret;
unsigned get, max = ((unsigned)-1 >> 2) + 1; unsigned get, max = ((unsigned)-1 >> 2) + 1;
@@ -40,7 +53,9 @@ local int gz_load(gz_statep state, unsigned char *buf, unsigned len,
If strm->avail_in != 0, then the current data is moved to the beginning of If strm->avail_in != 0, then the current data is moved to the beginning of
the input buffer, and then the remainder of the buffer is loaded with the the input buffer, and then the remainder of the buffer is loaded with the
available data from the input file. */ available data from the input file. */
local int gz_avail(gz_statep state) { local int gz_avail(state)
gz_statep state;
{
unsigned got; unsigned got;
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
@@ -73,7 +88,9 @@ local int gz_avail(gz_statep state) {
case, all further file reads will be directly to either the output buffer or case, all further file reads will be directly to either the output buffer or
a user buffer. If decompressing, the inflate state will be initialized. a user buffer. If decompressing, the inflate state will be initialized.
gz_look() will return 0 on success or -1 on failure. */ gz_look() will return 0 on success or -1 on failure. */
local int gz_look(gz_statep state) { local int gz_look(state)
gz_statep state;
{
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
/* allocate read buffers and inflate memory */ /* allocate read buffers and inflate memory */
@@ -153,7 +170,9 @@ local int gz_look(gz_statep state) {
data. If the gzip stream completes, state->how is reset to LOOK to look for data. If the gzip stream completes, state->how is reset to LOOK to look for
the next gzip stream or raw data, once state->x.have is depleted. Returns 0 the next gzip stream or raw data, once state->x.have is depleted. Returns 0
on success, -1 on failure. */ on success, -1 on failure. */
local int gz_decomp(gz_statep state) { local int gz_decomp(state)
gz_statep state;
{
int ret = Z_OK; int ret = Z_OK;
unsigned had; unsigned had;
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
@@ -205,7 +224,9 @@ local int gz_decomp(gz_statep state) {
looked for to determine whether to copy or decompress. Returns -1 on error, looked for to determine whether to copy or decompress. Returns -1 on error,
otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the
end of the input file has been reached and all data has been processed. */ end of the input file has been reached and all data has been processed. */
local int gz_fetch(gz_statep state) { local int gz_fetch(state)
gz_statep state;
{
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
do { do {
@@ -233,7 +254,10 @@ local int gz_fetch(gz_statep state) {
} }
/* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */ /* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */
local int gz_skip(gz_statep state, z_off64_t len) { local int gz_skip(state, len)
gz_statep state;
z_off64_t len;
{
unsigned n; unsigned n;
/* skip over len bytes or reach end-of-file, whichever comes first */ /* skip over len bytes or reach end-of-file, whichever comes first */
@@ -265,7 +289,11 @@ local int gz_skip(gz_statep state, z_off64_t len) {
input. Return the number of bytes read. If zero is returned, either the input. Return the number of bytes read. If zero is returned, either the
end of file was reached, or there was an error. state->err must be end of file was reached, or there was an error. state->err must be
consulted in that case to determine which. */ consulted in that case to determine which. */
local z_size_t gz_read(gz_statep state, voidp buf, z_size_t len) { local z_size_t gz_read(state, buf, len)
gz_statep state;
voidp buf;
z_size_t len;
{
z_size_t got; z_size_t got;
unsigned n; unsigned n;
@@ -342,7 +370,11 @@ local z_size_t gz_read(gz_statep state, voidp buf, z_size_t len) {
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzread(gzFile file, voidp buf, unsigned len) { int ZEXPORT gzread(file, buf, len)
gzFile file;
voidp buf;
unsigned len;
{
gz_statep state; gz_statep state;
/* get internal structure */ /* get internal structure */
@@ -374,7 +406,12 @@ int ZEXPORT gzread(gzFile file, voidp buf, unsigned len) {
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems, gzFile file) { z_size_t ZEXPORT gzfread(buf, size, nitems, file)
voidp buf;
z_size_t size;
z_size_t nitems;
gzFile file;
{
z_size_t len; z_size_t len;
gz_statep state; gz_statep state;
@@ -405,7 +442,9 @@ z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems, gzFile file)
#else #else
# undef gzgetc # undef gzgetc
#endif #endif
int ZEXPORT gzgetc(gzFile file) { int ZEXPORT gzgetc(file)
gzFile file;
{
unsigned char buf[1]; unsigned char buf[1];
gz_statep state; gz_statep state;
@@ -430,12 +469,17 @@ int ZEXPORT gzgetc(gzFile file) {
return gz_read(state, buf, 1) < 1 ? -1 : buf[0]; return gz_read(state, buf, 1) < 1 ? -1 : buf[0];
} }
int ZEXPORT gzgetc_(gzFile file) { int ZEXPORT gzgetc_(file)
gzFile file;
{
return gzgetc(file); return gzgetc(file);
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzungetc(int c, gzFile file) { int ZEXPORT gzungetc(c, file)
int c;
gzFile file;
{
gz_statep state; gz_statep state;
/* get internal structure */ /* get internal structure */
@@ -443,10 +487,6 @@ int ZEXPORT gzungetc(int c, gzFile file) {
return -1; return -1;
state = (gz_statep)file; state = (gz_statep)file;
/* in case this was just opened, set up the input buffer */
if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
(void)gz_look(state);
/* check that we're reading and that there's no (serious) error */ /* check that we're reading and that there's no (serious) error */
if (state->mode != GZ_READ || if (state->mode != GZ_READ ||
(state->err != Z_OK && state->err != Z_BUF_ERROR)) (state->err != Z_OK && state->err != Z_BUF_ERROR))
@@ -496,7 +536,11 @@ int ZEXPORT gzungetc(int c, gzFile file) {
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
char * ZEXPORT gzgets(gzFile file, char *buf, int len) { char * ZEXPORT gzgets(file, buf, len)
gzFile file;
char *buf;
int len;
{
unsigned left, n; unsigned left, n;
char *str; char *str;
unsigned char *eol; unsigned char *eol;
@@ -556,7 +600,9 @@ char * ZEXPORT gzgets(gzFile file, char *buf, int len) {
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzdirect(gzFile file) { int ZEXPORT gzdirect(file)
gzFile file;
{
gz_statep state; gz_statep state;
/* get internal structure */ /* get internal structure */
@@ -574,7 +620,9 @@ int ZEXPORT gzdirect(gzFile file) {
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzclose_r(gzFile file) { int ZEXPORT gzclose_r(file)
gzFile file;
{
int ret, err; int ret, err;
gz_statep state; gz_statep state;
+65 -19
View File
@@ -5,10 +5,18 @@
#include "gzguts.h" #include "gzguts.h"
/* Local functions */
local int gz_init OF((gz_statep));
local int gz_comp OF((gz_statep, int));
local int gz_zero OF((gz_statep, z_off64_t));
local z_size_t gz_write OF((gz_statep, voidpc, z_size_t));
/* Initialize state for writing a gzip file. Mark initialization by setting /* Initialize state for writing a gzip file. Mark initialization by setting
state->size to non-zero. Return -1 on a memory allocation failure, or 0 on state->size to non-zero. Return -1 on a memory allocation failure, or 0 on
success. */ success. */
local int gz_init(gz_statep state) { local int gz_init(state)
gz_statep state;
{
int ret; int ret;
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
@@ -62,7 +70,10 @@ local int gz_init(gz_statep state) {
deflate() flush value. If flush is Z_FINISH, then the deflate() state is deflate() flush value. If flush is Z_FINISH, then the deflate() state is
reset to start a new gzip stream. If gz->direct is true, then simply write reset to start a new gzip stream. If gz->direct is true, then simply write
to the output file without compressing, and ignore flush. */ to the output file without compressing, and ignore flush. */
local int gz_comp(gz_statep state, int flush) { local int gz_comp(state, flush)
gz_statep state;
int flush;
{
int ret, writ; int ret, writ;
unsigned have, put, max = ((unsigned)-1 >> 2) + 1; unsigned have, put, max = ((unsigned)-1 >> 2) + 1;
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
@@ -140,7 +151,10 @@ local int gz_comp(gz_statep state, int flush) {
/* Compress len zeros to output. Return -1 on a write error or memory /* Compress len zeros to output. Return -1 on a write error or memory
allocation failure by gz_comp(), or 0 on success. */ allocation failure by gz_comp(), or 0 on success. */
local int gz_zero(gz_statep state, z_off64_t len) { local int gz_zero(state, len)
gz_statep state;
z_off64_t len;
{
int first; int first;
unsigned n; unsigned n;
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
@@ -170,7 +184,11 @@ local int gz_zero(gz_statep state, z_off64_t len) {
/* Write len bytes from buf to file. Return the number of bytes written. If /* Write len bytes from buf to file. Return the number of bytes written. If
the returned value is less than len, then there was an error. */ the returned value is less than len, then there was an error. */
local z_size_t gz_write(gz_statep state, voidpc buf, z_size_t len) { local z_size_t gz_write(state, buf, len)
gz_statep state;
voidpc buf;
z_size_t len;
{
z_size_t put = len; z_size_t put = len;
/* if len is zero, avoid unnecessary operations */ /* if len is zero, avoid unnecessary operations */
@@ -234,7 +252,11 @@ local z_size_t gz_write(gz_statep state, voidpc buf, z_size_t len) {
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len) { int ZEXPORT gzwrite(file, buf, len)
gzFile file;
voidpc buf;
unsigned len;
{
gz_statep state; gz_statep state;
/* get internal structure */ /* get internal structure */
@@ -258,8 +280,12 @@ int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len) {
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size, z_size_t nitems, z_size_t ZEXPORT gzfwrite(buf, size, nitems, file)
gzFile file) { voidpc buf;
z_size_t size;
z_size_t nitems;
gzFile file;
{
z_size_t len; z_size_t len;
gz_statep state; gz_statep state;
@@ -284,7 +310,10 @@ z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size, z_size_t nitems,
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzputc(gzFile file, int c) { int ZEXPORT gzputc(file, c)
gzFile file;
int c;
{
unsigned have; unsigned have;
unsigned char buf[1]; unsigned char buf[1];
gz_statep state; gz_statep state;
@@ -329,7 +358,10 @@ int ZEXPORT gzputc(gzFile file, int c) {
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzputs(gzFile file, const char *s) { int ZEXPORT gzputs(file, s)
gzFile file;
const char *s;
{
z_size_t len, put; z_size_t len, put;
gz_statep state; gz_statep state;
@@ -356,7 +388,8 @@ int ZEXPORT gzputs(gzFile file, const char *s) {
#include <stdarg.h> #include <stdarg.h>
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) { int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va)
{
int len; int len;
unsigned left; unsigned left;
char *next; char *next;
@@ -427,7 +460,8 @@ int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) {
return len; return len;
} }
int ZEXPORTVA gzprintf(gzFile file, const char *format, ...) { int ZEXPORTVA gzprintf(gzFile file, const char *format, ...)
{
va_list va; va_list va;
int ret; int ret;
@@ -440,10 +474,13 @@ int ZEXPORTVA gzprintf(gzFile file, const char *format, ...) {
#else /* !STDC && !Z_HAVE_STDARG_H */ #else /* !STDC && !Z_HAVE_STDARG_H */
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORTVA gzprintf(gzFile file, const char *format, int a1, int a2, int a3, int ZEXPORTVA gzprintf(file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
int a4, int a5, int a6, int a7, int a8, int a9, int a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
int a11, int a12, int a13, int a14, int a15, int a16, gzFile file;
int a17, int a18, int a19, int a20) { const char *format;
int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
{
unsigned len, left; unsigned len, left;
char *next; char *next;
gz_statep state; gz_statep state;
@@ -525,7 +562,10 @@ int ZEXPORTVA gzprintf(gzFile file, const char *format, int a1, int a2, int a3,
#endif #endif
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzflush(gzFile file, int flush) { int ZEXPORT gzflush(file, flush)
gzFile file;
int flush;
{
gz_statep state; gz_statep state;
/* get internal structure */ /* get internal structure */
@@ -554,7 +594,11 @@ int ZEXPORT gzflush(gzFile file, int flush) {
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzsetparams(gzFile file, int level, int strategy) { int ZEXPORT gzsetparams(file, level, strategy)
gzFile file;
int level;
int strategy;
{
gz_statep state; gz_statep state;
z_streamp strm; z_streamp strm;
@@ -565,7 +609,7 @@ int ZEXPORT gzsetparams(gzFile file, int level, int strategy) {
strm = &(state->strm); strm = &(state->strm);
/* check that we're writing and that there's no error */ /* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK || state->direct) if (state->mode != GZ_WRITE || state->err != Z_OK)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
/* if no change is requested, then do nothing */ /* if no change is requested, then do nothing */
@@ -592,7 +636,9 @@ int ZEXPORT gzsetparams(gzFile file, int level, int strategy) {
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzclose_w(gzFile file) { int ZEXPORT gzclose_w(file)
gzFile file;
{
int ret = Z_OK; int ret = Z_OK;
gz_statep state; gz_statep state;
+23 -7
View File
@@ -15,6 +15,9 @@
#include "inflate.h" #include "inflate.h"
#include "inffast.h" #include "inffast.h"
/* function prototypes */
local void fixedtables OF((struct inflate_state FAR *state));
/* /*
strm provides memory allocation functions in zalloc and zfree, or strm provides memory allocation functions in zalloc and zfree, or
Z_NULL to use the library memory allocation functions. Z_NULL to use the library memory allocation functions.
@@ -22,9 +25,13 @@
windowBits is in the range 8..15, and window is a user-supplied windowBits is in the range 8..15, and window is a user-supplied
window and output buffer that is 2**windowBits bytes. window and output buffer that is 2**windowBits bytes.
*/ */
int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits, int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size)
unsigned char FAR *window, const char *version, z_streamp strm;
int stream_size) { int windowBits;
unsigned char FAR *window;
const char *version;
int stream_size;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
@@ -73,7 +80,9 @@ int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits,
used for threaded applications, since the rewriting of the tables and virgin used for threaded applications, since the rewriting of the tables and virgin
may not be thread-safe. may not be thread-safe.
*/ */
local void fixedtables(struct inflate_state FAR *state) { local void fixedtables(state)
struct inflate_state FAR *state;
{
#ifdef BUILDFIXED #ifdef BUILDFIXED
static int virgin = 1; static int virgin = 1;
static code *lenfix, *distfix; static code *lenfix, *distfix;
@@ -239,8 +248,13 @@ local void fixedtables(struct inflate_state FAR *state) {
inflateBack() can also return Z_STREAM_ERROR if the input parameters inflateBack() can also return Z_STREAM_ERROR if the input parameters
are not correct, i.e. strm is Z_NULL or the state was not initialized. are not correct, i.e. strm is Z_NULL or the state was not initialized.
*/ */
int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc)
out_func out, void FAR *out_desc) { z_streamp strm;
in_func in;
void FAR *in_desc;
out_func out;
void FAR *out_desc;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
z_const unsigned char FAR *next; /* next input */ z_const unsigned char FAR *next; /* next input */
unsigned char FAR *put; /* next output */ unsigned char FAR *put; /* next output */
@@ -618,7 +632,9 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
return ret; return ret;
} }
int ZEXPORT inflateBackEnd(z_streamp strm) { int ZEXPORT inflateBackEnd(strm)
z_streamp strm;
{
if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
ZFREE(strm, strm->state); ZFREE(strm, strm->state);
+4 -1
View File
@@ -47,7 +47,10 @@
requires strm->avail_out >= 258 for each loop to avoid checking for requires strm->avail_out >= 258 for each loop to avoid checking for
output space. output space.
*/ */
void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) { void ZLIB_INTERNAL inflate_fast(strm, start)
z_streamp strm;
unsigned start; /* inflate()'s starting value for strm->avail_out */
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
z_const unsigned char FAR *in; /* local strm->next_in */ z_const unsigned char FAR *in; /* local strm->next_in */
z_const unsigned char FAR *last; /* have enough input while in < last */ z_const unsigned char FAR *last; /* have enough input while in < last */
+1 -1
View File
@@ -8,4 +8,4 @@
subject to change. Applications should only use zlib.h. subject to change. Applications should only use zlib.h.
*/ */
void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start); void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start));
+99 -30
View File
@@ -91,7 +91,20 @@
# endif # endif
#endif #endif
local int inflateStateCheck(z_streamp strm) { /* function prototypes */
local int inflateStateCheck OF((z_streamp strm));
local void fixedtables OF((struct inflate_state FAR *state));
local int updatewindow OF((z_streamp strm, const unsigned char FAR *end,
unsigned copy));
#ifdef BUILDFIXED
void makefixed OF((void));
#endif
local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf,
unsigned len));
local int inflateStateCheck(strm)
z_streamp strm;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (strm == Z_NULL || if (strm == Z_NULL ||
strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0)
@@ -103,7 +116,9 @@ local int inflateStateCheck(z_streamp strm) {
return 0; return 0;
} }
int ZEXPORT inflateResetKeep(z_streamp strm) { int ZEXPORT inflateResetKeep(strm)
z_streamp strm;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
@@ -127,7 +142,9 @@ int ZEXPORT inflateResetKeep(z_streamp strm) {
return Z_OK; return Z_OK;
} }
int ZEXPORT inflateReset(z_streamp strm) { int ZEXPORT inflateReset(strm)
z_streamp strm;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
@@ -138,7 +155,10 @@ int ZEXPORT inflateReset(z_streamp strm) {
return inflateResetKeep(strm); return inflateResetKeep(strm);
} }
int ZEXPORT inflateReset2(z_streamp strm, int windowBits) { int ZEXPORT inflateReset2(strm, windowBits)
z_streamp strm;
int windowBits;
{
int wrap; int wrap;
struct inflate_state FAR *state; struct inflate_state FAR *state;
@@ -175,8 +195,12 @@ int ZEXPORT inflateReset2(z_streamp strm, int windowBits) {
return inflateReset(strm); return inflateReset(strm);
} }
int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size)
const char *version, int stream_size) { z_streamp strm;
int windowBits;
const char *version;
int stream_size;
{
int ret; int ret;
struct inflate_state FAR *state; struct inflate_state FAR *state;
@@ -216,17 +240,22 @@ int ZEXPORT inflateInit2_(z_streamp strm, int windowBits,
return ret; return ret;
} }
int ZEXPORT inflateInit_(z_streamp strm, const char *version, int ZEXPORT inflateInit_(strm, version, stream_size)
int stream_size) { z_streamp strm;
const char *version;
int stream_size;
{
return inflateInit2_(strm, DEF_WBITS, version, stream_size); return inflateInit2_(strm, DEF_WBITS, version, stream_size);
} }
int ZEXPORT inflatePrime(z_streamp strm, int bits, int value) { int ZEXPORT inflatePrime(strm, bits, value)
z_streamp strm;
int bits;
int value;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
if (bits == 0)
return Z_OK;
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
if (bits < 0) { if (bits < 0) {
state->hold = 0; state->hold = 0;
@@ -250,7 +279,9 @@ int ZEXPORT inflatePrime(z_streamp strm, int bits, int value) {
used for threaded applications, since the rewriting of the tables and virgin used for threaded applications, since the rewriting of the tables and virgin
may not be thread-safe. may not be thread-safe.
*/ */
local void fixedtables(struct inflate_state FAR *state) { local void fixedtables(state)
struct inflate_state FAR *state;
{
#ifdef BUILDFIXED #ifdef BUILDFIXED
static int virgin = 1; static int virgin = 1;
static code *lenfix, *distfix; static code *lenfix, *distfix;
@@ -312,7 +343,7 @@ local void fixedtables(struct inflate_state FAR *state) {
a.out > inffixed.h a.out > inffixed.h
*/ */
void makefixed(void) void makefixed()
{ {
unsigned low, size; unsigned low, size;
struct inflate_state state; struct inflate_state state;
@@ -366,7 +397,11 @@ void makefixed(void)
output will fall in the output data, making match copies simpler and faster. output will fall in the output data, making match copies simpler and faster.
The advantage may be dependent on the size of the processor's data caches. The advantage may be dependent on the size of the processor's data caches.
*/ */
local int updatewindow(z_streamp strm, const Bytef *end, unsigned copy) { local int updatewindow(strm, end, copy)
z_streamp strm;
const Bytef *end;
unsigned copy;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
unsigned dist; unsigned dist;
@@ -588,7 +623,10 @@ local int updatewindow(z_streamp strm, const Bytef *end, unsigned copy) {
will return Z_BUF_ERROR if it has not reached the end of the stream. will return Z_BUF_ERROR if it has not reached the end of the stream.
*/ */
int ZEXPORT inflate(z_streamp strm, int flush) { int ZEXPORT inflate(strm, flush)
z_streamp strm;
int flush;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
z_const unsigned char FAR *next; /* next input */ z_const unsigned char FAR *next; /* next input */
unsigned char FAR *put; /* next output */ unsigned char FAR *put; /* next output */
@@ -1264,7 +1302,9 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
return ret; return ret;
} }
int ZEXPORT inflateEnd(z_streamp strm) { int ZEXPORT inflateEnd(strm)
z_streamp strm;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) if (inflateStateCheck(strm))
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
@@ -1276,8 +1316,11 @@ int ZEXPORT inflateEnd(z_streamp strm) {
return Z_OK; return Z_OK;
} }
int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary, int ZEXPORT inflateGetDictionary(strm, dictionary, dictLength)
uInt *dictLength) { z_streamp strm;
Bytef *dictionary;
uInt *dictLength;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
/* check state */ /* check state */
@@ -1296,8 +1339,11 @@ int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary,
return Z_OK; return Z_OK;
} }
int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary, int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength)
uInt dictLength) { z_streamp strm;
const Bytef *dictionary;
uInt dictLength;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
unsigned long dictid; unsigned long dictid;
int ret; int ret;
@@ -1328,7 +1374,10 @@ int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary,
return Z_OK; return Z_OK;
} }
int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head) { int ZEXPORT inflateGetHeader(strm, head)
z_streamp strm;
gz_headerp head;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
/* check state */ /* check state */
@@ -1353,8 +1402,11 @@ int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head) {
called again with more data and the *have state. *have is initialized to called again with more data and the *have state. *have is initialized to
zero for the first call. zero for the first call.
*/ */
local unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf, local unsigned syncsearch(have, buf, len)
unsigned len) { unsigned FAR *have;
const unsigned char FAR *buf;
unsigned len;
{
unsigned got; unsigned got;
unsigned next; unsigned next;
@@ -1373,7 +1425,9 @@ local unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf,
return next; return next;
} }
int ZEXPORT inflateSync(z_streamp strm) { int ZEXPORT inflateSync(strm)
z_streamp strm;
{
unsigned len; /* number of bytes to look at or looked at */ unsigned len; /* number of bytes to look at or looked at */
int flags; /* temporary to save header status */ int flags; /* temporary to save header status */
unsigned long in, out; /* temporary to save total_in and total_out */ unsigned long in, out; /* temporary to save total_in and total_out */
@@ -1429,7 +1483,9 @@ int ZEXPORT inflateSync(z_streamp strm) {
block. When decompressing, PPP checks that at the end of input packet, block. When decompressing, PPP checks that at the end of input packet,
inflate is waiting for these length bytes. inflate is waiting for these length bytes.
*/ */
int ZEXPORT inflateSyncPoint(z_streamp strm) { int ZEXPORT inflateSyncPoint(strm)
z_streamp strm;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
@@ -1437,7 +1493,10 @@ int ZEXPORT inflateSyncPoint(z_streamp strm) {
return state->mode == STORED && state->bits == 0; return state->mode == STORED && state->bits == 0;
} }
int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) { int ZEXPORT inflateCopy(dest, source)
z_streamp dest;
z_streamp source;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
struct inflate_state FAR *copy; struct inflate_state FAR *copy;
unsigned char FAR *window; unsigned char FAR *window;
@@ -1481,7 +1540,10 @@ int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) {
return Z_OK; return Z_OK;
} }
int ZEXPORT inflateUndermine(z_streamp strm, int subvert) { int ZEXPORT inflateUndermine(strm, subvert)
z_streamp strm;
int subvert;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
@@ -1496,7 +1558,10 @@ int ZEXPORT inflateUndermine(z_streamp strm, int subvert) {
#endif #endif
} }
int ZEXPORT inflateValidate(z_streamp strm, int check) { int ZEXPORT inflateValidate(strm, check)
z_streamp strm;
int check;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
@@ -1508,7 +1573,9 @@ int ZEXPORT inflateValidate(z_streamp strm, int check) {
return Z_OK; return Z_OK;
} }
long ZEXPORT inflateMark(z_streamp strm) { long ZEXPORT inflateMark(strm)
z_streamp strm;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) if (inflateStateCheck(strm))
@@ -1519,7 +1586,9 @@ long ZEXPORT inflateMark(z_streamp strm) {
(state->mode == MATCH ? state->was - state->length : 0)); (state->mode == MATCH ? state->was - state->length : 0));
} }
unsigned long ZEXPORT inflateCodesUsed(z_streamp strm) { unsigned long ZEXPORT inflateCodesUsed(strm)
z_streamp strm;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) return (unsigned long)-1; if (inflateStateCheck(strm)) return (unsigned long)-1;
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
+11 -6
View File
@@ -1,5 +1,5 @@
/* inftrees.c -- generate Huffman trees for efficient decoding /* inftrees.c -- generate Huffman trees for efficient decoding
* Copyright (C) 1995-2023 Mark Adler * Copyright (C) 1995-2022 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@@ -9,7 +9,7 @@
#define MAXBITS 15 #define MAXBITS 15
const char inflate_copyright[] = const char inflate_copyright[] =
" inflate 1.3 Copyright 1995-2023 Mark Adler "; " inflate 1.2.13 Copyright 1995-2022 Mark Adler ";
/* /*
If you use the zlib library in a product, an acknowledgment is welcome If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot in the documentation of your product. If for some reason you cannot
@@ -29,9 +29,14 @@ const char inflate_copyright[] =
table index bits. It will differ if the request is greater than the table index bits. It will differ if the request is greater than the
longest code or if it is less than the shortest code. longest code or if it is less than the shortest code.
*/ */
int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work)
unsigned codes, code FAR * FAR *table, codetype type;
unsigned FAR *bits, unsigned short FAR *work) { unsigned short FAR *lens;
unsigned codes;
code FAR * FAR *table;
unsigned FAR *bits;
unsigned short FAR *work;
{
unsigned len; /* a code's length in bits */ unsigned len; /* a code's length in bits */
unsigned sym; /* index of code symbols */ unsigned sym; /* index of code symbols */
unsigned min, max; /* minimum and maximum code lengths */ unsigned min, max; /* minimum and maximum code lengths */
@@ -57,7 +62,7 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
static const unsigned short lext[31] = { /* Length codes 257..285 extra */ static const unsigned short lext[31] = { /* Length codes 257..285 extra */
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 198, 203}; 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 194, 65};
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
+3 -3
View File
@@ -57,6 +57,6 @@ typedef enum {
DISTS DISTS
} codetype; } codetype;
int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens,
unsigned codes, code FAR * FAR *table, unsigned codes, code FAR * FAR *table,
unsigned FAR *bits, unsigned short FAR *work); unsigned FAR *bits, unsigned short FAR *work));
+302 -224
View File
@@ -122,116 +122,39 @@ struct static_tree_desc_s {
int max_length; /* max bit length for the codes */ int max_length; /* max bit length for the codes */
}; };
#ifdef NO_INIT_GLOBAL_POINTERS local const static_tree_desc static_l_desc =
# define TCONST
#else
# define TCONST const
#endif
local TCONST static_tree_desc static_l_desc =
{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
local TCONST static_tree_desc static_d_desc = local const static_tree_desc static_d_desc =
{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
local TCONST static_tree_desc static_bl_desc = local const static_tree_desc static_bl_desc =
{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
/* =========================================================================== /* ===========================================================================
* Output a short LSB first on the stream. * Local (static) routines in this file.
* IN assertion: there is enough room in pendingBuf.
*/ */
#define put_short(s, w) { \
put_byte(s, (uch)((w) & 0xff)); \
put_byte(s, (uch)((ush)(w) >> 8)); \
}
/* =========================================================================== local void tr_static_init OF((void));
* Reverse the first len bits of a code, using straightforward code (a faster local void init_block OF((deflate_state *s));
* method would use a table) local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
* IN assertion: 1 <= len <= 15 local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
*/ local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
local unsigned bi_reverse(unsigned code, int len) { local void build_tree OF((deflate_state *s, tree_desc *desc));
register unsigned res = 0; local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
do { local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
res |= code & 1; local int build_bl_tree OF((deflate_state *s));
code >>= 1, res <<= 1; local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
} while (--len > 0); int blcodes));
return res >> 1; local void compress_block OF((deflate_state *s, const ct_data *ltree,
} const ct_data *dtree));
local int detect_data_type OF((deflate_state *s));
/* =========================================================================== local unsigned bi_reverse OF((unsigned code, int len));
* Flush the bit buffer, keeping at most 7 bits in it. local void bi_windup OF((deflate_state *s));
*/ local void bi_flush OF((deflate_state *s));
local void bi_flush(deflate_state *s) {
if (s->bi_valid == 16) {
put_short(s, s->bi_buf);
s->bi_buf = 0;
s->bi_valid = 0;
} else if (s->bi_valid >= 8) {
put_byte(s, (Byte)s->bi_buf);
s->bi_buf >>= 8;
s->bi_valid -= 8;
}
}
/* ===========================================================================
* Flush the bit buffer and align the output on a byte boundary
*/
local void bi_windup(deflate_state *s) {
if (s->bi_valid > 8) {
put_short(s, s->bi_buf);
} else if (s->bi_valid > 0) {
put_byte(s, (Byte)s->bi_buf);
}
s->bi_buf = 0;
s->bi_valid = 0;
#ifdef ZLIB_DEBUG
s->bits_sent = (s->bits_sent + 7) & ~7;
#endif
}
/* ===========================================================================
* Generate the codes for a given tree and bit counts (which need not be
* optimal).
* IN assertion: the array bl_count contains the bit length statistics for
* the given tree and the field len is set for all tree elements.
* OUT assertion: the field code is set for all tree elements of non
* zero code length.
*/
local void gen_codes(ct_data *tree, int max_code, ushf *bl_count) {
ush next_code[MAX_BITS+1]; /* next code value for each bit length */
unsigned code = 0; /* running code value */
int bits; /* bit index */
int n; /* code index */
/* The distribution counts are first used to generate the code values
* without bit reversal.
*/
for (bits = 1; bits <= MAX_BITS; bits++) {
code = (code + bl_count[bits - 1]) << 1;
next_code[bits] = (ush)code;
}
/* Check that the bit counts in bl_count are consistent. The last code
* must be all ones.
*/
Assert (code + bl_count[MAX_BITS] - 1 == (1 << MAX_BITS) - 1,
"inconsistent bit counts");
Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
for (n = 0; n <= max_code; n++) {
int len = tree[n].Len;
if (len == 0) continue;
/* Now reverse the bits */
tree[n].Code = (ush)bi_reverse(next_code[len]++, len);
Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len] - 1));
}
}
#ifdef GEN_TREES_H #ifdef GEN_TREES_H
local void gen_trees_header(void); local void gen_trees_header OF((void));
#endif #endif
#ifndef ZLIB_DEBUG #ifndef ZLIB_DEBUG
@@ -244,12 +167,27 @@ local void gen_trees_header(void);
send_bits(s, tree[c].Code, tree[c].Len); } send_bits(s, tree[c].Code, tree[c].Len); }
#endif #endif
/* ===========================================================================
* Output a short LSB first on the stream.
* IN assertion: there is enough room in pendingBuf.
*/
#define put_short(s, w) { \
put_byte(s, (uch)((w) & 0xff)); \
put_byte(s, (uch)((ush)(w) >> 8)); \
}
/* =========================================================================== /* ===========================================================================
* Send a value on a given number of bits. * Send a value on a given number of bits.
* IN assertion: length <= 16 and value fits in length bits. * IN assertion: length <= 16 and value fits in length bits.
*/ */
#ifdef ZLIB_DEBUG #ifdef ZLIB_DEBUG
local void send_bits(deflate_state *s, int value, int length) { local void send_bits OF((deflate_state *s, int value, int length));
local void send_bits(s, value, length)
deflate_state *s;
int value; /* value to send */
int length; /* number of bits */
{
Tracevv((stderr," l %2d v %4x ", length, value)); Tracevv((stderr," l %2d v %4x ", length, value));
Assert(length > 0 && length <= 15, "invalid length"); Assert(length > 0 && length <= 15, "invalid length");
s->bits_sent += (ulg)length; s->bits_sent += (ulg)length;
@@ -291,7 +229,8 @@ local void send_bits(deflate_state *s, int value, int length) {
/* =========================================================================== /* ===========================================================================
* Initialize the various 'constant' tables. * Initialize the various 'constant' tables.
*/ */
local void tr_static_init(void) { local void tr_static_init()
{
#if defined(GEN_TREES_H) || !defined(STDC) #if defined(GEN_TREES_H) || !defined(STDC)
static int static_init_done = 0; static int static_init_done = 0;
int n; /* iterates over tree elements */ int n; /* iterates over tree elements */
@@ -384,7 +323,8 @@ local void tr_static_init(void) {
((i) == (last)? "\n};\n\n" : \ ((i) == (last)? "\n};\n\n" : \
((i) % (width) == (width) - 1 ? ",\n" : ", ")) ((i) % (width) == (width) - 1 ? ",\n" : ", "))
void gen_trees_header(void) { void gen_trees_header()
{
FILE *header = fopen("trees.h", "w"); FILE *header = fopen("trees.h", "w");
int i; int i;
@@ -433,26 +373,12 @@ void gen_trees_header(void) {
} }
#endif /* GEN_TREES_H */ #endif /* GEN_TREES_H */
/* ===========================================================================
* Initialize a new block.
*/
local void init_block(deflate_state *s) {
int n; /* iterates over tree elements */
/* Initialize the trees. */
for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
s->dyn_ltree[END_BLOCK].Freq = 1;
s->opt_len = s->static_len = 0L;
s->sym_next = s->matches = 0;
}
/* =========================================================================== /* ===========================================================================
* Initialize the tree data structures for a new zlib stream. * Initialize the tree data structures for a new zlib stream.
*/ */
void ZLIB_INTERNAL _tr_init(deflate_state *s) { void ZLIB_INTERNAL _tr_init(s)
deflate_state *s;
{
tr_static_init(); tr_static_init();
s->l_desc.dyn_tree = s->dyn_ltree; s->l_desc.dyn_tree = s->dyn_ltree;
@@ -475,6 +401,24 @@ void ZLIB_INTERNAL _tr_init(deflate_state *s) {
init_block(s); init_block(s);
} }
/* ===========================================================================
* Initialize a new block.
*/
local void init_block(s)
deflate_state *s;
{
int n; /* iterates over tree elements */
/* Initialize the trees. */
for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
s->dyn_ltree[END_BLOCK].Freq = 1;
s->opt_len = s->static_len = 0L;
s->sym_next = s->matches = 0;
}
#define SMALLEST 1 #define SMALLEST 1
/* Index within the heap array of least frequent node in the Huffman tree */ /* Index within the heap array of least frequent node in the Huffman tree */
@@ -504,7 +448,11 @@ void ZLIB_INTERNAL _tr_init(deflate_state *s) {
* when the heap property is re-established (each father smaller than its * when the heap property is re-established (each father smaller than its
* two sons). * two sons).
*/ */
local void pqdownheap(deflate_state *s, ct_data *tree, int k) { local void pqdownheap(s, tree, k)
deflate_state *s;
ct_data *tree; /* the tree to restore */
int k; /* node to move down */
{
int v = s->heap[k]; int v = s->heap[k];
int j = k << 1; /* left son of k */ int j = k << 1; /* left son of k */
while (j <= s->heap_len) { while (j <= s->heap_len) {
@@ -535,7 +483,10 @@ local void pqdownheap(deflate_state *s, ct_data *tree, int k) {
* The length opt_len is updated; static_len is also updated if stree is * The length opt_len is updated; static_len is also updated if stree is
* not null. * not null.
*/ */
local void gen_bitlen(deflate_state *s, tree_desc *desc) { local void gen_bitlen(s, desc)
deflate_state *s;
tree_desc *desc; /* the tree descriptor */
{
ct_data *tree = desc->dyn_tree; ct_data *tree = desc->dyn_tree;
int max_code = desc->max_code; int max_code = desc->max_code;
const ct_data *stree = desc->stat_desc->static_tree; const ct_data *stree = desc->stat_desc->static_tree;
@@ -610,9 +561,48 @@ local void gen_bitlen(deflate_state *s, tree_desc *desc) {
} }
} }
#ifdef DUMP_BL_TREE /* ===========================================================================
# include <stdio.h> * Generate the codes for a given tree and bit counts (which need not be
#endif * optimal).
* IN assertion: the array bl_count contains the bit length statistics for
* the given tree and the field len is set for all tree elements.
* OUT assertion: the field code is set for all tree elements of non
* zero code length.
*/
local void gen_codes(tree, max_code, bl_count)
ct_data *tree; /* the tree to decorate */
int max_code; /* largest code with non zero frequency */
ushf *bl_count; /* number of codes at each bit length */
{
ush next_code[MAX_BITS+1]; /* next code value for each bit length */
unsigned code = 0; /* running code value */
int bits; /* bit index */
int n; /* code index */
/* The distribution counts are first used to generate the code values
* without bit reversal.
*/
for (bits = 1; bits <= MAX_BITS; bits++) {
code = (code + bl_count[bits - 1]) << 1;
next_code[bits] = (ush)code;
}
/* Check that the bit counts in bl_count are consistent. The last code
* must be all ones.
*/
Assert (code + bl_count[MAX_BITS] - 1 == (1 << MAX_BITS) - 1,
"inconsistent bit counts");
Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
for (n = 0; n <= max_code; n++) {
int len = tree[n].Len;
if (len == 0) continue;
/* Now reverse the bits */
tree[n].Code = (ush)bi_reverse(next_code[len]++, len);
Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len] - 1));
}
}
/* =========================================================================== /* ===========================================================================
* Construct one Huffman tree and assigns the code bit strings and lengths. * Construct one Huffman tree and assigns the code bit strings and lengths.
@@ -622,7 +612,10 @@ local void gen_bitlen(deflate_state *s, tree_desc *desc) {
* and corresponding code. The length opt_len is updated; static_len is * and corresponding code. The length opt_len is updated; static_len is
* also updated if stree is not null. The field max_code is set. * also updated if stree is not null. The field max_code is set.
*/ */
local void build_tree(deflate_state *s, tree_desc *desc) { local void build_tree(s, desc)
deflate_state *s;
tree_desc *desc; /* the tree descriptor */
{
ct_data *tree = desc->dyn_tree; ct_data *tree = desc->dyn_tree;
const ct_data *stree = desc->stat_desc->static_tree; const ct_data *stree = desc->stat_desc->static_tree;
int elems = desc->stat_desc->elems; int elems = desc->stat_desc->elems;
@@ -707,7 +700,11 @@ local void build_tree(deflate_state *s, tree_desc *desc) {
* Scan a literal or distance tree to determine the frequencies of the codes * Scan a literal or distance tree to determine the frequencies of the codes
* in the bit length tree. * in the bit length tree.
*/ */
local void scan_tree(deflate_state *s, ct_data *tree, int max_code) { local void scan_tree(s, tree, max_code)
deflate_state *s;
ct_data *tree; /* the tree to be scanned */
int max_code; /* and its largest code of non zero frequency */
{
int n; /* iterates over all tree elements */ int n; /* iterates over all tree elements */
int prevlen = -1; /* last emitted length */ int prevlen = -1; /* last emitted length */
int curlen; /* length of current code */ int curlen; /* length of current code */
@@ -748,7 +745,11 @@ local void scan_tree(deflate_state *s, ct_data *tree, int max_code) {
* Send a literal or distance tree in compressed form, using the codes in * Send a literal or distance tree in compressed form, using the codes in
* bl_tree. * bl_tree.
*/ */
local void send_tree(deflate_state *s, ct_data *tree, int max_code) { local void send_tree(s, tree, max_code)
deflate_state *s;
ct_data *tree; /* the tree to be scanned */
int max_code; /* and its largest code of non zero frequency */
{
int n; /* iterates over all tree elements */ int n; /* iterates over all tree elements */
int prevlen = -1; /* last emitted length */ int prevlen = -1; /* last emitted length */
int curlen; /* length of current code */ int curlen; /* length of current code */
@@ -795,7 +796,9 @@ local void send_tree(deflate_state *s, ct_data *tree, int max_code) {
* Construct the Huffman tree for the bit lengths and return the index in * Construct the Huffman tree for the bit lengths and return the index in
* bl_order of the last bit length code to send. * bl_order of the last bit length code to send.
*/ */
local int build_bl_tree(deflate_state *s) { local int build_bl_tree(s)
deflate_state *s;
{
int max_blindex; /* index of last bit length code of non zero freq */ int max_blindex; /* index of last bit length code of non zero freq */
/* Determine the bit length frequencies for literal and distance trees */ /* Determine the bit length frequencies for literal and distance trees */
@@ -828,8 +831,10 @@ local int build_bl_tree(deflate_state *s) {
* lengths of the bit length codes, the literal tree and the distance tree. * lengths of the bit length codes, the literal tree and the distance tree.
* IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
*/ */
local void send_all_trees(deflate_state *s, int lcodes, int dcodes, local void send_all_trees(s, lcodes, dcodes, blcodes)
int blcodes) { deflate_state *s;
int lcodes, dcodes, blcodes; /* number of codes for each tree */
{
int rank; /* index in bl_order */ int rank; /* index in bl_order */
Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
@@ -855,8 +860,12 @@ local void send_all_trees(deflate_state *s, int lcodes, int dcodes,
/* =========================================================================== /* ===========================================================================
* Send a stored block * Send a stored block
*/ */
void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last)
ulg stored_len, int last) { deflate_state *s;
charf *buf; /* input block */
ulg stored_len; /* length of input block */
int last; /* one if this is the last block for a file */
{
send_bits(s, (STORED_BLOCK<<1) + last, 3); /* send block type */ send_bits(s, (STORED_BLOCK<<1) + last, 3); /* send block type */
bi_windup(s); /* align on byte boundary */ bi_windup(s); /* align on byte boundary */
put_short(s, (ush)stored_len); put_short(s, (ush)stored_len);
@@ -875,7 +884,9 @@ void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf,
/* =========================================================================== /* ===========================================================================
* Flush the bits in the bit buffer to pending output (leaves at most 7 bits) * Flush the bits in the bit buffer to pending output (leaves at most 7 bits)
*/ */
void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s) { void ZLIB_INTERNAL _tr_flush_bits(s)
deflate_state *s;
{
bi_flush(s); bi_flush(s);
} }
@@ -883,7 +894,9 @@ void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s) {
* Send one empty static block to give enough lookahead for inflate. * Send one empty static block to give enough lookahead for inflate.
* This takes 10 bits, of which 7 may remain in the bit buffer. * This takes 10 bits, of which 7 may remain in the bit buffer.
*/ */
void ZLIB_INTERNAL _tr_align(deflate_state *s) { void ZLIB_INTERNAL _tr_align(s)
deflate_state *s;
{
send_bits(s, STATIC_TREES<<1, 3); send_bits(s, STATIC_TREES<<1, 3);
send_code(s, END_BLOCK, static_ltree); send_code(s, END_BLOCK, static_ltree);
#ifdef ZLIB_DEBUG #ifdef ZLIB_DEBUG
@@ -892,99 +905,16 @@ void ZLIB_INTERNAL _tr_align(deflate_state *s) {
bi_flush(s); bi_flush(s);
} }
/* ===========================================================================
* Send the block data compressed using the given Huffman trees
*/
local void compress_block(deflate_state *s, const ct_data *ltree,
const ct_data *dtree) {
unsigned dist; /* distance of matched string */
int lc; /* match length or unmatched char (if dist == 0) */
unsigned sx = 0; /* running index in sym_buf */
unsigned code; /* the code to send */
int extra; /* number of extra bits to send */
if (s->sym_next != 0) do {
dist = s->sym_buf[sx++] & 0xff;
dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8;
lc = s->sym_buf[sx++];
if (dist == 0) {
send_code(s, lc, ltree); /* send a literal byte */
Tracecv(isgraph(lc), (stderr," '%c' ", lc));
} else {
/* Here, lc is the match length - MIN_MATCH */
code = _length_code[lc];
send_code(s, code + LITERALS + 1, ltree); /* send length code */
extra = extra_lbits[code];
if (extra != 0) {
lc -= base_length[code];
send_bits(s, lc, extra); /* send the extra length bits */
}
dist--; /* dist is now the match distance - 1 */
code = d_code(dist);
Assert (code < D_CODES, "bad d_code");
send_code(s, code, dtree); /* send the distance code */
extra = extra_dbits[code];
if (extra != 0) {
dist -= (unsigned)base_dist[code];
send_bits(s, dist, extra); /* send the extra distance bits */
}
} /* literal or match pair ? */
/* Check that the overlay between pending_buf and sym_buf is ok: */
Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow");
} while (sx < s->sym_next);
send_code(s, END_BLOCK, ltree);
}
/* ===========================================================================
* Check if the data type is TEXT or BINARY, using the following algorithm:
* - TEXT if the two conditions below are satisfied:
* a) There are no non-portable control characters belonging to the
* "block list" (0..6, 14..25, 28..31).
* b) There is at least one printable character belonging to the
* "allow list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
* - BINARY otherwise.
* - The following partially-portable control characters form a
* "gray list" that is ignored in this detection algorithm:
* (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
* IN assertion: the fields Freq of dyn_ltree are set.
*/
local int detect_data_type(deflate_state *s) {
/* block_mask is the bit mask of block-listed bytes
* set bits 0..6, 14..25, and 28..31
* 0xf3ffc07f = binary 11110011111111111100000001111111
*/
unsigned long block_mask = 0xf3ffc07fUL;
int n;
/* Check for non-textual ("block-listed") bytes. */
for (n = 0; n <= 31; n++, block_mask >>= 1)
if ((block_mask & 1) && (s->dyn_ltree[n].Freq != 0))
return Z_BINARY;
/* Check for textual ("allow-listed") bytes. */
if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0
|| s->dyn_ltree[13].Freq != 0)
return Z_TEXT;
for (n = 32; n < LITERALS; n++)
if (s->dyn_ltree[n].Freq != 0)
return Z_TEXT;
/* There are no "block-listed" or "allow-listed" bytes:
* this stream either is empty or has tolerated ("gray-listed") bytes only.
*/
return Z_BINARY;
}
/* =========================================================================== /* ===========================================================================
* Determine the best encoding for the current block: dynamic trees, static * Determine the best encoding for the current block: dynamic trees, static
* trees or store, and write out the encoded block. * trees or store, and write out the encoded block.
*/ */
void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
ulg stored_len, int last) { deflate_state *s;
charf *buf; /* input block, or NULL if too old */
ulg stored_len; /* length of input block */
int last; /* one if this is the last block for a file */
{
ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
int max_blindex = 0; /* index of last bit length code of non zero freq */ int max_blindex = 0; /* index of last bit length code of non zero freq */
@@ -1081,7 +1011,11 @@ void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf,
* Save the match info and tally the frequency counts. Return true if * Save the match info and tally the frequency counts. Return true if
* the current block must be flushed. * the current block must be flushed.
*/ */
int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc) { int ZLIB_INTERNAL _tr_tally(s, dist, lc)
deflate_state *s;
unsigned dist; /* distance of matched string */
unsigned lc; /* match length - MIN_MATCH or unmatched char (dist==0) */
{
s->sym_buf[s->sym_next++] = (uch)dist; s->sym_buf[s->sym_next++] = (uch)dist;
s->sym_buf[s->sym_next++] = (uch)(dist >> 8); s->sym_buf[s->sym_next++] = (uch)(dist >> 8);
s->sym_buf[s->sym_next++] = (uch)lc; s->sym_buf[s->sym_next++] = (uch)lc;
@@ -1101,3 +1035,147 @@ int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc) {
} }
return (s->sym_next == s->sym_end); return (s->sym_next == s->sym_end);
} }
/* ===========================================================================
* Send the block data compressed using the given Huffman trees
*/
local void compress_block(s, ltree, dtree)
deflate_state *s;
const ct_data *ltree; /* literal tree */
const ct_data *dtree; /* distance tree */
{
unsigned dist; /* distance of matched string */
int lc; /* match length or unmatched char (if dist == 0) */
unsigned sx = 0; /* running index in sym_buf */
unsigned code; /* the code to send */
int extra; /* number of extra bits to send */
if (s->sym_next != 0) do {
dist = s->sym_buf[sx++] & 0xff;
dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8;
lc = s->sym_buf[sx++];
if (dist == 0) {
send_code(s, lc, ltree); /* send a literal byte */
Tracecv(isgraph(lc), (stderr," '%c' ", lc));
} else {
/* Here, lc is the match length - MIN_MATCH */
code = _length_code[lc];
send_code(s, code + LITERALS + 1, ltree); /* send length code */
extra = extra_lbits[code];
if (extra != 0) {
lc -= base_length[code];
send_bits(s, lc, extra); /* send the extra length bits */
}
dist--; /* dist is now the match distance - 1 */
code = d_code(dist);
Assert (code < D_CODES, "bad d_code");
send_code(s, code, dtree); /* send the distance code */
extra = extra_dbits[code];
if (extra != 0) {
dist -= (unsigned)base_dist[code];
send_bits(s, dist, extra); /* send the extra distance bits */
}
} /* literal or match pair ? */
/* Check that the overlay between pending_buf and sym_buf is ok: */
Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow");
} while (sx < s->sym_next);
send_code(s, END_BLOCK, ltree);
}
/* ===========================================================================
* Check if the data type is TEXT or BINARY, using the following algorithm:
* - TEXT if the two conditions below are satisfied:
* a) There are no non-portable control characters belonging to the
* "block list" (0..6, 14..25, 28..31).
* b) There is at least one printable character belonging to the
* "allow list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
* - BINARY otherwise.
* - The following partially-portable control characters form a
* "gray list" that is ignored in this detection algorithm:
* (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
* IN assertion: the fields Freq of dyn_ltree are set.
*/
local int detect_data_type(s)
deflate_state *s;
{
/* block_mask is the bit mask of block-listed bytes
* set bits 0..6, 14..25, and 28..31
* 0xf3ffc07f = binary 11110011111111111100000001111111
*/
unsigned long block_mask = 0xf3ffc07fUL;
int n;
/* Check for non-textual ("block-listed") bytes. */
for (n = 0; n <= 31; n++, block_mask >>= 1)
if ((block_mask & 1) && (s->dyn_ltree[n].Freq != 0))
return Z_BINARY;
/* Check for textual ("allow-listed") bytes. */
if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0
|| s->dyn_ltree[13].Freq != 0)
return Z_TEXT;
for (n = 32; n < LITERALS; n++)
if (s->dyn_ltree[n].Freq != 0)
return Z_TEXT;
/* There are no "block-listed" or "allow-listed" bytes:
* this stream either is empty or has tolerated ("gray-listed") bytes only.
*/
return Z_BINARY;
}
/* ===========================================================================
* Reverse the first len bits of a code, using straightforward code (a faster
* method would use a table)
* IN assertion: 1 <= len <= 15
*/
local unsigned bi_reverse(code, len)
unsigned code; /* the value to invert */
int len; /* its bit length */
{
register unsigned res = 0;
do {
res |= code & 1;
code >>= 1, res <<= 1;
} while (--len > 0);
return res >> 1;
}
/* ===========================================================================
* Flush the bit buffer, keeping at most 7 bits in it.
*/
local void bi_flush(s)
deflate_state *s;
{
if (s->bi_valid == 16) {
put_short(s, s->bi_buf);
s->bi_buf = 0;
s->bi_valid = 0;
} else if (s->bi_valid >= 8) {
put_byte(s, (Byte)s->bi_buf);
s->bi_buf >>= 8;
s->bi_valid -= 8;
}
}
/* ===========================================================================
* Flush the bit buffer and align the output on a byte boundary
*/
local void bi_windup(s)
deflate_state *s;
{
if (s->bi_valid > 8) {
put_short(s, s->bi_buf);
} else if (s->bi_valid > 0) {
put_byte(s, (Byte)s->bi_buf);
}
s->bi_buf = 0;
s->bi_valid = 0;
#ifdef ZLIB_DEBUG
s->bits_sent = (s->bits_sent + 7) & ~7;
#endif
}
+12 -4
View File
@@ -24,8 +24,12 @@
Z_DATA_ERROR if the input data was corrupted, including if the input data is Z_DATA_ERROR if the input data was corrupted, including if the input data is
an incomplete zlib stream. an incomplete zlib stream.
*/ */
int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source, int ZEXPORT uncompress2(dest, destLen, source, sourceLen)
uLong *sourceLen) { Bytef *dest;
uLongf *destLen;
const Bytef *source;
uLong *sourceLen;
{
z_stream stream; z_stream stream;
int err; int err;
const uInt max = (uInt)-1; const uInt max = (uInt)-1;
@@ -79,7 +83,11 @@ int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source,
err; err;
} }
int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, int ZEXPORT uncompress(dest, destLen, source, sourceLen)
uLong sourceLen) { Bytef *dest;
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
{
return uncompress2(dest, destLen, source, &sourceLen); return uncompress2(dest, destLen, source, &sourceLen);
} }
+2 -6
View File
@@ -241,11 +241,7 @@
#endif #endif
#ifdef Z_SOLO #ifdef Z_SOLO
# ifdef _WIN64 typedef unsigned long z_size_t;
typedef unsigned long long z_size_t;
# else
typedef unsigned long z_size_t;
# endif
#else #else
# define z_longlong long long # define z_longlong long long
# if defined(NO_SIZE_T) # if defined(NO_SIZE_T)
@@ -524,7 +520,7 @@ typedef uLong FAR uLongf;
#if !defined(_WIN32) && defined(Z_LARGE64) #if !defined(_WIN32) && defined(Z_LARGE64)
# define z_off64_t off64_t # define z_off64_t off64_t
#else #else
# if defined(_WIN32) && !defined(__GNUC__) # if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
# define z_off64_t __int64 # define z_off64_t __int64
# else # else
# define z_off64_t z_off_t # define z_off64_t z_off_t
+188 -191
View File
@@ -1,7 +1,7 @@
/* zlib.h -- interface of the 'zlib' general purpose compression library /* zlib.h -- interface of the 'zlib' general purpose compression library
version 1.3, August 18th, 2023 version 1.2.13, October 13th, 2022
Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
@@ -37,11 +37,11 @@
extern "C" { extern "C" {
#endif #endif
#define ZLIB_VERSION "1.3" #define ZLIB_VERSION "1.2.13"
#define ZLIB_VERNUM 0x1300 #define ZLIB_VERNUM 0x12d0
#define ZLIB_VER_MAJOR 1 #define ZLIB_VER_MAJOR 1
#define ZLIB_VER_MINOR 3 #define ZLIB_VER_MINOR 2
#define ZLIB_VER_REVISION 0 #define ZLIB_VER_REVISION 13
#define ZLIB_VER_SUBREVISION 0 #define ZLIB_VER_SUBREVISION 0
/* /*
@@ -78,8 +78,8 @@ extern "C" {
even in the case of corrupted input. even in the case of corrupted input.
*/ */
typedef voidpf (*alloc_func)(voidpf opaque, uInt items, uInt size); typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
typedef void (*free_func)(voidpf opaque, voidpf address); typedef void (*free_func) OF((voidpf opaque, voidpf address));
struct internal_state; struct internal_state;
@@ -217,7 +217,7 @@ typedef gz_header FAR *gz_headerp;
/* basic functions */ /* basic functions */
ZEXTERN const char * ZEXPORT zlibVersion(void); ZEXTERN const char * ZEXPORT zlibVersion OF((void));
/* The application can compare zlibVersion and ZLIB_VERSION for consistency. /* The application can compare zlibVersion and ZLIB_VERSION for consistency.
If the first character differs, the library code actually used is not If the first character differs, the library code actually used is not
compatible with the zlib.h header file used by the application. This check compatible with the zlib.h header file used by the application. This check
@@ -225,12 +225,12 @@ ZEXTERN const char * ZEXPORT zlibVersion(void);
*/ */
/* /*
ZEXTERN int ZEXPORT deflateInit(z_streamp strm, int level); ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
Initializes the internal stream state for compression. The fields Initializes the internal stream state for compression. The fields
zalloc, zfree and opaque must be initialized before by the caller. If zalloc, zfree and opaque must be initialized before by the caller. If
zalloc and zfree are set to Z_NULL, deflateInit updates them to use default zalloc and zfree are set to Z_NULL, deflateInit updates them to use default
allocation functions. total_in, total_out, adler, and msg are initialized. allocation functions.
The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
1 gives best speed, 9 gives best compression, 0 gives no compression at all 1 gives best speed, 9 gives best compression, 0 gives no compression at all
@@ -247,7 +247,7 @@ ZEXTERN int ZEXPORT deflateInit(z_streamp strm, int level);
*/ */
ZEXTERN int ZEXPORT deflate(z_streamp strm, int flush); ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
/* /*
deflate compresses as much data as possible, and stops when the input deflate compresses as much data as possible, and stops when the input
buffer becomes empty or the output buffer becomes full. It may introduce buffer becomes empty or the output buffer becomes full. It may introduce
@@ -320,8 +320,8 @@ ZEXTERN int ZEXPORT deflate(z_streamp strm, int flush);
with the same value of the flush parameter and more output space (updated with the same value of the flush parameter and more output space (updated
avail_out), until the flush is complete (deflate returns with non-zero avail_out), until the flush is complete (deflate returns with non-zero
avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
avail_out is greater than six when the flush marker begins, in order to avoid avail_out is greater than six to avoid repeated flush markers due to
repeated flush markers upon calling deflate() again when avail_out == 0. avail_out == 0 on return.
If the parameter flush is set to Z_FINISH, pending input is processed, If the parameter flush is set to Z_FINISH, pending input is processed,
pending output is flushed and deflate returns with Z_STREAM_END if there was pending output is flushed and deflate returns with Z_STREAM_END if there was
@@ -360,7 +360,7 @@ ZEXTERN int ZEXPORT deflate(z_streamp strm, int flush);
*/ */
ZEXTERN int ZEXPORT deflateEnd(z_streamp strm); ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
/* /*
All dynamically allocated data structures for this stream are freed. All dynamically allocated data structures for this stream are freed.
This function discards any unprocessed input and does not flush any pending This function discards any unprocessed input and does not flush any pending
@@ -375,7 +375,7 @@ ZEXTERN int ZEXPORT deflateEnd(z_streamp strm);
/* /*
ZEXTERN int ZEXPORT inflateInit(z_streamp strm); ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
Initializes the internal stream state for decompression. The fields Initializes the internal stream state for decompression. The fields
next_in, avail_in, zalloc, zfree and opaque must be initialized before by next_in, avail_in, zalloc, zfree and opaque must be initialized before by
@@ -383,8 +383,7 @@ ZEXTERN int ZEXPORT inflateInit(z_streamp strm);
read or consumed. The allocation of a sliding window will be deferred to read or consumed. The allocation of a sliding window will be deferred to
the first call of inflate (if the decompression does not complete on the the first call of inflate (if the decompression does not complete on the
first call). If zalloc and zfree are set to Z_NULL, inflateInit updates first call). If zalloc and zfree are set to Z_NULL, inflateInit updates
them to use default allocation functions. total_in, total_out, adler, and them to use default allocation functions.
msg are initialized.
inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_VERSION_ERROR if the zlib library version is incompatible with the memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
@@ -398,7 +397,7 @@ ZEXTERN int ZEXPORT inflateInit(z_streamp strm);
*/ */
ZEXTERN int ZEXPORT inflate(z_streamp strm, int flush); ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
/* /*
inflate decompresses as much data as possible, and stops when the input inflate decompresses as much data as possible, and stops when the input
buffer becomes empty or the output buffer becomes full. It may introduce buffer becomes empty or the output buffer becomes full. It may introduce
@@ -518,7 +517,7 @@ ZEXTERN int ZEXPORT inflate(z_streamp strm, int flush);
*/ */
ZEXTERN int ZEXPORT inflateEnd(z_streamp strm); ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
/* /*
All dynamically allocated data structures for this stream are freed. All dynamically allocated data structures for this stream are freed.
This function discards any unprocessed input and does not flush any pending This function discards any unprocessed input and does not flush any pending
@@ -536,12 +535,12 @@ ZEXTERN int ZEXPORT inflateEnd(z_streamp strm);
*/ */
/* /*
ZEXTERN int ZEXPORT deflateInit2(z_streamp strm, ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
int level, int level,
int method, int method,
int windowBits, int windowBits,
int memLevel, int memLevel,
int strategy); int strategy));
This is another version of deflateInit with more compression options. The This is another version of deflateInit with more compression options. The
fields zalloc, zfree and opaque must be initialized before by the caller. fields zalloc, zfree and opaque must be initialized before by the caller.
@@ -608,9 +607,9 @@ ZEXTERN int ZEXPORT deflateInit2(z_streamp strm,
compression: this will be done by deflate(). compression: this will be done by deflate().
*/ */
ZEXTERN int ZEXPORT deflateSetDictionary(z_streamp strm, ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
const Bytef *dictionary, const Bytef *dictionary,
uInt dictLength); uInt dictLength));
/* /*
Initializes the compression dictionary from the given byte sequence Initializes the compression dictionary from the given byte sequence
without producing any compressed output. When using the zlib format, this without producing any compressed output. When using the zlib format, this
@@ -652,9 +651,9 @@ ZEXTERN int ZEXPORT deflateSetDictionary(z_streamp strm,
not perform any compression: this will be done by deflate(). not perform any compression: this will be done by deflate().
*/ */
ZEXTERN int ZEXPORT deflateGetDictionary(z_streamp strm, ZEXTERN int ZEXPORT deflateGetDictionary OF((z_streamp strm,
Bytef *dictionary, Bytef *dictionary,
uInt *dictLength); uInt *dictLength));
/* /*
Returns the sliding dictionary being maintained by deflate. dictLength is Returns the sliding dictionary being maintained by deflate. dictLength is
set to the number of bytes in the dictionary, and that many bytes are copied set to the number of bytes in the dictionary, and that many bytes are copied
@@ -674,8 +673,8 @@ ZEXTERN int ZEXPORT deflateGetDictionary(z_streamp strm,
stream state is inconsistent. stream state is inconsistent.
*/ */
ZEXTERN int ZEXPORT deflateCopy(z_streamp dest, ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
z_streamp source); z_streamp source));
/* /*
Sets the destination stream as a complete copy of the source stream. Sets the destination stream as a complete copy of the source stream.
@@ -692,20 +691,20 @@ ZEXTERN int ZEXPORT deflateCopy(z_streamp dest,
destination. destination.
*/ */
ZEXTERN int ZEXPORT deflateReset(z_streamp strm); ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
/* /*
This function is equivalent to deflateEnd followed by deflateInit, but This function is equivalent to deflateEnd followed by deflateInit, but
does not free and reallocate the internal compression state. The stream does not free and reallocate the internal compression state. The stream
will leave the compression level and any other attributes that may have been will leave the compression level and any other attributes that may have been
set unchanged. total_in, total_out, adler, and msg are initialized. set unchanged.
deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent (such as zalloc or state being Z_NULL). stream state was inconsistent (such as zalloc or state being Z_NULL).
*/ */
ZEXTERN int ZEXPORT deflateParams(z_streamp strm, ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
int level, int level,
int strategy); int strategy));
/* /*
Dynamically update the compression level and compression strategy. The Dynamically update the compression level and compression strategy. The
interpretation of level and strategy is as in deflateInit2(). This can be interpretation of level and strategy is as in deflateInit2(). This can be
@@ -730,7 +729,7 @@ ZEXTERN int ZEXPORT deflateParams(z_streamp strm,
Then no more input data should be provided before the deflateParams() call. Then no more input data should be provided before the deflateParams() call.
If this is done, the old level and strategy will be applied to the data If this is done, the old level and strategy will be applied to the data
compressed before deflateParams(), and the new level and strategy will be compressed before deflateParams(), and the new level and strategy will be
applied to the data compressed after deflateParams(). applied to the the data compressed after deflateParams().
deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream
state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if
@@ -741,11 +740,11 @@ ZEXTERN int ZEXPORT deflateParams(z_streamp strm,
retried with more output space. retried with more output space.
*/ */
ZEXTERN int ZEXPORT deflateTune(z_streamp strm, ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
int good_length, int good_length,
int max_lazy, int max_lazy,
int nice_length, int nice_length,
int max_chain); int max_chain));
/* /*
Fine tune deflate's internal compression parameters. This should only be Fine tune deflate's internal compression parameters. This should only be
used by someone who understands the algorithm used by zlib's deflate for used by someone who understands the algorithm used by zlib's deflate for
@@ -758,8 +757,8 @@ ZEXTERN int ZEXPORT deflateTune(z_streamp strm,
returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
*/ */
ZEXTERN uLong ZEXPORT deflateBound(z_streamp strm, ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
uLong sourceLen); uLong sourceLen));
/* /*
deflateBound() returns an upper bound on the compressed size after deflateBound() returns an upper bound on the compressed size after
deflation of sourceLen bytes. It must be called after deflateInit() or deflation of sourceLen bytes. It must be called after deflateInit() or
@@ -773,9 +772,9 @@ ZEXTERN uLong ZEXPORT deflateBound(z_streamp strm,
than Z_FINISH or Z_NO_FLUSH are used. than Z_FINISH or Z_NO_FLUSH are used.
*/ */
ZEXTERN int ZEXPORT deflatePending(z_streamp strm, ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm,
unsigned *pending, unsigned *pending,
int *bits); int *bits));
/* /*
deflatePending() returns the number of bytes and bits of output that have deflatePending() returns the number of bytes and bits of output that have
been generated, but not yet provided in the available output. The bytes not been generated, but not yet provided in the available output. The bytes not
@@ -788,9 +787,9 @@ ZEXTERN int ZEXPORT deflatePending(z_streamp strm,
stream state was inconsistent. stream state was inconsistent.
*/ */
ZEXTERN int ZEXPORT deflatePrime(z_streamp strm, ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
int bits, int bits,
int value); int value));
/* /*
deflatePrime() inserts bits in the deflate output stream. The intent deflatePrime() inserts bits in the deflate output stream. The intent
is that this function is used to start off the deflate output with the bits is that this function is used to start off the deflate output with the bits
@@ -805,8 +804,8 @@ ZEXTERN int ZEXPORT deflatePrime(z_streamp strm,
source stream state was inconsistent. source stream state was inconsistent.
*/ */
ZEXTERN int ZEXPORT deflateSetHeader(z_streamp strm, ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
gz_headerp head); gz_headerp head));
/* /*
deflateSetHeader() provides gzip header information for when a gzip deflateSetHeader() provides gzip header information for when a gzip
stream is requested by deflateInit2(). deflateSetHeader() may be called stream is requested by deflateInit2(). deflateSetHeader() may be called
@@ -822,17 +821,16 @@ ZEXTERN int ZEXPORT deflateSetHeader(z_streamp strm,
gzip file" and give up. gzip file" and give up.
If deflateSetHeader is not used, the default gzip header has text false, If deflateSetHeader is not used, the default gzip header has text false,
the time set to zero, and os set to the current operating system, with no the time set to zero, and os set to 255, with no extra, name, or comment
extra, name, or comment fields. The gzip header is returned to the default fields. The gzip header is returned to the default state by deflateReset().
state by deflateReset().
deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent. stream state was inconsistent.
*/ */
/* /*
ZEXTERN int ZEXPORT inflateInit2(z_streamp strm, ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
int windowBits); int windowBits));
This is another version of inflateInit with an extra parameter. The This is another version of inflateInit with an extra parameter. The
fields next_in, avail_in, zalloc, zfree and opaque must be initialized fields next_in, avail_in, zalloc, zfree and opaque must be initialized
@@ -885,9 +883,9 @@ ZEXTERN int ZEXPORT inflateInit2(z_streamp strm,
deferred until inflate() is called. deferred until inflate() is called.
*/ */
ZEXTERN int ZEXPORT inflateSetDictionary(z_streamp strm, ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
const Bytef *dictionary, const Bytef *dictionary,
uInt dictLength); uInt dictLength));
/* /*
Initializes the decompression dictionary from the given uncompressed byte Initializes the decompression dictionary from the given uncompressed byte
sequence. This function must be called immediately after a call of inflate, sequence. This function must be called immediately after a call of inflate,
@@ -908,9 +906,9 @@ ZEXTERN int ZEXPORT inflateSetDictionary(z_streamp strm,
inflate(). inflate().
*/ */
ZEXTERN int ZEXPORT inflateGetDictionary(z_streamp strm, ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm,
Bytef *dictionary, Bytef *dictionary,
uInt *dictLength); uInt *dictLength));
/* /*
Returns the sliding dictionary being maintained by inflate. dictLength is Returns the sliding dictionary being maintained by inflate. dictLength is
set to the number of bytes in the dictionary, and that many bytes are copied set to the number of bytes in the dictionary, and that many bytes are copied
@@ -923,7 +921,7 @@ ZEXTERN int ZEXPORT inflateGetDictionary(z_streamp strm,
stream state is inconsistent. stream state is inconsistent.
*/ */
ZEXTERN int ZEXPORT inflateSync(z_streamp strm); ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
/* /*
Skips invalid compressed data until a possible full flush point (see above Skips invalid compressed data until a possible full flush point (see above
for the description of deflate with Z_FULL_FLUSH) can be found, or until all for the description of deflate with Z_FULL_FLUSH) can be found, or until all
@@ -942,8 +940,8 @@ ZEXTERN int ZEXPORT inflateSync(z_streamp strm);
input each time, until success or end of the input data. input each time, until success or end of the input data.
*/ */
ZEXTERN int ZEXPORT inflateCopy(z_streamp dest, ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
z_streamp source); z_streamp source));
/* /*
Sets the destination stream as a complete copy of the source stream. Sets the destination stream as a complete copy of the source stream.
@@ -958,19 +956,18 @@ ZEXTERN int ZEXPORT inflateCopy(z_streamp dest,
destination. destination.
*/ */
ZEXTERN int ZEXPORT inflateReset(z_streamp strm); ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
/* /*
This function is equivalent to inflateEnd followed by inflateInit, This function is equivalent to inflateEnd followed by inflateInit,
but does not free and reallocate the internal decompression state. The but does not free and reallocate the internal decompression state. The
stream will keep attributes that may have been set by inflateInit2. stream will keep attributes that may have been set by inflateInit2.
total_in, total_out, adler, and msg are initialized.
inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent (such as zalloc or state being Z_NULL). stream state was inconsistent (such as zalloc or state being Z_NULL).
*/ */
ZEXTERN int ZEXPORT inflateReset2(z_streamp strm, ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm,
int windowBits); int windowBits));
/* /*
This function is the same as inflateReset, but it also permits changing This function is the same as inflateReset, but it also permits changing
the wrap and window size requests. The windowBits parameter is interpreted the wrap and window size requests. The windowBits parameter is interpreted
@@ -983,9 +980,9 @@ ZEXTERN int ZEXPORT inflateReset2(z_streamp strm,
the windowBits parameter is invalid. the windowBits parameter is invalid.
*/ */
ZEXTERN int ZEXPORT inflatePrime(z_streamp strm, ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
int bits, int bits,
int value); int value));
/* /*
This function inserts bits in the inflate input stream. The intent is This function inserts bits in the inflate input stream. The intent is
that this function is used to start inflating at a bit position in the that this function is used to start inflating at a bit position in the
@@ -1004,7 +1001,7 @@ ZEXTERN int ZEXPORT inflatePrime(z_streamp strm,
stream state was inconsistent. stream state was inconsistent.
*/ */
ZEXTERN long ZEXPORT inflateMark(z_streamp strm); ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm));
/* /*
This function returns two values, one in the lower 16 bits of the return This function returns two values, one in the lower 16 bits of the return
value, and the other in the remaining upper bits, obtained by shifting the value, and the other in the remaining upper bits, obtained by shifting the
@@ -1032,8 +1029,8 @@ ZEXTERN long ZEXPORT inflateMark(z_streamp strm);
source stream state was inconsistent. source stream state was inconsistent.
*/ */
ZEXTERN int ZEXPORT inflateGetHeader(z_streamp strm, ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
gz_headerp head); gz_headerp head));
/* /*
inflateGetHeader() requests that gzip header information be stored in the inflateGetHeader() requests that gzip header information be stored in the
provided gz_header structure. inflateGetHeader() may be called after provided gz_header structure. inflateGetHeader() may be called after
@@ -1073,8 +1070,8 @@ ZEXTERN int ZEXPORT inflateGetHeader(z_streamp strm,
*/ */
/* /*
ZEXTERN int ZEXPORT inflateBackInit(z_streamp strm, int windowBits, ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
unsigned char FAR *window); unsigned char FAR *window));
Initialize the internal stream state for decompression using inflateBack() Initialize the internal stream state for decompression using inflateBack()
calls. The fields zalloc, zfree and opaque in strm must be initialized calls. The fields zalloc, zfree and opaque in strm must be initialized
@@ -1094,13 +1091,13 @@ ZEXTERN int ZEXPORT inflateBackInit(z_streamp strm, int windowBits,
the version of the header file. the version of the header file.
*/ */
typedef unsigned (*in_func)(void FAR *, typedef unsigned (*in_func) OF((void FAR *,
z_const unsigned char FAR * FAR *); z_const unsigned char FAR * FAR *));
typedef int (*out_func)(void FAR *, unsigned char FAR *, unsigned); typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
ZEXTERN int ZEXPORT inflateBack(z_streamp strm, ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
in_func in, void FAR *in_desc, in_func in, void FAR *in_desc,
out_func out, void FAR *out_desc); out_func out, void FAR *out_desc));
/* /*
inflateBack() does a raw inflate with a single call using a call-back inflateBack() does a raw inflate with a single call using a call-back
interface for input and output. This is potentially more efficient than interface for input and output. This is potentially more efficient than
@@ -1168,7 +1165,7 @@ ZEXTERN int ZEXPORT inflateBack(z_streamp strm,
cannot return Z_OK. cannot return Z_OK.
*/ */
ZEXTERN int ZEXPORT inflateBackEnd(z_streamp strm); ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
/* /*
All memory allocated by inflateBackInit() is freed. All memory allocated by inflateBackInit() is freed.
@@ -1176,7 +1173,7 @@ ZEXTERN int ZEXPORT inflateBackEnd(z_streamp strm);
state was inconsistent. state was inconsistent.
*/ */
ZEXTERN uLong ZEXPORT zlibCompileFlags(void); ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
/* Return flags indicating compile-time options. /* Return flags indicating compile-time options.
Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
@@ -1229,8 +1226,8 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags(void);
you need special options. you need special options.
*/ */
ZEXTERN int ZEXPORT compress(Bytef *dest, uLongf *destLen, ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen); const Bytef *source, uLong sourceLen));
/* /*
Compresses the source buffer into the destination buffer. sourceLen is Compresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total size the byte length of the source buffer. Upon entry, destLen is the total size
@@ -1244,9 +1241,9 @@ ZEXTERN int ZEXPORT compress(Bytef *dest, uLongf *destLen,
buffer. buffer.
*/ */
ZEXTERN int ZEXPORT compress2(Bytef *dest, uLongf *destLen, ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen, const Bytef *source, uLong sourceLen,
int level); int level));
/* /*
Compresses the source buffer into the destination buffer. The level Compresses the source buffer into the destination buffer. The level
parameter has the same meaning as in deflateInit. sourceLen is the byte parameter has the same meaning as in deflateInit. sourceLen is the byte
@@ -1260,15 +1257,15 @@ ZEXTERN int ZEXPORT compress2(Bytef *dest, uLongf *destLen,
Z_STREAM_ERROR if the level parameter is invalid. Z_STREAM_ERROR if the level parameter is invalid.
*/ */
ZEXTERN uLong ZEXPORT compressBound(uLong sourceLen); ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
/* /*
compressBound() returns an upper bound on the compressed size after compressBound() returns an upper bound on the compressed size after
compress() or compress2() on sourceLen bytes. It would be used before a compress() or compress2() on sourceLen bytes. It would be used before a
compress() or compress2() call to allocate the destination buffer. compress() or compress2() call to allocate the destination buffer.
*/ */
ZEXTERN int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen); const Bytef *source, uLong sourceLen));
/* /*
Decompresses the source buffer into the destination buffer. sourceLen is Decompresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total size the byte length of the source buffer. Upon entry, destLen is the total size
@@ -1285,8 +1282,8 @@ ZEXTERN int ZEXPORT uncompress(Bytef *dest, uLongf *destLen,
buffer with the uncompressed data up to that point. buffer with the uncompressed data up to that point.
*/ */
ZEXTERN int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong *sourceLen); const Bytef *source, uLong *sourceLen));
/* /*
Same as uncompress, except that sourceLen is a pointer, where the Same as uncompress, except that sourceLen is a pointer, where the
length of the source is *sourceLen. On return, *sourceLen is the number of length of the source is *sourceLen. On return, *sourceLen is the number of
@@ -1305,7 +1302,7 @@ ZEXTERN int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen,
typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */ typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */
/* /*
ZEXTERN gzFile ZEXPORT gzopen(const char *path, const char *mode); ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
Open the gzip (.gz) file at path for reading and decompressing, or Open the gzip (.gz) file at path for reading and decompressing, or
compressing and writing. The mode parameter is as in fopen ("rb" or "wb") compressing and writing. The mode parameter is as in fopen ("rb" or "wb")
@@ -1342,7 +1339,7 @@ ZEXTERN gzFile ZEXPORT gzopen(const char *path, const char *mode);
file could not be opened. file could not be opened.
*/ */
ZEXTERN gzFile ZEXPORT gzdopen(int fd, const char *mode); ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
/* /*
Associate a gzFile with the file descriptor fd. File descriptors are Associate a gzFile with the file descriptor fd. File descriptors are
obtained from calls like open, dup, creat, pipe or fileno (if the file has obtained from calls like open, dup, creat, pipe or fileno (if the file has
@@ -1365,7 +1362,7 @@ ZEXTERN gzFile ZEXPORT gzdopen(int fd, const char *mode);
will not detect if fd is invalid (unless fd is -1). will not detect if fd is invalid (unless fd is -1).
*/ */
ZEXTERN int ZEXPORT gzbuffer(gzFile file, unsigned size); ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));
/* /*
Set the internal buffer size used by this library's functions for file to Set the internal buffer size used by this library's functions for file to
size. The default buffer size is 8192 bytes. This function must be called size. The default buffer size is 8192 bytes. This function must be called
@@ -1381,7 +1378,7 @@ ZEXTERN int ZEXPORT gzbuffer(gzFile file, unsigned size);
too late. too late.
*/ */
ZEXTERN int ZEXPORT gzsetparams(gzFile file, int level, int strategy); ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
/* /*
Dynamically update the compression level and strategy for file. See the Dynamically update the compression level and strategy for file. See the
description of deflateInit2 for the meaning of these parameters. Previously description of deflateInit2 for the meaning of these parameters. Previously
@@ -1392,7 +1389,7 @@ ZEXTERN int ZEXPORT gzsetparams(gzFile file, int level, int strategy);
or Z_MEM_ERROR if there is a memory allocation error. or Z_MEM_ERROR if there is a memory allocation error.
*/ */
ZEXTERN int ZEXPORT gzread(gzFile file, voidp buf, unsigned len); ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
/* /*
Read and decompress up to len uncompressed bytes from file into buf. If Read and decompress up to len uncompressed bytes from file into buf. If
the input file is not in gzip format, gzread copies the given number of the input file is not in gzip format, gzread copies the given number of
@@ -1422,8 +1419,8 @@ ZEXTERN int ZEXPORT gzread(gzFile file, voidp buf, unsigned len);
Z_STREAM_ERROR. Z_STREAM_ERROR.
*/ */
ZEXTERN z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems, ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems,
gzFile file); gzFile file));
/* /*
Read and decompress up to nitems items of size size from file into buf, Read and decompress up to nitems items of size size from file into buf,
otherwise operating as gzread() does. This duplicates the interface of otherwise operating as gzread() does. This duplicates the interface of
@@ -1448,14 +1445,14 @@ ZEXTERN z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems,
file, resetting and retrying on end-of-file, when size is not 1. file, resetting and retrying on end-of-file, when size is not 1.
*/ */
ZEXTERN int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len); ZEXTERN int ZEXPORT gzwrite OF((gzFile file, voidpc buf, unsigned len));
/* /*
Compress and write the len uncompressed bytes at buf to file. gzwrite Compress and write the len uncompressed bytes at buf to file. gzwrite
returns the number of uncompressed bytes written or 0 in case of error. returns the number of uncompressed bytes written or 0 in case of error.
*/ */
ZEXTERN z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size, ZEXTERN z_size_t ZEXPORT gzfwrite OF((voidpc buf, z_size_t size,
z_size_t nitems, gzFile file); z_size_t nitems, gzFile file));
/* /*
Compress and write nitems items of size size from buf to file, duplicating Compress and write nitems items of size size from buf to file, duplicating
the interface of stdio's fwrite(), with size_t request and return types. If the interface of stdio's fwrite(), with size_t request and return types. If
@@ -1468,7 +1465,7 @@ ZEXTERN z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size,
is returned, and the error state is set to Z_STREAM_ERROR. is returned, and the error state is set to Z_STREAM_ERROR.
*/ */
ZEXTERN int ZEXPORTVA gzprintf(gzFile file, const char *format, ...); ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...));
/* /*
Convert, format, compress, and write the arguments (...) to file under Convert, format, compress, and write the arguments (...) to file under
control of the string format, as in fprintf. gzprintf returns the number of control of the string format, as in fprintf. gzprintf returns the number of
@@ -1483,7 +1480,7 @@ ZEXTERN int ZEXPORTVA gzprintf(gzFile file, const char *format, ...);
This can be determined using zlibCompileFlags(). This can be determined using zlibCompileFlags().
*/ */
ZEXTERN int ZEXPORT gzputs(gzFile file, const char *s); ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
/* /*
Compress and write the given null-terminated string s to file, excluding Compress and write the given null-terminated string s to file, excluding
the terminating null character. the terminating null character.
@@ -1491,7 +1488,7 @@ ZEXTERN int ZEXPORT gzputs(gzFile file, const char *s);
gzputs returns the number of characters written, or -1 in case of error. gzputs returns the number of characters written, or -1 in case of error.
*/ */
ZEXTERN char * ZEXPORT gzgets(gzFile file, char *buf, int len); ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
/* /*
Read and decompress bytes from file into buf, until len-1 characters are Read and decompress bytes from file into buf, until len-1 characters are
read, or until a newline character is read and transferred to buf, or an read, or until a newline character is read and transferred to buf, or an
@@ -1505,13 +1502,13 @@ ZEXTERN char * ZEXPORT gzgets(gzFile file, char *buf, int len);
buf are indeterminate. buf are indeterminate.
*/ */
ZEXTERN int ZEXPORT gzputc(gzFile file, int c); ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
/* /*
Compress and write c, converted to an unsigned char, into file. gzputc Compress and write c, converted to an unsigned char, into file. gzputc
returns the value that was written, or -1 in case of error. returns the value that was written, or -1 in case of error.
*/ */
ZEXTERN int ZEXPORT gzgetc(gzFile file); ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
/* /*
Read and decompress one byte from file. gzgetc returns this byte or -1 Read and decompress one byte from file. gzgetc returns this byte or -1
in case of end of file or error. This is implemented as a macro for speed. in case of end of file or error. This is implemented as a macro for speed.
@@ -1520,7 +1517,7 @@ ZEXTERN int ZEXPORT gzgetc(gzFile file);
points to has been clobbered or not. points to has been clobbered or not.
*/ */
ZEXTERN int ZEXPORT gzungetc(int c, gzFile file); ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
/* /*
Push c back onto the stream for file to be read as the first character on Push c back onto the stream for file to be read as the first character on
the next read. At least one character of push-back is always allowed. the next read. At least one character of push-back is always allowed.
@@ -1532,7 +1529,7 @@ ZEXTERN int ZEXPORT gzungetc(int c, gzFile file);
gzseek() or gzrewind(). gzseek() or gzrewind().
*/ */
ZEXTERN int ZEXPORT gzflush(gzFile file, int flush); ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
/* /*
Flush all pending output to file. The parameter flush is as in the Flush all pending output to file. The parameter flush is as in the
deflate() function. The return value is the zlib error number (see function deflate() function. The return value is the zlib error number (see function
@@ -1548,8 +1545,8 @@ ZEXTERN int ZEXPORT gzflush(gzFile file, int flush);
*/ */
/* /*
ZEXTERN z_off_t ZEXPORT gzseek(gzFile file, ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
z_off_t offset, int whence); z_off_t offset, int whence));
Set the starting position to offset relative to whence for the next gzread Set the starting position to offset relative to whence for the next gzread
or gzwrite on file. The offset represents a number of bytes in the or gzwrite on file. The offset represents a number of bytes in the
@@ -1567,7 +1564,7 @@ ZEXTERN z_off_t ZEXPORT gzseek(gzFile file,
would be before the current position. would be before the current position.
*/ */
ZEXTERN int ZEXPORT gzrewind(gzFile file); ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
/* /*
Rewind file. This function is supported only for reading. Rewind file. This function is supported only for reading.
@@ -1575,7 +1572,7 @@ ZEXTERN int ZEXPORT gzrewind(gzFile file);
*/ */
/* /*
ZEXTERN z_off_t ZEXPORT gztell(gzFile file); ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
Return the starting position for the next gzread or gzwrite on file. Return the starting position for the next gzread or gzwrite on file.
This position represents a number of bytes in the uncompressed data stream, This position represents a number of bytes in the uncompressed data stream,
@@ -1586,7 +1583,7 @@ ZEXTERN z_off_t ZEXPORT gztell(gzFile file);
*/ */
/* /*
ZEXTERN z_off_t ZEXPORT gzoffset(gzFile file); ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file));
Return the current compressed (actual) read or write offset of file. This Return the current compressed (actual) read or write offset of file. This
offset includes the count of bytes that precede the gzip stream, for example offset includes the count of bytes that precede the gzip stream, for example
@@ -1595,7 +1592,7 @@ ZEXTERN z_off_t ZEXPORT gzoffset(gzFile file);
be used for a progress indicator. On error, gzoffset() returns -1. be used for a progress indicator. On error, gzoffset() returns -1.
*/ */
ZEXTERN int ZEXPORT gzeof(gzFile file); ZEXTERN int ZEXPORT gzeof OF((gzFile file));
/* /*
Return true (1) if the end-of-file indicator for file has been set while Return true (1) if the end-of-file indicator for file has been set while
reading, false (0) otherwise. Note that the end-of-file indicator is set reading, false (0) otherwise. Note that the end-of-file indicator is set
@@ -1610,7 +1607,7 @@ ZEXTERN int ZEXPORT gzeof(gzFile file);
has grown since the previous end of file was detected. has grown since the previous end of file was detected.
*/ */
ZEXTERN int ZEXPORT gzdirect(gzFile file); ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
/* /*
Return true (1) if file is being copied directly while reading, or false Return true (1) if file is being copied directly while reading, or false
(0) if file is a gzip stream being decompressed. (0) if file is a gzip stream being decompressed.
@@ -1631,7 +1628,7 @@ ZEXTERN int ZEXPORT gzdirect(gzFile file);
gzip file reading and decompression, which may not be desired.) gzip file reading and decompression, which may not be desired.)
*/ */
ZEXTERN int ZEXPORT gzclose(gzFile file); ZEXTERN int ZEXPORT gzclose OF((gzFile file));
/* /*
Flush all pending output for file, if necessary, close file and Flush all pending output for file, if necessary, close file and
deallocate the (de)compression state. Note that once file is closed, you deallocate the (de)compression state. Note that once file is closed, you
@@ -1644,8 +1641,8 @@ ZEXTERN int ZEXPORT gzclose(gzFile file);
last read ended in the middle of a gzip stream, or Z_OK on success. last read ended in the middle of a gzip stream, or Z_OK on success.
*/ */
ZEXTERN int ZEXPORT gzclose_r(gzFile file); ZEXTERN int ZEXPORT gzclose_r OF((gzFile file));
ZEXTERN int ZEXPORT gzclose_w(gzFile file); ZEXTERN int ZEXPORT gzclose_w OF((gzFile file));
/* /*
Same as gzclose(), but gzclose_r() is only for use when reading, and Same as gzclose(), but gzclose_r() is only for use when reading, and
gzclose_w() is only for use when writing or appending. The advantage to gzclose_w() is only for use when writing or appending. The advantage to
@@ -1656,7 +1653,7 @@ ZEXTERN int ZEXPORT gzclose_w(gzFile file);
zlib library. zlib library.
*/ */
ZEXTERN const char * ZEXPORT gzerror(gzFile file, int *errnum); ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
/* /*
Return the error message for the last error which occurred on file. Return the error message for the last error which occurred on file.
errnum is set to zlib error number. If an error occurred in the file system errnum is set to zlib error number. If an error occurred in the file system
@@ -1672,7 +1669,7 @@ ZEXTERN const char * ZEXPORT gzerror(gzFile file, int *errnum);
functions above that do not distinguish those cases in their return values. functions above that do not distinguish those cases in their return values.
*/ */
ZEXTERN void ZEXPORT gzclearerr(gzFile file); ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
/* /*
Clear the error and end-of-file flags for file. This is analogous to the Clear the error and end-of-file flags for file. This is analogous to the
clearerr() function in stdio. This is useful for continuing to read a gzip clearerr() function in stdio. This is useful for continuing to read a gzip
@@ -1689,7 +1686,7 @@ ZEXTERN void ZEXPORT gzclearerr(gzFile file);
library. library.
*/ */
ZEXTERN uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len); ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
/* /*
Update a running Adler-32 checksum with the bytes buf[0..len-1] and Update a running Adler-32 checksum with the bytes buf[0..len-1] and
return the updated checksum. An Adler-32 value is in the range of a 32-bit return the updated checksum. An Adler-32 value is in the range of a 32-bit
@@ -1709,15 +1706,15 @@ ZEXTERN uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len);
if (adler != original_adler) error(); if (adler != original_adler) error();
*/ */
ZEXTERN uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, ZEXTERN uLong ZEXPORT adler32_z OF((uLong adler, const Bytef *buf,
z_size_t len); z_size_t len));
/* /*
Same as adler32(), but with a size_t length. Same as adler32(), but with a size_t length.
*/ */
/* /*
ZEXTERN uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
z_off_t len2); z_off_t len2));
Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
@@ -1727,7 +1724,7 @@ ZEXTERN uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2,
negative, the result has no meaning or utility. negative, the result has no meaning or utility.
*/ */
ZEXTERN uLong ZEXPORT crc32(uLong crc, const Bytef *buf, uInt len); ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
/* /*
Update a running CRC-32 with the bytes buf[0..len-1] and return the Update a running CRC-32 with the bytes buf[0..len-1] and return the
updated CRC-32. A CRC-32 value is in the range of a 32-bit unsigned integer. updated CRC-32. A CRC-32 value is in the range of a 32-bit unsigned integer.
@@ -1745,14 +1742,14 @@ ZEXTERN uLong ZEXPORT crc32(uLong crc, const Bytef *buf, uInt len);
if (crc != original_crc) error(); if (crc != original_crc) error();
*/ */
ZEXTERN uLong ZEXPORT crc32_z(uLong crc, const Bytef *buf, ZEXTERN uLong ZEXPORT crc32_z OF((uLong crc, const Bytef *buf,
z_size_t len); z_size_t len));
/* /*
Same as crc32(), but with a size_t length. Same as crc32(), but with a size_t length.
*/ */
/* /*
ZEXTERN uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2); ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
Combine two CRC-32 check values into one. For two sequences of bytes, Combine two CRC-32 check values into one. For two sequences of bytes,
seq1 and seq2 with lengths len1 and len2, CRC-32 check values were seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
@@ -1762,13 +1759,13 @@ ZEXTERN uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2);
*/ */
/* /*
ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t len2); ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t len2));
Return the operator corresponding to length len2, to be used with Return the operator corresponding to length len2, to be used with
crc32_combine_op(). crc32_combine_op().
*/ */
ZEXTERN uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op); ZEXTERN uLong ZEXPORT crc32_combine_op OF((uLong crc1, uLong crc2, uLong op));
/* /*
Give the same result as crc32_combine(), using op in place of len2. op is Give the same result as crc32_combine(), using op in place of len2. op is
is generated from len2 by crc32_combine_gen(). This will be faster than is generated from len2 by crc32_combine_gen(). This will be faster than
@@ -1781,20 +1778,20 @@ ZEXTERN uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op);
/* deflateInit and inflateInit are macros to allow checking the zlib version /* deflateInit and inflateInit are macros to allow checking the zlib version
* and the compiler's view of z_stream: * and the compiler's view of z_stream:
*/ */
ZEXTERN int ZEXPORT deflateInit_(z_streamp strm, int level, ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
const char *version, int stream_size); const char *version, int stream_size));
ZEXTERN int ZEXPORT inflateInit_(z_streamp strm, ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
const char *version, int stream_size); const char *version, int stream_size));
ZEXTERN int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
int windowBits, int memLevel, int windowBits, int memLevel,
int strategy, const char *version, int strategy, const char *version,
int stream_size); int stream_size));
ZEXTERN int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
const char *version, int stream_size); const char *version, int stream_size));
ZEXTERN int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits, ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
unsigned char FAR *window, unsigned char FAR *window,
const char *version, const char *version,
int stream_size); int stream_size));
#ifdef Z_PREFIX_SET #ifdef Z_PREFIX_SET
# define z_deflateInit(strm, level) \ # define z_deflateInit(strm, level) \
deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
@@ -1839,7 +1836,7 @@ struct gzFile_s {
unsigned char *next; unsigned char *next;
z_off64_t pos; z_off64_t pos;
}; };
ZEXTERN int ZEXPORT gzgetc_(gzFile file); /* backward compatibility */ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
#ifdef Z_PREFIX_SET #ifdef Z_PREFIX_SET
# undef z_gzgetc # undef z_gzgetc
# define z_gzgetc(g) \ # define z_gzgetc(g) \
@@ -1856,13 +1853,13 @@ ZEXTERN int ZEXPORT gzgetc_(gzFile file); /* backward compatibility */
* without large file support, _LFS64_LARGEFILE must also be true * without large file support, _LFS64_LARGEFILE must also be true
*/ */
#ifdef Z_LARGE64 #ifdef Z_LARGE64
ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *); ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int); ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
ZEXTERN z_off64_t ZEXPORT gztell64(gzFile); ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile); ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off64_t); ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t));
ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off64_t); ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t));
ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off64_t); ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off64_t));
#endif #endif
#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) #if !defined(ZLIB_INTERNAL) && defined(Z_WANT64)
@@ -1884,50 +1881,50 @@ ZEXTERN int ZEXPORT gzgetc_(gzFile file); /* backward compatibility */
# define crc32_combine_gen crc32_combine_gen64 # define crc32_combine_gen crc32_combine_gen64
# endif # endif
# ifndef Z_LARGE64 # ifndef Z_LARGE64
ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *); ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
ZEXTERN z_off_t ZEXPORT gzseek64(gzFile, z_off_t, int); ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int));
ZEXTERN z_off_t ZEXPORT gztell64(gzFile); ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile));
ZEXTERN z_off_t ZEXPORT gzoffset64(gzFile); ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile));
ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t); ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t); ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t); ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t));
# endif # endif
#else #else
ZEXTERN gzFile ZEXPORT gzopen(const char *, const char *); ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *));
ZEXTERN z_off_t ZEXPORT gzseek(gzFile, z_off_t, int); ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int));
ZEXTERN z_off_t ZEXPORT gztell(gzFile); ZEXTERN z_off_t ZEXPORT gztell OF((gzFile));
ZEXTERN z_off_t ZEXPORT gzoffset(gzFile); ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile));
ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t); ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t); ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t); ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t));
#endif #endif
#else /* Z_SOLO */ #else /* Z_SOLO */
ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t); ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t); ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t); ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t));
#endif /* !Z_SOLO */ #endif /* !Z_SOLO */
/* undocumented functions */ /* undocumented functions */
ZEXTERN const char * ZEXPORT zError(int); ZEXTERN const char * ZEXPORT zError OF((int));
ZEXTERN int ZEXPORT inflateSyncPoint(z_streamp); ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp));
ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table(void); ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void));
ZEXTERN int ZEXPORT inflateUndermine(z_streamp, int); ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int));
ZEXTERN int ZEXPORT inflateValidate(z_streamp, int); ZEXTERN int ZEXPORT inflateValidate OF((z_streamp, int));
ZEXTERN unsigned long ZEXPORT inflateCodesUsed(z_streamp); ZEXTERN unsigned long ZEXPORT inflateCodesUsed OF((z_streamp));
ZEXTERN int ZEXPORT inflateResetKeep(z_streamp); ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp));
ZEXTERN int ZEXPORT deflateResetKeep(z_streamp); ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp));
#if defined(_WIN32) && !defined(Z_SOLO) #if defined(_WIN32) && !defined(Z_SOLO)
ZEXTERN gzFile ZEXPORT gzopen_w(const wchar_t *path, ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path,
const char *mode); const char *mode));
#endif #endif
#if defined(STDC) || defined(Z_HAVE_STDARG_H) #if defined(STDC) || defined(Z_HAVE_STDARG_H)
# ifndef Z_SOLO # ifndef Z_SOLO
ZEXTERN int ZEXPORTVA gzvprintf(gzFile file, ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file,
const char *format, const char *format,
va_list va); va_list va));
# endif # endif
#endif #endif
+44 -16
View File
@@ -24,11 +24,13 @@ z_const char * const z_errmsg[10] = {
}; };
const char * ZEXPORT zlibVersion(void) { const char * ZEXPORT zlibVersion()
{
return ZLIB_VERSION; return ZLIB_VERSION;
} }
uLong ZEXPORT zlibCompileFlags(void) { uLong ZEXPORT zlibCompileFlags()
{
uLong flags; uLong flags;
flags = 0; flags = 0;
@@ -119,7 +121,9 @@ uLong ZEXPORT zlibCompileFlags(void) {
# endif # endif
int ZLIB_INTERNAL z_verbose = verbose; int ZLIB_INTERNAL z_verbose = verbose;
void ZLIB_INTERNAL z_error(char *m) { void ZLIB_INTERNAL z_error(m)
char *m;
{
fprintf(stderr, "%s\n", m); fprintf(stderr, "%s\n", m);
exit(1); exit(1);
} }
@@ -128,7 +132,9 @@ void ZLIB_INTERNAL z_error(char *m) {
/* exported to allow conversion of error code to string for compress() and /* exported to allow conversion of error code to string for compress() and
* uncompress() * uncompress()
*/ */
const char * ZEXPORT zError(int err) { const char * ZEXPORT zError(err)
int err;
{
return ERR_MSG(err); return ERR_MSG(err);
} }
@@ -142,14 +148,22 @@ const char * ZEXPORT zError(int err) {
#ifndef HAVE_MEMCPY #ifndef HAVE_MEMCPY
void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len) { void ZLIB_INTERNAL zmemcpy(dest, source, len)
Bytef* dest;
const Bytef* source;
uInt len;
{
if (len == 0) return; if (len == 0) return;
do { do {
*dest++ = *source++; /* ??? to be unrolled */ *dest++ = *source++; /* ??? to be unrolled */
} while (--len != 0); } while (--len != 0);
} }
int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len) { int ZLIB_INTERNAL zmemcmp(s1, s2, len)
const Bytef* s1;
const Bytef* s2;
uInt len;
{
uInt j; uInt j;
for (j = 0; j < len; j++) { for (j = 0; j < len; j++) {
@@ -158,7 +172,10 @@ int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len) {
return 0; return 0;
} }
void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len) { void ZLIB_INTERNAL zmemzero(dest, len)
Bytef* dest;
uInt len;
{
if (len == 0) return; if (len == 0) return;
do { do {
*dest++ = 0; /* ??? to be unrolled */ *dest++ = 0; /* ??? to be unrolled */
@@ -199,7 +216,8 @@ local ptr_table table[MAX_PTR];
* a protected system like OS/2. Use Microsoft C instead. * a protected system like OS/2. Use Microsoft C instead.
*/ */
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) { voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size)
{
voidpf buf; voidpf buf;
ulg bsize = (ulg)items*size; ulg bsize = (ulg)items*size;
@@ -224,7 +242,8 @@ voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) {
return buf; return buf;
} }
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) { void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr)
{
int n; int n;
(void)opaque; (void)opaque;
@@ -260,12 +279,14 @@ void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
# define _hfree hfree # define _hfree hfree
#endif #endif
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, uInt items, uInt size) { voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, uInt items, uInt size)
{
(void)opaque; (void)opaque;
return _halloc((long)items, size); return _halloc((long)items, size);
} }
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) { void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr)
{
(void)opaque; (void)opaque;
_hfree(ptr); _hfree(ptr);
} }
@@ -278,18 +299,25 @@ void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
#ifndef MY_ZCALLOC /* Any system without a special alloc function */ #ifndef MY_ZCALLOC /* Any system without a special alloc function */
#ifndef STDC #ifndef STDC
extern voidp malloc(uInt size); extern voidp malloc OF((uInt size));
extern voidp calloc(uInt items, uInt size); extern voidp calloc OF((uInt items, uInt size));
extern void free(voidpf ptr); extern void free OF((voidpf ptr));
#endif #endif
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) { voidpf ZLIB_INTERNAL zcalloc(opaque, items, size)
voidpf opaque;
unsigned items;
unsigned size;
{
(void)opaque; (void)opaque;
return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
(voidpf)calloc(items, size); (voidpf)calloc(items, size);
} }
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) { void ZLIB_INTERNAL zcfree(opaque, ptr)
voidpf opaque;
voidpf ptr;
{
(void)opaque; (void)opaque;
free(ptr); free(ptr);
} }
+10 -10
View File
@@ -191,9 +191,9 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
/* provide prototypes for these when building zlib without LFS */ /* provide prototypes for these when building zlib without LFS */
#if !defined(_WIN32) && \ #if !defined(_WIN32) && \
(!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t); ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t); ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t); ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t));
#endif #endif
/* common defaults */ /* common defaults */
@@ -232,16 +232,16 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
# define zmemzero(dest, len) memset(dest, 0, len) # define zmemzero(dest, len) memset(dest, 0, len)
# endif # endif
#else #else
void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len); void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len); int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len); void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len));
#endif #endif
/* Diagnostic functions */ /* Diagnostic functions */
#ifdef ZLIB_DEBUG #ifdef ZLIB_DEBUG
# include <stdio.h> # include <stdio.h>
extern int ZLIB_INTERNAL z_verbose; extern int ZLIB_INTERNAL z_verbose;
extern void ZLIB_INTERNAL z_error(char *m); extern void ZLIB_INTERNAL z_error OF((char *m));
# define Assert(cond,msg) {if(!(cond)) z_error(msg);} # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
# define Trace(x) {if (z_verbose>=0) fprintf x ;} # define Trace(x) {if (z_verbose>=0) fprintf x ;}
# define Tracev(x) {if (z_verbose>0) fprintf x ;} # define Tracev(x) {if (z_verbose>0) fprintf x ;}
@@ -258,9 +258,9 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
#endif #endif
#ifndef Z_SOLO #ifndef Z_SOLO
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
unsigned size); unsigned size));
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr); void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr));
#endif #endif
#define ZALLOC(strm, items, size) \ #define ZALLOC(strm, items, size) \
+52 -120
View File
@@ -5,6 +5,7 @@
# $ cmake <PATH_TO_OPENCV_ROOT> # $ cmake <PATH_TO_OPENCV_ROOT>
# #
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# Disable in-source builds to prevent source tree corruption. # Disable in-source builds to prevent source tree corruption.
if(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}") if(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}")
message(FATAL_ERROR " message(FATAL_ERROR "
@@ -73,14 +74,6 @@ if(POLICY CMP0077)
cmake_policy(SET CMP0077 NEW) # CMake 3.13+: option() honors normal variables. cmake_policy(SET CMP0077 NEW) # CMake 3.13+: option() honors normal variables.
endif() endif()
if(POLICY CMP0091)
cmake_policy(SET CMP0091 NEW) # CMake 3.15+: leave MSVC runtime selection out of default CMAKE_<LANG>_FLAGS_<CONFIG> flags
endif()
if(POLICY CMP0146)
cmake_policy(SET CMP0146 OLD) # CMake 3.27+: use CMake FindCUDA if available.
endif()
# #
# Configure OpenCV CMake hooks # Configure OpenCV CMake hooks
# #
@@ -242,9 +235,9 @@ OCV_OPTION(BUILD_ITT "Build Intel ITT from source"
# Optional 3rd party components # Optional 3rd party components
# =================================================== # ===================================================
OCV_OPTION(WITH_1394 "Include IEEE1394 support" ON OCV_OPTION(WITH_1394 "Include IEEE1394 support" ON
VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT XROS AND NOT WINRT VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT
VERIFY HAVE_DC1394_2) VERIFY HAVE_DC1394_2)
OCV_OPTION(WITH_AVFOUNDATION "Use AVFoundation for Video I/O (iOS/visionOS/Mac)" ON OCV_OPTION(WITH_AVFOUNDATION "Use AVFoundation for Video I/O (iOS/Mac)" ON
VISIBLE_IF APPLE VISIBLE_IF APPLE
VERIFY HAVE_AVFOUNDATION) VERIFY HAVE_AVFOUNDATION)
OCV_OPTION(WITH_AVIF "Enable AVIF support" OFF OCV_OPTION(WITH_AVIF "Enable AVIF support" OFF
@@ -253,15 +246,15 @@ OCV_OPTION(WITH_CAP_IOS "Enable iOS video capture" ON
VISIBLE_IF IOS VISIBLE_IF IOS
VERIFY HAVE_CAP_IOS) VERIFY HAVE_CAP_IOS)
OCV_OPTION(WITH_CAROTENE "Use NVidia carotene acceleration library for ARM platform" (NOT CV_DISABLE_OPTIMIZATION) OCV_OPTION(WITH_CAROTENE "Use NVidia carotene acceleration library for ARM platform" (NOT CV_DISABLE_OPTIMIZATION)
VISIBLE_IF (ARM OR AARCH64) AND NOT IOS AND NOT XROS) VISIBLE_IF (ARM OR AARCH64) AND NOT IOS)
OCV_OPTION(WITH_CPUFEATURES "Use cpufeatures Android library" ON OCV_OPTION(WITH_CPUFEATURES "Use cpufeatures Android library" ON
VISIBLE_IF ANDROID VISIBLE_IF ANDROID
VERIFY HAVE_CPUFEATURES) VERIFY HAVE_CPUFEATURES)
OCV_OPTION(WITH_VTK "Include VTK library support (and build opencv_viz module eiher)" ON OCV_OPTION(WITH_VTK "Include VTK library support (and build opencv_viz module eiher)" ON
VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT XROS AND NOT WINRT AND NOT CMAKE_CROSSCOMPILING VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT AND NOT CMAKE_CROSSCOMPILING
VERIFY HAVE_VTK) VERIFY HAVE_VTK)
OCV_OPTION(WITH_CUDA "Include NVidia Cuda Runtime support" OFF OCV_OPTION(WITH_CUDA "Include NVidia Cuda Runtime support" OFF
VISIBLE_IF NOT IOS AND NOT XROS AND NOT WINRT VISIBLE_IF NOT IOS AND NOT WINRT
VERIFY HAVE_CUDA) VERIFY HAVE_CUDA)
OCV_OPTION(WITH_CUFFT "Include NVidia Cuda Fast Fourier Transform (FFT) library support" WITH_CUDA OCV_OPTION(WITH_CUFFT "Include NVidia Cuda Fast Fourier Transform (FFT) library support" WITH_CUDA
VISIBLE_IF WITH_CUDA VISIBLE_IF WITH_CUDA
@@ -282,10 +275,10 @@ OCV_OPTION(WITH_EIGEN "Include Eigen2/Eigen3 support" (NOT CV_DISABLE_OPTIMIZATI
VISIBLE_IF NOT WINRT VISIBLE_IF NOT WINRT
VERIFY HAVE_EIGEN) VERIFY HAVE_EIGEN)
OCV_OPTION(WITH_FFMPEG "Include FFMPEG support" (NOT ANDROID) OCV_OPTION(WITH_FFMPEG "Include FFMPEG support" (NOT ANDROID)
VISIBLE_IF NOT IOS AND NOT XROS AND NOT WINRT VISIBLE_IF NOT IOS AND NOT WINRT
VERIFY HAVE_FFMPEG) VERIFY HAVE_FFMPEG)
OCV_OPTION(WITH_GSTREAMER "Include Gstreamer support" ON OCV_OPTION(WITH_GSTREAMER "Include Gstreamer support" ON
VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT XROS AND NOT WINRT VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT
VERIFY HAVE_GSTREAMER AND GSTREAMER_VERSION VERSION_GREATER "0.99") VERIFY HAVE_GSTREAMER AND GSTREAMER_VERSION VERSION_GREATER "0.99")
OCV_OPTION(WITH_GTK "Include GTK support" ON OCV_OPTION(WITH_GTK "Include GTK support" ON
VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID
@@ -297,7 +290,7 @@ OCV_OPTION(WITH_WAYLAND "Include Wayland support" OFF
VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID
VERIFY HAVE_WAYLAND) VERIFY HAVE_WAYLAND)
OCV_OPTION(WITH_IPP "Include Intel IPP support" (NOT MINGW AND NOT CV_DISABLE_OPTIMIZATION) OCV_OPTION(WITH_IPP "Include Intel IPP support" (NOT MINGW AND NOT CV_DISABLE_OPTIMIZATION)
VISIBLE_IF (X86_64 OR X86) AND NOT WINRT AND NOT IOS AND NOT XROS VISIBLE_IF (X86_64 OR X86) AND NOT WINRT AND NOT IOS
VERIFY HAVE_IPP) VERIFY HAVE_IPP)
OCV_OPTION(WITH_HALIDE "Include Halide support" OFF OCV_OPTION(WITH_HALIDE "Include Halide support" OFF
VISIBLE_IF TRUE VISIBLE_IF TRUE
@@ -313,10 +306,10 @@ OCV_OPTION(WITH_WEBNN "Include WebNN support" OFF
VISIBLE_IF TRUE VISIBLE_IF TRUE
VERIFY HAVE_WEBNN) VERIFY HAVE_WEBNN)
OCV_OPTION(WITH_JASPER "Include JPEG2K support (Jasper)" ON OCV_OPTION(WITH_JASPER "Include JPEG2K support (Jasper)" ON
VISIBLE_IF NOT IOS AND NOT XROS VISIBLE_IF NOT IOS
VERIFY HAVE_JASPER) VERIFY HAVE_JASPER)
OCV_OPTION(WITH_OPENJPEG "Include JPEG2K support (OpenJPEG)" ON OCV_OPTION(WITH_OPENJPEG "Include JPEG2K support (OpenJPEG)" ON
VISIBLE_IF NOT IOS AND NOT XROS VISIBLE_IF NOT IOS
VERIFY HAVE_OPENJPEG) VERIFY HAVE_OPENJPEG)
OCV_OPTION(WITH_JPEG "Include JPEG support" ON OCV_OPTION(WITH_JPEG "Include JPEG support" ON
VISIBLE_IF TRUE VISIBLE_IF TRUE
@@ -334,10 +327,10 @@ OCV_OPTION(WITH_OPENVX "Include OpenVX support" OFF
VISIBLE_IF TRUE VISIBLE_IF TRUE
VERIFY HAVE_OPENVX) VERIFY HAVE_OPENVX)
OCV_OPTION(WITH_OPENNI "Include OpenNI support" OFF OCV_OPTION(WITH_OPENNI "Include OpenNI support" OFF
VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT XROS AND NOT WINRT VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT
VERIFY HAVE_OPENNI) VERIFY HAVE_OPENNI)
OCV_OPTION(WITH_OPENNI2 "Include OpenNI2 support" OFF OCV_OPTION(WITH_OPENNI2 "Include OpenNI2 support" OFF
VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT XROS AND NOT WINRT VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT
VERIFY HAVE_OPENNI2) VERIFY HAVE_OPENNI2)
OCV_OPTION(WITH_PNG "Include PNG support" ON OCV_OPTION(WITH_PNG "Include PNG support" ON
VISIBLE_IF TRUE VISIBLE_IF TRUE
@@ -349,19 +342,19 @@ OCV_OPTION(WITH_GDCM "Include DICOM support" OFF
VISIBLE_IF TRUE VISIBLE_IF TRUE
VERIFY HAVE_GDCM) VERIFY HAVE_GDCM)
OCV_OPTION(WITH_PVAPI "Include Prosilica GigE support" OFF OCV_OPTION(WITH_PVAPI "Include Prosilica GigE support" OFF
VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT XROS AND NOT WINRT VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT
VERIFY HAVE_PVAPI) VERIFY HAVE_PVAPI)
OCV_OPTION(WITH_ARAVIS "Include Aravis GigE support" OFF OCV_OPTION(WITH_ARAVIS "Include Aravis GigE support" OFF
VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT XROS AND NOT WINRT AND NOT WIN32 VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT AND NOT WIN32
VERIFY HAVE_ARAVIS_API) VERIFY HAVE_ARAVIS_API)
OCV_OPTION(WITH_QT "Build with Qt Backend support" OFF OCV_OPTION(WITH_QT "Build with Qt Backend support" OFF
VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT XROS AND NOT WINRT VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT
VERIFY HAVE_QT) VERIFY HAVE_QT)
OCV_OPTION(WITH_WIN32UI "Build with Win32 UI Backend support" ON OCV_OPTION(WITH_WIN32UI "Build with Win32 UI Backend support" ON
VISIBLE_IF WIN32 AND NOT WINRT VISIBLE_IF WIN32 AND NOT WINRT
VERIFY HAVE_WIN32UI) VERIFY HAVE_WIN32UI)
OCV_OPTION(WITH_TBB "Include Intel TBB support" OFF OCV_OPTION(WITH_TBB "Include Intel TBB support" OFF
VISIBLE_IF NOT IOS AND NOT XROS AND NOT WINRT VISIBLE_IF NOT IOS AND NOT WINRT
VERIFY HAVE_TBB) VERIFY HAVE_TBB)
OCV_OPTION(WITH_HPX "Include Ste||ar Group HPX support" OFF OCV_OPTION(WITH_HPX "Include Ste||ar Group HPX support" OFF
VISIBLE_IF TRUE VISIBLE_IF TRUE
@@ -373,7 +366,7 @@ OCV_OPTION(WITH_PTHREADS_PF "Use pthreads-based parallel_for" ON
VISIBLE_IF NOT WIN32 OR MINGW VISIBLE_IF NOT WIN32 OR MINGW
VERIFY HAVE_PTHREADS_PF) VERIFY HAVE_PTHREADS_PF)
OCV_OPTION(WITH_TIFF "Include TIFF support" ON OCV_OPTION(WITH_TIFF "Include TIFF support" ON
VISIBLE_IF NOT IOS AND NOT XROS VISIBLE_IF NOT IOS
VERIFY HAVE_TIFF) VERIFY HAVE_TIFF)
OCV_OPTION(WITH_V4L "Include Video 4 Linux support" ON OCV_OPTION(WITH_V4L "Include Video 4 Linux support" ON
VISIBLE_IF UNIX AND NOT ANDROID AND NOT APPLE VISIBLE_IF UNIX AND NOT ANDROID AND NOT APPLE
@@ -400,23 +393,20 @@ OCV_OPTION(WITH_CLP "Include Clp support (EPL)" OFF
VISIBLE_IF TRUE VISIBLE_IF TRUE
VERIFY HAVE_CLP) VERIFY HAVE_CLP)
OCV_OPTION(WITH_OPENCL "Include OpenCL Runtime support" (NOT ANDROID AND NOT CV_DISABLE_OPTIMIZATION) OCV_OPTION(WITH_OPENCL "Include OpenCL Runtime support" (NOT ANDROID AND NOT CV_DISABLE_OPTIMIZATION)
VISIBLE_IF NOT IOS AND NOT XROS AND NOT WINRT VISIBLE_IF NOT IOS AND NOT WINRT
VERIFY HAVE_OPENCL) VERIFY HAVE_OPENCL)
OCV_OPTION(WITH_OPENCL_SVM "Include OpenCL Shared Virtual Memory support" OFF OCV_OPTION(WITH_OPENCL_SVM "Include OpenCL Shared Virtual Memory support" OFF
VISIBLE_IF TRUE VISIBLE_IF TRUE
VERIFY HAVE_OPENCL_SVM) # experimental VERIFY HAVE_OPENCL_SVM) # experimental
OCV_OPTION(WITH_OPENCLAMDFFT "Include AMD OpenCL FFT library support" ON OCV_OPTION(WITH_OPENCLAMDFFT "Include AMD OpenCL FFT library support" ON
VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT XROS AND NOT WINRT VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT
VERIFY HAVE_CLAMDFFT) VERIFY HAVE_CLAMDFFT)
OCV_OPTION(WITH_OPENCLAMDBLAS "Include AMD OpenCL BLAS library support" ON OCV_OPTION(WITH_OPENCLAMDBLAS "Include AMD OpenCL BLAS library support" ON
VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT XROS AND NOT WINRT VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT
VERIFY HAVE_CLAMDBLAS) VERIFY HAVE_CLAMDBLAS)
OCV_OPTION(WITH_DIRECTX "Include DirectX support" ON OCV_OPTION(WITH_DIRECTX "Include DirectX support" ON
VISIBLE_IF WIN32 AND NOT WINRT VISIBLE_IF WIN32 AND NOT WINRT
VERIFY HAVE_DIRECTX) VERIFY HAVE_DIRECTX)
OCV_OPTION(WITH_DIRECTML "Include DirectML support" ON
VISIBLE_IF WIN32 AND NOT WINRT
VERIFY HAVE_DIRECTML)
OCV_OPTION(WITH_OPENCL_D3D11_NV "Include NVIDIA OpenCL D3D11 support" WITH_DIRECTX OCV_OPTION(WITH_OPENCL_D3D11_NV "Include NVIDIA OpenCL D3D11 support" WITH_DIRECTX
VISIBLE_IF WIN32 AND NOT WINRT VISIBLE_IF WIN32 AND NOT WINRT
VERIFY HAVE_OPENCL_D3D11_NV) VERIFY HAVE_OPENCL_D3D11_NV)
@@ -433,13 +423,13 @@ OCV_OPTION(WITH_MFX "Include Intel Media SDK support" OFF
VISIBLE_IF (UNIX AND NOT ANDROID) OR (WIN32 AND NOT WINRT AND NOT MINGW) VISIBLE_IF (UNIX AND NOT ANDROID) OR (WIN32 AND NOT WINRT AND NOT MINGW)
VERIFY HAVE_MFX) VERIFY HAVE_MFX)
OCV_OPTION(WITH_GDAL "Include GDAL Support" OFF OCV_OPTION(WITH_GDAL "Include GDAL Support" OFF
VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT XROS AND NOT WINRT VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT
VERIFY HAVE_GDAL) VERIFY HAVE_GDAL)
OCV_OPTION(WITH_GPHOTO2 "Include gPhoto2 library support" OFF OCV_OPTION(WITH_GPHOTO2 "Include gPhoto2 library support" OFF
VISIBLE_IF UNIX AND NOT ANDROID AND NOT IOS AND NOT XROS VISIBLE_IF UNIX AND NOT ANDROID AND NOT IOS
VERIFY HAVE_GPHOTO2) VERIFY HAVE_GPHOTO2)
OCV_OPTION(WITH_LAPACK "Include Lapack library support" (NOT CV_DISABLE_OPTIMIZATION) OCV_OPTION(WITH_LAPACK "Include Lapack library support" (NOT CV_DISABLE_OPTIMIZATION)
VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT XROS VISIBLE_IF NOT ANDROID AND NOT IOS
VERIFY HAVE_LAPACK) VERIFY HAVE_LAPACK)
OCV_OPTION(WITH_ITT "Include Intel ITT support" ON OCV_OPTION(WITH_ITT "Include Intel ITT support" ON
VISIBLE_IF NOT APPLE_FRAMEWORK VISIBLE_IF NOT APPLE_FRAMEWORK
@@ -459,7 +449,7 @@ OCV_OPTION(WITH_IMGCODEC_PXM "Include PNM (PBM,PGM,PPM) and PAM formats support"
OCV_OPTION(WITH_IMGCODEC_PFM "Include PFM formats support" ON OCV_OPTION(WITH_IMGCODEC_PFM "Include PFM formats support" ON
VISIBLE_IF TRUE VISIBLE_IF TRUE
VERIFY HAVE_IMGCODEC_PFM) VERIFY HAVE_IMGCODEC_PFM)
OCV_OPTION(WITH_QUIRC "Include library QR-code decoding" OFF OCV_OPTION(WITH_QUIRC "Include library QR-code decoding" ON
VISIBLE_IF TRUE VISIBLE_IF TRUE
VERIFY HAVE_QUIRC) VERIFY HAVE_QUIRC)
OCV_OPTION(WITH_ANDROID_MEDIANDK "Use Android Media NDK for Video I/O (Android)" (ANDROID_NATIVE_API_LEVEL GREATER 20) OCV_OPTION(WITH_ANDROID_MEDIANDK "Use Android Media NDK for Video I/O (Android)" (ANDROID_NATIVE_API_LEVEL GREATER 20)
@@ -468,15 +458,17 @@ OCV_OPTION(WITH_ANDROID_MEDIANDK "Use Android Media NDK for Video I/O (Android)"
OCV_OPTION(WITH_ANDROID_NATIVE_CAMERA "Use Android NDK for Camera I/O (Android)" (ANDROID_NATIVE_API_LEVEL GREATER 23) OCV_OPTION(WITH_ANDROID_NATIVE_CAMERA "Use Android NDK for Camera I/O (Android)" (ANDROID_NATIVE_API_LEVEL GREATER 23)
VISIBLE_IF ANDROID VISIBLE_IF ANDROID
VERIFY HAVE_ANDROID_NATIVE_CAMERA) VERIFY HAVE_ANDROID_NATIVE_CAMERA)
OCV_OPTION(WITH_TENGINE "Include Arm Inference Tengine support" OFF
VISIBLE_IF (ARM OR AARCH64) AND (UNIX OR ANDROID) AND NOT IOS
VERIFY HAVE_TENGINE)
OCV_OPTION(WITH_ONNX "Include Microsoft ONNX Runtime support" OFF OCV_OPTION(WITH_ONNX "Include Microsoft ONNX Runtime support" OFF
VISIBLE_IF TRUE VISIBLE_IF TRUE
VERIFY HAVE_ONNX) VERIFY HAVE_ONNX)
OCV_OPTION(WITH_TIMVX "Include Tim-VX support" OFF OCV_OPTION(WITH_TIMVX "Include Tim-VX support" OFF
VISIBLE_IF TRUE VISIBLE_IF TRUE
VERIFY HAVE_TIMVX) VERIFY HAVE_TIMVX)
# attention: Astra2, Gemini2, and Gemini2L cameras currently only support Windows and Linux kernel versions no higher than 4.15, and higher versions of Linux kernel may have exceptions.
OCV_OPTION(WITH_OBSENSOR "Include obsensor support (Orbbec RGB-D modules: Astra+/Femto)" ON OCV_OPTION(WITH_OBSENSOR "Include obsensor support (Orbbec RGB-D modules: Astra+/Femto)" ON
VISIBLE_IF (WIN32 AND NOT ARM AND NOT WINRT AND NOT MINGW) OR ( UNIX AND NOT APPLE AND NOT ANDROID) VISIBLE_IF (WIN32 AND NOT ARM AND NOT WINRT) OR ( UNIX AND NOT APPLE AND NOT ANDROID)
VERIFY HAVE_OBSENSOR) VERIFY HAVE_OBSENSOR)
OCV_OPTION(WITH_CANN "Include CANN support" OFF OCV_OPTION(WITH_CANN "Include CANN support" OFF
VISIBLE_IF TRUE VISIBLE_IF TRUE
@@ -520,7 +512,7 @@ OCV_OPTION(INSTALL_TESTS "Install accuracy and performance test binar
# OpenCV build options # OpenCV build options
# =================================================== # ===================================================
OCV_OPTION(ENABLE_CCACHE "Use ccache" (UNIX AND (CMAKE_GENERATOR MATCHES "Makefile" OR CMAKE_GENERATOR MATCHES "Ninja" OR CMAKE_GENERATOR MATCHES "Xcode")) ) OCV_OPTION(ENABLE_CCACHE "Use ccache" (UNIX AND (CMAKE_GENERATOR MATCHES "Makefile" OR CMAKE_GENERATOR MATCHES "Ninja" OR CMAKE_GENERATOR MATCHES "Xcode")) )
OCV_OPTION(ENABLE_PRECOMPILED_HEADERS "Use precompiled headers" MSVC IF (MSVC OR (NOT IOS AND NOT XROS AND NOT CMAKE_CROSSCOMPILING) ) ) OCV_OPTION(ENABLE_PRECOMPILED_HEADERS "Use precompiled headers" MSVC IF (MSVC OR (NOT IOS AND NOT CMAKE_CROSSCOMPILING) ) )
OCV_OPTION(ENABLE_DELAYLOAD "Enable delayed loading of OpenCV DLLs" OFF VISIBLE_IF MSVC AND BUILD_SHARED_LIBS) OCV_OPTION(ENABLE_DELAYLOAD "Enable delayed loading of OpenCV DLLs" OFF VISIBLE_IF MSVC AND BUILD_SHARED_LIBS)
OCV_OPTION(ENABLE_SOLUTION_FOLDERS "Solution folder in Visual Studio or in other IDEs" (MSVC_IDE OR CMAKE_GENERATOR MATCHES Xcode) ) OCV_OPTION(ENABLE_SOLUTION_FOLDERS "Solution folder in Visual Studio or in other IDEs" (MSVC_IDE OR CMAKE_GENERATOR MATCHES Xcode) )
OCV_OPTION(ENABLE_PROFILING "Enable profiling in the GCC compiler (Add flags: -g -pg)" OFF IF CV_GCC ) OCV_OPTION(ENABLE_PROFILING "Enable profiling in the GCC compiler (Add flags: -g -pg)" OFF IF CV_GCC )
@@ -530,8 +522,8 @@ OCV_OPTION(ENABLE_OMIT_FRAME_POINTER "Enable -fomit-frame-pointer for GCC"
OCV_OPTION(ENABLE_POWERPC "Enable PowerPC for GCC" ON IF (CV_GCC AND CMAKE_SYSTEM_PROCESSOR MATCHES powerpc.*) ) OCV_OPTION(ENABLE_POWERPC "Enable PowerPC for GCC" ON IF (CV_GCC AND CMAKE_SYSTEM_PROCESSOR MATCHES powerpc.*) )
OCV_OPTION(ENABLE_FAST_MATH "Enable compiler options for fast math optimizations on FP computations (not recommended)" OFF) OCV_OPTION(ENABLE_FAST_MATH "Enable compiler options for fast math optimizations on FP computations (not recommended)" OFF)
if(NOT IOS AND (NOT ANDROID OR OPENCV_ANDROID_USE_LEGACY_FLAGS) AND CMAKE_CROSSCOMPILING) # Use CPU_BASELINE instead if(NOT IOS AND (NOT ANDROID OR OPENCV_ANDROID_USE_LEGACY_FLAGS) AND CMAKE_CROSSCOMPILING) # Use CPU_BASELINE instead
OCV_OPTION(ENABLE_NEON "Enable NEON instructions" (NEON OR ANDROID_ARM_NEON OR AARCH64) IF (CV_GCC OR CV_CLANG) AND (ARM OR AARCH64 OR IOS OR XROS) ) OCV_OPTION(ENABLE_NEON "Enable NEON instructions" (NEON OR ANDROID_ARM_NEON OR AARCH64) IF (CV_GCC OR CV_CLANG) AND (ARM OR AARCH64 OR IOS) )
OCV_OPTION(ENABLE_VFPV3 "Enable VFPv3-D32 instructions" OFF IF (CV_GCC OR CV_CLANG) AND (ARM OR AARCH64 OR IOS OR XROS) ) OCV_OPTION(ENABLE_VFPV3 "Enable VFPv3-D32 instructions" OFF IF (CV_GCC OR CV_CLANG) AND (ARM OR AARCH64 OR IOS) )
endif() endif()
OCV_OPTION(ENABLE_NOISY_WARNINGS "Show all warnings even if they are too noisy" OFF ) OCV_OPTION(ENABLE_NOISY_WARNINGS "Show all warnings even if they are too noisy" OFF )
OCV_OPTION(OPENCV_WARNINGS_ARE_ERRORS "Treat warnings as errors" OFF ) OCV_OPTION(OPENCV_WARNINGS_ARE_ERRORS "Treat warnings as errors" OFF )
@@ -553,9 +545,6 @@ OCV_OPTION(OPENCV_ENABLE_MEMALIGN "Enable posix_memalign or memalign usage"
OCV_OPTION(OPENCV_DISABLE_FILESYSTEM_SUPPORT "Disable filesystem support" OFF) OCV_OPTION(OPENCV_DISABLE_FILESYSTEM_SUPPORT "Disable filesystem support" OFF)
OCV_OPTION(OPENCV_DISABLE_THREAD_SUPPORT "Build the library without multi-threaded code." OFF) OCV_OPTION(OPENCV_DISABLE_THREAD_SUPPORT "Build the library without multi-threaded code." OFF)
OCV_OPTION(OPENCV_SEMIHOSTING "Build the library for semihosting target (Arm). See https://developer.arm.com/documentation/100863/latest." OFF) OCV_OPTION(OPENCV_SEMIHOSTING "Build the library for semihosting target (Arm). See https://developer.arm.com/documentation/100863/latest." OFF)
OCV_OPTION(ENABLE_CUDA_FIRST_CLASS_LANGUAGE "Enable CUDA as a first class language, if enabled dependant projects will need to use CMake >= 3.18" OFF
VISIBLE_IF (WITH_CUDA AND NOT CMAKE_VERSION VERSION_LESS 3.18)
VERIFY HAVE_CUDA)
OCV_OPTION(ENABLE_PYLINT "Add target with Pylint checks" (BUILD_DOCS OR BUILD_EXAMPLES) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) ) OCV_OPTION(ENABLE_PYLINT "Add target with Pylint checks" (BUILD_DOCS OR BUILD_EXAMPLES) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) )
OCV_OPTION(ENABLE_FLAKE8 "Add target with Python flake8 checker" (BUILD_DOCS OR BUILD_EXAMPLES) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) ) OCV_OPTION(ENABLE_FLAKE8 "Add target with Python flake8 checker" (BUILD_DOCS OR BUILD_EXAMPLES) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) )
@@ -656,7 +645,7 @@ endif()
ocv_cmake_hook(POST_CMAKE_BUILD_OPTIONS) ocv_cmake_hook(POST_CMAKE_BUILD_OPTIONS)
# --- Python Support --- # --- Python Support ---
if(NOT IOS AND NOT XROS) if(NOT IOS)
include(cmake/OpenCVDetectPython.cmake) include(cmake/OpenCVDetectPython.cmake)
endif() endif()
@@ -664,51 +653,6 @@ include(cmake/OpenCVCompilerOptions.cmake)
ocv_cmake_hook(POST_COMPILER_OPTIONS) ocv_cmake_hook(POST_COMPILER_OPTIONS)
# --- CUDA Support ---
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
if(CMAKE_VERSION VERSION_LESS 3.18)
message(WARNING "CUDA: First class language only supported for CMake versions >= 3.18, falling back to FindCUDA!")
set(ENABLE_CUDA_FIRST_CLASS_LANGUAGE OFF CACHE BOOL "Enable CUDA as a first class language, if enabled dependant projects will need to use CMake >= 3.18" FORCE)
else()
# Check CUDA_PATH if supplied
if(UNIX AND CUDA_PATH AND NOT ENV{CUDA_PATH})
set(ENV{CUDA_PATH} ${CUDA_PATH})
elseif(WIN32 AND CUDA_PATH)
set(ENV{PATH} "${CUDA_PATH}\\bin\;$ENV{PATH}")
endif()
include(CheckLanguage)
check_language(CUDA)
# Fallback to checking default locations
if(NOT CMAKE_CUDA_COMPILER)
# Checking windows default search location isn't possible because the CUDA Toolkit is installed to C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/vXX.X
if(WIN32)
if(CMAKE_GENERATOR MATCHES "Visual Studio")
message(STATUS "CUDA: Not detected, when using stand alone installations with the Visual Studio generator the path to the CUDA toolkit should be manually specified with -Tcuda=. e.g. -Tcuda=\"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/vXX.X\"")
else()
message(STATUS "CUDA: Not detected, for stand alone installations the path to the CUDA toolkit should be manually specified with -DCUDA_PATH=. e.g. -DCUDA_PATH=\"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/vXX.X\"")
endif()
elseif(UNIX)
message(STATUS "CUDA: Not detected, make sure you have performed the mandatory Post-installation actions described in the CUDA installation guide.\n For stand alone installations you can set the CUDA_PATH environmental or CMake variable. e.g. export CUDA_PATH=/usr/local/cuda-XX.X or -DCUDA_PATH=/usr/local/cuda-XX.X.")
message(STATUS "CUDA: Falling back to searching for the CUDA compiler in its default location (/usr/local/cuda)")
set(CUDA_PATH "/usr/local/cuda" CACHE INTERNAL "")
set(ENV{CUDA_PATH} ${CUDA_PATH})
unset(CMAKE_CUDA_COMPILER CACHE)
unset(CMAKE_CUDA_COMPILER)
check_language(CUDA)
endif()
endif()
cmake_policy(SET CMP0092 NEW) # CMake 3.15+: leave warning flags out of default CMAKE_<LANG>_FLAGS flags.
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)
elseif(UNIX)
message(WARNING "CUDA: Not detected! If you are not using the default host compiler (g++) then you need to specify both CMAKE_CUDA_HOST_COMPILER and CMAKE_CUDA_COMPILER. e.g. -DCMAKE_CUDA_HOST_COMPILER=/usr/bin/clang++ -DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc.")
endif()
endif()
endif()
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# CHECK FOR SYSTEM LIBRARIES, OPTIONS, ETC.. # CHECK FOR SYSTEM LIBRARIES, OPTIONS, ETC..
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
@@ -786,7 +730,7 @@ include(cmake/OpenCVModule.cmake)
# Detect endianness of build platform # Detect endianness of build platform
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
if(IOS OR XROS) if(IOS)
# test_big_endian needs try_compile, which doesn't work for iOS # test_big_endian needs try_compile, which doesn't work for iOS
# http://public.kitware.com/Bug/view.php?id=12288 # http://public.kitware.com/Bug/view.php?id=12288
set(WORDS_BIGENDIAN 0) set(WORDS_BIGENDIAN 0)
@@ -813,6 +757,9 @@ include(cmake/OpenCVFindLibsPerf.cmake)
include(cmake/OpenCVFindLAPACK.cmake) include(cmake/OpenCVFindLAPACK.cmake)
include(cmake/OpenCVFindProtobuf.cmake) include(cmake/OpenCVFindProtobuf.cmake)
include(cmake/OpenCVDetectFlatbuffers.cmake) include(cmake/OpenCVDetectFlatbuffers.cmake)
if(WITH_TENGINE)
include(cmake/OpenCVFindTengine.cmake)
endif()
if(WITH_TIMVX) if(WITH_TIMVX)
include(cmake/OpenCVFindTIMVX.cmake) include(cmake/OpenCVFindTIMVX.cmake)
endif() endif()
@@ -903,10 +850,6 @@ endif()
if(WITH_DIRECTX) if(WITH_DIRECTX)
include(cmake/OpenCVDetectDirectX.cmake) include(cmake/OpenCVDetectDirectX.cmake)
endif() endif()
# --- DirectML ---
if(WITH_DIRECTML)
include(cmake/OpenCVDetectDirectML.cmake)
endif()
if(WITH_VTK) if(WITH_VTK)
include(cmake/OpenCVDetectVTK.cmake) include(cmake/OpenCVDetectVTK.cmake)
@@ -967,15 +910,7 @@ foreach(hal ${OpenCV_HAL})
if(";${CPU_BASELINE_FINAL};" MATCHES ";NEON;") if(";${CPU_BASELINE_FINAL};" MATCHES ";NEON;")
add_subdirectory(3rdparty/carotene/hal) add_subdirectory(3rdparty/carotene/hal)
ocv_hal_register(CAROTENE_HAL_LIBRARIES CAROTENE_HAL_HEADERS CAROTENE_HAL_INCLUDE_DIRS) ocv_hal_register(CAROTENE_HAL_LIBRARIES CAROTENE_HAL_HEADERS CAROTENE_HAL_INCLUDE_DIRS)
list(APPEND OpenCV_USED_HAL "carotene (ver ${CAROTENE_HAL_VERSION})")
if( NOT DEFINED CAROTENE_NEON_ARCH)
set(CAROTENE_NEON_MSG "Auto detected")
elseif( CAROTENE_NEON_ARCH GREATER 7)
set(CAROTENE_NEON_MSG "Force ARMv8+")
else()
set(CAROTENE_NEON_MSG "Force ARMv7")
endif()
list(APPEND OpenCV_USED_HAL "carotene (ver ${CAROTENE_HAL_VERSION}, ${CAROTENE_NEON_MSG})")
else() else()
message(STATUS "Carotene: NEON is not available, disabling carotene...") message(STATUS "Carotene: NEON is not available, disabling carotene...")
endif() endif()
@@ -1047,6 +982,10 @@ if(BUILD_EXAMPLES OR BUILD_ANDROID_EXAMPLES OR INSTALL_ANDROID_EXAMPLES OR INSTA
add_subdirectory(samples) add_subdirectory(samples)
endif() endif()
if(ANDROID)
add_subdirectory(platforms/android/service)
endif()
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# Finalization: generate configuration-based files # Finalization: generate configuration-based files
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
@@ -1067,7 +1006,7 @@ include(cmake/OpenCVGenAndroidMK.cmake)
# Generate OpenCVConfig.cmake and OpenCVConfig-version.cmake for cmake projects # Generate OpenCVConfig.cmake and OpenCVConfig-version.cmake for cmake projects
include(cmake/OpenCVGenConfig.cmake) include(cmake/OpenCVGenConfig.cmake)
# Generate Info.plist for the iOS/visionOS framework # Generate Info.plist for the IOS framework
if(APPLE_FRAMEWORK) if(APPLE_FRAMEWORK)
include(cmake/OpenCVGenInfoPlist.cmake) include(cmake/OpenCVGenInfoPlist.cmake)
endif() endif()
@@ -1459,14 +1398,12 @@ if(WITH_AVIF OR HAVE_AVIF)
endif() endif()
endif() endif()
if(WITH_SPNG) if(WITH_PNG OR HAVE_PNG OR WITH_SPNG)
if(BUILD_SPNG) if(WITH_SPNG)
status(" PNG:" "build-${SPNG_LIBRARY} (ver ${SPNG_VERSION})") status(" PNG:" "build-${SPNG_LIBRARY} (ver ${SPNG_VERSION})")
elseif(HAVE_SPNG) else()
status(" PNG:" "${SPNG_LIBRARY} (ver ${SPNG_VERSION})") status(" PNG:" PNG_FOUND THEN "${PNG_LIBRARY} (ver ${PNG_VERSION})" ELSE "build (ver ${PNG_VERSION})")
endif() endif()
elseif(WITH_PNG OR HAVE_PNG)
status(" PNG:" PNG_FOUND THEN "${PNG_LIBRARY} (ver ${PNG_VERSION_STRING})" ELSE "build (ver ${PNG_VERSION_STRING})")
endif() endif()
if(WITH_TIFF OR HAVE_TIFF) if(WITH_TIFF OR HAVE_TIFF)
@@ -1475,7 +1412,7 @@ endif()
if(HAVE_OPENJPEG) if(HAVE_OPENJPEG)
status(" JPEG 2000:" OpenJPEG_FOUND status(" JPEG 2000:" OpenJPEG_FOUND
THEN "OpenJPEG (ver ${OPENJPEG_VERSION})" THEN "OpenJPEG (ver ${OPENJPEG_MAJOR_VERSION}.${OPENJPEG_MINOR_VERSION}.${OPENJPEG_BUILD_VERSION})"
ELSE "build (ver ${OPENJPEG_VERSION})" ELSE "build (ver ${OPENJPEG_VERSION})"
) )
elseif(HAVE_JASPER) elseif(HAVE_JASPER)
@@ -1616,11 +1553,6 @@ if(WITH_GPHOTO2 OR HAVE_GPHOTO2)
status(" gPhoto2:" HAVE_GPHOTO2 THEN "YES" ELSE NO) status(" gPhoto2:" HAVE_GPHOTO2 THEN "YES" ELSE NO)
endif() endif()
if(ANDROID)
status(" MEDIANDK:" HAVE_ANDROID_MEDIANDK THEN "YES" ELSE NO)
status(" NDK Camera:" HAVE_ANDROID_NATIVE_CAMERA THEN "YES" ELSE NO)
endif()
# Order is similar to CV_PARALLEL_FRAMEWORK in core/src/parallel.cpp # Order is similar to CV_PARALLEL_FRAMEWORK in core/src/parallel.cpp
ocv_build_features_string(parallel_status EXCLUSIVE ocv_build_features_string(parallel_status EXCLUSIVE
IF HAVE_TBB THEN "TBB (ver ${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR} interface ${TBB_INTERFACE_VERSION})" IF HAVE_TBB THEN "TBB (ver ${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR} interface ${TBB_INTERFACE_VERSION})"
@@ -1676,6 +1608,10 @@ if(WITH_VA OR HAVE_VA)
status(" VA:" HAVE_VA THEN "YES" ELSE NO) status(" VA:" HAVE_VA THEN "YES" ELSE NO)
endif() endif()
if(WITH_TENGINE OR HAVE_TENGINE)
status(" Tengine:" HAVE_TENGINE THEN "YES (${TENGINE_LIBRARIES})" ELSE NO)
endif()
if(WITH_LAPACK OR HAVE_LAPACK) if(WITH_LAPACK OR HAVE_LAPACK)
status(" Lapack:" HAVE_LAPACK THEN "YES (${LAPACK_LIBRARIES})" ELSE NO) status(" Lapack:" HAVE_LAPACK THEN "YES (${LAPACK_LIBRARIES})" ELSE NO)
endif() endif()
@@ -1742,10 +1678,6 @@ else()
endif() endif()
endif() endif()
if(BUILD_opencv_dnn AND OPENCV_DNN_BACKEND_DEFAULT)
status(" Default DNN backend:" ${OPENCV_DNN_BACKEND_DEFAULT})
endif()
if(WITH_EIGEN OR HAVE_EIGEN) if(WITH_EIGEN OR HAVE_EIGEN)
status(" Eigen:" HAVE_EIGEN THEN "YES (ver ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION})" ELSE NO) status(" Eigen:" HAVE_EIGEN THEN "YES (ver ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION})" ELSE NO)
endif() endif()
+1 -15
View File
@@ -1,9 +1,5 @@
## OpenCV: Open Source Computer Vision Library ## OpenCV: Open Source Computer Vision Library
### Keep OpenCV Free
OpenCV is raising funds to keep the library free for everyone, and we need the support of the entire community to do it. [Donate to OpenCV on IndieGoGo](http://igg.me/at/opencv5) before the campaign ends on December 16 to show your support.
### Resources ### Resources
* Homepage: <https://opencv.org> * Homepage: <https://opencv.org>
@@ -12,7 +8,7 @@ OpenCV is raising funds to keep the library free for everyone, and we need the s
* Q&A forum: <https://forum.opencv.org> * Q&A forum: <https://forum.opencv.org>
* previous forum (read only): <http://answers.opencv.org> * previous forum (read only): <http://answers.opencv.org>
* Issue tracking: <https://github.com/opencv/opencv/issues> * Issue tracking: <https://github.com/opencv/opencv/issues>
* Additional OpenCV functionality: <https://github.com/opencv/opencv_contrib> * Additional OpenCV functionality: <https://github.com/opencv/opencv_contrib>
### Contributing ### Contributing
@@ -26,13 +22,3 @@ Please read the [contribution guidelines](https://github.com/opencv/opencv/wiki/
* Include tests and documentation; * Include tests and documentation;
* Clean up "oops" commits before submitting; * Clean up "oops" commits before submitting;
* Follow the [coding style guide](https://github.com/opencv/opencv/wiki/Coding_Style_Guide). * Follow the [coding style guide](https://github.com/opencv/opencv/wiki/Coding_Style_Guide).
### Additional Resources
* [Submit your OpenCV-based project](https://form.jotform.com/233105358823151) for inclusion in Community Friday on opencv.org
* [Subscribe to the OpenCV YouTube Channel](http://youtube.com/@opencvofficial) featuring OpenCV Live, an hour-long streaming show
* [Follow OpenCV on LinkedIn](http://linkedin.com/company/opencv/) for daily posts showing the state-of-the-art in computer vision &AI
* [Apply to be an OpenCV Volunteer](https://form.jotform.com/232745316792159) to help organize events and online campaigns as well as amplify them
* [Follow OpenCV on Mastodon](http://mastodon.social/@opencv) in the Fediverse
* [Follow OpenCV on Twitter](https://twitter.com/opencvlive)
* [OpenCV.ai](https://opencv.ai): Computer Vision and AI development services from the OpenCV team.
@@ -60,7 +60,6 @@ Created by: Puttemans Steven - April 2016
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <sstream>
using namespace std; using namespace std;
using namespace cv; using namespace cv;
-25
View File
@@ -11,37 +11,12 @@ if(ONNXRT_ROOT_DIR)
find_library(ORT_LIB onnxruntime find_library(ORT_LIB onnxruntime
${ONNXRT_ROOT_DIR}/lib ${ONNXRT_ROOT_DIR}/lib
CMAKE_FIND_ROOT_PATH_BOTH) CMAKE_FIND_ROOT_PATH_BOTH)
# The location of headers varies across different versions of ONNX Runtime
find_path(ORT_INCLUDE onnxruntime_cxx_api.h find_path(ORT_INCLUDE onnxruntime_cxx_api.h
${ONNXRT_ROOT_DIR}/include/onnxruntime/
${ONNXRT_ROOT_DIR}/include/onnxruntime/core/session ${ONNXRT_ROOT_DIR}/include/onnxruntime/core/session
CMAKE_FIND_ROOT_PATH_BOTH) CMAKE_FIND_ROOT_PATH_BOTH)
endif() endif()
macro(detect_onxxrt_ep filename dir have_ep_var)
find_path(ORT_EP_INCLUDE ${filename} ${dir} CMAKE_FIND_ROOT_PATH_BOTH)
if(ORT_EP_INCLUDE)
set(${have_ep_var} TRUE)
endif()
endmacro()
if(ORT_LIB AND ORT_INCLUDE) if(ORT_LIB AND ORT_INCLUDE)
# Check DirectML Execution Provider availability
get_filename_component(dml_dir ${ONNXRT_ROOT_DIR}/include/onnxruntime/core/providers/dml ABSOLUTE)
detect_onxxrt_ep(
dml_provider_factory.h
${dml_dir}
HAVE_ONNX_DML
)
# Check CoreML Execution Provider availability
get_filename_component(coreml_dir ${ONNXRT_ROOT_DIR}/include/onnxruntime/core/providers/coreml ABSOLUTE)
detect_onxxrt_ep(
coreml_provider_factory.h
${coreml_dir}
HAVE_ONNX_COREML
)
set(HAVE_ONNX TRUE) set(HAVE_ONNX TRUE)
# For CMake output only # For CMake output only
set(ONNX_LIBRARIES "${ORT_LIB}" CACHE STRING "ONNX Runtime libraries") set(ONNX_LIBRARIES "${ORT_LIB}" CACHE STRING "ONNX Runtime libraries")
+24 -34
View File
@@ -33,44 +33,34 @@ endif()
# Ignore warning: This object file does not define any previously undefined public symbols, ... # Ignore warning: This object file does not define any previously undefined public symbols, ...
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /IGNORE:4221") set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /IGNORE:4221")
if(POLICY CMP0091)
cmake_policy(GET CMP0091 MSVC_RUNTIME_SET_BY_ABSTRACTION)
endif()
if(NOT BUILD_SHARED_LIBS AND BUILD_WITH_STATIC_CRT) if(NOT BUILD_SHARED_LIBS AND BUILD_WITH_STATIC_CRT)
if(MSVC_RUNTIME_SET_BY_ABSTRACTION STREQUAL "NEW") foreach(flag_var
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
else() CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
foreach(flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO if(${flag_var} MATCHES "/MD")
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) endif()
if(${flag_var} MATCHES "/MD") if(${flag_var} MATCHES "/MDd")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") string(REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}")
endif() endif()
if(${flag_var} MATCHES "/MDd") endforeach(flag_var)
string(REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}")
endif()
endforeach(flag_var)
endif()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:atlthunk.lib") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:atlthunk.lib")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcpmt.lib /NODEFAULTLIB:msvcrt.lib") set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcpmt.lib /NODEFAULTLIB:msvcrt.lib")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:libcpmtd.lib /NODEFAULTLIB:msvcrtd.lib") set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:libcpmtd.lib /NODEFAULTLIB:msvcrtd.lib")
else() else()
if(NOT MSVC_RUNTIME_SET_BY_ABSTRACTION STREQUAL "NEW") foreach(flag_var
foreach(flag_var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) if(${flag_var} MATCHES "/MT")
if(${flag_var} MATCHES "/MT") string(REGEX REPLACE "/MT" "/MD" ${flag_var} "${${flag_var}}")
string(REGEX REPLACE "/MT" "/MD" ${flag_var} "${${flag_var}}") endif()
endif() if(${flag_var} MATCHES "/MTd")
if(${flag_var} MATCHES "/MTd") string(REGEX REPLACE "/MTd" "/MDd" ${flag_var} "${${flag_var}}")
string(REGEX REPLACE "/MTd" "/MDd" ${flag_var} "${${flag_var}}") endif()
endif() endforeach(flag_var)
endforeach(flag_var)
endif()
endif() endif()
+10 -53
View File
@@ -49,11 +49,10 @@
set(CPU_ALL_OPTIMIZATIONS "SSE;SSE2;SSE3;SSSE3;SSE4_1;SSE4_2;POPCNT;AVX;FP16;AVX2;FMA3;AVX_512F") set(CPU_ALL_OPTIMIZATIONS "SSE;SSE2;SSE3;SSSE3;SSE4_1;SSE4_2;POPCNT;AVX;FP16;AVX2;FMA3;AVX_512F")
list(APPEND CPU_ALL_OPTIMIZATIONS "AVX512_COMMON;AVX512_KNL;AVX512_KNM;AVX512_SKX;AVX512_CNL;AVX512_CLX;AVX512_ICL") list(APPEND CPU_ALL_OPTIMIZATIONS "AVX512_COMMON;AVX512_KNL;AVX512_KNM;AVX512_SKX;AVX512_CNL;AVX512_CLX;AVX512_ICL")
list(APPEND CPU_ALL_OPTIMIZATIONS NEON VFPV3 FP16 NEON_DOTPROD NEON_FP16 NEON_BF16) list(APPEND CPU_ALL_OPTIMIZATIONS NEON VFPV3 FP16 NEON_DOTPROD)
list(APPEND CPU_ALL_OPTIMIZATIONS MSA) list(APPEND CPU_ALL_OPTIMIZATIONS MSA)
list(APPEND CPU_ALL_OPTIMIZATIONS VSX VSX3) list(APPEND CPU_ALL_OPTIMIZATIONS VSX VSX3)
list(APPEND CPU_ALL_OPTIMIZATIONS RVV) list(APPEND CPU_ALL_OPTIMIZATIONS RVV)
list(APPEND CPU_ALL_OPTIMIZATIONS LSX)
list(APPEND CPU_ALL_OPTIMIZATIONS LASX) list(APPEND CPU_ALL_OPTIMIZATIONS LASX)
list(REMOVE_DUPLICATES CPU_ALL_OPTIMIZATIONS) list(REMOVE_DUPLICATES CPU_ALL_OPTIMIZATIONS)
@@ -225,7 +224,7 @@ if(X86 OR X86_64)
ocv_update(CPU_SSE2_IMPLIES "SSE") ocv_update(CPU_SSE2_IMPLIES "SSE")
endif() endif()
if(CV_ICC OR CV_ICX) if(CV_ICC)
macro(ocv_intel_compiler_optimization_option name unix_flags msvc_flags) macro(ocv_intel_compiler_optimization_option name unix_flags msvc_flags)
ocv_update(CPU_${name}_FLAGS_NAME "${name}") ocv_update(CPU_${name}_FLAGS_NAME "${name}")
if(MSVC) if(MSVC)
@@ -261,7 +260,7 @@ if(X86 OR X86_64)
ocv_intel_compiler_optimization_option(AVX512_CNL "-xCANNONLAKE" "/Qx:CANNONLAKE") ocv_intel_compiler_optimization_option(AVX512_CNL "-xCANNONLAKE" "/Qx:CANNONLAKE")
ocv_intel_compiler_optimization_option(AVX512_CLX "-xCASCADELAKE" "/Qx:CASCADELAKE") ocv_intel_compiler_optimization_option(AVX512_CLX "-xCASCADELAKE" "/Qx:CASCADELAKE")
ocv_intel_compiler_optimization_option(AVX512_ICL "-xICELAKE-CLIENT" "/Qx:ICELAKE-CLIENT") ocv_intel_compiler_optimization_option(AVX512_ICL "-xICELAKE-CLIENT" "/Qx:ICELAKE-CLIENT")
elseif(CV_GCC OR CV_CLANG OR CV_ICX) elseif(CV_GCC OR CV_CLANG)
ocv_update(CPU_AVX2_FLAGS_ON "-mavx2") ocv_update(CPU_AVX2_FLAGS_ON "-mavx2")
ocv_update(CPU_FP16_FLAGS_ON "-mf16c") ocv_update(CPU_FP16_FLAGS_ON "-mf16c")
ocv_update(CPU_AVX_FLAGS_ON "-mavx") ocv_update(CPU_AVX_FLAGS_ON "-mavx")
@@ -332,9 +331,7 @@ if(X86 OR X86_64)
elseif(ARM OR AARCH64) elseif(ARM OR AARCH64)
ocv_update(CPU_NEON_TEST_FILE "${OpenCV_SOURCE_DIR}/cmake/checks/cpu_neon.cpp") ocv_update(CPU_NEON_TEST_FILE "${OpenCV_SOURCE_DIR}/cmake/checks/cpu_neon.cpp")
ocv_update(CPU_FP16_TEST_FILE "${OpenCV_SOURCE_DIR}/cmake/checks/cpu_fp16.cpp") ocv_update(CPU_FP16_TEST_FILE "${OpenCV_SOURCE_DIR}/cmake/checks/cpu_fp16.cpp")
ocv_update(CPU_NEON_FP16_TEST_FILE "${OpenCV_SOURCE_DIR}/cmake/checks/cpu_neon_fp16.cpp") ocv_update(CPU_NEON_DOTPROD_TEST_FILE "${OpenCV_SOURCE_DIR}/cmake/checks/cpu_dotprod.cpp")
ocv_update(CPU_NEON_BF16_TEST_FILE "${OpenCV_SOURCE_DIR}/cmake/checks/cpu_neon_bf16.cpp")
ocv_update(CPU_NEON_DOTPROD_TEST_FILE "${OpenCV_SOURCE_DIR}/cmake/checks/cpu_neon_dotprod.cpp")
if(NOT AARCH64) if(NOT AARCH64)
ocv_update(CPU_KNOWN_OPTIMIZATIONS "VFPV3;NEON;FP16") ocv_update(CPU_KNOWN_OPTIMIZATIONS "VFPV3;NEON;FP16")
if(NOT MSVC) if(NOT MSVC)
@@ -346,23 +343,12 @@ elseif(ARM OR AARCH64)
endif() endif()
ocv_update(CPU_FP16_IMPLIES "NEON") ocv_update(CPU_FP16_IMPLIES "NEON")
else() else()
ocv_update(CPU_KNOWN_OPTIMIZATIONS "NEON;FP16;NEON_DOTPROD;NEON_FP16;NEON_BF16") ocv_update(CPU_KNOWN_OPTIMIZATIONS "NEON;FP16;NEON_DOTPROD")
ocv_update(CPU_NEON_FLAGS_ON "") ocv_update(CPU_NEON_FLAGS_ON "")
ocv_update(CPU_FP16_IMPLIES "NEON") ocv_update(CPU_FP16_IMPLIES "NEON")
ocv_update(CPU_NEON_DOTPROD_FLAGS_ON "-march=armv8.2-a+dotprod")
ocv_update(CPU_NEON_DOTPROD_IMPLIES "NEON") ocv_update(CPU_NEON_DOTPROD_IMPLIES "NEON")
ocv_update(CPU_NEON_FP16_IMPLIES "NEON")
ocv_update(CPU_NEON_BF16_IMPLIES "NEON")
if(MSVC)
ocv_update(CPU_NEON_DOTPROD_FLAGS_ON "")
ocv_update(CPU_NEON_FP16_FLAGS_ON "")
ocv_update(CPU_NEON_BF16_FLAGS_ON "")
else()
ocv_update(CPU_NEON_DOTPROD_FLAGS_ON "-march=armv8.2-a+dotprod")
ocv_update(CPU_NEON_FP16_FLAGS_ON "-march=armv8.2-a+fp16")
ocv_update(CPU_NEON_BF16_FLAGS_ON "-march=armv8.2-a+bf16")
endif()
set(CPU_BASELINE "NEON;FP16" CACHE STRING "${HELP_CPU_BASELINE}") set(CPU_BASELINE "NEON;FP16" CACHE STRING "${HELP_CPU_BASELINE}")
set(CPU_DISPATCH "NEON_FP16;NEON_BF16;NEON_DOTPROD" CACHE STRING "${HELP_CPU_DISPATCH}")
endif() endif()
elseif(MIPS) elseif(MIPS)
ocv_update(CPU_MSA_TEST_FILE "${OpenCV_SOURCE_DIR}/cmake/checks/cpu_msa.cpp") ocv_update(CPU_MSA_TEST_FILE "${OpenCV_SOURCE_DIR}/cmake/checks/cpu_msa.cpp")
@@ -404,13 +390,10 @@ elseif(RISCV)
set(CPU_BASELINE "DETECT" CACHE STRING "${HELP_CPU_BASELINE}") set(CPU_BASELINE "DETECT" CACHE STRING "${HELP_CPU_BASELINE}")
elseif(LOONGARCH64) elseif(LOONGARCH64)
ocv_update(CPU_LSX_TEST_FILE "${OpenCV_SOURCE_DIR}/cmake/checks/cpu_lsx.cpp")
ocv_update(CPU_LASX_TEST_FILE "${OpenCV_SOURCE_DIR}/cmake/checks/cpu_lasx.cpp") ocv_update(CPU_LASX_TEST_FILE "${OpenCV_SOURCE_DIR}/cmake/checks/cpu_lasx.cpp")
ocv_update(CPU_KNOWN_OPTIMIZATIONS "LSX;LASX") ocv_update(CPU_KNOWN_OPTIMIZATIONS "LASX")
ocv_update(CPU_LSX_FLAGS_ON "-mlsx")
ocv_update(CPU_LASX_FLAGS_ON "-mlasx") ocv_update(CPU_LASX_FLAGS_ON "-mlasx")
set(CPU_BASELINE "LSX" CACHE STRING "${HELP_CPU_BASELINE}") set(CPU_BASELINE "LASX" CACHE STRING "${HELP_CPU_BASELINE}")
set(CPU_DISPATCH "LASX" CACHE STRING "${HELP_CPU_DISPATCH}")
endif() endif()
@@ -483,25 +466,6 @@ macro(ocv_check_compiler_optimization OPT)
endif() endif()
endmacro() endmacro()
macro(ocv_cpu_aarch64_baseline_merge_feature_options FEATURE_NAME_LIST FLAG_STRING COMMON_OPTION)
if(NOT MSVC)
unset(_POSTFIX)
# Check each feature option
foreach(OPT IN LISTS ${FEATURE_NAME_LIST})
string(FIND "${${FLAG_STRING}}" "${CPU_${OPT}_FLAGS_ON}" OPT_FOUND)
if(NOT ${OPT_FOUND} EQUAL -1)
string(REPLACE "${COMMON_OPTION}" "" TRAILING_PART "${CPU_${OPT}_FLAGS_ON}")
string(APPEND _POSTFIX "${TRAILING_PART}")
string(REPLACE " ${CPU_${OPT}_FLAGS_ON}" "" ${FLAG_STRING} ${${FLAG_STRING}})
endif()
endforeach()
# If more than one option found, merge them
if(NOT "x${_POSTFIX}" STREQUAL "x")
set(${FLAG_STRING} "${${FLAG_STRING}} ${COMMON_OPTION}${_POSTFIX}")
endif()
endif()
endmacro()
foreach(OPT ${CPU_KNOWN_OPTIMIZATIONS}) foreach(OPT ${CPU_KNOWN_OPTIMIZATIONS})
set(CPU_${OPT}_USAGE_COUNT 0 CACHE INTERNAL "") set(CPU_${OPT}_USAGE_COUNT 0 CACHE INTERNAL "")
if("${CPU_${OPT}_FLAGS_ON}" STREQUAL "disabled") if("${CPU_${OPT}_FLAGS_ON}" STREQUAL "disabled")
@@ -595,13 +559,6 @@ foreach(OPT ${CPU_KNOWN_OPTIMIZATIONS})
endif() endif()
endforeach() endforeach()
if(AARCH64)
# Define the list of NEON options to check
set(NEON_OPTIONS_LIST NEON_DOTPROD NEON_FP16 NEON_BF16)
set(BASE_ARCHITECTURE "-march=armv8.2-a")
ocv_cpu_aarch64_baseline_merge_feature_options(NEON_OPTIONS_LIST CPU_BASELINE_FLAGS ${BASE_ARCHITECTURE})
endif()
foreach(OPT ${CPU_BASELINE_REQUIRE}) foreach(OPT ${CPU_BASELINE_REQUIRE})
if(NOT ";${CPU_BASELINE_FINAL};" MATCHES ";${OPT};") if(NOT ";${CPU_BASELINE_FINAL};" MATCHES ";${OPT};")
message(SEND_ERROR "Required baseline optimization is not supported: ${OPT} (CPU_BASELINE_REQUIRE=${CPU_BASELINE_REQUIRE})") message(SEND_ERROR "Required baseline optimization is not supported: ${OPT} (CPU_BASELINE_REQUIRE=${CPU_BASELINE_REQUIRE})")
@@ -700,7 +657,7 @@ macro(ocv_compiler_optimization_options)
endmacro() endmacro()
macro(ocv_compiler_optimization_options_finalize) macro(ocv_compiler_optimization_options_finalize)
if((CV_GCC OR CV_CLANG OR CV_ICX) AND (X86 OR X86_64)) if((CV_GCC OR CV_CLANG) AND (X86 OR X86_64))
if(NOT APPLE AND CMAKE_SIZEOF_VOID_P EQUAL 4) if(NOT APPLE AND CMAKE_SIZEOF_VOID_P EQUAL 4)
if(OPENCV_EXTRA_CXX_FLAGS MATCHES "-m(sse2|avx)") if(OPENCV_EXTRA_CXX_FLAGS MATCHES "-m(sse2|avx)")
add_extra_compiler_option(-mfpmath=sse) # !! important - be on the same wave with x64 compilers add_extra_compiler_option(-mfpmath=sse) # !! important - be on the same wave with x64 compilers
@@ -987,7 +944,7 @@ macro(ocv_add_dispatched_file_force_all)
endmacro() endmacro()
if(CV_DISABLE_OPTIMIZATION OR CV_ICC OR CX_ICX) if(CV_DISABLE_OPTIMIZATION OR CV_ICC)
ocv_update(CV_ENABLE_UNROLLED 0) ocv_update(CV_ENABLE_UNROLLED 0)
else() else()
ocv_update(CV_ENABLE_UNROLLED 1) ocv_update(CV_ENABLE_UNROLLED 1)
+3 -21
View File
@@ -105,27 +105,13 @@ elseif(CV_ICC)
add_extra_compiler_option("-fp-model precise") add_extra_compiler_option("-fp-model precise")
endif() endif()
endif() endif()
elseif(CV_ICX)
# ICX uses -ffast-math by default.
# use own flags, if no one of the flags provided by user: -fp-model, -ffast-math -fno-fast-math
if(NOT " ${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}" MATCHES " /fp:"
AND NOT " ${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}" MATCHES " -fp-model"
AND NOT " ${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}" MATCHES " -ffast-math"
AND NOT " ${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}" MATCHES " -fno-fast-math"
)
if(NOT ENABLE_FAST_MATH)
add_extra_compiler_option(-fno-fast-math)
add_extra_compiler_option(-fp-model=precise)
endif()
endif()
elseif(CV_GCC OR CV_CLANG) elseif(CV_GCC OR CV_CLANG)
if(ENABLE_FAST_MATH) if(ENABLE_FAST_MATH)
add_extra_compiler_option(-ffast-math) add_extra_compiler_option(-ffast-math)
add_extra_compiler_option(-fno-finite-math-only)
endif() endif()
endif() endif()
if(CV_GCC OR CV_CLANG OR CV_ICX) if(CV_GCC OR CV_CLANG)
# High level of warnings. # High level of warnings.
add_extra_compiler_option(-W) add_extra_compiler_option(-W)
if (NOT MSVC) if (NOT MSVC)
@@ -274,11 +260,7 @@ if(CV_GCC OR CV_CLANG OR CV_ICX)
endif() endif()
if(ENABLE_LTO) if(ENABLE_LTO)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12) add_extra_compiler_option(-flto)
add_extra_compiler_option(-flto=auto)
else()
add_extra_compiler_option(-flto)
endif()
endif() endif()
if(ENABLE_THIN_LTO) if(ENABLE_THIN_LTO)
add_extra_compiler_option(-flto=thin) add_extra_compiler_option(-flto=thin)
@@ -349,7 +331,7 @@ if(COMMAND ocv_compiler_optimization_options_finalize)
endif() endif()
# set default visibility to hidden # set default visibility to hidden
if((CV_GCC OR CV_CLANG OR CV_ICX) if((CV_GCC OR CV_CLANG)
AND NOT MSVC AND NOT MSVC
AND NOT OPENCV_SKIP_VISIBILITY_HIDDEN AND NOT OPENCV_SKIP_VISIBILITY_HIDDEN
AND NOT " ${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}" MATCHES " -fvisibility") AND NOT " ${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}" MATCHES " -fvisibility")
+471 -142
View File
@@ -1,10 +1,10 @@
if((WIN32 AND NOT MSVC) OR OPENCV_CMAKE_FORCE_CUDA) if((WIN32 AND NOT MSVC) OR OPENCV_CMAKE_FORCE_CUDA)
message(STATUS "CUDA: Compilation is disabled (due to only Visual Studio compiler supported on your platform).") message(STATUS "CUDA compilation is disabled (due to only Visual Studio compiler supported on your platform).")
return() return()
endif() endif()
if((NOT UNIX AND CV_CLANG) OR OPENCV_CMAKE_FORCE_CUDA) if((NOT UNIX AND CV_CLANG) OR OPENCV_CMAKE_FORCE_CUDA)
message(STATUS "CUDA: Compilation is disabled (due to Clang unsupported on your platform).") message(STATUS "CUDA compilation is disabled (due to Clang unsupported on your platform).")
return() return()
endif() endif()
@@ -31,144 +31,435 @@ else()
list(REMOVE_AT CMAKE_MODULE_PATH 0) list(REMOVE_AT CMAKE_MODULE_PATH 0)
endif() endif()
if(NOT CUDA_FOUND) if(CUDA_FOUND)
unset(CUDA_nvcuvenc_LIBRARY CACHE)
set(HAVE_CUDA 1)
if(NOT CUDA_VERSION VERSION_LESS 11.0)
# CUDA 11.0 removes nppicom
ocv_list_filterout(CUDA_nppi_LIBRARY "nppicom")
ocv_list_filterout(CUDA_npp_LIBRARY "nppicom")
endif()
if(WITH_CUFFT)
set(HAVE_CUFFT 1)
endif()
if(WITH_CUBLAS)
set(HAVE_CUBLAS 1)
endif()
if(WITH_CUDNN)
set(CMAKE_MODULE_PATH "${OpenCV_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
find_host_package(CUDNN "${MIN_VER_CUDNN}")
list(REMOVE_AT CMAKE_MODULE_PATH 0)
if(CUDNN_FOUND)
set(HAVE_CUDNN 1)
endif()
endif()
if(WITH_NVCUVID OR WITH_NVCUVENC)
macro(ocv_cuda_SEARCH_NVCUVID_HEADER _filename _result)
# place header file under CUDA_TOOLKIT_TARGET_DIR or CUDA_TOOLKIT_ROOT_DIR
find_path(_header_result
${_filename}
PATHS "${CUDA_TOOLKIT_TARGET_DIR}" "${CUDA_TOOLKIT_ROOT_DIR}"
ENV CUDA_PATH
ENV CUDA_INC_PATH
PATH_SUFFIXES include
NO_DEFAULT_PATH
)
if("x${_header_result}" STREQUAL "x_header_result-NOTFOUND")
set(${_result} 0)
else()
set(${_result} 1)
endif()
unset(_header_result CACHE)
endmacro()
if(WITH_NVCUVID)
ocv_cuda_SEARCH_NVCUVID_HEADER("nvcuvid.h" HAVE_NVCUVID_HEADER)
ocv_cuda_SEARCH_NVCUVID_HEADER("dynlink_nvcuvid.h" HAVE_DYNLINK_NVCUVID_HEADER)
find_cuda_helper_libs(nvcuvid)
if(CUDA_nvcuvid_LIBRARY AND (${HAVE_NVCUVID_HEADER} OR ${HAVE_DYNLINK_NVCUVID_HEADER}))
# make sure to have both header and library before enabling
set(HAVE_NVCUVID 1)
endif()
endif()
if(WITH_NVCUVENC)
ocv_cuda_SEARCH_NVCUVID_HEADER("nvEncodeAPI.h" HAVE_NVCUVENC_HEADER)
if(WIN32)
find_cuda_helper_libs(nvencodeapi)
else()
find_cuda_helper_libs(nvidia-encode)
endif()
if((CUDA_nvencodeapi_LIBRARY OR CUDA_nvidia-encode_LIBRARY) AND ${HAVE_NVCUVENC_HEADER})
set(HAVE_NVCUVENC 1)
endif()
endif()
endif()
message(STATUS "CUDA detected: " ${CUDA_VERSION})
OCV_OPTION(CUDA_ENABLE_DEPRECATED_GENERATION "Enable deprecated generations in the list" OFF)
set(_generations "Maxwell" "Pascal" "Volta" "Turing" "Ampere" "Lovelace" "Hopper")
if(CUDA_ENABLE_DEPRECATED_GENERATION)
set(_generations "Fermi" "${_generations}")
set(_generations "Kepler" "${_generations}")
endif()
set(_arch_fermi "2.0")
set(_arch_kepler "3.0;3.5;3.7")
set(_arch_maxwell "5.0;5.2")
set(_arch_pascal "6.0;6.1")
set(_arch_volta "7.0")
set(_arch_turing "7.5")
set(_arch_ampere "8.0;8.6")
set(_arch_lovelace "8.9")
set(_arch_hopper "9.0")
if(NOT CMAKE_CROSSCOMPILING)
list(APPEND _generations "Auto")
endif()
set(CUDA_GENERATION "" CACHE STRING "Build CUDA device code only for specific GPU architecture. Leave empty to build for all architectures.")
if( CMAKE_VERSION VERSION_GREATER "2.8" )
set_property( CACHE CUDA_GENERATION PROPERTY STRINGS "" ${_generations} )
endif()
if(CUDA_GENERATION)
if(NOT ";${_generations};" MATCHES ";${CUDA_GENERATION};")
string(REPLACE ";" ", " _generations "${_generations}")
message(FATAL_ERROR "ERROR: ${_generations} Generations are supported.")
endif()
unset(CUDA_ARCH_BIN CACHE)
unset(CUDA_ARCH_PTX CACHE)
endif()
if(OPENCV_CUDA_DETECTION_NVCC_FLAGS MATCHES "-ccbin")
# already specified by user
elseif(CUDA_HOST_COMPILER AND EXISTS "${CUDA_HOST_COMPILER}")
get_filename_component(c_compiler_realpath "${CMAKE_C_COMPILER}" REALPATH)
# C compiler doesn't work with --run option, forcing C++ compiler instead
if(CUDA_HOST_COMPILER STREQUAL c_compiler_realpath OR CUDA_HOST_COMPILER STREQUAL CMAKE_C_COMPILER)
if(DEFINED CMAKE_CXX_COMPILER)
get_filename_component(cxx_compiler_realpath "${CMAKE_CXX_COMPILER}" REALPATH)
LIST(APPEND OPENCV_CUDA_DETECTION_NVCC_FLAGS -ccbin "${cxx_compiler_realpath}")
else()
message(STATUS "CUDA: CMAKE_CXX_COMPILER is not available. You may need to specify CUDA_HOST_COMPILER.")
endif()
else()
LIST(APPEND OPENCV_CUDA_DETECTION_NVCC_FLAGS -ccbin "${CUDA_HOST_COMPILER}")
endif()
elseif(WIN32 AND CMAKE_LINKER) # Workaround for VS cl.exe not being in the env. path
get_filename_component(host_compiler_bindir ${CMAKE_LINKER} DIRECTORY)
LIST(APPEND OPENCV_CUDA_DETECTION_NVCC_FLAGS -ccbin "${host_compiler_bindir}")
else()
if(CUDA_HOST_COMPILER)
message(STATUS "CUDA: CUDA_HOST_COMPILER='${CUDA_HOST_COMPILER}' is not valid, autodetection may not work. Specify OPENCV_CUDA_DETECTION_NVCC_FLAGS with -ccbin option for fix that")
endif()
endif()
macro(ocv_filter_available_architecture result_list)
set(__cache_key_check "${ARGN} : ${CUDA_NVCC_EXECUTABLE} ${OPENCV_CUDA_DETECTION_NVCC_FLAGS}")
if(DEFINED OPENCV_CACHE_CUDA_SUPPORTED_CC AND OPENCV_CACHE_CUDA_SUPPORTED_CC_check STREQUAL __cache_key_check)
set(${result_list} "${OPENCV_CACHE_CUDA_SUPPORTED_CC}")
else()
set(CC_LIST ${ARGN})
foreach(target_arch ${CC_LIST})
string(REPLACE "." "" target_arch_short "${target_arch}")
set(NVCC_OPTION "-gencode;arch=compute_${target_arch_short},code=sm_${target_arch_short}")
set(_cmd "${CUDA_NVCC_EXECUTABLE}" ${OPENCV_CUDA_DETECTION_NVCC_FLAGS} ${NVCC_OPTION} "${OpenCV_SOURCE_DIR}/cmake/checks/OpenCVDetectCudaArch.cu" --compile)
execute_process(
COMMAND ${_cmd}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/"
RESULT_VARIABLE _nvcc_res
OUTPUT_VARIABLE _nvcc_out
ERROR_VARIABLE _nvcc_err
#ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(OPENCV_CMAKE_CUDA_DEBUG)
message(WARNING "COMMAND: ${_cmd}")
message(STATUS "Result: ${_nvcc_res}")
message(STATUS "Out: ${_nvcc_out}")
message(STATUS "Err: ${_nvcc_err}")
endif()
if(_nvcc_res EQUAL 0)
LIST(APPEND ${result_list} "${target_arch}")
endif()
endforeach()
string(STRIP "${${result_list}}" ${result_list})
if(" ${${result_list}}" STREQUAL " ")
message(WARNING "CUDA: Autodetection arch list is empty. Please enable OPENCV_CMAKE_CUDA_DEBUG=1 and check/specify OPENCV_CUDA_DETECTION_NVCC_FLAGS variable")
endif()
# cache detected values
set(OPENCV_CACHE_CUDA_SUPPORTED_CC ${${result_list}} CACHE INTERNAL "")
set(OPENCV_CACHE_CUDA_SUPPORTED_CC_check "${__cache_key_check}" CACHE INTERNAL "")
endif()
endmacro()
macro(ocv_detect_native_cuda_arch status output)
set(OPENCV_CUDA_DETECT_ARCHS_COMMAND "${CUDA_NVCC_EXECUTABLE}" ${OPENCV_CUDA_DETECTION_NVCC_FLAGS} "${OpenCV_SOURCE_DIR}/cmake/checks/OpenCVDetectCudaArch.cu" "--run")
set(__cache_key_check "${OPENCV_CUDA_DETECT_ARCHS_COMMAND}")
if(DEFINED OPENCV_CACHE_CUDA_ACTIVE_CC AND OPENCV_CACHE_CUDA_ACTIVE_CC_check STREQUAL __cache_key_check)
set(${output} "${OPENCV_CACHE_CUDA_ACTIVE_CC}")
set(${status} 0)
else()
execute_process(
COMMAND ${OPENCV_CUDA_DETECT_ARCHS_COMMAND}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/"
RESULT_VARIABLE ${status}
OUTPUT_VARIABLE _nvcc_out
ERROR_VARIABLE _nvcc_err
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(OPENCV_CMAKE_CUDA_DEBUG)
message(WARNING "COMMAND: ${OPENCV_CUDA_DETECT_ARCHS_COMMAND}")
message(STATUS "Result: ${${status}}")
message(STATUS "Out: ${_nvcc_out}")
message(STATUS "Err: ${_nvcc_err}")
endif()
string(REGEX REPLACE ".*\n" "" ${output} "${_nvcc_out}") #Strip leading warning messages, if any
if(${status} EQUAL 0)
# cache detected values
set(OPENCV_CACHE_CUDA_ACTIVE_CC ${${output}} CACHE INTERNAL "")
set(OPENCV_CACHE_CUDA_ACTIVE_CC_check "${__cache_key_check}" CACHE INTERNAL "")
endif()
endif()
endmacro()
set(__cuda_arch_ptx "")
if(CUDA_GENERATION STREQUAL "Fermi")
set(__cuda_arch_bin ${_arch_fermi})
elseif(CUDA_GENERATION STREQUAL "Kepler")
set(__cuda_arch_bin ${_arch_kepler})
elseif(CUDA_GENERATION STREQUAL "Maxwell")
set(__cuda_arch_bin ${_arch_maxwell})
elseif(CUDA_GENERATION STREQUAL "Pascal")
set(__cuda_arch_bin ${_arch_pascal})
elseif(CUDA_GENERATION STREQUAL "Volta")
set(__cuda_arch_bin ${_arch_volta})
elseif(CUDA_GENERATION STREQUAL "Turing")
set(__cuda_arch_bin ${_arch_turing})
elseif(CUDA_GENERATION STREQUAL "Ampere")
set(__cuda_arch_bin ${_arch_ampere})
elseif(CUDA_GENERATION STREQUAL "Lovelace")
set(__cuda_arch_bin ${_arch_lovelace})
elseif(CUDA_GENERATION STREQUAL "Hopper")
set(__cuda_arch_bin ${_arch_hopper})
elseif(CUDA_GENERATION STREQUAL "Auto")
ocv_detect_native_cuda_arch(_nvcc_res _nvcc_out)
if(NOT _nvcc_res EQUAL 0)
message(STATUS "Automatic detection of CUDA generation failed. Going to build for all known architectures.")
else()
string(REGEX MATCHALL "[0-9]+\\.[0-9]" __cuda_arch_bin "${_nvcc_out}")
endif()
elseif(CUDA_ARCH_BIN)
message(STATUS "CUDA: Using CUDA_ARCH_BIN=${CUDA_ARCH_BIN}")
set(__cuda_arch_bin ${CUDA_ARCH_BIN})
endif()
if(NOT DEFINED __cuda_arch_bin)
if(ARM)
set(__cuda_arch_bin "3.2")
set(__cuda_arch_ptx "")
elseif(AARCH64)
if(NOT CMAKE_CROSSCOMPILING)
ocv_detect_native_cuda_arch(_nvcc_res _nvcc_out)
else()
set(_nvcc_res -1) # emulate error, see below
endif()
if(NOT _nvcc_res EQUAL 0)
message(STATUS "Automatic detection of CUDA generation failed. Going to build for all known architectures.")
# TX1 (5.3) TX2 (6.2) Xavier (7.2) V100 (7.0) Orin (8.7)
ocv_filter_available_architecture(__cuda_arch_bin
5.3
6.2
7.2
7.0
8.7
)
else()
set(__cuda_arch_bin "${_nvcc_out}")
endif()
set(__cuda_arch_ptx "")
else()
ocv_filter_available_architecture(__cuda_arch_bin
${_arch_fermi}
${_arch_kepler}
${_arch_maxwell}
${_arch_pascal}
${_arch_volta}
${_arch_turing}
${_arch_ampere}
${_arch_lovelace}
${_arch_hopper}
)
endif()
endif()
set(CUDA_ARCH_BIN ${__cuda_arch_bin} CACHE STRING "Specify 'real' GPU architectures to build binaries for, BIN(PTX) format is supported")
set(CUDA_ARCH_PTX ${__cuda_arch_ptx} CACHE STRING "Specify 'virtual' PTX architectures to build PTX intermediate code for")
string(REGEX REPLACE "\\." "" ARCH_BIN_NO_POINTS "${CUDA_ARCH_BIN}")
string(REGEX REPLACE "\\." "" ARCH_PTX_NO_POINTS "${CUDA_ARCH_PTX}")
# Check if user specified 1.0/2.1 compute capability: we don't support it
macro(ocv_wipeout_deprecated_cc target_cc)
if(" ${CUDA_ARCH_BIN} ${CUDA_ARCH_PTX}" MATCHES " ${target_cc}")
message(SEND_ERROR "CUDA: ${target_cc} compute capability is not supported - exclude it from ARCH/PTX list and re-run CMake")
endif()
endmacro()
ocv_wipeout_deprecated_cc("1.0")
ocv_wipeout_deprecated_cc("2.1")
# NVCC flags to be set
set(NVCC_FLAGS_EXTRA "")
# These vars will be passed into the templates
set(OPENCV_CUDA_ARCH_BIN "")
set(OPENCV_CUDA_ARCH_PTX "")
set(OPENCV_CUDA_ARCH_FEATURES "")
# Tell NVCC to add binaries for the specified GPUs
string(REGEX MATCHALL "[0-9()]+" ARCH_LIST "${ARCH_BIN_NO_POINTS}")
foreach(ARCH IN LISTS ARCH_LIST)
if(ARCH MATCHES "([0-9]+)\\(([0-9]+)\\)")
# User explicitly specified PTX for the concrete BIN
set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -gencode arch=compute_${CMAKE_MATCH_2},code=sm_${CMAKE_MATCH_1})
set(OPENCV_CUDA_ARCH_BIN "${OPENCV_CUDA_ARCH_BIN} ${CMAKE_MATCH_1}")
set(OPENCV_CUDA_ARCH_FEATURES "${OPENCV_CUDA_ARCH_FEATURES} ${CMAKE_MATCH_2}")
else()
# User didn't explicitly specify PTX for the concrete BIN, we assume PTX=BIN
set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -gencode arch=compute_${ARCH},code=sm_${ARCH})
set(OPENCV_CUDA_ARCH_BIN "${OPENCV_CUDA_ARCH_BIN} ${ARCH}")
set(OPENCV_CUDA_ARCH_FEATURES "${OPENCV_CUDA_ARCH_FEATURES} ${ARCH}")
endif()
endforeach()
set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -D_FORCE_INLINES)
# Tell NVCC to add PTX intermediate code for the specified architectures
string(REGEX MATCHALL "[0-9]+" ARCH_LIST "${ARCH_PTX_NO_POINTS}")
foreach(ARCH IN LISTS ARCH_LIST)
set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -gencode arch=compute_${ARCH},code=compute_${ARCH})
set(OPENCV_CUDA_ARCH_PTX "${OPENCV_CUDA_ARCH_PTX} ${ARCH}")
set(OPENCV_CUDA_ARCH_FEATURES "${OPENCV_CUDA_ARCH_FEATURES} ${ARCH}")
endforeach()
# These vars will be processed in other scripts
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} ${NVCC_FLAGS_EXTRA})
set(OpenCV_CUDA_CC "${NVCC_FLAGS_EXTRA}")
if(ANDROID)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-Xptxas;-dlcm=ca")
endif()
message(STATUS "CUDA NVCC target flags: ${CUDA_NVCC_FLAGS}")
OCV_OPTION(CUDA_FAST_MATH "Enable --use_fast_math for CUDA compiler " OFF)
if(CUDA_FAST_MATH)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --use_fast_math)
endif()
OCV_OPTION(CUDA_ENABLE_DELAYLOAD "Enable delayed loading of CUDA DLLs" OFF VISIBLE_IF MSVC)
mark_as_advanced(CUDA_BUILD_CUBIN CUDA_BUILD_EMULATION CUDA_VERBOSE_BUILD CUDA_SDK_ROOT_DIR)
macro(ocv_cuda_filter_options)
foreach(var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG)
set(${var}_backup_in_cuda_compile_ "${${var}}")
if (CV_CLANG)
# we remove -Winconsistent-missing-override and -Qunused-arguments
# just in case we are compiling CUDA with gcc but OpenCV with clang
string(REPLACE "-Winconsistent-missing-override" "" ${var} "${${var}}")
string(REPLACE "-Qunused-arguments" "" ${var} "${${var}}")
endif()
# we remove /EHa as it generates warnings under windows
string(REPLACE "/EHa" "" ${var} "${${var}}")
# we remove -ggdb3 flag as it leads to preprocessor errors when compiling CUDA files (CUDA 4.1)
string(REPLACE "-ggdb3" "" ${var} "${${var}}")
# we remove -Wsign-promo as it generates warnings under linux
string(REPLACE "-Wsign-promo" "" ${var} "${${var}}")
# we remove -Wno-sign-promo as it generates warnings under linux
string(REPLACE "-Wno-sign-promo" "" ${var} "${${var}}")
# we remove -Wno-delete-non-virtual-dtor because it's used for C++ compiler
# but NVCC uses C compiler by default
string(REPLACE "-Wno-delete-non-virtual-dtor" "" ${var} "${${var}}")
# we remove -frtti because it's used for C++ compiler
# but NVCC uses C compiler by default
string(REPLACE "-frtti" "" ${var} "${${var}}")
string(REPLACE "-fvisibility-inlines-hidden" "" ${var} "${${var}}")
# cc1: warning: command line option '-Wsuggest-override' is valid for C++/ObjC++ but not for C
string(REPLACE "-Wsuggest-override" "" ${var} "${${var}}")
# issue: #11552 (from OpenCVCompilerOptions.cmake)
string(REGEX REPLACE "-Wimplicit-fallthrough(=[0-9]+)? " "" ${var} "${${var}}")
# removal of custom specified options
if(OPENCV_CUDA_NVCC_FILTEROUT_OPTIONS)
foreach(__flag ${OPENCV_CUDA_NVCC_FILTEROUT_OPTIONS})
string(REPLACE "${__flag}" "" ${var} "${${var}}")
endforeach()
endif()
endforeach()
endmacro()
macro(ocv_cuda_compile VAR)
ocv_cuda_filter_options()
if(BUILD_SHARED_LIBS)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler -DCVAPI_EXPORTS)
endif()
if(UNIX OR APPLE)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler -fPIC)
if(NOT " ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_DEBUG} ${CUDA_NVCC_FLAGS}" MATCHES "-std=")
if(CUDA_VERSION VERSION_LESS "11.0")
list(APPEND CUDA_NVCC_FLAGS "--std=c++11")
else()
list(APPEND CUDA_NVCC_FLAGS "--std=c++14")
endif()
endif()
endif()
if(APPLE)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler -fno-finite-math-only)
endif()
if(WIN32 AND NOT (CUDA_VERSION VERSION_LESS "11.2"))
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388)
endif()
if(CMAKE_CROSSCOMPILING AND (ARM OR AARCH64))
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xlinker --unresolved-symbols=ignore-in-shared-libs)
endif()
# disabled because of multiple warnings during building nvcc auto generated files
if(CV_GCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.6.0")
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wunused-but-set-variable)
endif()
CUDA_COMPILE(${VAR} ${ARGN})
foreach(var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG)
set(${var} "${${var}_backup_in_cuda_compile_}")
unset(${var}_backup_in_cuda_compile_)
endforeach()
endmacro()
else()
unset(CUDA_ARCH_BIN CACHE) unset(CUDA_ARCH_BIN CACHE)
unset(CUDA_ARCH_PTX CACHE) unset(CUDA_ARCH_PTX CACHE)
return()
endif() endif()
unset(CUDA_nvcuvenc_LIBRARY CACHE)
set(HAVE_CUDA 1)
if(NOT CUDA_VERSION VERSION_LESS 11.0)
# CUDA 11.0 removes nppicom
ocv_list_filterout(CUDA_nppi_LIBRARY "nppicom")
ocv_list_filterout(CUDA_npp_LIBRARY "nppicom")
endif()
if(WITH_CUFFT)
set(HAVE_CUFFT 1)
endif()
if(WITH_CUBLAS)
set(HAVE_CUBLAS 1)
endif()
if(WITH_CUDNN)
set(CMAKE_MODULE_PATH "${OpenCV_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
find_host_package(CUDNN "${MIN_VER_CUDNN}")
list(REMOVE_AT CMAKE_MODULE_PATH 0)
if(CUDNN_FOUND)
set(HAVE_CUDNN 1)
endif()
endif()
include(cmake/OpenCVDetectCUDAUtils.cmake)
if(WITH_NVCUVID OR WITH_NVCUVENC)
set(cuda_toolkit_dirs "${CUDA_TOOLKIT_TARGET_DIR}" "${CUDA_TOOLKIT_ROOT_DIR}")
ocv_check_for_nvidia_video_codec_sdk("${cuda_toolkit_dirs}")
endif()
message(STATUS "CUDA detected: " ${CUDA_VERSION})
ocv_set_cuda_detection_nvcc_flags(CUDA_HOST_COMPILER)
ocv_set_cuda_arch_bin_and_ptx(${CUDA_NVCC_EXECUTABLE})
# NVCC flags to be set
set(NVCC_FLAGS_EXTRA "")
# These vars will be passed into the templates
set(OPENCV_CUDA_ARCH_BIN "")
set(OPENCV_CUDA_ARCH_PTX "")
set(OPENCV_CUDA_ARCH_FEATURES "")
# Tell NVCC to add binaries for the specified GPUs
string(REGEX MATCHALL "[0-9()]+" ARCH_LIST "${ARCH_BIN_NO_POINTS}")
foreach(ARCH IN LISTS ARCH_LIST)
if(ARCH MATCHES "([0-9]+)\\(([0-9]+)\\)")
# User explicitly specified PTX for the concrete BIN
set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -gencode arch=compute_${CMAKE_MATCH_2},code=sm_${CMAKE_MATCH_1})
set(OPENCV_CUDA_ARCH_BIN "${OPENCV_CUDA_ARCH_BIN} ${CMAKE_MATCH_1}")
set(OPENCV_CUDA_ARCH_FEATURES "${OPENCV_CUDA_ARCH_FEATURES} ${CMAKE_MATCH_2}")
else()
# User didn't explicitly specify PTX for the concrete BIN, we assume PTX=BIN
set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -gencode arch=compute_${ARCH},code=sm_${ARCH})
set(OPENCV_CUDA_ARCH_BIN "${OPENCV_CUDA_ARCH_BIN} ${ARCH}")
set(OPENCV_CUDA_ARCH_FEATURES "${OPENCV_CUDA_ARCH_FEATURES} ${ARCH}")
endif()
endforeach()
set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -D_FORCE_INLINES)
# Tell NVCC to add PTX intermediate code for the specified architectures
string(REGEX MATCHALL "[0-9]+" ARCH_LIST "${ARCH_PTX_NO_POINTS}")
foreach(ARCH IN LISTS ARCH_LIST)
set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -gencode arch=compute_${ARCH},code=compute_${ARCH})
set(OPENCV_CUDA_ARCH_PTX "${OPENCV_CUDA_ARCH_PTX} ${ARCH}")
set(OPENCV_CUDA_ARCH_FEATURES "${OPENCV_CUDA_ARCH_FEATURES} ${ARCH}")
endforeach()
# These vars will be processed in other scripts
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} ${NVCC_FLAGS_EXTRA})
set(OpenCV_CUDA_CC "${NVCC_FLAGS_EXTRA}")
if(ANDROID)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-Xptxas;-dlcm=ca")
endif()
ocv_set_nvcc_threads_for_vs()
message(STATUS "CUDA: NVCC target flags ${CUDA_NVCC_FLAGS}")
OCV_OPTION(CUDA_FAST_MATH "Enable --use_fast_math for CUDA compiler " OFF)
if(CUDA_FAST_MATH)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --use_fast_math)
endif()
OCV_OPTION(CUDA_ENABLE_DELAYLOAD "Enable delayed loading of CUDA DLLs" OFF VISIBLE_IF MSVC)
mark_as_advanced(CUDA_BUILD_CUBIN CUDA_BUILD_EMULATION CUDA_VERBOSE_BUILD CUDA_SDK_ROOT_DIR)
macro(ocv_check_windows_crt_linkage)
# The new MSVC runtime abstraction is only useable if CUDA is a first class language
if(WIN32 AND POLICY CMP0091)
cmake_policy(GET CMP0091 MSVC_RUNTIME_SET_BY_ABSTRACTION)
if(MSVC_RUNTIME_SET_BY_ABSTRACTION STREQUAL "NEW")
if(NOT BUILD_SHARED_LIBS AND BUILD_WITH_STATIC_CRT)
set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} " /MT")
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} " /MTd")
else()
set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} " /MD")
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} " /MDd")
endif()
endif()
endif()
endmacro()
macro(ocv_cuda_compile VAR)
ocv_cuda_filter_options()
ocv_check_windows_crt_linkage()
ocv_nvcc_flags()
if(UNIX OR APPLE)
if(NOT " ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_DEBUG} ${CUDA_NVCC_FLAGS}" MATCHES "-std=")
if(CUDA_VERSION VERSION_LESS "11.0")
list(APPEND CUDA_NVCC_FLAGS "--std=c++11")
else()
list(APPEND CUDA_NVCC_FLAGS "--std=c++14")
endif()
endif()
endif()
CUDA_COMPILE(${VAR} ${ARGN})
foreach(var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG)
set(${var} "${${var}_backup_in_cuda_compile_}")
unset(${var}_backup_in_cuda_compile_)
endforeach()
endmacro()
if(HAVE_CUDA) if(HAVE_CUDA)
set(CUDA_LIBS_PATH "") set(CUDA_LIBS_PATH "")
foreach(p ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY}) foreach(p ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY})
@@ -225,13 +516,36 @@ if(HAVE_CUDA)
endif() endif()
endif() endif()
if(HAVE_CUDA)
ocv_apply_cuda_stub_workaround("${CUDA_CUDA_LIBRARY}")
ocv_check_cuda_delayed_load("${CUDA_TOOLKIT_ROOT_DIR}")
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# Add CUDA libraries (needed for apps/tools, samples) # Add CUDA libraries (needed for apps/tools, samples)
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
if(HAVE_CUDA)
# details: https://github.com/NVIDIA/nvidia-docker/issues/775
if(" ${CUDA_CUDA_LIBRARY}" MATCHES "/stubs/libcuda.so" AND NOT OPENCV_SKIP_CUDA_STUB_WORKAROUND)
set(CUDA_STUB_ENABLED_LINK_WORKAROUND 1)
if(EXISTS "${CUDA_CUDA_LIBRARY}" AND NOT OPENCV_SKIP_CUDA_STUB_WORKAROUND_RPATH_LINK)
set(CUDA_STUB_TARGET_PATH "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/")
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${CUDA_CUDA_LIBRARY}" "${CUDA_STUB_TARGET_PATH}/libcuda.so.1"
RESULT_VARIABLE CUDA_STUB_SYMLINK_RESULT)
if(NOT CUDA_STUB_SYMLINK_RESULT EQUAL 0)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CUDA_CUDA_LIBRARY}" "${CUDA_STUB_TARGET_PATH}/libcuda.so.1"
RESULT_VARIABLE CUDA_STUB_COPY_RESULT)
if(NOT CUDA_STUB_COPY_RESULT EQUAL 0)
set(CUDA_STUB_ENABLED_LINK_WORKAROUND 0)
endif()
endif()
if(CUDA_STUB_ENABLED_LINK_WORKAROUND)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath-link,\"${CUDA_STUB_TARGET_PATH}\"")
endif()
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--allow-shlib-undefined")
endif()
if(NOT CUDA_STUB_ENABLED_LINK_WORKAROUND)
message(WARNING "CUDA: workaround for stubs/libcuda.so.1 is not applied")
endif()
endif()
set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY}) set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY})
if(HAVE_CUBLAS) if(HAVE_CUBLAS)
set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${CUDA_cublas_LIBRARY}) set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${CUDA_cublas_LIBRARY})
@@ -249,4 +563,19 @@ if(HAVE_CUDA)
set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${CMAKE_LIBRARY_PATH_FLAG}${p}) set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${CMAKE_LIBRARY_PATH_FLAG}${p})
endif() endif()
endforeach() endforeach()
if(MSVC AND CUDA_ENABLE_DELAYLOAD)
set(DELAYFLAGS "delayimp.lib")
file(GLOB CUDA_DLLS "${CUDA_TOOLKIT_ROOT_DIR}/bin/*.dll")
foreach(d ${CUDA_DLLS})
cmake_path(GET "d" FILENAME DLL_NAME)
if(NOT ${DLL_NAME} MATCHES "cudart")
set(DELAYFLAGS "${DELAYFLAGS} /DELAYLOAD:${DLL_NAME}")
endif()
endforeach()
set(DELAYFLAGS "${DELAYFLAGS} /DELAYLOAD:nvcuda.dll /DELAYLOAD:nvml.dll /IGNORE:4199")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${DELAYFLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${DELAYFLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${DELAYFLAGS}")
endif()
endif() endif()
-154
View File
@@ -1,154 +0,0 @@
#######################
# Previously in FindCUDA and still required for FindCUDNN
macro(FIND_CUDA_HELPER_LIBS _name)
if(CMAKE_CROSSCOMPILING AND (ARM OR AARCH64))
set(_cuda_cross_arm_lib_dir "lib/stubs")
endif()
find_library(CUDA_${_name}_LIBRARY ${_name}
NAMES ${_name}
PATHS "${CUDAToolkit_LIBRARY_ROOT}"
PATH_SUFFIXES "lib/x64" "lib64" ${_cuda_cross_arm_lib_dir} "lib/Win32" "lib"
DOC "\"${_name}\" library"
)
mark_as_advanced(CUDA_${_name}_LIBRARY)
endmacro()
#######################
include(cmake/OpenCVDetectCUDAUtils.cmake)
if((WIN32 AND NOT MSVC) OR OPENCV_CMAKE_FORCE_CUDA)
message(STATUS "CUDA: Compilation is disabled (due to only Visual Studio compiler supported on your platform).")
return()
endif()
if((NOT UNIX AND CV_CLANG) OR OPENCV_CMAKE_FORCE_CUDA)
message(STATUS "CUDA: Compilation is disabled (due to Clang unsupported on your platform).")
return()
endif()
#set(OPENCV_CMAKE_CUDA_DEBUG 1)
find_package(CUDAToolkit)
if(CMAKE_CUDA_COMPILER AND CUDAToolkit_FOUND)
set(CUDA_FOUND TRUE)
set(CUDA_TOOLKIT_INCLUDE ${CUDAToolkit_INCLUDE_DIRS})
set(CUDA_VERSION_STRING ${CUDAToolkit_VERSION})
set(CUDA_VERSION ${CUDAToolkit_VERSION})
if(NOT CUDA_VERSION VERSION_LESS 11.0)
set(CMAKE_CUDA_STANDARD 14)
else()
set(CMAKE_CUDA_STANDARD 11)
endif()
if(UNIX AND NOT BUILD_SHARED_LIBS)
set(CUDA_LIB_EXT "_static")
endif()
endif()
if(NOT CUDA_FOUND)
unset(CUDA_ARCH_BIN CACHE)
unset(CUDA_ARCH_PTX CACHE)
return()
endif()
set(HAVE_CUDA 1)
if(WITH_CUFFT)
set(HAVE_CUFFT 1)
endif()
if(WITH_CUBLAS)
set(HAVE_CUBLAS 1)
endif()
if(WITH_CUDNN)
set(CMAKE_MODULE_PATH "${OpenCV_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
find_host_package(CUDNN "${MIN_VER_CUDNN}")
list(REMOVE_AT CMAKE_MODULE_PATH 0)
if(CUDNN_FOUND)
set(HAVE_CUDNN 1)
endif()
endif()
if(WITH_NVCUVID OR WITH_NVCUVENC)
ocv_check_for_nvidia_video_codec_sdk("${CUDAToolkit_LIBRARY_ROOT}")
endif()
ocv_check_for_cmake_cuda_architectures()
ocv_set_cuda_detection_nvcc_flags(CMAKE_CUDA_HOST_COMPILER)
ocv_set_cuda_arch_bin_and_ptx(${CUDAToolkit_NVCC_EXECUTABLE})
# NVCC flags to be set
set(NVCC_FLAGS_EXTRA "")
# These vars will be passed into the templates
set(OPENCV_CUDA_ARCH_BIN "")
set(OPENCV_CUDA_ARCH_PTX "")
set(OPENCV_CUDA_ARCH_FEATURES "")
# Tell NVCC to add binaries for the specified GPUs
string(REGEX MATCHALL "[0-9()]+" ARCH_LIST "${ARCH_BIN_NO_POINTS}")
foreach(ARCH IN LISTS ARCH_LIST)
if(ARCH MATCHES "([0-9]+)\\(([0-9]+)\\)")
# User explicitly specified PTX for the concrete BIN
set(CMAKE_CUDA_ARCHITECTURES ${CMAKE_CUDA_ARCHITECTURES} ${CMAKE_MATCH_2}-virtual;${CMAKE_MATCH_1}-real;)
set(OPENCV_CUDA_ARCH_BIN "${OPENCV_CUDA_ARCH_BIN} ${CMAKE_MATCH_1}")
set(OPENCV_CUDA_ARCH_FEATURES "${OPENCV_CUDA_ARCH_FEATURES} ${CMAKE_MATCH_2}")
else()
# User didn't explicitly specify PTX for the concrete BIN, we assume PTX=BIN
set(CMAKE_CUDA_ARCHITECTURES ${CMAKE_CUDA_ARCHITECTURES} ${ARCH}-real;)
set(OPENCV_CUDA_ARCH_BIN "${OPENCV_CUDA_ARCH_BIN} ${ARCH}")
set(OPENCV_CUDA_ARCH_FEATURES "${OPENCV_CUDA_ARCH_FEATURES} ${ARCH}")
endif()
endforeach()
set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -D_FORCE_INLINES)
# Tell NVCC to add PTX intermediate code for the specified architectures
string(REGEX MATCHALL "[0-9]+" ARCH_LIST "${ARCH_PTX_NO_POINTS}")
foreach(ARCH IN LISTS ARCH_LIST)
set(CMAKE_CUDA_ARCHITECTURES ${CMAKE_CUDA_ARCHITECTURES} ${ARCH}-virtual;)
set(OPENCV_CUDA_ARCH_PTX "${OPENCV_CUDA_ARCH_PTX} ${ARCH}")
set(OPENCV_CUDA_ARCH_FEATURES "${OPENCV_CUDA_ARCH_FEATURES} ${ARCH}")
endforeach()
ocv_set_nvcc_threads_for_vs()
# These vars will be processed in other scripts
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} ${NVCC_FLAGS_EXTRA})
set(OpenCV_CUDA_CC "${CMAKE_CUDA_ARCHITECTURES}")
if(ANDROID)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-Xptxas;-dlcm=ca")
endif()
message(STATUS "CUDA: NVCC target flags ${CUDA_NVCC_FLAGS}")
OCV_OPTION(CUDA_FAST_MATH "Enable --use_fast_math for CUDA compiler " OFF)
if(CUDA_FAST_MATH)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --use_fast_math)
endif()
OCV_OPTION(CUDA_ENABLE_DELAYLOAD "Enable delayed loading of CUDA DLLs" OFF VISIBLE_IF MSVC)
mark_as_advanced(CUDA_BUILD_CUBIN CUDA_BUILD_EMULATION CUDA_VERBOSE_BUILD CUDA_SDK_ROOT_DIR)
macro(ocv_cuda_unfilter_options)
foreach(var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG)
set(${var} "${${var}_backup_in_cuda_compile_}")
unset(${var}_backup_in_cuda_compile_)
endforeach()
endmacro()
macro(ocv_cuda_compile_flags)
ocv_cuda_filter_options()
ocv_nvcc_flags()
set(CMAKE_CXX_FLAGS_CUDA ${CMAKE_CXX_FLAGS})
set(CMAKE_CXX_FLAGS_RELEASE_CUDA ${CMAKE_CXX_FLAGS_RELEASE})
set(CMAKE_CXX_FLAGS_DEBUG_CUDA ${CMAKE_CXX_FLAGS_DEBUG})
ocv_cuda_unfilter_options()
endmacro()
if(HAVE_CUDA)
ocv_apply_cuda_stub_workaround("${CUDA_cuda_driver_LIBRARY}")
ocv_check_cuda_delayed_load("${cuda_toolkit_root_dir}")
endif()
-442
View File
@@ -1,442 +0,0 @@
macro(ocv_check_for_nvidia_video_codec_sdk cuda_toolkit_dirs)
macro(ocv_cuda_SEARCH_NVCUVID_HEADER _filename _result)
# place header file under CUDAToolkit_LIBRARY_ROOT
find_path(_header_result
${_filename}
PATHS ${cuda_toolkit_dirs}
PATH_SUFFIXES include
NO_DEFAULT_PATH
)
if("x${_header_result}" STREQUAL "x_header_result-NOTFOUND")
set(${_result} 0)
else()
set(${_result} 1)
endif()
unset(_header_result CACHE)
endmacro()
if(WITH_NVCUVID)
ocv_cuda_SEARCH_NVCUVID_HEADER("nvcuvid.h" HAVE_NVCUVID_HEADER)
# make sure to have both header and library before enabling
if(${HAVE_NVCUVID_HEADER})
find_cuda_helper_libs(nvcuvid)
if(CUDA_nvcuvid_LIBRARY)
set(HAVE_NVCUVID 1)
message(STATUS "Found NVCUVID: ${CUDA_nvcuvid_LIBRARY}")
else()
if(WIN32)
message(STATUS "NVCUVID: Library not found, WITH_NVCUVID requires Nvidia decoding library nvcuvid.lib to either be inside ${cuda_toolkit_dirs}/lib or its location manually set with CUDA_nvcuvid_LIBRARY, i.e. CUDA_nvcuvid_LIBRARY=${cuda_toolkit_dirs}/lib/nvcuvid.lib")
else()
message(STATUS "NVCUVID: Library not found, WITH_NVCUVID requires the Nvidia decoding shared library nvcuvid.so from the driver installation or the location of the stub library to be manually set with CUDA_nvcuvid_LIBRARY i.e. CUDA_nvcuvid_LIBRARY=/home/user/Video_Codec_SDK_X.X.X/Lib/linux/stubs/x86_64/nvcuvid.so")
endif()
endif()
else()
message(STATUS "NVCUVID: Header not found, WITH_NVCUVID requires Nvidia decoding library header ${cuda_toolkit_dirs}/include/nvcuvid.h")
endif()
endif()
if(WITH_NVCUVENC)
ocv_cuda_SEARCH_NVCUVID_HEADER("nvEncodeAPI.h" HAVE_NVCUVENC_HEADER)
if(${HAVE_NVCUVENC_HEADER})
if(WIN32)
find_cuda_helper_libs(nvencodeapi)
else()
find_cuda_helper_libs(nvidia-encode)
endif()
if(CUDA_nvencodeapi_LIBRARY OR CUDA_nvidia-encode_LIBRARY)
set(HAVE_NVCUVENC 1)
message(STATUS "Found NVCUVENC: ${CUDA_nvencodeapi_LIBRARY} ${CUDA_nvidia-encode_LIBRARY}")
else()
if(WIN32)
message(STATUS "NVCUVENC: Library not found, WITH_NVCUVENC requires Nvidia encoding library nvencodeapi.lib to either be inside ${cuda_toolkit_dirs}/lib or its location manually set with CUDA_nvencodeapi_LIBRARY, i.e. CUDA_nvencodeapi_LIBRARY=${cuda_toolkit_dirs}/lib/nvencodeapi.lib")
else()
message(STATUS "NVCUVENC: Library not found, WITH_NVCUVENC requires the Nvidia encoding shared library libnvidia-encode.so from the driver installation or the location of the stub library to be manually set with CUDA_nvidia-encode_LIBRARY i.e. CUDA_nvidia-encode_LIBRARY=/home/user/Video_Codec_SDK_X.X.X/Lib/linux/stubs/x86_64/libnvidia-encode.so")
endif()
endif()
else()
message(STATUS "NVCUVENC: Header not found, WITH_NVCUVENC requires Nvidia encoding library header ${cuda_toolkit_dirs}/include/nvEncodeAPI.h")
endif()
endif()
endmacro()
# Use CMAKE_CUDA_ARCHITECTURES if provided: order of preference CMAKE_CUDA_ARCHITECTURES > CUDA_GENERATION > CUDA_ARCH_BIN and/or CUDA_ARCH_PTX
function(ocv_check_for_cmake_cuda_architectures)
if(NOT CMAKE_CUDA_ARCHITECTURES)
return()
endif()
if(CMAKE_CUDA_ARCHITECTURES STREQUAL "all" OR CMAKE_CUDA_ARCHITECTURES STREQUAL "all-major" OR CMAKE_CUDA_ARCHITECTURES STREQUAL "native")
message(WARNING "CUDA: CMAKE_CUDA_ARCHITECTURES=${CMAKE_CUDA_ARCHITECTURES}, special values all, all-major and native are not supported by OpenCV, specify only CUDA real and/or virtual architectures or use combinations of CUDA_ARCH_BIN and CUDA_ARCH_PTX or specify the CUDA_GENERATION where -DCUDA_GENERATION=Auto is equivalent to native!")
return()
endif()
set(internal_ptx "")
set(internal_bin "")
foreach(ARCH IN LISTS CMAKE_CUDA_ARCHITECTURES)
if(ARCH MATCHES "([0-9]+)\-real")
set(internal_bin ${internal_bin} ${CMAKE_MATCH_1};)
elseif(ARCH MATCHES "([0-9]+)\-virtual")
set(internal_ptx ${internal_ptx} ${CMAKE_MATCH_1};)
elseif(ARCH MATCHES "([0-9]+)")
set(internal_bin ${internal_bin} ${CMAKE_MATCH_1};)
set(internal_ptx ${internal_ptx} ${CMAKE_MATCH_1};)
endif()
endforeach()
if(internal_bin OR internal_ptx)
unset(CUDA_ARCH_BIN CACHE)
unset(CUDA_ARCH_PTX CACHE)
endif()
if(internal_ptx)
set(CUDA_ARCH_PTX ${internal_ptx} CACHE STRING "Specify 'virtual' PTX architectures to build PTX intermediate code for (see https://docs.opencv.org/4.x/d2/dbc/cuda_intro.html)")
endif()
if(internal_bin)
set(CUDA_ARCH_BIN ${internal_bin} CACHE STRING "Specify 'real' GPU architectures to build binaries for, BIN(PTX) format is supported (see https://docs.opencv.org/4.x/d2/dbc/cuda_intro.html)")
endif()
set(CMAKE_CUDA_ARCHITECTURES "" PARENT)
unset(CUDA_GENERATION CACHE)
endfunction()
macro(ocv_initialize_nvidia_device_generations)
OCV_OPTION(CUDA_ENABLE_DEPRECATED_GENERATION "Enable deprecated generations in the list" OFF)
set(_generations "Maxwell" "Pascal" "Volta" "Turing" "Ampere" "Lovelace" "Hopper")
if(CUDA_ENABLE_DEPRECATED_GENERATION)
set(_generations "Fermi" "${_generations}")
set(_generations "Kepler" "${_generations}")
endif()
set(_arch_fermi "2.0")
set(_arch_kepler "3.0;3.5;3.7")
set(_arch_maxwell "5.0;5.2")
set(_arch_pascal "6.0;6.1")
set(_arch_volta "7.0")
set(_arch_turing "7.5")
set(_arch_ampere "8.0;8.6")
set(_arch_lovelace "8.9")
set(_arch_hopper "9.0")
if(NOT CMAKE_CROSSCOMPILING)
list(APPEND _generations "Auto")
endif()
set(CUDA_GENERATION "" CACHE STRING "Build CUDA device code only for specific GPU architecture. Leave empty to build for all architectures (see https://docs.opencv.org/4.x/d2/dbc/cuda_intro.html).")
if( CMAKE_VERSION VERSION_GREATER "2.8" )
set_property( CACHE CUDA_GENERATION PROPERTY STRINGS "" ${_generations} )
endif()
if(CUDA_GENERATION)
if(NOT ";${_generations};" MATCHES ";${CUDA_GENERATION};")
string(REPLACE ";" ", " _generations "${_generations}")
message(FATAL_ERROR "ERROR: ${_generations} Generations are supported.")
endif()
unset(CUDA_ARCH_BIN CACHE)
unset(CUDA_ARCH_PTX CACHE)
endif()
endmacro()
macro(ocv_set_cuda_detection_nvcc_flags cuda_host_compiler_var)
if(OPENCV_CUDA_DETECTION_NVCC_FLAGS MATCHES "-ccbin")
# already specified by user
elseif(${cuda_host_compiler_var} AND EXISTS "${${cuda_host_compiler_var}}")
get_filename_component(c_compiler_realpath "${CMAKE_C_COMPILER}" REALPATH)
# C compiler doesn't work with --run option, forcing C++ compiler instead
if(${cuda_host_compiler_var} STREQUAL c_compiler_realpath OR ${cuda_host_compiler_var} STREQUAL CMAKE_C_COMPILER)
if(DEFINED CMAKE_CXX_COMPILER)
get_filename_component(cxx_compiler_realpath "${CMAKE_CXX_COMPILER}" REALPATH)
LIST(APPEND OPENCV_CUDA_DETECTION_NVCC_FLAGS -ccbin "${cxx_compiler_realpath}")
else()
message(STATUS "CUDA: CMAKE_CXX_COMPILER is not available. You may need to specify ${cuda_host_compiler_var}.")
endif()
else()
LIST(APPEND OPENCV_CUDA_DETECTION_NVCC_FLAGS -ccbin "${${cuda_host_compiler_var}}")
endif()
elseif(WIN32 AND CMAKE_LINKER) # Workaround for VS cl.exe not being in the env. path
get_filename_component(host_compiler_bindir ${CMAKE_LINKER} DIRECTORY)
LIST(APPEND OPENCV_CUDA_DETECTION_NVCC_FLAGS -ccbin "${host_compiler_bindir}")
else()
if(${cuda_host_compiler_var})
message(STATUS "CUDA: ${cuda_host_compiler_var}='${cuda_host_compiler}' is not valid, autodetection may not work. Specify OPENCV_CUDA_DETECTION_NVCC_FLAGS with -ccbin option for fix that")
endif()
endif()
endmacro()
macro(ocv_filter_available_architecture nvcc_executable result_list)
set(__cache_key_check "${ARGN} : ${nvcc_executable} ${OPENCV_CUDA_DETECTION_NVCC_FLAGS}")
if(DEFINED OPENCV_CACHE_CUDA_SUPPORTED_CC AND OPENCV_CACHE_CUDA_SUPPORTED_CC_check STREQUAL __cache_key_check)
set(${result_list} "${OPENCV_CACHE_CUDA_SUPPORTED_CC}")
else()
set(CC_LIST ${ARGN})
foreach(target_arch ${CC_LIST})
string(REPLACE "." "" target_arch_short "${target_arch}")
set(NVCC_OPTION "-gencode;arch=compute_${target_arch_short},code=sm_${target_arch_short}")
set(_cmd "${nvcc_executable}" ${OPENCV_CUDA_DETECTION_NVCC_FLAGS} ${NVCC_OPTION} "${OpenCV_SOURCE_DIR}/cmake/checks/OpenCVDetectCudaArch.cu" --compile)
execute_process(
COMMAND ${_cmd}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/"
RESULT_VARIABLE _nvcc_res
OUTPUT_VARIABLE _nvcc_out
ERROR_VARIABLE _nvcc_err
#ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(OPENCV_CMAKE_CUDA_DEBUG)
message(WARNING "COMMAND: ${_cmd}")
message(STATUS "Result: ${_nvcc_res}")
message(STATUS "Out: ${_nvcc_out}")
message(STATUS "Err: ${_nvcc_err}")
endif()
if(_nvcc_res EQUAL 0)
LIST(APPEND ${result_list} "${target_arch}")
endif()
endforeach()
string(STRIP "${${result_list}}" ${result_list})
if(" ${${result_list}}" STREQUAL " ")
message(WARNING "CUDA: Autodetection arch list is empty. Please enable OPENCV_CMAKE_CUDA_DEBUG=1 and check/specify OPENCV_CUDA_DETECTION_NVCC_FLAGS variable")
endif()
# cache detected values
set(OPENCV_CACHE_CUDA_SUPPORTED_CC ${${result_list}} CACHE INTERNAL "")
set(OPENCV_CACHE_CUDA_SUPPORTED_CC_check "${__cache_key_check}" CACHE INTERNAL "")
endif()
endmacro()
macro(ocv_detect_native_cuda_arch nvcc_executable status output)
set(OPENCV_CUDA_DETECT_ARCHS_COMMAND "${nvcc_executable}" ${OPENCV_CUDA_DETECTION_NVCC_FLAGS} "${OpenCV_SOURCE_DIR}/cmake/checks/OpenCVDetectCudaArch.cu" "--run")
set(__cache_key_check "${OPENCV_CUDA_DETECT_ARCHS_COMMAND}")
if(DEFINED OPENCV_CACHE_CUDA_ACTIVE_CC AND OPENCV_CACHE_CUDA_ACTIVE_CC_check STREQUAL __cache_key_check)
set(${output} "${OPENCV_CACHE_CUDA_ACTIVE_CC}")
set(${status} 0)
else()
execute_process(
COMMAND ${OPENCV_CUDA_DETECT_ARCHS_COMMAND}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/"
RESULT_VARIABLE ${status}
OUTPUT_VARIABLE _nvcc_out
ERROR_VARIABLE _nvcc_err
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(OPENCV_CMAKE_CUDA_DEBUG)
message(WARNING "COMMAND: ${OPENCV_CUDA_DETECT_ARCHS_COMMAND}")
message(STATUS "Result: ${${status}}")
message(STATUS "Out: ${_nvcc_out}")
message(STATUS "Err: ${_nvcc_err}")
endif()
string(REGEX REPLACE ".*\n" "" ${output} "${_nvcc_out}") #Strip leading warning messages, if any
if(${status} EQUAL 0)
# cache detected values
set(OPENCV_CACHE_CUDA_ACTIVE_CC ${${output}} CACHE INTERNAL "")
set(OPENCV_CACHE_CUDA_ACTIVE_CC_check "${__cache_key_check}" CACHE INTERNAL "")
endif()
endif()
endmacro()
macro(ocv_set_cuda_arch_bin_and_ptx nvcc_executable)
ocv_initialize_nvidia_device_generations()
set(__cuda_arch_ptx ${CUDA_ARCH_PTX})
if(CUDA_GENERATION STREQUAL "Fermi")
set(__cuda_arch_bin ${_arch_fermi})
elseif(CUDA_GENERATION STREQUAL "Kepler")
set(__cuda_arch_bin ${_arch_kepler})
elseif(CUDA_GENERATION STREQUAL "Maxwell")
set(__cuda_arch_bin ${_arch_maxwell})
elseif(CUDA_GENERATION STREQUAL "Pascal")
set(__cuda_arch_bin ${_arch_pascal})
elseif(CUDA_GENERATION STREQUAL "Volta")
set(__cuda_arch_bin ${_arch_volta})
elseif(CUDA_GENERATION STREQUAL "Turing")
set(__cuda_arch_bin ${_arch_turing})
elseif(CUDA_GENERATION STREQUAL "Ampere")
set(__cuda_arch_bin ${_arch_ampere})
elseif(CUDA_GENERATION STREQUAL "Lovelace")
set(__cuda_arch_bin ${_arch_lovelace})
elseif(CUDA_GENERATION STREQUAL "Hopper")
set(__cuda_arch_bin ${_arch_hopper})
elseif(CUDA_GENERATION STREQUAL "Auto")
ocv_detect_native_cuda_arch(${nvcc_executable} _nvcc_res _nvcc_out)
if(NOT _nvcc_res EQUAL 0)
message(STATUS "CUDA: Automatic detection of CUDA generation failed. Going to build for all known architectures")
else()
string(REGEX MATCHALL "[0-9]+\\.[0-9]" __cuda_arch_bin "${_nvcc_out}")
endif()
elseif(CUDA_ARCH_BIN)
message(STATUS "CUDA: Using CUDA_ARCH_BIN=${CUDA_ARCH_BIN}")
set(__cuda_arch_bin ${CUDA_ARCH_BIN})
endif()
if(NOT DEFINED __cuda_arch_bin AND NOT DEFINED __cuda_arch_ptx)
if(ARM)
set(__cuda_arch_bin "3.2")
set(__cuda_arch_ptx "")
elseif(AARCH64)
if(NOT CMAKE_CROSSCOMPILING)
ocv_detect_native_cuda_arch(${nvcc_executable} _nvcc_res _nvcc_out)
else()
set(_nvcc_res -1) # emulate error, see below
endif()
if(NOT _nvcc_res EQUAL 0)
message(STATUS "CUDA: Automatic detection of CUDA generation failed. Going to build for all known architectures")
# TX1 (5.3) TX2 (6.2) Xavier (7.2) V100 (7.0) Orin (8.7)
ocv_filter_available_architecture(${nvcc_executable} __cuda_arch_bin
5.3
6.2
7.2
7.0
8.7
)
else()
set(__cuda_arch_bin "${_nvcc_out}")
endif()
set(__cuda_arch_ptx "")
else()
ocv_filter_available_architecture(${nvcc_executable} __cuda_arch_bin
${_arch_fermi}
${_arch_kepler}
${_arch_maxwell}
${_arch_pascal}
${_arch_volta}
${_arch_turing}
${_arch_ampere}
${_arch_lovelace}
${_arch_hopper}
)
list(GET __cuda_arch_bin -1 __cuda_arch_ptx)
endif()
endif()
set(CUDA_ARCH_BIN ${__cuda_arch_bin} CACHE STRING "Specify 'real' GPU architectures to build binaries for, BIN(PTX) format is supported (see https://docs.opencv.org/4.x/d2/dbc/cuda_intro.html)")
set(CUDA_ARCH_PTX ${__cuda_arch_ptx} CACHE STRING "Specify 'virtual' PTX architectures to build PTX intermediate code for (see https://docs.opencv.org/4.x/d2/dbc/cuda_intro.html)")
string(REGEX REPLACE "\\." "" ARCH_BIN_NO_POINTS "${CUDA_ARCH_BIN}")
string(REGEX REPLACE "\\." "" ARCH_PTX_NO_POINTS "${CUDA_ARCH_PTX}")
# Check if user specified 1.0/2.1 compute capability: we don't support it
macro(ocv_wipeout_deprecated_cc target_cc)
if(" ${CUDA_ARCH_BIN} ${CUDA_ARCH_PTX}" MATCHES " ${target_cc}")
message(SEND_ERROR "CUDA: ${target_cc} compute capability is not supported - exclude it from ARCH/PTX list and re-run CMake")
endif()
endmacro()
ocv_wipeout_deprecated_cc("1.0")
ocv_wipeout_deprecated_cc("2.1")
endmacro()
macro(ocv_set_nvcc_threads_for_vs)
# Tell NVCC the maximum number of threads to be used to execute the compilation steps in parallel
# (option --threads was introduced in version 11.2)
if(NOT CUDA_VERSION VERSION_LESS "11.2")
if(CMAKE_GENERATOR MATCHES "Visual Studio" AND NOT $ENV{CMAKE_BUILD_PARALLEL_LEVEL} STREQUAL "")
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "--threads=$ENV{CMAKE_BUILD_PARALLEL_LEVEL}")
endif()
endif()
endmacro()
macro(ocv_cuda_filter_options)
foreach(var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG)
set(${var}_backup_in_cuda_compile_ "${${var}}")
if (CV_CLANG)
# we remove -Winconsistent-missing-override and -Qunused-arguments
# just in case we are compiling CUDA with gcc but OpenCV with clang
string(REPLACE "-Winconsistent-missing-override" "" ${var} "${${var}}")
string(REPLACE "-Qunused-arguments" "" ${var} "${${var}}")
endif()
# we remove /EHa as it generates warnings under windows
string(REPLACE "/EHa" "" ${var} "${${var}}")
# we remove -ggdb3 flag as it leads to preprocessor errors when compiling CUDA files (CUDA 4.1)
string(REPLACE "-ggdb3" "" ${var} "${${var}}")
# we remove -Wsign-promo as it generates warnings under linux
string(REPLACE "-Wsign-promo" "" ${var} "${${var}}")
# we remove -Wno-sign-promo as it generates warnings under linux
string(REPLACE "-Wno-sign-promo" "" ${var} "${${var}}")
# we remove -Wno-delete-non-virtual-dtor because it's used for C++ compiler
# but NVCC uses C compiler by default
string(REPLACE "-Wno-delete-non-virtual-dtor" "" ${var} "${${var}}")
# we remove -frtti because it's used for C++ compiler
# but NVCC uses C compiler by default
string(REPLACE "-frtti" "" ${var} "${${var}}")
string(REPLACE "-fvisibility-inlines-hidden" "" ${var} "${${var}}")
# cc1: warning: command line option '-Wsuggest-override' is valid for C++/ObjC++ but not for C
string(REPLACE "-Wsuggest-override" "" ${var} "${${var}}")
# issue: #11552 (from OpenCVCompilerOptions.cmake)
string(REGEX REPLACE "-Wimplicit-fallthrough(=[0-9]+)? " "" ${var} "${${var}}")
# removal of custom specified options
if(OPENCV_CUDA_NVCC_FILTEROUT_OPTIONS)
foreach(__flag ${OPENCV_CUDA_NVCC_FILTEROUT_OPTIONS})
string(REPLACE "${__flag}" "" ${var} "${${var}}")
endforeach()
endif()
endforeach()
endmacro()
macro(ocv_nvcc_flags)
if(BUILD_SHARED_LIBS)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler=-DCVAPI_EXPORTS)
endif()
if(UNIX OR APPLE)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler=-fPIC)
endif()
if(APPLE)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler=-fno-finite-math-only)
endif()
if(WIN32 AND NOT (CUDA_VERSION VERSION_LESS "11.2"))
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388)
endif()
if(CMAKE_CROSSCOMPILING AND (ARM OR AARCH64))
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xlinker --unresolved-symbols=ignore-in-shared-libs)
endif()
# disabled because of multiple warnings during building nvcc auto generated files
if(CV_GCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.6.0")
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wunused-but-set-variable)
endif()
endmacro()
macro(ocv_apply_cuda_stub_workaround cuda_driver_library_path)
# details: https://github.com/NVIDIA/nvidia-docker/issues/775
if(" ${cuda_driver_library_path}" MATCHES "/stubs/libcuda.so" AND NOT OPENCV_SKIP_CUDA_STUB_WORKAROUND)
set(CUDA_STUB_ENABLED_LINK_WORKAROUND 1)
if(EXISTS "${cuda_driver_library_path}" AND NOT OPENCV_SKIP_CUDA_STUB_WORKAROUND_RPATH_LINK)
set(CUDA_STUB_TARGET_PATH "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/")
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${cuda_driver_library_path}" "${CUDA_STUB_TARGET_PATH}/libcuda.so.1"
RESULT_VARIABLE CUDA_STUB_SYMLINK_RESULT)
if(NOT CUDA_STUB_SYMLINK_RESULT EQUAL 0)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${cuda_driver_library_path}" "${CUDA_STUB_TARGET_PATH}/libcuda.so.1"
RESULT_VARIABLE CUDA_STUB_COPY_RESULT)
if(NOT CUDA_STUB_COPY_RESULT EQUAL 0)
set(CUDA_STUB_ENABLED_LINK_WORKAROUND 0)
endif()
endif()
if(CUDA_STUB_ENABLED_LINK_WORKAROUND)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath-link,\"${CUDA_STUB_TARGET_PATH}\"")
endif()
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--allow-shlib-undefined")
endif()
if(NOT CUDA_STUB_ENABLED_LINK_WORKAROUND)
message(WARNING "CUDA: Workaround for stubs/libcuda.so.1 is not applied")
endif()
endif()
endmacro()
macro(ocv_check_cuda_delayed_load cuda_toolkit_root_dir)
if(MSVC AND CUDA_ENABLE_DELAYLOAD)
set(DELAYFLAGS "delayimp.lib")
file(GLOB CUDA_DLLS "${cuda_toolkit_root_dir}/bin/*.dll")
foreach(d ${CUDA_DLLS})
cmake_path(GET "d" FILENAME DLL_NAME)
if(NOT ${DLL_NAME} MATCHES "cudart")
set(DELAYFLAGS "${DELAYFLAGS} /DELAYLOAD:${DLL_NAME}")
endif()
endforeach()
set(DELAYFLAGS "${DELAYFLAGS} /DELAYLOAD:nvcuda.dll /DELAYLOAD:nvml.dll /IGNORE:4199")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${DELAYFLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${DELAYFLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${DELAYFLAGS}")
endif()
endmacro()
+14 -17
View File
@@ -28,8 +28,22 @@ if(NOT DEFINED CV_GCC AND CMAKE_CXX_COMPILER_ID MATCHES "GNU")
endif() endif()
if(NOT DEFINED CV_CLANG AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") # Clang or AppleClang (see CMP0025) if(NOT DEFINED CV_CLANG AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") # Clang or AppleClang (see CMP0025)
set(CV_CLANG 1) set(CV_CLANG 1)
set(CMAKE_COMPILER_IS_CLANGCXX 1) # TODO next release: remove this
set(CMAKE_COMPILER_IS_CLANGCC 1) # TODO next release: remove this
endif() endif()
function(access_CMAKE_COMPILER_IS_CLANGCXX)
if(NOT OPENCV_SUPPRESS_DEPRECATIONS)
message(WARNING "DEPRECATED: CMAKE_COMPILER_IS_CLANGCXX support is deprecated in OpenCV.
Consider using:
- CV_GCC # GCC
- CV_CLANG # Clang or AppleClang (see CMP0025)
")
endif()
endfunction()
variable_watch(CMAKE_COMPILER_IS_CLANGCXX access_CMAKE_COMPILER_IS_CLANGCXX)
variable_watch(CMAKE_COMPILER_IS_CLANGCC access_CMAKE_COMPILER_IS_CLANGCXX)
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# Detect Intel ICC compiler # Detect Intel ICC compiler
@@ -54,23 +68,6 @@ if(MSVC AND CMAKE_C_COMPILER MATCHES "icc|icl")
set(CV_ICC __INTEL_COMPILER_FOR_WINDOWS) set(CV_ICC __INTEL_COMPILER_FOR_WINDOWS)
endif() endif()
# ----------------------------------------------------------------------------
# Detect Intel ICXC compiler
# ----------------------------------------------------------------------------
if(UNIX)
if(__INTEL_COMPILER)
set(CV_ICX __INTEL_LLVM_COMPILER)
elseif(CMAKE_C_COMPILER MATCHES "icx")
set(CV_ICX icx_matches_c_compiler)
elseif(CMAKE_CXX_COMPILER MATCHES "icpx")
set(CV_ICX icpx_matches_cxx_compiler)
endif()
endif()
if(MSVC AND CMAKE_CXX_COMPILER MATCHES ".*(dpcpp-cl|dpcpp|icx-cl|icpx|icx)(.exe)?$")
set(CV_ICX __INTEL_LLVM_COMPILER_WINDOWS)
endif()
if(NOT DEFINED CMAKE_CXX_COMPILER_VERSION if(NOT DEFINED CMAKE_CXX_COMPILER_VERSION
AND NOT OPENCV_SUPPRESS_MESSAGE_MISSING_COMPILER_VERSION) AND NOT OPENCV_SUPPRESS_MESSAGE_MISSING_COMPILER_VERSION)
message(WARNING "OpenCV: Compiler version is not available: CMAKE_CXX_COMPILER_VERSION is not set") message(WARNING "OpenCV: Compiler version is not available: CMAKE_CXX_COMPILER_VERSION is not set")
-13
View File
@@ -1,13 +0,0 @@
if(WIN32)
try_compile(__VALID_DIRECTML
"${OpenCV_BINARY_DIR}"
"${OpenCV_SOURCE_DIR}/cmake/checks/directml.cpp"
LINK_LIBRARIES d3d12 dxcore directml
OUTPUT_VARIABLE TRY_OUT
)
if(NOT __VALID_DIRECTML)
message(STATUS "No support for DirectML (d3d12, dxcore, directml libs are required)")
return()
endif()
set(HAVE_DIRECTML ON)
endif()
+5 -11
View File
@@ -175,7 +175,7 @@ if(NOT ${found})
endif() endif()
endif() endif()
if(NOT ANDROID AND NOT IOS AND NOT XROS) if(NOT ANDROID AND NOT IOS)
if(CMAKE_HOST_UNIX) if(CMAKE_HOST_UNIX)
execute_process(COMMAND ${_executable} -c "from sysconfig import *; print(get_path('purelib'))" execute_process(COMMAND ${_executable} -c "from sysconfig import *; print(get_path('purelib'))"
RESULT_VARIABLE _cvpy_process RESULT_VARIABLE _cvpy_process
@@ -216,7 +216,7 @@ if(NOT ${found})
message(STATUS " PYTHON3_NUMPY_INCLUDE_DIRS") message(STATUS " PYTHON3_NUMPY_INCLUDE_DIRS")
else() else()
# Attempt to discover the NumPy include directory. If this succeeds, then build python API with NumPy # Attempt to discover the NumPy include directory. If this succeeds, then build python API with NumPy
execute_process(COMMAND "${_executable}" -c "import numpy; print(numpy.get_include())" execute_process(COMMAND "${_executable}" -c "import os; os.environ['DISTUTILS_USE_SDK']='1'; import numpy.distutils; print(os.pathsep.join(numpy.distutils.misc_util.get_numpy_include_dirs()))"
RESULT_VARIABLE _numpy_process RESULT_VARIABLE _numpy_process
OUTPUT_VARIABLE _numpy_include_dirs OUTPUT_VARIABLE _numpy_include_dirs
OUTPUT_STRIP_TRAILING_WHITESPACE) OUTPUT_STRIP_TRAILING_WHITESPACE)
@@ -240,7 +240,7 @@ if(NOT ${found})
OUTPUT_STRIP_TRAILING_WHITESPACE) OUTPUT_STRIP_TRAILING_WHITESPACE)
endif() endif()
endif() endif()
endif(NOT ANDROID AND NOT IOS AND NOT XROS) endif(NOT ANDROID AND NOT IOS)
endif() endif()
# Export return values # Export return values
@@ -258,7 +258,7 @@ if(NOT ${found})
set(${include_path} "${_include_path}" CACHE INTERNAL "") set(${include_path} "${_include_path}" CACHE INTERNAL "")
set(${include_dir} "${_include_dir}" CACHE PATH "Python include dir") set(${include_dir} "${_include_dir}" CACHE PATH "Python include dir")
set(${include_dir2} "${_include_dir2}" CACHE PATH "Python include dir 2") set(${include_dir2} "${_include_dir2}" CACHE PATH "Python include dir 2")
set(${packages_path} "${_packages_path}" CACHE STRING "Where to install the python packages.") set(${packages_path} "${_packages_path}" CACHE PATH "Where to install the python packages.")
set(${numpy_include_dirs} ${_numpy_include_dirs} CACHE PATH "Path to numpy headers") set(${numpy_include_dirs} ${_numpy_include_dirs} CACHE PATH "Path to numpy headers")
set(${numpy_version} "${_numpy_version}" CACHE INTERNAL "") set(${numpy_version} "${_numpy_version}" CACHE INTERNAL "")
endif() endif()
@@ -268,19 +268,13 @@ if(OPENCV_PYTHON_SKIP_DETECTION)
return() return()
endif() endif()
ocv_check_environment_variables(OPENCV_ENABLE_PYTHON2) find_python("" "${MIN_VER_PYTHON2}" PYTHON2_LIBRARY PYTHON2_INCLUDE_DIR
ocv_check_environment_variables(PYTHON2_EXECUTABLE)
if((OPENCV_ENABLE_PYTHON2 OR PYTHON2_EXECUTABLE OR BUILD_opencv_python2)
AND NOT OPENCV_PYTHON2_SKIP_DETECTION
)
find_python("" "${MIN_VER_PYTHON2}" PYTHON2_LIBRARY PYTHON2_INCLUDE_DIR
PYTHON2INTERP_FOUND PYTHON2_EXECUTABLE PYTHON2_VERSION_STRING PYTHON2INTERP_FOUND PYTHON2_EXECUTABLE PYTHON2_VERSION_STRING
PYTHON2_VERSION_MAJOR PYTHON2_VERSION_MINOR PYTHON2LIBS_FOUND PYTHON2_VERSION_MAJOR PYTHON2_VERSION_MINOR PYTHON2LIBS_FOUND
PYTHON2LIBS_VERSION_STRING PYTHON2_LIBRARIES PYTHON2_LIBRARY PYTHON2LIBS_VERSION_STRING PYTHON2_LIBRARIES PYTHON2_LIBRARY
PYTHON2_DEBUG_LIBRARIES PYTHON2_LIBRARY_DEBUG PYTHON2_INCLUDE_PATH PYTHON2_DEBUG_LIBRARIES PYTHON2_LIBRARY_DEBUG PYTHON2_INCLUDE_PATH
PYTHON2_INCLUDE_DIR PYTHON2_INCLUDE_DIR2 PYTHON2_PACKAGES_PATH PYTHON2_INCLUDE_DIR PYTHON2_INCLUDE_DIR2 PYTHON2_PACKAGES_PATH
PYTHON2_NUMPY_INCLUDE_DIRS PYTHON2_NUMPY_VERSION) PYTHON2_NUMPY_INCLUDE_DIRS PYTHON2_NUMPY_VERSION)
endif()
option(OPENCV_PYTHON3_VERSION "Python3 version" "") option(OPENCV_PYTHON3_VERSION "Python3 version" "")
find_python("${OPENCV_PYTHON3_VERSION}" "${MIN_VER_PYTHON3}" PYTHON3_LIBRARY PYTHON3_INCLUDE_DIR find_python("${OPENCV_PYTHON3_VERSION}" "${MIN_VER_PYTHON3}" PYTHON3_LIBRARY PYTHON3_INCLUDE_DIR
+7 -50
View File
@@ -5,24 +5,13 @@ if("cann${CANN_INSTALL_DIR}" STREQUAL "cann" AND DEFINED ENV{ASCEND_TOOLKIT_HOME
message(STATUS "CANN: updated CANN_INSTALL_DIR from ASCEND_TOOLKIT_HOME=$ENV{ASCEND_TOOLKIT_HOME}") message(STATUS "CANN: updated CANN_INSTALL_DIR from ASCEND_TOOLKIT_HOME=$ENV{ASCEND_TOOLKIT_HOME}")
endif() endif()
if(EXISTS "${CANN_INSTALL_DIR}/opp/op_proto/built-in/inc")
set(CANN_VERSION_BELOW_6_3_ALPHA002 "YES" )
add_definitions(-DCANN_VERSION_BELOW_6_3_ALPHA002="YES")
endif()
if(CANN_INSTALL_DIR) if(CANN_INSTALL_DIR)
# Supported system: UNIX
if(NOT UNIX)
set(HAVE_CANN OFF)
message(WARNING "CANN: CANN toolkit supports unix but not ${CMAKE_SYSTEM_NAME}. Turning off HAVE_CANN")
return()
endif()
# Supported platforms: x86-64, arm64 # Supported platforms: x86-64, arm64
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64") if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64") elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64")
else() else()
set(HAVE_CANN OFF) set(HAVE_CANN OFF)
message(WARNING "CANN: CANN toolkit supports x86-64 and arm64 but not ${CMAKE_SYSTEM_PROCESSOR}. Turning off HAVE_CANN") message(STATUS "CANN: CANN toolkit supports x86-64 and arm64 but not ${CMAKE_SYSTEM_PROCESSOR}. Turning off HAVE_CANN")
return() return()
endif() endif()
@@ -42,18 +31,7 @@ if(CANN_INSTALL_DIR)
set(lib_ascendcl ${found_lib_ascendcl}) set(lib_ascendcl ${found_lib_ascendcl})
message(STATUS "CANN: libascendcl.so is found at ${lib_ascendcl}") message(STATUS "CANN: libascendcl.so is found at ${lib_ascendcl}")
else() else()
message(WARNING "CANN: Missing libascendcl.so. Turning off HAVE_CANN") message(STATUS "CANN: Missing libascendcl.so. Turning off HAVE_CANN")
set(HAVE_CANN OFF)
return()
endif()
# * libacl_op_compiler.so
set(lib_acl_op_compiler "${CANN_INSTALL_DIR}/lib64")
find_library(found_lib_acl_op_compiler NAMES acl_op_compiler PATHS ${lib_acl_op_compiler} NO_DEFAULT_PATH)
if(found_lib_acl_op_compiler)
set(lib_acl_op_compiler ${found_lib_acl_op_compiler})
message(STATUS "CANN: libacl_op_compiler.so is found at ${lib_acl_op_compiler}")
else()
message(STATUS "CANN: Missing libacl_op_compiler.so. Turning off HAVE_CANN")
set(HAVE_CANN OFF) set(HAVE_CANN OFF)
return() return()
endif() endif()
@@ -64,7 +42,7 @@ if(CANN_INSTALL_DIR)
set(lib_graph ${found_lib_graph}) set(lib_graph ${found_lib_graph})
message(STATUS "CANN: libgraph.so is found at ${lib_graph}") message(STATUS "CANN: libgraph.so is found at ${lib_graph}")
else() else()
message(WARNING "CANN: Missing libgraph.so. Turning off HAVE_CANN") message(STATUS "CANN: Missing libgraph.so. Turning off HAVE_CANN")
set(HAVE_CANN OFF) set(HAVE_CANN OFF)
return() return()
endif() endif()
@@ -75,50 +53,29 @@ if(CANN_INSTALL_DIR)
set(lib_ge_compiler ${found_lib_ge_compiler}) set(lib_ge_compiler ${found_lib_ge_compiler})
message(STATUS "CANN: libge_compiler.so is found at ${lib_ge_compiler}") message(STATUS "CANN: libge_compiler.so is found at ${lib_ge_compiler}")
else() else()
message(WARNING "CANN: Missing libge_compiler.so. Turning off HAVE_CANN") message(STATUS "CANN: Missing libge_compiler.so. Turning off HAVE_CANN")
set(HAVE_CANN OFF) set(HAVE_CANN OFF)
return() return()
endif() endif()
# * libopsproto.so # * libopsproto.so
if (CANN_VERSION_BELOW_6_3_ALPHA002) set(lib_opsproto "${CANN_INSTALL_DIR}/opp/op_proto/built-in")
set(lib_opsproto "${CANN_INSTALL_DIR}/opp/op_proto/built-in/")
else()
if(EXISTS "${CANN_INSTALL_DIR}/opp/built-in/op_proto/lib/linux")
set(lib_opsproto "${CANN_INSTALL_DIR}/opp/built-in/op_proto/lib/linux/${CMAKE_HOST_SYSTEM_PROCESSOR}")
else()
set(lib_opsproto "${CANN_INSTALL_DIR}/opp/built-in/op_proto")
endif()
endif()
find_library(found_lib_opsproto NAMES opsproto PATHS ${lib_opsproto} NO_DEFAULT_PATH) find_library(found_lib_opsproto NAMES opsproto PATHS ${lib_opsproto} NO_DEFAULT_PATH)
if(found_lib_opsproto) if(found_lib_opsproto)
set(lib_opsproto ${found_lib_opsproto}) set(lib_opsproto ${found_lib_opsproto})
message(STATUS "CANN: libopsproto.so is found at ${lib_opsproto}") message(STATUS "CANN: libopsproto.so is found at ${lib_opsproto}")
else() else()
message(WARNING "CANN: Missing libopsproto.so can't found at ${lib_opsproto}. Turning off HAVE_CANN") message(STATUS "CANN: Missing libopsproto.so. Turning off HAVE_CANN")
set(HAVE_CANN OFF) set(HAVE_CANN OFF)
return() return()
endif() endif()
set(libs_cann "") set(libs_cann "")
list(APPEND libs_cann ${lib_ascendcl}) list(APPEND libs_cann ${lib_ascendcl})
list(APPEND libs_cann ${lib_acl_op_compiler})
list(APPEND libs_cann ${lib_opsproto}) list(APPEND libs_cann ${lib_opsproto})
list(APPEND libs_cann ${lib_graph}) list(APPEND libs_cann ${lib_graph})
list(APPEND libs_cann ${lib_ge_compiler}) list(APPEND libs_cann ${lib_ge_compiler})
# * lib_graph_base.so
if(NOT CANN_VERSION_BELOW_6_3_ALPHA002)
set(lib_graph_base "${CANN_INSTALL_DIR}/compiler/lib64")
find_library(found_libgraph_base NAMES graph_base PATHS ${lib_graph_base} NO_DEFAULT_PATH)
if(found_libgraph_base)
set(lib_graph_base ${found_libgraph_base})
message(STATUS "CANN: lib_graph_base.so is found at ${lib_graph_base}")
list(APPEND libs_cann ${lib_graph_base})
else()
message(STATUS "CANN: Missing lib_graph_base.so. It is only required after cann version 6.3.RC1.alpha002")
endif()
endif()
try_compile(VALID_ASCENDCL try_compile(VALID_ASCENDCL
"${OpenCV_BINARY_DIR}" "${OpenCV_BINARY_DIR}"
"${OpenCV_SOURCE_DIR}/cmake/checks/cann.cpp" "${OpenCV_SOURCE_DIR}/cmake/checks/cann.cpp"
+1 -1
View File
@@ -77,7 +77,7 @@ endif(WITH_OPENGL)
# --- Cocoa --- # --- Cocoa ---
if(APPLE) if(APPLE)
if(NOT IOS AND NOT XROS AND CV_CLANG) if(NOT IOS AND CV_CLANG)
set(HAVE_COCOA YES) set(HAVE_COCOA YES)
endif() endif()
endif() endif()
+23 -36
View File
@@ -34,7 +34,7 @@ if(NOT ZLIB_FOUND)
set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR}) set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR})
set(ZLIB_LIBRARIES ${ZLIB_LIBRARY}) set(ZLIB_LIBRARIES ${ZLIB_LIBRARY})
ocv_parse_header_version(ZLIB "${${ZLIB_LIBRARY}_SOURCE_DIR}/zlib.h" ZLIB_VERSION) ocv_parse_header2(ZLIB "${${ZLIB_LIBRARY}_SOURCE_DIR}/zlib.h" ZLIB_VERSION)
endif() endif()
# --- libavif (optional) --- # --- libavif (optional) ---
@@ -202,7 +202,6 @@ if(WITH_OPENJPEG)
endif() endif()
else() else()
set(HAVE_OPENJPEG YES) set(HAVE_OPENJPEG YES)
set(OPENJPEG_VERSION "${OPENJPEG_MAJOR_VERSION}.${OPENJPEG_MINOR_VERSION}.${OPENJPEG_BUILD_VERSION}")
message(STATUS "Found system OpenJPEG: ${OPENJPEG_LIBRARIES} " message(STATUS "Found system OpenJPEG: ${OPENJPEG_LIBRARIES} "
"(found version \"${OPENJPEG_VERSION}\")") "(found version \"${OPENJPEG_VERSION}\")")
endif() endif()
@@ -233,38 +232,16 @@ if(WITH_JASPER AND NOT HAVE_OPENJPEG)
endif() endif()
if(WITH_SPNG) if(WITH_SPNG)
if(BUILD_SPNG) set(SPNG_LIBRARY libspng CACHE INTERNAL "")
ocv_clear_vars(PNG_FOUND) set(SPNG_LIBRARIES ${SPNG_LIBRARY})
else() add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/libspng")
# CMakeConfig bug in SPNG, include is missing there in version 0.7.4 and older set(SPNG_INCLUDE_DIR "${${SPNG_LIBRARY}_SOURCE_DIR}" CACHE INTERNAL "")
# See https://github.com/randy408/libspng/pull/264 set(SPNG_DEFINITIONS "")
include(CMakeFindDependencyMacro) ocv_parse_header("${SPNG_INCLUDE_DIR}/spng.h" SPNG_VERSION_LINES SPNG_VERSION_MAJOR SPNG_VERSION_MINOR SPNG_VERSION_PATCH)
find_package(SPNG QUIET)
if(SPNG_FOUND)
set(SPNG_LIBRARY "spng::spng" CACHE INTERNAL "")
set(SPNG_LIBRARIES ${SPNG_LIBRARY})
else()
if(PkgConfig_FOUND)
pkg_check_modules(SPNG QUIET spng)
endif()
endif()
if(SPNG_FOUND)
set(HAVE_SPNG YES)
message(STATUS "imgcodecs: PNG codec will use SPNG, version: ${SPNG_VERSION}")
endif()
endif()
if(NOT SPNG_FOUND)
set(SPNG_LIBRARY libspng CACHE INTERNAL "")
set(SPNG_LIBRARIES ${SPNG_LIBRARY})
add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/libspng")
set(SPNG_INCLUDE_DIR "${${SPNG_LIBRARY}_SOURCE_DIR}" CACHE INTERNAL "")
set(SPNG_DEFINITIONS "")
ocv_parse_header("${SPNG_INCLUDE_DIR}/spng.h" SPNG_VERSION_LINES SPNG_VERSION_MAJOR SPNG_VERSION_MINOR SPNG_VERSION_PATCH)
set(HAVE_SPNG YES) set(HAVE_SPNG YES)
set(SPNG_VERSION "${SPNG_VERSION_MAJOR}.${SPNG_VERSION_MINOR}.${SPNG_VERSION_PATCH}") set(SPNG_VERSION "${SPNG_VERSION_MAJOR}.${SPNG_VERSION_MINOR}.${SPNG_VERSION_PATCH}")
message(STATUS "imgcodecs: PNG codec will use SPNG, version: ${SPNG_VERSION} ") message(STATUS "imgcodecs: PNG codec will use SPNG, version: ${SPNG_VERSION} ")
endif()
endif() endif()
# --- libpng (optional, should be searched after zlib) --- # --- libpng (optional, should be searched after zlib) ---
@@ -273,21 +250,31 @@ if(NOT HAVE_SPNG AND WITH_PNG)
ocv_clear_vars(PNG_FOUND) ocv_clear_vars(PNG_FOUND)
else() else()
ocv_clear_internal_cache_vars(PNG_LIBRARY PNG_INCLUDE_DIR) ocv_clear_internal_cache_vars(PNG_LIBRARY PNG_INCLUDE_DIR)
find_package(PNG QUIET) include(FindPNG)
if(PNG_FOUND)
include(CheckIncludeFile)
check_include_file("${PNG_PNG_INCLUDE_DIR}/libpng/png.h" HAVE_LIBPNG_PNG_H)
if(HAVE_LIBPNG_PNG_H)
ocv_parse_header("${PNG_PNG_INCLUDE_DIR}/libpng/png.h" PNG_VERSION_LINES PNG_LIBPNG_VER_MAJOR PNG_LIBPNG_VER_MINOR PNG_LIBPNG_VER_RELEASE)
else()
ocv_parse_header("${PNG_PNG_INCLUDE_DIR}/png.h" PNG_VERSION_LINES PNG_LIBPNG_VER_MAJOR PNG_LIBPNG_VER_MINOR PNG_LIBPNG_VER_RELEASE)
endif()
endif()
endif() endif()
if(NOT PNG_FOUND) if(NOT PNG_FOUND)
ocv_clear_vars(PNG_LIBRARY PNG_LIBRARIES PNG_INCLUDE_DIR PNG_DEFINITIONS) ocv_clear_vars(PNG_LIBRARY PNG_LIBRARIES PNG_INCLUDE_DIR PNG_PNG_INCLUDE_DIR HAVE_LIBPNG_PNG_H PNG_DEFINITIONS)
set(PNG_LIBRARY libpng CACHE INTERNAL "") set(PNG_LIBRARY libpng CACHE INTERNAL "")
set(PNG_LIBRARIES ${PNG_LIBRARY}) set(PNG_LIBRARIES ${PNG_LIBRARY})
add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/libpng") add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/libpng")
set(PNG_INCLUDE_DIR "${${PNG_LIBRARY}_SOURCE_DIR}" CACHE INTERNAL "") set(PNG_INCLUDE_DIR "${${PNG_LIBRARY}_SOURCE_DIR}" CACHE INTERNAL "")
set(PNG_DEFINITIONS "") set(PNG_DEFINITIONS "")
ocv_parse_header_version(PNG "${PNG_INCLUDE_DIR}/png.h" PNG_LIBPNG_VER_STRING) ocv_parse_header("${PNG_INCLUDE_DIR}/png.h" PNG_VERSION_LINES PNG_LIBPNG_VER_MAJOR PNG_LIBPNG_VER_MINOR PNG_LIBPNG_VER_RELEASE)
endif() endif()
set(HAVE_PNG YES) set(HAVE_PNG YES)
set(PNG_VERSION "${PNG_LIBPNG_VER_MAJOR}.${PNG_LIBPNG_VER_MINOR}.${PNG_LIBPNG_VER_RELEASE}")
endif() endif()
+1 -5
View File
@@ -40,11 +40,7 @@ endif()
# --- CUDA --- # --- CUDA ---
if(WITH_CUDA) if(WITH_CUDA)
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE) include("${OpenCV_SOURCE_DIR}/cmake/OpenCVDetectCUDA.cmake")
include("${OpenCV_SOURCE_DIR}/cmake/OpenCVDetectCUDALanguage.cmake")
else()
include("${OpenCV_SOURCE_DIR}/cmake/OpenCVDetectCUDA.cmake")
endif()
if(NOT HAVE_CUDA) if(NOT HAVE_CUDA)
message(WARNING "OpenCV is not able to find/configure CUDA SDK (required by WITH_CUDA). message(WARNING "OpenCV is not able to find/configure CUDA SDK (required by WITH_CUDA).
CUDA support will be disabled in OpenCV build. CUDA support will be disabled in OpenCV build.
+1 -1
View File
@@ -73,7 +73,7 @@ SET(Open_BLAS_LIB_SEARCH_PATHS
) )
FIND_PATH(OpenBLAS_INCLUDE_DIR NAMES cblas.h PATHS ${Open_BLAS_INCLUDE_SEARCH_PATHS} NO_DEFAULT_PATH) FIND_PATH(OpenBLAS_INCLUDE_DIR NAMES cblas.h PATHS ${Open_BLAS_INCLUDE_SEARCH_PATHS} NO_DEFAULT_PATH)
FIND_LIBRARY(OpenBLAS_LIB NAMES openblas libopenblas PATHS ${Open_BLAS_LIB_SEARCH_PATHS} NO_DEFAULT_PATH) FIND_LIBRARY(OpenBLAS_LIB NAMES openblas PATHS ${Open_BLAS_LIB_SEARCH_PATHS} NO_DEFAULT_PATH)
SET(OpenBLAS_FOUND ON) SET(OpenBLAS_FOUND ON)
+5 -30
View File
@@ -30,14 +30,8 @@ if(BUILD_PROTOBUF)
set(Protobuf_LIBRARIES "libprotobuf") set(Protobuf_LIBRARIES "libprotobuf")
set(HAVE_PROTOBUF TRUE) set(HAVE_PROTOBUF TRUE)
else() else()
# we still need this for command PROTOBUF_GENERATE_CPP.
set(protobuf_MODULE_COMPATIBLE ON)
unset(Protobuf_VERSION CACHE) unset(Protobuf_VERSION CACHE)
find_package(Protobuf QUIET CONFIG) find_package(Protobuf QUIET)
if(NOT Protobuf_FOUND)
find_package(Protobuf QUIET)
endif()
# Backwards compatibility # Backwards compatibility
# Define camel case versions of input variables # Define camel case versions of input variables
@@ -73,20 +67,6 @@ else()
endif() endif()
endif() endif()
# See https://github.com/opencv/opencv/issues/24369
# In Protocol Buffers v22.0 and later drops C++11 support and depends abseil-cpp.
# Details: https://protobuf.dev/news/2022-08-03/
# And if std::text_view is in abseil-cpp requests C++17 and later.
if(HAVE_PROTOBUF)
if(NOT (Protobuf_VERSION VERSION_LESS 22))
if((CMAKE_CXX_STANDARD EQUAL 98) OR (CMAKE_CXX_STANDARD LESS 17))
message(STATUS "CMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} is too old to support protobuf(${Protobuf_VERSION}) and/or abseil-cpp. Use C++17 or later. Turning HAVE_PROTOBUF off")
set(HAVE_PROTOBUF FALSE)
endif()
endif()
endif()
if(HAVE_PROTOBUF AND PROTOBUF_UPDATE_FILES AND NOT COMMAND PROTOBUF_GENERATE_CPP) if(HAVE_PROTOBUF AND PROTOBUF_UPDATE_FILES AND NOT COMMAND PROTOBUF_GENERATE_CPP)
message(FATAL_ERROR "Can't configure protobuf dependency (BUILD_PROTOBUF=${BUILD_PROTOBUF} PROTOBUF_UPDATE_FILES=${PROTOBUF_UPDATE_FILES})") message(FATAL_ERROR "Can't configure protobuf dependency (BUILD_PROTOBUF=${BUILD_PROTOBUF} PROTOBUF_UPDATE_FILES=${PROTOBUF_UPDATE_FILES})")
endif() endif()
@@ -94,20 +74,15 @@ endif()
if(HAVE_PROTOBUF) if(HAVE_PROTOBUF)
list(APPEND CUSTOM_STATUS protobuf) list(APPEND CUSTOM_STATUS protobuf)
if(NOT BUILD_PROTOBUF) if(NOT BUILD_PROTOBUF)
unset( __location)
if(TARGET "${Protobuf_LIBRARIES}") if(TARGET "${Protobuf_LIBRARIES}")
get_target_property(__location "${Protobuf_LIBRARIES}" IMPORTED_LOCATION_RELEASE) get_target_property(__location "${Protobuf_LIBRARIES}" IMPORTED_LOCATION_RELEASE)
if(NOT __location) if(NOT __location)
get_target_property(__location "${Protobuf_LIBRARIES}" IMPORTED_LOCATION) get_target_property(__location "${Protobuf_LIBRARIES}" IMPORTED_LOCATION)
endif() endif()
endif() elseif(Protobuf_LIBRARY)
set(__location "${Protobuf_LIBRARY}")
if(NOT __location) else()
if(Protobuf_LIBRARY) set(__location "${Protobuf_LIBRARIES}")
set(__location "${Protobuf_LIBRARY}")
else()
set(__location "${Protobuf_LIBRARIES}")
endif()
endif() endif()
endif() endif()
list(APPEND CUSTOM_STATUS_protobuf " Protobuf:" list(APPEND CUSTOM_STATUS_protobuf " Protobuf:"
+78
View File
@@ -0,0 +1,78 @@
# COPYRIGHT
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# License); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# Copyright (c) 2020, OPEN AI LAB
# Author: qtang@openailab.com or https://github.com/BUG1989
#
# ----------------------------------------------------------------------------
# Path for Tengine binaries
# ----------------------------------------------------------------------------
set(OPENCV_LIBTENGINE_ROOT_DIR "" CACHE PATH "Path to TENGINE binaries installation")
IF(OPENCV_LIBTENGINE_ROOT_DIR AND NOT BUILD_TENGINE)
MESSAGE(STATUS "TENGINE:-- Use binaries at ${OPENCV_LIBTENGINE_ROOT_DIR}")
SET(Tengine_FOUND ON)
set(BUILD_TENGINE OFF)
SET(Tengine_INCLUDE_DIR "${OPENCV_LIBTENGINE_ROOT_DIR}/include" CACHE PATH "TENGINE include dir")
SET(Tengine_LIB "${OPENCV_LIBTENGINE_ROOT_DIR}/lib/libtengine.a" CACHE PATH "TENGINE library dir")
ELSE()
IF(ANDROID)
IF(OPENCV_TENGINE_FORCE_ANDROID)
# nothing, use Android
ELSEIF(OPENCV_TENGINE_SKIP_ANDROID)
set(Tengine_FOUND OFF)
set(HAVE_TENGINE FALSE)
return()
ELSEIF(NOT DEFINED ANDROID_NDK_REVISION)
MESSAGE(STATUS "Android NDK version Tengine not support: ANDROID_NDK_REVISION is not defined")
set(Tengine_FOUND OFF)
set(HAVE_TENGINE FALSE)
return()
ELSEIF(ANDROID_NDK_REVISION VERSION_LESS 14)
MESSAGE(STATUS "Android NDK version Tengine not support: ANDROID_NDK_REVISION=${ANDROID_NDK_REVISION}")
set(Tengine_FOUND OFF)
set(HAVE_TENGINE FALSE)
return()
ENDIF()
ENDIF()
MESSAGE(STATUS "TENGINE:-- Build Tengine from source code. ")
include("${OpenCV_SOURCE_DIR}/3rdparty/libtengine/tengine.cmake")
ENDIF()
IF(NOT Tengine_LIB)
SET(Tengine_FOUND OFF)
MESSAGE(STATUS "#### Could not find Tengine lib. Turning Tengine_FOUND off")
ENDIF()
IF (Tengine_FOUND)
MESSAGE(STATUS "Found Tengine include: ${Tengine_INCLUDE_DIR}")
MESSAGE(STATUS "Found Tengine libraries: ${Tengine_LIB}")
set(HAVE_TENGINE 1)
set(TENGINE_LIBRARIES ${Tengine_LIB})
set(TENGINE_INCLUDE_DIRS ${Tengine_INCLUDE_DIR})
ENDIF (Tengine_FOUND)
MARK_AS_ADVANCED(
Tengine_INCLUDE_DIR
Tengine_LIB
)
+2 -5
View File
@@ -12,11 +12,7 @@ else()
endif() endif()
if(HAVE_CUDA) if(HAVE_CUDA)
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE) ocv_cmake_configure("${CMAKE_CURRENT_LIST_DIR}/templates/OpenCVConfig-CUDA.cmake.in" CUDA_CONFIGCMAKE @ONLY)
ocv_cmake_configure("${CMAKE_CURRENT_LIST_DIR}/templates/OpenCVConfig-CUDALanguage.cmake.in" CUDA_CONFIGCMAKE @ONLY)
else()
ocv_cmake_configure("${CMAKE_CURRENT_LIST_DIR}/templates/OpenCVConfig-CUDA.cmake.in" CUDA_CONFIGCMAKE @ONLY)
endif()
endif() endif()
if(ANDROID) if(ANDROID)
@@ -124,6 +120,7 @@ endif()
if(ANDROID) if(ANDROID)
ocv_gen_config("${CMAKE_BINARY_DIR}/unix-install" "abi-${ANDROID_NDK_ABI_NAME}" "OpenCVConfig.root-ANDROID.cmake.in") ocv_gen_config("${CMAKE_BINARY_DIR}/unix-install" "abi-${ANDROID_NDK_ABI_NAME}" "OpenCVConfig.root-ANDROID.cmake.in")
install(FILES "${OpenCV_SOURCE_DIR}/platforms/android/android.toolchain.cmake" DESTINATION "${OPENCV_CONFIG_INSTALL_PATH}" COMPONENT dev)
endif() endif()
# -------------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------------
-8
View File
@@ -13,14 +13,6 @@ if(IOS)
configure_file("${OpenCV_SOURCE_DIR}/platforms/ios/Info.plist.in" configure_file("${OpenCV_SOURCE_DIR}/platforms/ios/Info.plist.in"
"${CMAKE_BINARY_DIR}/ios/Info.plist") "${CMAKE_BINARY_DIR}/ios/Info.plist")
endif() endif()
elseif(XROS)
if(APPLE_FRAMEWORK AND DYNAMIC_PLIST)
configure_file("${OpenCV_SOURCE_DIR}/platforms/ios/Info.Dynamic.plist.in"
"${CMAKE_BINARY_DIR}/visionos/Info.plist")
else()
configure_file("${OpenCV_SOURCE_DIR}/platforms/ios/Info.plist.in"
"${CMAKE_BINARY_DIR}/visionos/Info.plist")
endif()
elseif(APPLE) elseif(APPLE)
configure_file("${OpenCV_SOURCE_DIR}/platforms/osx/Info.plist.in" configure_file("${OpenCV_SOURCE_DIR}/platforms/osx/Info.plist.in"
"${CMAKE_BINARY_DIR}/osx/Info.plist") "${CMAKE_BINARY_DIR}/osx/Info.plist")
+1 -1
View File
@@ -1,4 +1,4 @@
if(MSVC OR IOS OR XROS) if(MSVC OR IOS)
return() return()
endif() endif()
+1 -1
View File
@@ -1003,7 +1003,7 @@ macro(_ocv_create_module)
INTERFACE ${OPENCV_MODULE_${the_module}_DEPS_EXT} INTERFACE ${OPENCV_MODULE_${the_module}_DEPS_EXT}
) )
ocv_target_link_libraries(${the_module} PRIVATE ${OPENCV_LINKER_LIBS} ${OPENCV_HAL_LINKER_LIBS} ${IPP_LIBS} ${ARGN}) ocv_target_link_libraries(${the_module} PRIVATE ${OPENCV_LINKER_LIBS} ${OPENCV_HAL_LINKER_LIBS} ${IPP_LIBS} ${ARGN})
if (NOT ENABLE_CUDA_FIRST_CLASS_LANGUAGE AND HAVE_CUDA) if (HAVE_CUDA)
ocv_target_link_libraries(${the_module} PRIVATE ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY}) ocv_target_link_libraries(${the_module} PRIVATE ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY})
endif() endif()
+2 -2
View File
@@ -52,8 +52,8 @@ else()
set(OPENCV_PACKAGE_ARCH_SUFFIX ${CMAKE_SYSTEM_PROCESSOR}) set(OPENCV_PACKAGE_ARCH_SUFFIX ${CMAKE_SYSTEM_PROCESSOR})
endif() endif()
set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION}-${OPENCV_PACKAGE_ARCH_SUFFIX}") set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${OPENCV_VCSVERSION}-${OPENCV_PACKAGE_ARCH_SUFFIX}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION}-${OPENCV_PACKAGE_ARCH_SUFFIX}") set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${OPENCV_VCSVERSION}-${OPENCV_PACKAGE_ARCH_SUFFIX}")
#rpm options #rpm options
set(CPACK_RPM_COMPONENT_INSTALL TRUE) set(CPACK_RPM_COMPONENT_INSTALL TRUE)
+3 -35
View File
@@ -1430,18 +1430,6 @@ macro(ocv_parse_header2 LIBNAME HDR_PATH VARNAME)
endif() endif()
endmacro() endmacro()
# set ${LIBNAME}_VERSION_STRING to ${LIBVER} without quotes
macro(ocv_parse_header_version LIBNAME HDR_PATH LIBVER)
ocv_clear_vars(${LIBNAME}_VERSION_STRING)
set(${LIBNAME}_H "")
if(EXISTS "${HDR_PATH}")
file(STRINGS "${HDR_PATH}" ${LIBNAME}_H REGEX "^#define[ \t]+${LIBVER}[ \t]+\"[^\"]*\".*$" LIMIT_COUNT 1)
endif()
if(${LIBNAME}_H)
string(REGEX REPLACE "^.*[ \t]${LIBVER}[ \t]+\"([0-9\.]+)\"$" "\\1" ${LIBNAME}_VERSION_STRING "${${LIBNAME}_H}")
endif()
endmacro()
################################################################################################ ################################################################################################
# short command to setup source group # short command to setup source group
function(ocv_source_group group) function(ocv_source_group group)
@@ -1557,23 +1545,13 @@ function(_ocv_append_target_includes target)
endif() endif()
endfunction() endfunction()
macro(ocv_add_cuda_compile_flags)
ocv_cuda_compile_flags()
target_compile_options(${target} PRIVATE $<$<COMPILE_LANGUAGE:CUDA>: ${CUDA_NVCC_FLAGS}
"-Xcompiler=${CMAKE_CXX_FLAGS_CUDA} $<$<CONFIG:Debug>:${CMAKE_CXX_FLAGS_DEBUG_CUDA}> \
$<$<CONFIG:Release>:${CMAKE_CXX_FLAGS_RELEASE_CUDA}>" >)
endmacro()
function(ocv_add_executable target) function(ocv_add_executable target)
add_executable(${target} ${ARGN}) add_executable(${target} ${ARGN})
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE AND HAVE_CUDA)
ocv_add_cuda_compile_flags()
endif()
_ocv_append_target_includes(${target}) _ocv_append_target_includes(${target})
endfunction() endfunction()
function(ocv_add_library target) function(ocv_add_library target)
if(NOT ENABLE_CUDA_FIRST_CLASS_LANGUAGE AND HAVE_CUDA AND ARGN MATCHES "\\.cu") if(HAVE_CUDA AND ARGN MATCHES "\\.cu")
ocv_include_directories(${CUDA_INCLUDE_DIRS}) ocv_include_directories(${CUDA_INCLUDE_DIRS})
ocv_cuda_compile(cuda_objs ${ARGN}) ocv_cuda_compile(cuda_objs ${ARGN})
set(OPENCV_MODULE_${target}_CUDA_OBJECTS ${cuda_objs} CACHE INTERNAL "Compiled CUDA object files") set(OPENCV_MODULE_${target}_CUDA_OBJECTS ${cuda_objs} CACHE INTERNAL "Compiled CUDA object files")
@@ -1581,16 +1559,12 @@ function(ocv_add_library target)
add_library(${target} ${ARGN} ${cuda_objs}) add_library(${target} ${ARGN} ${cuda_objs})
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE AND HAVE_CUDA)
ocv_add_cuda_compile_flags()
endif()
if(APPLE_FRAMEWORK AND BUILD_SHARED_LIBS) if(APPLE_FRAMEWORK AND BUILD_SHARED_LIBS)
message(STATUS "Setting Apple target properties for ${target}") message(STATUS "Setting Apple target properties for ${target}")
set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG 1) set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG 1)
if((IOS OR XROS) AND NOT MAC_CATALYST) if(IOS AND NOT MAC_CATALYST)
set(OPENCV_APPLE_INFO_PLIST "${CMAKE_BINARY_DIR}/ios/Info.plist") set(OPENCV_APPLE_INFO_PLIST "${CMAKE_BINARY_DIR}/ios/Info.plist")
else() else()
set(OPENCV_APPLE_INFO_PLIST "${CMAKE_BINARY_DIR}/osx/Info.plist") set(OPENCV_APPLE_INFO_PLIST "${CMAKE_BINARY_DIR}/osx/Info.plist")
@@ -1658,19 +1632,13 @@ function(ocv_add_external_target name inc link def)
endif() endif()
endfunction() endfunction()
set(__OPENCV_EXPORTED_EXTERNAL_TARGETS "" CACHE INTERNAL "")
function(ocv_install_used_external_targets) function(ocv_install_used_external_targets)
if(NOT BUILD_SHARED_LIBS if(NOT BUILD_SHARED_LIBS
AND NOT (CMAKE_VERSION VERSION_LESS "3.13.0") # upgrade CMake: https://gitlab.kitware.com/cmake/cmake/-/merge_requests/2152 AND NOT (CMAKE_VERSION VERSION_LESS "3.13.0") # upgrade CMake: https://gitlab.kitware.com/cmake/cmake/-/merge_requests/2152
) )
foreach(tgt in ${ARGN}) foreach(tgt in ${ARGN})
if(tgt MATCHES "^ocv\.3rdparty\.") if(tgt MATCHES "^ocv\.3rdparty\.")
list(FIND __OPENCV_EXPORTED_EXTERNAL_TARGETS "${tgt}" _found) install(TARGETS ${tgt} EXPORT OpenCVModules)
if(_found EQUAL -1) # don't export target twice
install(TARGETS ${tgt} EXPORT OpenCVModules)
list(APPEND __OPENCV_EXPORTED_EXTERNAL_TARGETS "${tgt}")
set(__OPENCV_EXPORTED_EXTERNAL_TARGETS "${__OPENCV_EXPORTED_EXTERNAL_TARGETS}" CACHE INTERNAL "")
endif()
endif() endif()
endforeach() endforeach()
endif() endif()
+12 -41
View File
@@ -1,8 +1,8 @@
# https://developer.android.com/studio/releases/gradle-plugin # https://developer.android.com/studio/releases/gradle-plugin
set(ANDROID_GRADLE_PLUGIN_VERSION "7.3.1" CACHE STRING "Android Gradle Plugin version") set(ANDROID_GRADLE_PLUGIN_VERSION "3.2.1" CACHE STRING "Android Gradle Plugin version")
message(STATUS "Android Gradle Plugin version: ${ANDROID_GRADLE_PLUGIN_VERSION}") message(STATUS "Android Gradle Plugin version: ${ANDROID_GRADLE_PLUGIN_VERSION}")
set(KOTLIN_PLUGIN_VERSION "1.5.20" CACHE STRING "Kotlin Plugin version") set(KOTLIN_PLUGIN_VERSION "1.4.10" CACHE STRING "Kotlin Plugin version")
message(STATUS "Kotlin Plugin version: ${KOTLIN_PLUGIN_VERSION}") message(STATUS "Kotlin Plugin version: ${KOTLIN_PLUGIN_VERSION}")
if(BUILD_KOTLIN_EXTENSIONS) if(BUILD_KOTLIN_EXTENSIONS)
@@ -13,16 +13,16 @@ else()
set(KOTLIN_STD_LIB "" CACHE STRING "Kotlin Standard Library dependency") set(KOTLIN_STD_LIB "" CACHE STRING "Kotlin Standard Library dependency")
endif() endif()
set(GRADLE_VERSION "7.6.3" CACHE STRING "Gradle version") set(GRADLE_VERSION "5.6.4" CACHE STRING "Gradle version")
message(STATUS "Gradle version: ${GRADLE_VERSION}") message(STATUS "Gradle version: ${GRADLE_VERSION}")
set(ANDROID_COMPILE_SDK_VERSION "31" CACHE STRING "Android compileSdkVersion") set(ANDROID_COMPILE_SDK_VERSION "26" CACHE STRING "Android compileSdkVersion")
if(ANDROID_NATIVE_API_LEVEL GREATER 21) if(ANDROID_NATIVE_API_LEVEL GREATER 21)
set(ANDROID_MIN_SDK_VERSION "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android minSdkVersion") set(ANDROID_MIN_SDK_VERSION "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android minSdkVersion")
else() else()
set(ANDROID_MIN_SDK_VERSION "21" CACHE STRING "Android minSdkVersion") set(ANDROID_MIN_SDK_VERSION "21" CACHE STRING "Android minSdkVersion")
endif() endif()
set(ANDROID_TARGET_SDK_VERSION "31" CACHE STRING "Android minSdkVersion") set(ANDROID_TARGET_SDK_VERSION "26" CACHE STRING "Android minSdkVersion")
set(ANDROID_BUILD_BASE_DIR "${OpenCV_BINARY_DIR}/opencv_android" CACHE INTERNAL "") set(ANDROID_BUILD_BASE_DIR "${OpenCV_BINARY_DIR}/opencv_android" CACHE INTERNAL "")
set(ANDROID_TMP_INSTALL_BASE_DIR "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/install/opencv_android") set(ANDROID_TMP_INSTALL_BASE_DIR "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/install/opencv_android")
@@ -109,39 +109,21 @@ if(NOT OPENCV_SKIP_ANDROID_FORCE_CMAKE)
get_filename_component(_CMAKE_INSTALL_DIR "${CMAKE_ROOT}" PATH) get_filename_component(_CMAKE_INSTALL_DIR "${CMAKE_ROOT}" PATH)
get_filename_component(_CMAKE_INSTALL_DIR "${_CMAKE_INSTALL_DIR}" PATH) get_filename_component(_CMAKE_INSTALL_DIR "${_CMAKE_INSTALL_DIR}" PATH)
endif() endif()
ocv_update_file("${ANDROID_BUILD_BASE_DIR}/local.properties" "cmake.dir=${_CMAKE_INSTALL_DIR}\nndk.dir=${ANDROID_NDK}") ocv_update_file("${ANDROID_BUILD_BASE_DIR}/local.properties" "cmake.dir=${_CMAKE_INSTALL_DIR}")
endif() endif()
file(WRITE "${ANDROID_BUILD_BASE_DIR}/settings.gradle" " file(WRITE "${ANDROID_BUILD_BASE_DIR}/settings.gradle" "
gradle.ext {
// possible options: 'maven_central', 'maven_local', 'sdk_path'
opencv_source = 'sdk_path'
}
include ':opencv' include ':opencv'
") ")
file(WRITE "${ANDROID_TMP_INSTALL_BASE_DIR}/settings.gradle" " file(WRITE "${ANDROID_TMP_INSTALL_BASE_DIR}/settings.gradle" "
rootProject.name = 'opencv_samples' rootProject.name = 'opencv_samples'
gradle.ext { def opencvsdk='../'
// possible options: 'maven_central', 'maven_local', 'sdk_path' //def opencvsdk='/<path to OpenCV-android-sdk>'
opencv_source = 'sdk_path' //println opencvsdk
} include ':opencv'
project(':opencv').projectDir = new File(opencvsdk + '/sdk')
if (gradle.opencv_source == 'maven_local') {
gradle.ext {
opencv_maven_path = '<path_to_maven_repo>'
}
}
if (gradle.opencv_source == 'sdk_path') {
def opencvsdk = '../'
//def opencvsdk='/<path to OpenCV-android-sdk>'
//println opencvsdk
include ':opencv'
project(':opencv').projectDir = new File(opencvsdk + '/sdk')
}
") ")
ocv_check_environment_variables(OPENCV_GRADLE_VERBOSE_OPTIONS) ocv_check_environment_variables(OPENCV_GRADLE_VERBOSE_OPTIONS)
@@ -225,20 +207,9 @@ include ':${__dir}'
configure_file("${path}/build.gradle.in" "${ANDROID_TMP_INSTALL_BASE_DIR}/${__dir}/build.gradle" @ONLY) configure_file("${path}/build.gradle.in" "${ANDROID_TMP_INSTALL_BASE_DIR}/${__dir}/build.gradle" @ONLY)
install(FILES "${ANDROID_TMP_INSTALL_BASE_DIR}/${__dir}/build.gradle" DESTINATION "${ANDROID_INSTALL_SAMPLES_DIR}/${__dir}" COMPONENT samples) install(FILES "${ANDROID_TMP_INSTALL_BASE_DIR}/${__dir}/build.gradle" DESTINATION "${ANDROID_INSTALL_SAMPLES_DIR}/${__dir}" COMPONENT samples)
# HACK: AAR packages generated from current OpenCV project has incomple prefab part file(APPEND "${ANDROID_TMP_INSTALL_BASE_DIR}/settings.gradle" "
# and cannot be used for native linkage against OpenCV.
# Alternative way to build AAR: https://github.com/opencv/opencv/blob/4.x/platforms/android/build_java_shared_aar.py
if("${__dir}" STREQUAL "tutorial-2-mixedprocessing" OR "${__dir}" STREQUAL "tutorial-4-opencl")
file(APPEND "${ANDROID_TMP_INSTALL_BASE_DIR}/settings.gradle" "
if (gradle.opencv_source == 'sdk_path') {
include ':${__dir}'
}
")
else()
file(APPEND "${ANDROID_TMP_INSTALL_BASE_DIR}/settings.gradle" "
include ':${__dir}' include ':${__dir}'
") ")
endif()
endmacro() endmacro()
@@ -1,6 +1,6 @@
#include <stdio.h> #include <stdio.h>
#if (defined __GNUC__ && (defined __arm__ || defined __aarch64__)) || (defined _MSC_VER && defined _M_ARM64) #if defined __GNUC__ && (defined __arm__ || defined __aarch64__)
#include "arm_neon.h" #include "arm_neon.h"
int test() int test()
{ {
+1 -1
View File
@@ -11,7 +11,7 @@ int test()
_mm_storel_epi64((__m128i*)dst, v_dst); _mm_storel_epi64((__m128i*)dst, v_dst);
return (int)dst[0]; return (int)dst[0];
} }
#elif (defined __GNUC__ && (defined __arm__ || defined __aarch64__)) || (defined _MSC_VER && defined _M_ARM64) #elif defined __GNUC__ && (defined __arm__ || defined __aarch64__)
#include "arm_neon.h" #include "arm_neon.h"
int test() int test()
{ {
-15
View File
@@ -1,15 +0,0 @@
#include <stdio.h>
#include <lsxintrin.h>
int test()
{
const float src[] = { 0.0f, 1.0f, 2.0f, 3.0f};
v4f32 val = (v4f32)__lsx_vld((const float*)(src), 0);
return __lsx_vpickve2gr_w(__lsx_vftint_w_s(val), 3);
}
int main()
{
printf("%d\n", test());
return 0;
}
-46
View File
@@ -1,46 +0,0 @@
#if (defined __GNUC__ && (defined __arm__ || defined __aarch64__)) || (defined _MSC_VER && defined _M_ARM64)
#include <stdio.h>
#include "arm_neon.h"
/*#if defined __clang__
#pragma clang attribute push (__attribute__((target("bf16"))), apply_to=function)
#elif defined GCC
#pragma GCC push_options
#pragma GCC target("armv8.2-a", "bf16")
#endif*/
bfloat16x8_t vld1q_as_bf16(const float* src)
{
float32x4_t s0 = vld1q_f32(src), s1 = vld1q_f32(src + 4);
return vcombine_bf16(vcvt_bf16_f32(s0), vcvt_bf16_f32(s1));
}
void vprintreg(const char* name, const float32x4_t& r)
{
float data[4];
vst1q_f32(data, r);
printf("%s: (%.2f, %.2f, %.2f, %.2f)\n",
name, data[0], data[1], data[2], data[3]);
}
void test()
{
const float src1[] = { 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f };
const float src2[] = { 1.f, 3.f, 6.f, 10.f, 15.f, 21.f, 28.f, 36.f };
bfloat16x8_t s1 = vld1q_as_bf16(src1), s2 = vld1q_as_bf16(src2);
float32x4_t d = vbfdotq_f32(vdupq_n_f32(0.f), s1, s2);
vprintreg("(s1[0]*s2[0] + s1[1]*s2[1], ... s1[6]*s2[6] + s1[7]*s2[7])", d);
}
/*#if defined __clang__
#pragma clang attribute pop
#elif defined GCC
#pragma GCC pop_options
#endif*/
#else
#error "BF16 is not supported"
#endif
int main()
{
test();
return 0;
}
-46
View File
@@ -1,46 +0,0 @@
#include <stdio.h>
#if (defined __GNUC__ && (defined __arm__ || defined __aarch64__)) || (defined _MSC_VER && defined _M_ARM64)
#include "arm_neon.h"
float16x8_t vld1q_as_f16(const float* src)
{
float32x4_t s0 = vld1q_f32(src), s1 = vld1q_f32(src + 4);
return vcombine_f16(vcvt_f16_f32(s0), vcvt_f16_f32(s1));
}
void vprintreg(const char* name, const float16x8_t& r)
{
float data[8];
vst1q_f32(data, vcvt_f32_f16(vget_low_f16(r)));
vst1q_f32(data + 4, vcvt_f32_f16(vget_high_f16(r)));
printf("%s: (%.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
name, data[0], data[1], data[2], data[3],
data[4], data[5], data[6], data[7]);
}
void test()
{
const float src1[] = { 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f };
const float src2[] = { 1.f, 3.f, 6.f, 10.f, 15.f, 21.f, 28.f, 36.f };
float16x8_t s1 = vld1q_as_f16(src1), s2 = vld1q_as_f16(src2);
float16x8_t d = vsubq_f16(s1, s1);
d = vfmaq_laneq_f16(d, s1, s2, 0);
d = vfmaq_laneq_f16(d, s1, s2, 1);
d = vfmaq_laneq_f16(d, s1, s2, 2);
d = vfmaq_laneq_f16(d, s1, s2, 3);
d = vfmaq_laneq_f16(d, s1, s2, 4);
d = vfmaq_laneq_f16(d, s1, s2, 5);
d = vfmaq_laneq_f16(d, s1, s2, 6);
d = vfmaq_laneq_f16(d, s1, s2, 7);
vprintreg("s1*s2[0]+s1*s2[1] + ... + s1*s2[7]", d);
}
#else
#error "FP16 is not supported"
#endif
int main()
{
test();
return 0;
}
-38
View File
@@ -1,38 +0,0 @@
#include <initguid.h>
#include <d3d11.h>
#include <dxgi1_2.h>
#include <dxgi1_4.h>
#include <dxgi.h>
#include <dxcore.h>
#include <dxcore_interface.h>
#include <d3d12.h>
#include <directml.h>
int main(int /*argc*/, char** /*argv*/)
{
IDXCoreAdapterFactory* factory;
DXCoreCreateAdapterFactory(__uuidof(IDXCoreAdapterFactory), (void**)&factory);
IDXCoreAdapterList* adapterList;
const GUID dxGUIDs[] = { DXCORE_ADAPTER_ATTRIBUTE_D3D12_CORE_COMPUTE };
factory->CreateAdapterList(ARRAYSIZE(dxGUIDs), dxGUIDs, __uuidof(IDXCoreAdapterList), (void**)&adapterList);
IDXCoreAdapter* adapter;
adapterList->GetAdapter(0u, __uuidof(IDXCoreAdapter), (void**)&adapter);
D3D_FEATURE_LEVEL d3dFeatureLevel = D3D_FEATURE_LEVEL_1_0_CORE;
ID3D12Device* d3d12Device = NULL;
D3D12CreateDevice((IUnknown*)adapter, d3dFeatureLevel, __uuidof(ID3D11Device), (void**)&d3d12Device);
D3D12_COMMAND_LIST_TYPE commandQueueType = D3D12_COMMAND_LIST_TYPE_COMPUTE;
ID3D12CommandQueue* cmdQueue;
D3D12_COMMAND_QUEUE_DESC commandQueueDesc = {};
commandQueueDesc.Type = commandQueueType;
d3d12Device->CreateCommandQueue(&commandQueueDesc, __uuidof(ID3D12CommandQueue), (void**)&cmdQueue);
IDMLDevice* dmlDevice;
DMLCreateDevice(d3d12Device, DML_CREATE_DEVICE_FLAG_NONE, IID_PPV_ARGS(&dmlDevice));
return 0;
}
+6 -6
View File
@@ -21,7 +21,7 @@ macro(copy_file_ src dst prefix)
endif() endif()
if(use_symlink) if(use_symlink)
if(local_update OR NOT IS_SYMLINK "${dst}") if(local_update OR NOT IS_SYMLINK "${dst}")
#message("${prefix}Symlink: '${dst_name}' ...") message("${prefix}Symlink: '${dst_name}' ...")
endif() endif()
get_filename_component(target_path "${dst}" PATH) get_filename_component(target_path "${dst}" PATH)
file(MAKE_DIRECTORY "${target_path}") file(MAKE_DIRECTORY "${target_path}")
@@ -38,7 +38,7 @@ macro(copy_file_ src dst prefix)
set(local_update 1) set(local_update 1)
endif() endif()
if(local_update) if(local_update)
#message("${prefix}Copying: '${dst_name}' ...") message("${prefix}Copying: '${dst_name}' ...")
configure_file(${src} ${dst} COPYONLY) configure_file(${src} ${dst} COPYONLY)
else() else()
#message("${prefix}Up-to-date: '${dst_name}'") #message("${prefix}Up-to-date: '${dst_name}'")
@@ -55,7 +55,7 @@ if(NOT DEFINED COPYLIST_VAR)
set(COPYLIST_VAR "COPYLIST") set(COPYLIST_VAR "COPYLIST")
endif() endif()
list(LENGTH ${COPYLIST_VAR} __length) list(LENGTH ${COPYLIST_VAR} __length)
#message("${prefix}... ${__length} entries (${COPYLIST_VAR})") message("${prefix}... ${__length} entries (${COPYLIST_VAR})")
foreach(id ${${COPYLIST_VAR}}) foreach(id ${${COPYLIST_VAR}})
set(src "${${COPYLIST_VAR}_SRC_${id}}") set(src "${${COPYLIST_VAR}_SRC_${id}}")
set(dst "${${COPYLIST_VAR}_DST_${id}}") set(dst "${${COPYLIST_VAR}_DST_${id}}")
@@ -80,7 +80,7 @@ foreach(id ${${COPYLIST_VAR}})
endif() endif()
file(GLOB_RECURSE _files RELATIVE "${src}" ${src_glob}) file(GLOB_RECURSE _files RELATIVE "${src}" ${src_glob})
list(LENGTH _files __length) list(LENGTH _files __length)
#message("${prefix} ... directory '.../${src_name2}/${src_name}' with ${__length} files") message("${prefix} ... directory '.../${src_name2}/${src_name}' with ${__length} files")
foreach(f ${_files}) foreach(f ${_files})
if(NOT EXISTS "${src}/${f}") if(NOT EXISTS "${src}/${f}")
message(FATAL_ERROR "COPY ERROR: Source file is missing: ${src}/${f}") message(FATAL_ERROR "COPY ERROR: Source file is missing: ${src}/${f}")
@@ -98,12 +98,12 @@ else()
endif() endif()
if(NOT "${__state}" STREQUAL "${__prev_state}") if(NOT "${__state}" STREQUAL "${__prev_state}")
file(WRITE "${STATE_FILE}" "${__state}") file(WRITE "${STATE_FILE}" "${__state}")
#message("${prefix}Updated!") message("${prefix}Updated!")
set(update_dephelper 1) set(update_dephelper 1)
endif() endif()
if(NOT update_dephelper) if(NOT update_dephelper)
#message("${prefix}All files are up-to-date.") message("${prefix}All files are up-to-date.")
elseif(DEFINED DEPHELPER) elseif(DEFINED DEPHELPER)
file(WRITE "${DEPHELPER}" "") file(WRITE "${DEPHELPER}" "")
endif() endif()
+5 -2
View File
@@ -1,12 +1,15 @@
# Gitlab-style mirror # Gitlab-style mirror
# CMake scripts look for opencv/opencv_3rdparty, # CMake scripts look for opencv/opencv_3rdparty,
# 01org/tbb(oneAPI/oneTBB), opencv/ade # OAID/Tengine, 01org/tbb(oneAPI/oneTBB), opencv/ade
# from OPENCV_DOWNLOAD_MIRROR # from OPENCV_DOWNLOAD_MIRROR
ocv_update(OPENCV_DOWNLOAD_MIRROR_URL "") ocv_update(OPENCV_DOWNLOAD_MIRROR_URL "")
###### ######
# Download via commit id # Download via commit id
###### ######
# Tengine
ocv_update(TENGINE_PKG_MD5_CUSTOM "")
ocv_update(TENGINE_PKG_MD5_ORIGINAL 23f61ebb1dd419f1207d8876496289c5) # same as tengine_md5sum for TENGINE commit of e89cf8870de2ff0a80cfe626c0b52b2a16fb302e
# NVIDIA_OPTICAL_FLOW # NVIDIA_OPTICAL_FLOW
ocv_update(NVIDIA_OPTICAL_FLOW_PKG_MD5_GITCODE "") ocv_update(NVIDIA_OPTICAL_FLOW_PKG_MD5_GITCODE "")
ocv_update(NVIDIA_OPTICAL_FLOW_PKG_MD5_ORIGINAL a73cd48b18dcc0cc8933b30796074191) ocv_update(NVIDIA_OPTICAL_FLOW_PKG_MD5_ORIGINAL a73cd48b18dcc0cc8933b30796074191)
@@ -74,7 +77,7 @@ else()
ocv_download_url_custom_usercontent(opencv) ocv_download_url_custom_usercontent(opencv)
elseif(DL_ID STREQUAL "wechat_qrcode") elseif(DL_ID STREQUAL "wechat_qrcode")
ocv_download_url_gitcode_usercontent(WeChatCV) ocv_download_url_gitcode_usercontent(WeChatCV)
elseif((DL_ID STREQUAL "NVIDIA_OPTICAL_FLOW") OR (DL_ID STREQUAL "TIM-VX")) elseif((DL_ID STREQUAL "TENGINE") OR (DL_ID STREQUAL "NVIDIA_OPTICAL_FLOW") OR (DL_ID STREQUAL "TIM-VX"))
ocv_download_url_custom_archive_commit_id() ocv_download_url_custom_archive_commit_id()
elseif(DL_ID STREQUAL "TBB") elseif(DL_ID STREQUAL "TBB")
ocv_download_url_custom_archive_release() ocv_download_url_custom_archive_release()
+4 -1
View File
@@ -1,6 +1,9 @@
###### ######
# Download via commit id # Download via commit id
###### ######
# Tengine
ocv_update(TENGINE_PKG_MD5_GITCODE 1b5908632b557275cd6e85b0c03f9690)
ocv_update(TENGINE_PKG_MD5_ORIGINAL 23f61ebb1dd419f1207d8876496289c5) # same as tengine_md5sum for TENGINE commit of e89cf8870de2ff0a80cfe626c0b52b2a16fb302e
# NVIDIA_OPTICAL_FLOW # NVIDIA_OPTICAL_FLOW
ocv_update(NVIDIA_OPTICAL_FLOW_PKG_MD5_GITCODE 8d5b7eeb24d6ca9c6bcfdff4196d5b47) ocv_update(NVIDIA_OPTICAL_FLOW_PKG_MD5_GITCODE 8d5b7eeb24d6ca9c6bcfdff4196d5b47)
ocv_update(NVIDIA_OPTICAL_FLOW_PKG_MD5_ORIGINAL a73cd48b18dcc0cc8933b30796074191) ocv_update(NVIDIA_OPTICAL_FLOW_PKG_MD5_ORIGINAL a73cd48b18dcc0cc8933b30796074191)
@@ -71,7 +74,7 @@ if((DL_ID STREQUAL "FFMPEG") OR (DL_ID STREQUAL "IPPICV") OR (DL_ID STREQUAL "da
ocv_download_url_gitcode_usercontent(opencv) ocv_download_url_gitcode_usercontent(opencv)
elseif(DL_ID STREQUAL "wechat_qrcode") elseif(DL_ID STREQUAL "wechat_qrcode")
ocv_download_url_gitcode_usercontent(mirrors/WeChatCV) ocv_download_url_gitcode_usercontent(mirrors/WeChatCV)
elseif((DL_ID STREQUAL "NVIDIA_OPTICAL_FLOW") OR (DL_ID STREQUAL "TIM-VX")) elseif((DL_ID STREQUAL "TENGINE") OR (DL_ID STREQUAL "NVIDIA_OPTICAL_FLOW") OR (DL_ID STREQUAL "TIM-VX"))
ocv_download_url_gitcode_archive_commit_id() ocv_download_url_gitcode_archive_commit_id()
elseif(DL_ID STREQUAL "TBB") elseif(DL_ID STREQUAL "TBB")
ocv_download_url_gitcode_archive_release(OPENCV_TBB_SUBDIR) ocv_download_url_gitcode_archive_release(OPENCV_TBB_SUBDIR)
@@ -1,31 +0,0 @@
# Version Compute Capability from which OpenCV has been compiled is remembered
set(OpenCV_COMPUTE_CAPABILITIES "@OpenCV_CUDA_CC@")
set(OpenCV_CUDA_VERSION "@CUDA_VERSION_STRING@")
set(OpenCV_USE_CUBLAS "@HAVE_CUBLAS@")
set(OpenCV_USE_CUFFT "@HAVE_CUFFT@")
set(OpenCV_USE_NVCUVID "@HAVE_NVCUVID@")
set(OpenCV_USE_NVCUVENC "@HAVE_NVCUVENC@")
set(OpenCV_CUDNN_VERSION "@CUDNN_VERSION@")
set(OpenCV_USE_CUDNN "@HAVE_CUDNN@")
set(ENABLE_CUDA_FIRST_CLASS_LANGUAGE ON)
if(NOT CUDAToolkit_FOUND)
if(NOT CMAKE_VERSION VERSION_LESS 3.18)
if(UNIX AND NOT CMAKE_CUDA_COMPILER AND NOT CUDAToolkit_ROOT)
message(STATUS "Checking for CUDAToolkit in default location (/usr/local/cuda)")
set(CUDA_PATH "/usr/local/cuda" CACHE INTERNAL "")
set(ENV{CUDA_PATH} ${CUDA_PATH})
endif()
find_package(CUDAToolkit ${OpenCV_CUDA_VERSION} EXACT REQUIRED)
else()
message(FATAL_ERROR "Using OpenCV compiled with CUDA as first class language requires CMake \>= 3.18.")
endif()
else()
if(CUDAToolkit_FOUND)
set(CUDA_VERSION_STRING ${CUDAToolkit_VERSION})
endif()
if(NOT CUDA_VERSION_STRING VERSION_EQUAL OpenCV_CUDA_VERSION)
message(FATAL_ERROR "OpenCV library was compiled with CUDA ${OpenCV_CUDA_VERSION} support. Please, use the same version or rebuild OpenCV with CUDA ${CUDA_VERSION_STRING}")
endif()
endif()
+3
View File
@@ -78,6 +78,9 @@
/* IJG JPEG codec */ /* IJG JPEG codec */
#cmakedefine HAVE_JPEG #cmakedefine HAVE_JPEG
/* libpng/png.h needs to be included */
#cmakedefine HAVE_LIBPNG_PNG_H
/* GDCM DICOM codec */ /* GDCM DICOM codec */
#cmakedefine HAVE_GDCM #cmakedefine HAVE_GDCM
+1 -1
View File
@@ -1,4 +1,4 @@
Starting from OpenCV 4.5-pre (2020 August) OpenCV has changed the license from BSD to Apache 2. See https://opencv.org/blog/opencv-is-to-change-the-license-to-apache-2/ and https://github.com/opencv/opencv/wiki/OE-32.--Change-OpenCV-License-to-Apache-2 for details. Starting from OpenCV 4.5-pre (2020 August) OpenCV has changed the license from BSD to Apache 2. See https://opencv.org/opencv-is-to-change-the-license-to-apache-2/ and https://github.com/opencv/opencv/wiki/OE-32.--Change-OpenCV-License-to-Apache-2 for details.
Here is the original OpenCV license: Here is the original OpenCV license:
------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------
@@ -54,7 +54,7 @@ repository](https://github.com/opencv/opencv.git).
### Obtaining the Latest Stable OpenCV Version ### Obtaining the Latest Stable OpenCV Version
- Go to our [releases page](https://opencv.org/releases). - Go to our [releases page](http://opencv.org/releases.html).
- Download the source archive and unpack it. - Download the source archive and unpack it.
### Obtaining the Cutting-edge OpenCV from the Git Repository ### Obtaining the Cutting-edge OpenCV from the Git Repository
-90
View File
@@ -1377,93 +1377,3 @@
year={2005}, year={2005},
pages={70-74} pages={70-74}
} }
@inproceedings{wang2016iros,
AUTHOR = {John Wang and Edwin Olson},
TITLE = {{AprilTag} 2: Efficient and robust fiducial detection},
BOOKTITLE = {Proceedings of the {IEEE/RSJ} International Conference on Intelligent
Robots and Systems {(IROS)}},
YEAR = {2016},
MONTH = {October},
}
@inproceedings{BarathGCRANSAC,
author = {Barath, Daniel and Matas, Jiri},
title = {Graph-Cut RANSAC},
booktitle = {Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
month = {June},
year = {2018}
}
@misc{barath2019progressive,
title={Progressive NAPSAC: sampling from gradually growing neighborhoods},
author={Barath, Daniel and Ivashechkin, Maksym and Matas, Jiri},
year={2019},
eprint={1906.02295},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
@inproceedings{BarathMAGSAC,
author = {Barath, Daniel and Noskova, Jana and Ivashechkin, Maksym and Matas, Jiri},
title = {MAGSAC++, a Fast, Reliable and Accurate Robust Estimator},
booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
month = {June},
year = {2020}
}
@inproceedings{ChumPROSAC,
title = {Matching with {PROSAC} - Progressive Sampling Consensus},
author = {Chum, Ondrej and Matas, Jiri},
booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
year = {2005}
}
@inproceedings{ChumLORANSAC,
title = {Locally Optimized {RANSAC}},
author = {Chum, Ondrej and Matas, Jiri and Kittler, Josef},
booktitle = {DAGM},
year = {2003}
}
@inproceedings{ChumEpipolar,
author={Chum, Ondrej and Werner, Tomas and Matas, Jiri},
booktitle={Proceedings of the 17th International Conference on Pattern Recognition. ICPR 2004},
title={Epipolar geometry estimation via RANSAC benefits from the oriented epipolar constraint},
year={2004},
volume={1},
pages={112-115 Vol.1}
}
@inproceedings{ChumDominant,
title = {Epipolar Geometry Estimation Unaffected by the Dominant Plane},
author = {Chum, Ondrej and Werner, Tomas and Matas, Jiri.},
booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
year = {2005}
}
@article{FischlerRANSAC,
author = {Fischler, Martin A. and Bolles, Robert C.},
title = {Random Sample Consensus: A Paradigm for Model Fitting with Applications to Image Analysis and Automated Cartography},
year = {1981},
publisher = {Association for Computing Machinery},
volume = {24},
number = {6},
month = {jun},
pages = {381395},
numpages = {15}
}
@article{Matas2005RandomizedRW,
title={Randomized RANSAC with sequential probability ratio test},
author={Matas, Jiri and Chum, Ondrej},
journal={Tenth IEEE International Conference on Computer Vision (ICCV) Volume 1},
year={2005},
volume={2},
pages={1727-1732 Vol. 2}
}
@inproceedings{MyattNAPSAC,
author = {Myatt, D. and Torr, Philip and Nasuto, Slawomir and Bishop, John and Craddock, R.},
year = {2002},
booktitle = {Proceedings of the British Machine Vision Conference (BMVC)},
title = {NAPSAC: High Noise, High Dimensional Robust Estimation - it's in the Bag}
}
@article{SteweniusRecent,
author = {Stewenius, Henrik and Engels, Christopher and Nister, David},
year = {2006},
month = {06},
pages = {284-294},
title = {Recent developments on direct relative orientation},
volume = {60},
journal = {ISPRS Journal of Photogrammetry and Remote Sensing}
}
-5
View File
@@ -186,8 +186,6 @@ class PatternMaker:
yspacing = (self.height - self.rows * self.square_size) / 2.0 yspacing = (self.height - self.rows * self.square_size) / 2.0
ch_ar_border = (self.square_size - self.aruco_marker_size)/2 ch_ar_border = (self.square_size - self.aruco_marker_size)/2
if ch_ar_border < side*0.7:
print("Marker border {} is less than 70% of ArUco pin size {}. Please increase --square_size or decrease --marker_size for stable board detection".format(ch_ar_border, int(side)))
marker_id = 0 marker_id = 0
for y in range(0, self.rows): for y in range(0, self.rows):
for x in range(0, self.cols): for x in range(0, self.cols):
@@ -285,9 +283,6 @@ def main():
else: else:
raise ValueError("The marker {},{} is outside the checkerboard".format(x, y)) raise ValueError("The marker {},{} is outside the checkerboard".format(x, y))
if p_type == "charuco_board" and aruco_marker_size >= square_size:
raise ValueError("ArUco markers size must be smaller than square size")
pm = PatternMaker(columns, rows, output, units, square_size, radius_rate, page_width, page_height, markers, aruco_marker_size, dict_file) pm = PatternMaker(columns, rows, output, units, square_size, radius_rate, page_width, page_height, markers, aruco_marker_size, dict_file)
# dict for easy lookup of pattern type # dict for easy lookup of pattern type
mp = {"circles": pm.make_circles_pattern, "acircles": pm.make_acircles_pattern, mp = {"circles": pm.make_circles_pattern, "acircles": pm.make_acircles_pattern,
+15 -27
View File
@@ -34,7 +34,7 @@ class aruco_objdetect_test(NewOpenCVTests):
aruco_dict = cv.aruco.getPredefinedDictionary(aruco_type[aruco_type_i]) aruco_dict = cv.aruco.getPredefinedDictionary(aruco_type[aruco_type_i])
board = cv.aruco.CharucoBoard((cols, rows), square_size, marker_size, aruco_dict) board = cv.aruco.CharucoBoard((cols, rows), square_size, marker_size, aruco_dict)
charuco_detector = cv.aruco.CharucoDetector(board) charuco_detector = cv.aruco.CharucoDetector(board)
from_cv_img = board.generateImage((cols*square_size, rows*square_size)) from_cv_img = board.generateImage((cols*square_size*10, rows*square_size*10))
#draw desk using svg #draw desk using svg
fd1, filesvg = tempfile.mkstemp(prefix="out", suffix=".svg") fd1, filesvg = tempfile.mkstemp(prefix="out", suffix=".svg")
@@ -50,20 +50,15 @@ class aruco_objdetect_test(NewOpenCVTests):
pm.make_charuco_board() pm.make_charuco_board()
pm.save() pm.save()
drawing = svg2rlg(filesvg) drawing = svg2rlg(filesvg)
renderPM.drawToFile(drawing, filepng, fmt='PNG', dpi=72) renderPM.drawToFile(drawing, filepng, fmt='PNG', dpi=720)
from_svg_img = cv.imread(filepng) from_svg_img = cv.imread(filepng)
_charucoCorners, _charuco_ids_svg, marker_corners_svg, marker_ids_svg = charuco_detector.detectBoard(from_svg_img)
_charucoCorners, _charuco_ids_cv, marker_corners_cv, marker_ids_cv = charuco_detector.detectBoard(from_cv_img)
marker_corners_svg_map, marker_corners_cv_map = {}, {}
for i in range(len(marker_ids_svg)):
marker_corners_svg_map[int(marker_ids_svg[i][0])] = marker_corners_svg[i]
for i in range(len(marker_ids_cv)):
marker_corners_cv_map[int(marker_ids_cv[i][0])] = marker_corners_cv[i]
for key_svg in marker_corners_svg_map.keys(): #test
marker_svg = marker_corners_svg_map[key_svg] _charucoCorners, _charucoIds, markerCorners_svg, markerIds_svg = charuco_detector.detectBoard(from_svg_img)
marker_cv = marker_corners_cv_map[key_svg] _charucoCorners, _charucoIds, markerCorners_cv, markerIds_cv = charuco_detector.detectBoard(from_cv_img)
np.testing.assert_allclose(marker_svg, marker_cv, 0.1, 0.1)
np.testing.assert_allclose(markerCorners_svg, markerCorners_cv, 0.1, 0.1)
np.testing.assert_allclose(markerIds_svg, markerIds_cv, 0.1, 0.1)
finally: finally:
if os.path.exists(filesvg): if os.path.exists(filesvg):
os.remove(filesvg) os.remove(filesvg)
@@ -92,7 +87,7 @@ class aruco_objdetect_test(NewOpenCVTests):
aruco_dict = cv.aruco.getPredefinedDictionary(aruco_type) aruco_dict = cv.aruco.getPredefinedDictionary(aruco_type)
board = cv.aruco.CharucoBoard((cols, rows), square_size, marker_size, aruco_dict) board = cv.aruco.CharucoBoard((cols, rows), square_size, marker_size, aruco_dict)
charuco_detector = cv.aruco.CharucoDetector(board) charuco_detector = cv.aruco.CharucoDetector(board)
from_cv_img = board.generateImage((cols*square_size, rows*square_size)) from_cv_img = board.generateImage((cols*square_size*10, rows*square_size*10))
#draw desk using svg #draw desk using svg
fd1, filesvg = tempfile.mkstemp(prefix="out", suffix=".svg") fd1, filesvg = tempfile.mkstemp(prefix="out", suffix=".svg")
@@ -107,24 +102,17 @@ class aruco_objdetect_test(NewOpenCVTests):
pm.make_charuco_board() pm.make_charuco_board()
pm.save() pm.save()
drawing = svg2rlg(filesvg) drawing = svg2rlg(filesvg)
renderPM.drawToFile(drawing, filepng, fmt='PNG', dpi=72) renderPM.drawToFile(drawing, filepng, fmt='PNG', dpi=720)
from_svg_img = cv.imread(filepng) from_svg_img = cv.imread(filepng)
#test #test
_charucoCorners, _charuco_ids_svg, marker_corners_svg, marker_ids_svg = charuco_detector.detectBoard(from_svg_img) _charucoCorners, _charucoIds, markerCorners_svg, markerIds_svg = charuco_detector.detectBoard(from_svg_img)
_charucoCorners, _charuco_ids_cv, marker_corners_cv, marker_ids_cv = charuco_detector.detectBoard(from_cv_img) _charucoCorners, _charucoIds, markerCorners_cv, markerIds_cv = charuco_detector.detectBoard(from_cv_img)
marker_corners_svg_map, marker_corners_cv_map = {}, {}
for i in range(len(marker_ids_svg)):
marker_corners_svg_map[int(marker_ids_svg[i][0])] = marker_corners_svg[i]
for i in range(len(marker_ids_cv)):
marker_corners_cv_map[int(marker_ids_cv[i][0])] = marker_corners_cv[i]
for key_svg in marker_corners_svg_map.keys(): np.testing.assert_allclose(markerCorners_svg, markerCorners_cv, 0.1, 0.1)
marker_svg = marker_corners_svg_map[key_svg] np.testing.assert_allclose(markerIds_svg, markerIds_cv, 0.1, 0.1)
marker_cv = marker_corners_cv_map[key_svg]
np.testing.assert_allclose(marker_svg, marker_cv, 0.1, 0.1)
finally: finally:
if os.path.exists(filesvg): if os.path.exists(filesvg):
os.remove(filesvg) os.remove(filesvg)
if os.path.exists(filepng): if os.path.exists(filepng):
os.remove(filepng) os.remove(filepng)
@@ -79,12 +79,9 @@ Functions are extended using `CV_EXPORTS_W` macro. An example is shown below.
@code{.cpp} @code{.cpp}
CV_EXPORTS_W void equalizeHist( InputArray src, OutputArray dst ); CV_EXPORTS_W void equalizeHist( InputArray src, OutputArray dst );
@endcode @endcode
Header parser can understand the input and output arguments from keywords like InputArray, Header parser can understand the input and output arguments from keywords like
OutputArray etc. The arguments semantics are kept in Python: anything that is modified in C++ InputArray, OutputArray etc. But sometimes, we may need to hardcode inputs and outputs. For that,
will be modified in Python. And vice-versa read-only Python objects cannot be modified by OpenCV, macros like `CV_OUT`, `CV_IN_OUT` etc. are used.
if they are used as output. Such situation will cause Python exception. Sometimes, the parameters
that are passed by reference in C++ may be used as input, output or both.
Macros `CV_OUT`, `CV_IN_OUT` allow to solve ambiguity and generate correct bindings.
@code{.cpp} @code{.cpp}
CV_EXPORTS_W void minEnclosingCircle( InputArray points, CV_EXPORTS_W void minEnclosingCircle( InputArray points,
CV_OUT Point2f& center, CV_OUT float& radius ); CV_OUT Point2f& center, CV_OUT float& radius );
@@ -111,7 +111,7 @@ frames per second (fps) and frame size should be passed. And the last one is the
`True`, the encoder expect color frame, otherwise it works with grayscale frame. `True`, the encoder expect color frame, otherwise it works with grayscale frame.
[FourCC](http://en.wikipedia.org/wiki/FourCC) is a 4-byte code used to specify the video codec. The [FourCC](http://en.wikipedia.org/wiki/FourCC) is a 4-byte code used to specify the video codec. The
list of available codes can be found in [fourcc.org](https://fourcc.org/codecs.php). It is list of available codes can be found in [fourcc.org](http://www.fourcc.org/codecs.php). It is
platform dependent. The following codecs work fine for me. platform dependent. The following codecs work fine for me.
- In Fedora: DIVX, XVID, MJPG, X264, WMV1, WMV2. (XVID is more preferable. MJPG results in high - In Fedora: DIVX, XVID, MJPG, X264, WMV1, WMV2. (XVID is more preferable. MJPG results in high
@@ -80,7 +80,7 @@ using **np.ifft2()** function. The result, again, will be a complex number. You
absolute value. absolute value.
@code{.py} @code{.py}
rows, cols = img.shape rows, cols = img.shape
crow, ccol = rows//2, cols//2 crow,ccol = rows//2 , cols//2
fshift[crow-30:crow+31, ccol-30:ccol+31] = 0 fshift[crow-30:crow+31, ccol-30:ccol+31] = 0
f_ishift = np.fft.ifftshift(fshift) f_ishift = np.fft.ifftshift(fshift)
img_back = np.fft.ifft2(f_ishift) img_back = np.fft.ifft2(f_ishift)
@@ -146,7 +146,7 @@ content, and 0 at HF region.
@code{.py} @code{.py}
rows, cols = img.shape rows, cols = img.shape
crow, ccol = rows//2, cols//2 crow,ccol = rows/2 , cols/2
# create a mask first, center square is 1, remaining all zeros # create a mask first, center square is 1, remaining all zeros
mask = np.zeros((rows,cols,2),np.uint8) mask = np.zeros((rows,cols,2),np.uint8)
@@ -141,7 +141,7 @@ Additional Resources
-------------------- --------------------
1. [NPTEL notes on Pattern Recognition, Chapter 1. [NPTEL notes on Pattern Recognition, Chapter
11](https://nptel.ac.in/courses/106108057) 11](https://nptel.ac.in/courses/106/108/106108057/)
2. [Wikipedia article on Nearest neighbor search](https://en.wikipedia.org/wiki/Nearest_neighbor_search) 2. [Wikipedia article on Nearest neighbor search](https://en.wikipedia.org/wiki/Nearest_neighbor_search)
3. [Wikipedia article on k-d tree](https://en.wikipedia.org/wiki/K-d_tree) 3. [Wikipedia article on k-d tree](https://en.wikipedia.org/wiki/K-d_tree)
@@ -129,6 +129,7 @@ Additional Resources
-------------------- --------------------
-# [NPTEL notes on Statistical Pattern Recognition, Chapters -# [NPTEL notes on Statistical Pattern Recognition, Chapters
25-29](https://nptel.ac.in/courses/117108048) 25-29](http://www.nptel.ac.in/courses/106108057/26).
Exercises Exercises
--------- ---------
@@ -4,7 +4,6 @@ Interactive camera calibration application {#tutorial_interactive_calibration}
@tableofcontents @tableofcontents
@prev_tutorial{tutorial_real_time_pose} @prev_tutorial{tutorial_real_time_pose}
@next_tutorial{tutorial_usac}
| | | | | |
| -: | :- | | -: | :- |

Some files were not shown because too many files have changed in this diff Show More