├── .editorconfig
├── .github
└── workflows
│ └── artifcats.yaml
├── .gitignore
├── CMakeLists.txt
├── Folder.DotSettings
├── Installer
├── Installer.sln
├── Installer.wixproj
├── Product.wxs
└── README.txt
├── LICENSE
├── README.md
├── __lib__
└── libwebp-1.1.0-windows-x64
│ ├── CMakeLists.txt
│ ├── Readme-mux.txt
│ ├── include
│ └── webp
│ │ ├── decode.h
│ │ ├── demux.h
│ │ ├── encode.h
│ │ ├── mux.h
│ │ ├── mux_types.h
│ │ └── types.h
│ ├── lib
│ ├── libwebp.lib
│ ├── libwebpdemux.lib
│ └── libwebpmux.lib
│ ├── test.webp
│ └── test_ref.ppm
├── docs
└── preview.png
└── src
├── ClassFactory.cpp
├── ClassFactory.h
├── Registry.cpp
├── Registry.h
├── ThumbnailProvider.cpp
├── ThumbnailProvider.h
├── WebpReader.cpp
├── WebpReader.h
├── dllmain.cpp
├── dllmain.def
└── dllmain.h
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | end_of_line = lf
5 | insert_final_newline = true
6 | indent_style = space
7 | indent_size = 4
8 |
--------------------------------------------------------------------------------
/.github/workflows/artifcats.yaml:
--------------------------------------------------------------------------------
1 | name: Artifacts
2 | on:
3 | push:
4 | branches-ignore:
5 | - main
6 | tags:
7 | - v*
8 |
9 | defaults:
10 | run:
11 | shell: powershell
12 |
13 | jobs:
14 | release:
15 | name: Make artifacts
16 | runs-on: windows-2022
17 | steps:
18 | - name: Set Short Sha
19 | run: |
20 | echo "git_sha=$('${{github.sha}}'.Substring(0, 7))" >> $env:GITHUB_ENV
21 |
22 | - name: Set Version Information - Main
23 | if: ${{startsWith(github.ref, 'refs/tags/v')}}
24 | run: |
25 | echo "product_version=$('${{github.ref}}-${{github.run_number}}-${{env.git_sha}}' -replace 'refs/tags/v','')" >> $env:GITHUB_ENV
26 | echo "product_installer_version=$('${{github.ref}}.${{github.run_number}}' -replace 'refs/tags/v','')" >> $env:GITHUB_ENV
27 |
28 | - name: Set Version Information - Branch
29 | if: ${{startsWith(github.ref, 'refs/heads/')}}
30 | run: |
31 | echo "product_version=$('${{github.ref}}' -replace 'refs/heads/','' -replace '[^\w\d]','_')-${{github.run_number}}-${{env.git_sha}}" >> $env:GITHUB_ENV
32 | echo "product_installer_version=0.0.${{github.run_number}}" >> $env:GITHUB_ENV
33 |
34 | - name: Install MSVC 2022
35 | uses: ilammy/msvc-dev-cmd@v1
36 | with:
37 | arch: x64
38 |
39 | - name: Checkout
40 | uses: actions/checkout@v2
41 | with:
42 | path: code
43 | submodules: true
44 |
45 | - name: CMake Cache
46 | run: |
47 | cmake -S ${{github.workspace}}\code\ -B ${{github.workspace}}\_build\ `
48 | -G Ninja -DCMAKE_BUILD_TYPE=Release
49 |
50 | - name: CMake Build
51 | run: cmake --build ${{github.workspace}}\_build\
52 |
53 | - name: CMake Install
54 | run: |
55 | cmake --install ${{github.workspace}}\_build\ --prefix "${{github.workspace}}\_install\"
56 | mkdir ${{github.workspace}}\_artifacts\
57 | cp -Path ${{github.workspace}}\_install\bin -Destination "${{github.workspace}}\_artifacts\" -Recurse
58 | mv -Path ${{github.workspace}}\_artifacts\bin -Destination "${{github.workspace}}\_artifacts\Windows Webp Explorer Preview"
59 |
60 | - name: Upload binaries
61 | uses: actions/upload-artifact@v2
62 | with:
63 | name: WebpExplorerPreview-binaries-${{env.product_version}}
64 | path: ${{github.workspace}}\_artifacts\
65 |
66 | - name: Build installer
67 | run: |
68 | $env:Path=$env:Path + ";C:\Program Files (x86)\WiX Toolset v3.11\bin"
69 | candle.exe -dArtifactsFolder=${{github.workspace}}\_install\bin\ -dProductVersion="${{env.product_installer_version}}" -out ${{github.workspace}}\_artifacts\WebpInstaller.wixobj ${{github.workspace}}\code\installer\Product.wxs
70 | light.exe -ext WixUIExtension -out ${{github.workspace}}\_artifacts\WebpPreviewForWindowsExplorer-${{env.product_installer_version}}.msi ${{github.workspace}}\_artifacts\WebpInstaller.wixobj
71 |
72 | - name: Upload installer
73 | uses: actions/upload-artifact@v2
74 | with:
75 | name: WebpExplorerPreview-installer-${{env.product_version}}
76 | path: ${{github.workspace}}\_artifacts\WebpPreviewForWindowsExplorer-${{env.product_installer_version}}.msi
77 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Ww][Ii][Nn]32/
27 | [Aa][Rr][Mm]/
28 | [Aa][Rr][Mm]64/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 | [Ll]og/
33 | [Ll]ogs/
34 |
35 | # Visual Studio 2015/2017 cache/options directory
36 | .vs/
37 | # Uncomment if you have tasks that create the project's static files in wwwroot
38 | #wwwroot/
39 |
40 | # Visual Studio 2017 auto generated files
41 | Generated\ Files/
42 |
43 | # MSTest test Results
44 | [Tt]est[Rr]esult*/
45 | [Bb]uild[Ll]og.*
46 |
47 | # NUnit
48 | *.VisualState.xml
49 | TestResult.xml
50 | nunit-*.xml
51 |
52 | # Build Results of an ATL Project
53 | [Dd]ebugPS/
54 | [Rr]eleasePS/
55 | dlldata.c
56 |
57 | # Benchmark Results
58 | BenchmarkDotNet.Artifacts/
59 |
60 | # .NET Core
61 | project.lock.json
62 | project.fragment.lock.json
63 | artifacts/
64 |
65 | # ASP.NET Scaffolding
66 | ScaffoldingReadMe.txt
67 |
68 | # StyleCop
69 | StyleCopReport.xml
70 |
71 | # Files built by Visual Studio
72 | *_i.c
73 | *_p.c
74 | *_h.h
75 | *.ilk
76 | *.meta
77 | *.obj
78 | *.iobj
79 | *.pch
80 | *.pdb
81 | *.ipdb
82 | *.pgc
83 | *.pgd
84 | *.rsp
85 | *.sbr
86 | *.tlb
87 | *.tli
88 | *.tlh
89 | *.tmp
90 | *.tmp_proj
91 | *_wpftmp.csproj
92 | *.log
93 | *.vspscc
94 | *.vssscc
95 | .builds
96 | *.pidb
97 | *.svclog
98 | *.scc
99 |
100 | # Chutzpah Test files
101 | _Chutzpah*
102 |
103 | # Visual C++ cache files
104 | ipch/
105 | *.aps
106 | *.ncb
107 | *.opendb
108 | *.opensdf
109 | *.sdf
110 | *.cachefile
111 | *.VC.db
112 | *.VC.VC.opendb
113 |
114 | # Visual Studio profiler
115 | *.psess
116 | *.vsp
117 | *.vspx
118 | *.sap
119 |
120 | # Visual Studio Trace Files
121 | *.e2e
122 |
123 | # TFS 2012 Local Workspace
124 | $tf/
125 |
126 | # Guidance Automation Toolkit
127 | *.gpState
128 |
129 | # ReSharper is a .NET coding add-in
130 | _ReSharper*/
131 | *.[Rr]e[Ss]harper
132 | *.DotSettings.user
133 |
134 | # TeamCity is a build add-in
135 | _TeamCity*
136 |
137 | # DotCover is a Code Coverage Tool
138 | *.dotCover
139 |
140 | # AxoCover is a Code Coverage Tool
141 | .axoCover/*
142 | !.axoCover/settings.json
143 |
144 | # Coverlet is a free, cross platform Code Coverage Tool
145 | coverage*.json
146 | coverage*.xml
147 | coverage*.info
148 |
149 | # Visual Studio code coverage results
150 | *.coverage
151 | *.coveragexml
152 |
153 | # NCrunch
154 | _NCrunch_*
155 | .*crunch*.local.xml
156 | nCrunchTemp_*
157 |
158 | # MightyMoose
159 | *.mm.*
160 | AutoTest.Net/
161 |
162 | # Web workbench (sass)
163 | .sass-cache/
164 |
165 | # Installshield output folder
166 | [Ee]xpress/
167 |
168 | # DocProject is a documentation generator add-in
169 | DocProject/buildhelp/
170 | DocProject/Help/*.HxT
171 | DocProject/Help/*.HxC
172 | DocProject/Help/*.hhc
173 | DocProject/Help/*.hhk
174 | DocProject/Help/*.hhp
175 | DocProject/Help/Html2
176 | DocProject/Help/html
177 |
178 | # Click-Once directory
179 | publish/
180 |
181 | # Publish Web Output
182 | *.[Pp]ublish.xml
183 | *.azurePubxml
184 | # Note: Comment the next line if you want to checkin your web deploy settings,
185 | # but database connection strings (with potential passwords) will be unencrypted
186 | *.pubxml
187 | *.publishproj
188 |
189 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
190 | # checkin your Azure Web App publish settings, but sensitive information contained
191 | # in these scripts will be unencrypted
192 | PublishScripts/
193 |
194 | # NuGet Packages
195 | *.nupkg
196 | # NuGet Symbol Packages
197 | *.snupkg
198 | # The packages folder can be ignored because of Package Restore
199 | **/[Pp]ackages/*
200 | # except build/, which is used as an MSBuild target.
201 | !**/[Pp]ackages/build/
202 | # Uncomment if necessary however generally it will be regenerated when needed
203 | #!**/[Pp]ackages/repositories.config
204 | # NuGet v3's project.json files produces more ignorable files
205 | *.nuget.props
206 | *.nuget.targets
207 |
208 | # Microsoft Azure Build Output
209 | csx/
210 | *.build.csdef
211 |
212 | # Microsoft Azure Emulator
213 | ecf/
214 | rcf/
215 |
216 | # Windows Store app package directories and files
217 | AppPackages/
218 | BundleArtifacts/
219 | Package.StoreAssociation.xml
220 | _pkginfo.txt
221 | *.appx
222 | *.appxbundle
223 | *.appxupload
224 |
225 | # Visual Studio cache files
226 | # files ending in .cache can be ignored
227 | *.[Cc]ache
228 | # but keep track of directories ending in .cache
229 | !?*.[Cc]ache/
230 |
231 | # Others
232 | ClientBin/
233 | ~$*
234 | *~
235 | *.dbmdl
236 | *.dbproj.schemaview
237 | *.jfm
238 | *.pfx
239 | *.publishsettings
240 | orleans.codegen.cs
241 |
242 | # Including strong name files can present a security risk
243 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
244 | #*.snk
245 |
246 | # Since there are multiple workflows, uncomment next line to ignore bower_components
247 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
248 | #bower_components/
249 |
250 | # RIA/Silverlight projects
251 | Generated_Code/
252 |
253 | # Backup & report files from converting an old project file
254 | # to a newer Visual Studio version. Backup files are not needed,
255 | # because we have git ;-)
256 | _UpgradeReport_Files/
257 | Backup*/
258 | UpgradeLog*.XML
259 | UpgradeLog*.htm
260 | ServiceFabricBackup/
261 | *.rptproj.bak
262 |
263 | # SQL Server files
264 | *.mdf
265 | *.ldf
266 | *.ndf
267 |
268 | # Business Intelligence projects
269 | *.rdl.data
270 | *.bim.layout
271 | *.bim_*.settings
272 | *.rptproj.rsuser
273 | *- [Bb]ackup.rdl
274 | *- [Bb]ackup ([0-9]).rdl
275 | *- [Bb]ackup ([0-9][0-9]).rdl
276 |
277 | # Microsoft Fakes
278 | FakesAssemblies/
279 |
280 | # GhostDoc plugin setting file
281 | *.GhostDoc.xml
282 |
283 | # Node.js Tools for Visual Studio
284 | .ntvs_analysis.dat
285 | node_modules/
286 |
287 | # Visual Studio 6 build log
288 | *.plg
289 |
290 | # Visual Studio 6 workspace options file
291 | *.opt
292 |
293 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
294 | *.vbw
295 |
296 | # Visual Studio LightSwitch build output
297 | **/*.HTMLClient/GeneratedArtifacts
298 | **/*.DesktopClient/GeneratedArtifacts
299 | **/*.DesktopClient/ModelManifest.xml
300 | **/*.Server/GeneratedArtifacts
301 | **/*.Server/ModelManifest.xml
302 | _Pvt_Extensions
303 |
304 | # Paket dependency manager
305 | .paket/paket.exe
306 | paket-files/
307 |
308 | # FAKE - F# Make
309 | .fake/
310 |
311 | # CodeRush personal settings
312 | .cr/personal
313 |
314 | # Python Tools for Visual Studio (PTVS)
315 | __pycache__/
316 | *.pyc
317 |
318 | # Cake - Uncomment if you are using it
319 | # tools/**
320 | # !tools/packages.config
321 |
322 | # Tabs Studio
323 | *.tss
324 |
325 | # Telerik's JustMock configuration file
326 | *.jmconfig
327 |
328 | # BizTalk build output
329 | *.btp.cs
330 | *.btm.cs
331 | *.odx.cs
332 | *.xsd.cs
333 |
334 | # OpenCover UI analysis results
335 | OpenCover/
336 |
337 | # Azure Stream Analytics local run output
338 | ASALocalRun/
339 |
340 | # MSBuild Binary and Structured Log
341 | *.binlog
342 |
343 | # NVidia Nsight GPU debugger configuration file
344 | *.nvuser
345 |
346 | # MFractors (Xamarin productivity tool) working folder
347 | .mfractor/
348 |
349 | # Local History for Visual Studio
350 | .localhistory/
351 |
352 | # BeatPulse healthcheck temp database
353 | healthchecksdb
354 |
355 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
356 | MigrationBackup/
357 |
358 | # Ionide (cross platform F# VS Code tools) working folder
359 | .ionide/
360 |
361 | # Fody - auto-generated XML schema
362 | FodyWeavers.xsd
363 |
364 | # Output
365 | out/
366 |
367 | # VS CMakeSettings file
368 | CMakeSettings.json
369 |
370 | # CLion
371 | .idea/
372 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.17)
2 | project(webpext CXX)
3 |
4 | set(CMAKE_SYSTEM_NAME Windows)
5 | set(CMAKE_CXX_STANDARD 17)
6 |
7 | if(MSVC)
8 | set(CMAKE_STATIC_LINKER_FLAGS
9 | "${CMAKE_MODULE_LINKER_FLAGS} /NODEFAULTLIB:LIBCMT")
10 | set(CMAKE_MODULE_LINKER_FLAGS
11 | "${CMAKE_MODULE_LINKER_FLAGS} /DEF:${webpext_SOURCE_DIR}/src/dllmain.def /NODEFAULTLIB:LIBCMT")
12 | endif()
13 |
14 | add_subdirectory(__lib__/libwebp-1.1.0-windows-x64)
15 |
16 | set(TARGET_NAME webpext64)
17 |
18 | set(SOURCE_FILES
19 | "src/ClassFactory.cpp"
20 | "src/dllmain.cpp"
21 | "src/Registry.cpp"
22 | "src/ThumbnailProvider.cpp"
23 | "src/WebpReader.cpp")
24 |
25 | add_library(${TARGET_NAME} MODULE ${SOURCE_FILES})
26 | target_link_libraries(${TARGET_NAME} PRIVATE libwebp shlwapi)
27 |
28 | include(GNUInstallDirs)
29 | install(TARGETS ${TARGET_NAME}
30 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
31 | LIBRARY DESTINATION ${CMAKE_INSTALL_BINDIR}
32 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
33 | PRIVATE_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
34 | PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
35 |
--------------------------------------------------------------------------------
/Folder.DotSettings:
--------------------------------------------------------------------------------
1 |
2 | True
3 | True
4 | HINT
5 | True
6 | True
7 | True
8 | True
9 | True
10 | True
11 | True
12 | True
13 | True
--------------------------------------------------------------------------------
/Installer/Installer.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.30907.101
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "Installer", "Installer.wixproj", "{2E869731-96E6-48ED-9FC2-B64FBA7DEF19}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {2E869731-96E6-48ED-9FC2-B64FBA7DEF19}.Debug|x64.ActiveCfg = Debug|x64
17 | {2E869731-96E6-48ED-9FC2-B64FBA7DEF19}.Debug|x64.Build.0 = Debug|x64
18 | {2E869731-96E6-48ED-9FC2-B64FBA7DEF19}.Debug|x86.ActiveCfg = Debug|x86
19 | {2E869731-96E6-48ED-9FC2-B64FBA7DEF19}.Debug|x86.Build.0 = Debug|x86
20 | {2E869731-96E6-48ED-9FC2-B64FBA7DEF19}.Release|x64.ActiveCfg = Release|x64
21 | {2E869731-96E6-48ED-9FC2-B64FBA7DEF19}.Release|x64.Build.0 = Release|x64
22 | {2E869731-96E6-48ED-9FC2-B64FBA7DEF19}.Release|x86.ActiveCfg = Release|x86
23 | {2E869731-96E6-48ED-9FC2-B64FBA7DEF19}.Release|x86.Build.0 = Release|x86
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {38681D21-A335-4520-B9C0-9C610A81EE98}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/Installer/Installer.wixproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | x86
6 | 3.10
7 | 2e869731-96e6-48ed-9fc2-b64fba7def19
8 | 2.0
9 | WebpPreviewForWindowsExplorer-1.0.0
10 | Package
11 |
12 |
13 | bin\$(Configuration)\
14 | obj\$(Configuration)\
15 | ArtifactsFolder=..\..\..\out\install\x64-Release\bin\
16 |
17 |
18 |
19 |
20 |
21 |
22 | $(WixToolPath)WixUIExtension.dll
23 | WixUIExtension
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
39 |
--------------------------------------------------------------------------------
/Installer/Product.wxs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
9 |
10 |
14 |
15 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | 1
31 | 1
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
52 |
54 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/Installer/README.txt:
--------------------------------------------------------------------------------
1 | Despite this is a VS project, I don't intend to compile it via Visual Studio.
2 |
3 | To compile, please use the commands:
4 |
5 | candle.exe -dArtifactsFolder={where-the-artifcats-are} -dProductVersion="0.0.1" Product.wxs
6 | light.exe -ext WixUIExtension .\Product.wixobj
7 |
8 | If you ever need to harvest the artifcats dir for the files, use:
9 |
10 | heat dir {where-the-artifcats-are} -srd -sreg -gg -g1 -o {result-file-name}
11 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Nikita Kobzev
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Webp Preview For Windows Explorer
2 |
3 | The shell extension teaches Windows Explorer to display previews of [webp](https://developers.google.com/speed/webp/gallery1).
4 |
5 | 
6 |
7 | ## Compatibility
8 |
9 | The extension was developed and tested on `Windows 10` though I expect it to work on other windows versions.
10 |
11 | ## Installation
12 |
13 | You can install the extension either manually or using the installer.
14 |
15 | ### Installer
16 |
17 | 1. Download the `Installer` from the [Releases][releases] section
18 | 2. Run the `Installer`
19 |
20 | ### Manual installation
21 |
22 | 1. Download the `DLL` from the [Releases][releases] section
23 | 2. Put the `DLL` into the desired place in your system
24 | 3. Register the `DLL` via `regsvr32`.
25 | ```
26 | C:\Windows\SysWOW64\regsvr32.exe C:\Where\The\Dll\Resides\webpext64.dll
27 | ```
28 |
29 | To unregister the `DLL` later again use `regsvr32`:
30 | ```
31 | C:\Windows\SysWOW64\regsvr32.exe /u C:\Where\The\Dll\Resides\webpext64.dll
32 | ```
33 | Normally no admin permissions should be required for the registration.
34 |
35 | [releases]: https://github.com/winseros/WebpPreviewForWindowsExplorer/releases
36 |
--------------------------------------------------------------------------------
/__lib__/libwebp-1.1.0-windows-x64/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.17)
2 | project(libwebp)
3 |
4 | add_library(libwebp INTERFACE)
5 | target_include_directories(libwebp INTERFACE include)
6 | target_link_libraries(libwebp INTERFACE ${libwebp_SOURCE_DIR}/lib/libwebp.lib)
7 |
--------------------------------------------------------------------------------
/__lib__/libwebp-1.1.0-windows-x64/Readme-mux.txt:
--------------------------------------------------------------------------------
1 | __ __ ____ ____ ____ __ __ _ __ __
2 | / \\/ \/ _ \/ _ \/ _ \/ \ \/ \___/_ / _\
3 | \ / __/ _ \ __/ / / (_/ /__
4 | \__\__/\_____/_____/__/ \__//_/\_____/__/___/v1.1.0
5 |
6 |
7 | Description:
8 | ============
9 |
10 | WebPMux: set of two libraries 'Mux' and 'Demux' for creation, extraction and
11 | manipulation of an extended format WebP file, which can have features like
12 | color profile, metadata and animation. Reference command-line tools 'webpmux'
13 | and 'vwebp' as well as the WebP container specification
14 | 'doc/webp-container-spec.txt' are also provided in this package.
15 |
16 | WebP Mux tool:
17 | ==============
18 |
19 | The examples/ directory contains a tool (webpmux) for manipulating WebP
20 | files. The webpmux tool can be used to create an extended format WebP file and
21 | also to extract or strip relevant data from such a file.
22 |
23 | A list of options is available using the -help command line flag:
24 |
25 | > webpmux -help
26 | Usage: webpmux -get GET_OPTIONS INPUT -o OUTPUT
27 | webpmux -set SET_OPTIONS INPUT -o OUTPUT
28 | webpmux -duration DURATION_OPTIONS [-duration ...]
29 | INPUT -o OUTPUT
30 | webpmux -strip STRIP_OPTIONS INPUT -o OUTPUT
31 | webpmux -frame FRAME_OPTIONS [-frame...] [-loop LOOP_COUNT]
32 | [-bgcolor BACKGROUND_COLOR] -o OUTPUT
33 | webpmux -info INPUT
34 | webpmux [-h|-help]
35 | webpmux -version
36 | webpmux argument_file_name
37 |
38 | GET_OPTIONS:
39 | Extract relevant data:
40 | icc get ICC profile
41 | exif get EXIF metadata
42 | xmp get XMP metadata
43 | frame n get nth frame
44 |
45 | SET_OPTIONS:
46 | Set color profile/metadata:
47 | icc file.icc set ICC profile
48 | exif file.exif set EXIF metadata
49 | xmp file.xmp set XMP metadata
50 | where: 'file.icc' contains the ICC profile to be set,
51 | 'file.exif' contains the EXIF metadata to be set
52 | 'file.xmp' contains the XMP metadata to be set
53 |
54 | DURATION_OPTIONS:
55 | Set duration of selected frames:
56 | duration set duration for each frames
57 | duration,frame set duration of a particular frame
58 | duration,start,end set duration of frames in the
59 | interval [start,end])
60 | where: 'duration' is the duration in milliseconds
61 | 'start' is the start frame index
62 | 'end' is the inclusive end frame index
63 | The special 'end' value '0' means: last frame.
64 |
65 | STRIP_OPTIONS:
66 | Strip color profile/metadata:
67 | icc strip ICC profile
68 | exif strip EXIF metadata
69 | xmp strip XMP metadata
70 |
71 | FRAME_OPTIONS(i):
72 | Create animation:
73 | file_i +di+[xi+yi[+mi[bi]]]
74 | where: 'file_i' is the i'th animation frame (WebP format),
75 | 'di' is the pause duration before next frame,
76 | 'xi','yi' specify the image offset for this frame,
77 | 'mi' is the dispose method for this frame (0 or 1),
78 | 'bi' is the blending method for this frame (+b or -b)
79 |
80 | LOOP_COUNT:
81 | Number of times to repeat the animation.
82 | Valid range is 0 to 65535 [Default: 0 (infinite)].
83 |
84 | BACKGROUND_COLOR:
85 | Background color of the canvas.
86 | A,R,G,B
87 | where: 'A', 'R', 'G' and 'B' are integers in the range 0 to 255 specifying
88 | the Alpha, Red, Green and Blue component values respectively
89 | [Default: 255,255,255,255]
90 |
91 | INPUT & OUTPUT are in WebP format.
92 |
93 | Note: The nature of EXIF, XMP and ICC data is not checked and is assumed to be
94 | valid.
95 |
96 | Note: if a single file name is passed as the argument, the arguments will be
97 | tokenized from this file. The file name must not start with the character '-'.
98 |
99 | Visualization tool:
100 | ===================
101 |
102 | The examples/ directory also contains a tool (vwebp) for viewing WebP files.
103 | It decodes the image and visualizes it using OpenGL. See the libwebp README
104 | for details on building and running this program.
105 |
106 | Mux API:
107 | ========
108 | The Mux API contains methods for adding data to and reading data from WebP
109 | files. This API currently supports XMP/EXIF metadata, ICC profile and animation.
110 | Other features may be added in subsequent releases.
111 |
112 | Example#1 (pseudo code): Creating a WebPMux object with image data, color
113 | profile and XMP metadata.
114 |
115 | int copy_data = 0;
116 | WebPMux* mux = WebPMuxNew();
117 | // ... (Prepare image data).
118 | WebPMuxSetImage(mux, &image, copy_data);
119 | // ... (Prepare ICC profile data).
120 | WebPMuxSetChunk(mux, "ICCP", &icc_profile, copy_data);
121 | // ... (Prepare XMP metadata).
122 | WebPMuxSetChunk(mux, "XMP ", &xmp, copy_data);
123 | // Get data from mux in WebP RIFF format.
124 | WebPMuxAssemble(mux, &output_data);
125 | WebPMuxDelete(mux);
126 | // ... (Consume output_data; e.g. write output_data.bytes to file).
127 | WebPDataClear(&output_data);
128 |
129 |
130 | Example#2 (pseudo code): Get image and color profile data from a WebP file.
131 |
132 | int copy_data = 0;
133 | // ... (Read data from file).
134 | WebPMux* mux = WebPMuxCreate(&data, copy_data);
135 | WebPMuxGetFrame(mux, 1, &image);
136 | // ... (Consume image; e.g. call WebPDecode() to decode the data).
137 | WebPMuxGetChunk(mux, "ICCP", &icc_profile);
138 | // ... (Consume icc_profile).
139 | WebPMuxDelete(mux);
140 | free(data);
141 |
142 |
143 | For a detailed Mux API reference, please refer to the header file
144 | (src/webp/mux.h).
145 |
146 | Demux API:
147 | ==========
148 | The Demux API enables extraction of images and extended format data from
149 | WebP files. This API currently supports reading of XMP/EXIF metadata, ICC
150 | profile and animated images. Other features may be added in subsequent
151 | releases.
152 |
153 | Code example: Demuxing WebP data to extract all the frames, ICC profile
154 | and EXIF/XMP metadata.
155 |
156 | WebPDemuxer* demux = WebPDemux(&webp_data);
157 | uint32_t width = WebPDemuxGetI(demux, WEBP_FF_CANVAS_WIDTH);
158 | uint32_t height = WebPDemuxGetI(demux, WEBP_FF_CANVAS_HEIGHT);
159 | // ... (Get information about the features present in the WebP file).
160 | uint32_t flags = WebPDemuxGetI(demux, WEBP_FF_FORMAT_FLAGS);
161 |
162 | // ... (Iterate over all frames).
163 | WebPIterator iter;
164 | if (WebPDemuxGetFrame(demux, 1, &iter)) {
165 | do {
166 | // ... (Consume 'iter'; e.g. Decode 'iter.fragment' with WebPDecode(),
167 | // ... and get other frame properties like width, height, offsets etc.
168 | // ... see 'struct WebPIterator' below for more info).
169 | } while (WebPDemuxNextFrame(&iter));
170 | WebPDemuxReleaseIterator(&iter);
171 | }
172 |
173 | // ... (Extract metadata).
174 | WebPChunkIterator chunk_iter;
175 | if (flags & ICCP_FLAG) WebPDemuxGetChunk(demux, "ICCP", 1, &chunk_iter);
176 | // ... (Consume the ICC profile in 'chunk_iter.chunk').
177 | WebPDemuxReleaseChunkIterator(&chunk_iter);
178 | if (flags & EXIF_FLAG) WebPDemuxGetChunk(demux, "EXIF", 1, &chunk_iter);
179 | // ... (Consume the EXIF metadata in 'chunk_iter.chunk').
180 | WebPDemuxReleaseChunkIterator(&chunk_iter);
181 | if (flags & XMP_FLAG) WebPDemuxGetChunk(demux, "XMP ", 1, &chunk_iter);
182 | // ... (Consume the XMP metadata in 'chunk_iter.chunk').
183 | WebPDemuxReleaseChunkIterator(&chunk_iter);
184 | WebPDemuxDelete(demux);
185 |
186 |
187 | For a detailed Demux API reference, please refer to the header file
188 | (src/webp/demux.h).
189 |
190 | AnimEncoder API:
191 | ================
192 | The AnimEncoder API can be used to create animated WebP images.
193 |
194 | Code example:
195 |
196 | WebPAnimEncoderOptions enc_options;
197 | WebPAnimEncoderOptionsInit(&enc_options);
198 | // ... (Tune 'enc_options' as needed).
199 | WebPAnimEncoder* enc = WebPAnimEncoderNew(width, height, &enc_options);
200 | while() {
201 | WebPConfig config;
202 | WebPConfigInit(&config);
203 | // ... (Tune 'config' as needed).
204 | WebPAnimEncoderAdd(enc, frame, duration, &config);
205 | }
206 | WebPAnimEncoderAssemble(enc, webp_data);
207 | WebPAnimEncoderDelete(enc);
208 | // ... (Write the 'webp_data' to a file, or re-mux it further).
209 |
210 |
211 | For a detailed AnimEncoder API reference, please refer to the header file
212 | (src/webp/mux.h).
213 |
214 | AnimDecoder API:
215 | ================
216 | This AnimDecoder API allows decoding (possibly) animated WebP images.
217 |
218 | Code Example:
219 |
220 | WebPAnimDecoderOptions dec_options;
221 | WebPAnimDecoderOptionsInit(&dec_options);
222 | // Tune 'dec_options' as needed.
223 | WebPAnimDecoder* dec = WebPAnimDecoderNew(webp_data, &dec_options);
224 | WebPAnimInfo anim_info;
225 | WebPAnimDecoderGetInfo(dec, &anim_info);
226 | for (uint32_t i = 0; i < anim_info.loop_count; ++i) {
227 | while (WebPAnimDecoderHasMoreFrames(dec)) {
228 | uint8_t* buf;
229 | int timestamp;
230 | WebPAnimDecoderGetNext(dec, &buf, ×tamp);
231 | // ... (Render 'buf' based on 'timestamp').
232 | // ... (Do NOT free 'buf', as it is owned by 'dec').
233 | }
234 | WebPAnimDecoderReset(dec);
235 | }
236 | const WebPDemuxer* demuxer = WebPAnimDecoderGetDemuxer(dec);
237 | // ... (Do something using 'demuxer'; e.g. get EXIF/XMP/ICC data).
238 | WebPAnimDecoderDelete(dec);
239 |
240 | For a detailed AnimDecoder API reference, please refer to the header file
241 | (src/webp/demux.h).
242 |
243 |
244 | Bugs:
245 | =====
246 |
247 | Please report all bugs to the issue tracker:
248 | https://bugs.chromium.org/p/webp
249 | Patches welcome! See this page to get started:
250 | http://www.webmproject.org/code/contribute/submitting-patches/
251 |
252 | Discuss:
253 | ========
254 |
255 | Email: webp-discuss@webmproject.org
256 | Web: http://groups.google.com/a/webmproject.org/group/webp-discuss
257 |
--------------------------------------------------------------------------------
/__lib__/libwebp-1.1.0-windows-x64/include/webp/decode.h:
--------------------------------------------------------------------------------
1 | // Copyright 2010 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Main decoding functions for WebP images.
11 | //
12 | // Author: Skal (pascal.massimino@gmail.com)
13 |
14 | #ifndef WEBP_WEBP_DECODE_H_
15 | #define WEBP_WEBP_DECODE_H_
16 |
17 | #include "./types.h"
18 |
19 | #ifdef __cplusplus
20 | extern "C" {
21 | #endif
22 |
23 | #define WEBP_DECODER_ABI_VERSION 0x0209 // MAJOR(8b) + MINOR(8b)
24 |
25 | // Note: forward declaring enumerations is not allowed in (strict) C and C++,
26 | // the types are left here for reference.
27 | // typedef enum VP8StatusCode VP8StatusCode;
28 | // typedef enum WEBP_CSP_MODE WEBP_CSP_MODE;
29 | typedef struct WebPRGBABuffer WebPRGBABuffer;
30 | typedef struct WebPYUVABuffer WebPYUVABuffer;
31 | typedef struct WebPDecBuffer WebPDecBuffer;
32 | typedef struct WebPIDecoder WebPIDecoder;
33 | typedef struct WebPBitstreamFeatures WebPBitstreamFeatures;
34 | typedef struct WebPDecoderOptions WebPDecoderOptions;
35 | typedef struct WebPDecoderConfig WebPDecoderConfig;
36 |
37 | // Return the decoder's version number, packed in hexadecimal using 8bits for
38 | // each of major/minor/revision. E.g: v2.5.7 is 0x020507.
39 | WEBP_EXTERN int WebPGetDecoderVersion(void);
40 |
41 | // Retrieve basic header information: width, height.
42 | // This function will also validate the header, returning true on success,
43 | // false otherwise. '*width' and '*height' are only valid on successful return.
44 | // Pointers 'width' and 'height' can be passed NULL if deemed irrelevant.
45 | // Note: The following chunk sequences (before the raw VP8/VP8L data) are
46 | // considered valid by this function:
47 | // RIFF + VP8(L)
48 | // RIFF + VP8X + (optional chunks) + VP8(L)
49 | // ALPH + VP8 <-- Not a valid WebP format: only allowed for internal purpose.
50 | // VP8(L) <-- Not a valid WebP format: only allowed for internal purpose.
51 | WEBP_EXTERN int WebPGetInfo(const uint8_t* data, size_t data_size,
52 | int* width, int* height);
53 |
54 | // Decodes WebP images pointed to by 'data' and returns RGBA samples, along
55 | // with the dimensions in *width and *height. The ordering of samples in
56 | // memory is R, G, B, A, R, G, B, A... in scan order (endian-independent).
57 | // The returned pointer should be deleted calling WebPFree().
58 | // Returns NULL in case of error.
59 | WEBP_EXTERN uint8_t* WebPDecodeRGBA(const uint8_t* data, size_t data_size,
60 | int* width, int* height);
61 |
62 | // Same as WebPDecodeRGBA, but returning A, R, G, B, A, R, G, B... ordered data.
63 | WEBP_EXTERN uint8_t* WebPDecodeARGB(const uint8_t* data, size_t data_size,
64 | int* width, int* height);
65 |
66 | // Same as WebPDecodeRGBA, but returning B, G, R, A, B, G, R, A... ordered data.
67 | WEBP_EXTERN uint8_t* WebPDecodeBGRA(const uint8_t* data, size_t data_size,
68 | int* width, int* height);
69 |
70 | // Same as WebPDecodeRGBA, but returning R, G, B, R, G, B... ordered data.
71 | // If the bitstream contains transparency, it is ignored.
72 | WEBP_EXTERN uint8_t* WebPDecodeRGB(const uint8_t* data, size_t data_size,
73 | int* width, int* height);
74 |
75 | // Same as WebPDecodeRGB, but returning B, G, R, B, G, R... ordered data.
76 | WEBP_EXTERN uint8_t* WebPDecodeBGR(const uint8_t* data, size_t data_size,
77 | int* width, int* height);
78 |
79 |
80 | // Decode WebP images pointed to by 'data' to Y'UV format(*). The pointer
81 | // returned is the Y samples buffer. Upon return, *u and *v will point to
82 | // the U and V chroma data. These U and V buffers need NOT be passed to
83 | // WebPFree(), unlike the returned Y luma one. The dimension of the U and V
84 | // planes are both (*width + 1) / 2 and (*height + 1)/ 2.
85 | // Upon return, the Y buffer has a stride returned as '*stride', while U and V
86 | // have a common stride returned as '*uv_stride'.
87 | // Return NULL in case of error.
88 | // (*) Also named Y'CbCr. See: http://en.wikipedia.org/wiki/YCbCr
89 | WEBP_EXTERN uint8_t* WebPDecodeYUV(const uint8_t* data, size_t data_size,
90 | int* width, int* height,
91 | uint8_t** u, uint8_t** v,
92 | int* stride, int* uv_stride);
93 |
94 | // These five functions are variants of the above ones, that decode the image
95 | // directly into a pre-allocated buffer 'output_buffer'. The maximum storage
96 | // available in this buffer is indicated by 'output_buffer_size'. If this
97 | // storage is not sufficient (or an error occurred), NULL is returned.
98 | // Otherwise, output_buffer is returned, for convenience.
99 | // The parameter 'output_stride' specifies the distance (in bytes)
100 | // between scanlines. Hence, output_buffer_size is expected to be at least
101 | // output_stride x picture-height.
102 | WEBP_EXTERN uint8_t* WebPDecodeRGBAInto(
103 | const uint8_t* data, size_t data_size,
104 | uint8_t* output_buffer, size_t output_buffer_size, int output_stride);
105 | WEBP_EXTERN uint8_t* WebPDecodeARGBInto(
106 | const uint8_t* data, size_t data_size,
107 | uint8_t* output_buffer, size_t output_buffer_size, int output_stride);
108 | WEBP_EXTERN uint8_t* WebPDecodeBGRAInto(
109 | const uint8_t* data, size_t data_size,
110 | uint8_t* output_buffer, size_t output_buffer_size, int output_stride);
111 |
112 | // RGB and BGR variants. Here too the transparency information, if present,
113 | // will be dropped and ignored.
114 | WEBP_EXTERN uint8_t* WebPDecodeRGBInto(
115 | const uint8_t* data, size_t data_size,
116 | uint8_t* output_buffer, size_t output_buffer_size, int output_stride);
117 | WEBP_EXTERN uint8_t* WebPDecodeBGRInto(
118 | const uint8_t* data, size_t data_size,
119 | uint8_t* output_buffer, size_t output_buffer_size, int output_stride);
120 |
121 | // WebPDecodeYUVInto() is a variant of WebPDecodeYUV() that operates directly
122 | // into pre-allocated luma/chroma plane buffers. This function requires the
123 | // strides to be passed: one for the luma plane and one for each of the
124 | // chroma ones. The size of each plane buffer is passed as 'luma_size',
125 | // 'u_size' and 'v_size' respectively.
126 | // Pointer to the luma plane ('*luma') is returned or NULL if an error occurred
127 | // during decoding (or because some buffers were found to be too small).
128 | WEBP_EXTERN uint8_t* WebPDecodeYUVInto(
129 | const uint8_t* data, size_t data_size,
130 | uint8_t* luma, size_t luma_size, int luma_stride,
131 | uint8_t* u, size_t u_size, int u_stride,
132 | uint8_t* v, size_t v_size, int v_stride);
133 |
134 | //------------------------------------------------------------------------------
135 | // Output colorspaces and buffer
136 |
137 | // Colorspaces
138 | // Note: the naming describes the byte-ordering of packed samples in memory.
139 | // For instance, MODE_BGRA relates to samples ordered as B,G,R,A,B,G,R,A,...
140 | // Non-capital names (e.g.:MODE_Argb) relates to pre-multiplied RGB channels.
141 | // RGBA-4444 and RGB-565 colorspaces are represented by following byte-order:
142 | // RGBA-4444: [r3 r2 r1 r0 g3 g2 g1 g0], [b3 b2 b1 b0 a3 a2 a1 a0], ...
143 | // RGB-565: [r4 r3 r2 r1 r0 g5 g4 g3], [g2 g1 g0 b4 b3 b2 b1 b0], ...
144 | // In the case WEBP_SWAP_16BITS_CSP is defined, the bytes are swapped for
145 | // these two modes:
146 | // RGBA-4444: [b3 b2 b1 b0 a3 a2 a1 a0], [r3 r2 r1 r0 g3 g2 g1 g0], ...
147 | // RGB-565: [g2 g1 g0 b4 b3 b2 b1 b0], [r4 r3 r2 r1 r0 g5 g4 g3], ...
148 |
149 | typedef enum WEBP_CSP_MODE {
150 | MODE_RGB = 0, MODE_RGBA = 1,
151 | MODE_BGR = 2, MODE_BGRA = 3,
152 | MODE_ARGB = 4, MODE_RGBA_4444 = 5,
153 | MODE_RGB_565 = 6,
154 | // RGB-premultiplied transparent modes (alpha value is preserved)
155 | MODE_rgbA = 7,
156 | MODE_bgrA = 8,
157 | MODE_Argb = 9,
158 | MODE_rgbA_4444 = 10,
159 | // YUV modes must come after RGB ones.
160 | MODE_YUV = 11, MODE_YUVA = 12, // yuv 4:2:0
161 | MODE_LAST = 13
162 | } WEBP_CSP_MODE;
163 |
164 | // Some useful macros:
165 | static WEBP_INLINE int WebPIsPremultipliedMode(WEBP_CSP_MODE mode) {
166 | return (mode == MODE_rgbA || mode == MODE_bgrA || mode == MODE_Argb ||
167 | mode == MODE_rgbA_4444);
168 | }
169 |
170 | static WEBP_INLINE int WebPIsAlphaMode(WEBP_CSP_MODE mode) {
171 | return (mode == MODE_RGBA || mode == MODE_BGRA || mode == MODE_ARGB ||
172 | mode == MODE_RGBA_4444 || mode == MODE_YUVA ||
173 | WebPIsPremultipliedMode(mode));
174 | }
175 |
176 | static WEBP_INLINE int WebPIsRGBMode(WEBP_CSP_MODE mode) {
177 | return (mode < MODE_YUV);
178 | }
179 |
180 | //------------------------------------------------------------------------------
181 | // WebPDecBuffer: Generic structure for describing the output sample buffer.
182 |
183 | struct WebPRGBABuffer { // view as RGBA
184 | uint8_t* rgba; // pointer to RGBA samples
185 | int stride; // stride in bytes from one scanline to the next.
186 | size_t size; // total size of the *rgba buffer.
187 | };
188 |
189 | struct WebPYUVABuffer { // view as YUVA
190 | uint8_t* y, *u, *v, *a; // pointer to luma, chroma U/V, alpha samples
191 | int y_stride; // luma stride
192 | int u_stride, v_stride; // chroma strides
193 | int a_stride; // alpha stride
194 | size_t y_size; // luma plane size
195 | size_t u_size, v_size; // chroma planes size
196 | size_t a_size; // alpha-plane size
197 | };
198 |
199 | // Output buffer
200 | struct WebPDecBuffer {
201 | WEBP_CSP_MODE colorspace; // Colorspace.
202 | int width, height; // Dimensions.
203 | int is_external_memory; // If non-zero, 'internal_memory' pointer is not
204 | // used. If value is '2' or more, the external
205 | // memory is considered 'slow' and multiple
206 | // read/write will be avoided.
207 | union {
208 | WebPRGBABuffer RGBA;
209 | WebPYUVABuffer YUVA;
210 | } u; // Nameless union of buffer parameters.
211 | uint32_t pad[4]; // padding for later use
212 |
213 | uint8_t* private_memory; // Internally allocated memory (only when
214 | // is_external_memory is 0). Should not be used
215 | // externally, but accessed via the buffer union.
216 | };
217 |
218 | // Internal, version-checked, entry point
219 | WEBP_EXTERN int WebPInitDecBufferInternal(WebPDecBuffer*, int);
220 |
221 | // Initialize the structure as empty. Must be called before any other use.
222 | // Returns false in case of version mismatch
223 | static WEBP_INLINE int WebPInitDecBuffer(WebPDecBuffer* buffer) {
224 | return WebPInitDecBufferInternal(buffer, WEBP_DECODER_ABI_VERSION);
225 | }
226 |
227 | // Free any memory associated with the buffer. Must always be called last.
228 | // Note: doesn't free the 'buffer' structure itself.
229 | WEBP_EXTERN void WebPFreeDecBuffer(WebPDecBuffer* buffer);
230 |
231 | //------------------------------------------------------------------------------
232 | // Enumeration of the status codes
233 |
234 | typedef enum VP8StatusCode {
235 | VP8_STATUS_OK = 0,
236 | VP8_STATUS_OUT_OF_MEMORY,
237 | VP8_STATUS_INVALID_PARAM,
238 | VP8_STATUS_BITSTREAM_ERROR,
239 | VP8_STATUS_UNSUPPORTED_FEATURE,
240 | VP8_STATUS_SUSPENDED,
241 | VP8_STATUS_USER_ABORT,
242 | VP8_STATUS_NOT_ENOUGH_DATA
243 | } VP8StatusCode;
244 |
245 | //------------------------------------------------------------------------------
246 | // Incremental decoding
247 | //
248 | // This API allows streamlined decoding of partial data.
249 | // Picture can be incrementally decoded as data become available thanks to the
250 | // WebPIDecoder object. This object can be left in a SUSPENDED state if the
251 | // picture is only partially decoded, pending additional input.
252 | // Code example:
253 | //
254 | // WebPInitDecBuffer(&output_buffer);
255 | // output_buffer.colorspace = mode;
256 | // ...
257 | // WebPIDecoder* idec = WebPINewDecoder(&output_buffer);
258 | // while (additional_data_is_available) {
259 | // // ... (get additional data in some new_data[] buffer)
260 | // status = WebPIAppend(idec, new_data, new_data_size);
261 | // if (status != VP8_STATUS_OK && status != VP8_STATUS_SUSPENDED) {
262 | // break; // an error occurred.
263 | // }
264 | //
265 | // // The above call decodes the current available buffer.
266 | // // Part of the image can now be refreshed by calling
267 | // // WebPIDecGetRGB()/WebPIDecGetYUVA() etc.
268 | // }
269 | // WebPIDelete(idec);
270 |
271 | // Creates a new incremental decoder with the supplied buffer parameter.
272 | // This output_buffer can be passed NULL, in which case a default output buffer
273 | // is used (with MODE_RGB). Otherwise, an internal reference to 'output_buffer'
274 | // is kept, which means that the lifespan of 'output_buffer' must be larger than
275 | // that of the returned WebPIDecoder object.
276 | // The supplied 'output_buffer' content MUST NOT be changed between calls to
277 | // WebPIAppend() or WebPIUpdate() unless 'output_buffer.is_external_memory' is
278 | // not set to 0. In such a case, it is allowed to modify the pointers, size and
279 | // stride of output_buffer.u.RGBA or output_buffer.u.YUVA, provided they remain
280 | // within valid bounds.
281 | // All other fields of WebPDecBuffer MUST remain constant between calls.
282 | // Returns NULL if the allocation failed.
283 | WEBP_EXTERN WebPIDecoder* WebPINewDecoder(WebPDecBuffer* output_buffer);
284 |
285 | // This function allocates and initializes an incremental-decoder object, which
286 | // will output the RGB/A samples specified by 'csp' into a preallocated
287 | // buffer 'output_buffer'. The size of this buffer is at least
288 | // 'output_buffer_size' and the stride (distance in bytes between two scanlines)
289 | // is specified by 'output_stride'.
290 | // Additionally, output_buffer can be passed NULL in which case the output
291 | // buffer will be allocated automatically when the decoding starts. The
292 | // colorspace 'csp' is taken into account for allocating this buffer. All other
293 | // parameters are ignored.
294 | // Returns NULL if the allocation failed, or if some parameters are invalid.
295 | WEBP_EXTERN WebPIDecoder* WebPINewRGB(
296 | WEBP_CSP_MODE csp,
297 | uint8_t* output_buffer, size_t output_buffer_size, int output_stride);
298 |
299 | // This function allocates and initializes an incremental-decoder object, which
300 | // will output the raw luma/chroma samples into a preallocated planes if
301 | // supplied. The luma plane is specified by its pointer 'luma', its size
302 | // 'luma_size' and its stride 'luma_stride'. Similarly, the chroma-u plane
303 | // is specified by the 'u', 'u_size' and 'u_stride' parameters, and the chroma-v
304 | // plane by 'v' and 'v_size'. And same for the alpha-plane. The 'a' pointer
305 | // can be pass NULL in case one is not interested in the transparency plane.
306 | // Conversely, 'luma' can be passed NULL if no preallocated planes are supplied.
307 | // In this case, the output buffer will be automatically allocated (using
308 | // MODE_YUVA) when decoding starts. All parameters are then ignored.
309 | // Returns NULL if the allocation failed or if a parameter is invalid.
310 | WEBP_EXTERN WebPIDecoder* WebPINewYUVA(
311 | uint8_t* luma, size_t luma_size, int luma_stride,
312 | uint8_t* u, size_t u_size, int u_stride,
313 | uint8_t* v, size_t v_size, int v_stride,
314 | uint8_t* a, size_t a_size, int a_stride);
315 |
316 | // Deprecated version of the above, without the alpha plane.
317 | // Kept for backward compatibility.
318 | WEBP_EXTERN WebPIDecoder* WebPINewYUV(
319 | uint8_t* luma, size_t luma_size, int luma_stride,
320 | uint8_t* u, size_t u_size, int u_stride,
321 | uint8_t* v, size_t v_size, int v_stride);
322 |
323 | // Deletes the WebPIDecoder object and associated memory. Must always be called
324 | // if WebPINewDecoder, WebPINewRGB or WebPINewYUV succeeded.
325 | WEBP_EXTERN void WebPIDelete(WebPIDecoder* idec);
326 |
327 | // Copies and decodes the next available data. Returns VP8_STATUS_OK when
328 | // the image is successfully decoded. Returns VP8_STATUS_SUSPENDED when more
329 | // data is expected. Returns error in other cases.
330 | WEBP_EXTERN VP8StatusCode WebPIAppend(
331 | WebPIDecoder* idec, const uint8_t* data, size_t data_size);
332 |
333 | // A variant of the above function to be used when data buffer contains
334 | // partial data from the beginning. In this case data buffer is not copied
335 | // to the internal memory.
336 | // Note that the value of the 'data' pointer can change between calls to
337 | // WebPIUpdate, for instance when the data buffer is resized to fit larger data.
338 | WEBP_EXTERN VP8StatusCode WebPIUpdate(
339 | WebPIDecoder* idec, const uint8_t* data, size_t data_size);
340 |
341 | // Returns the RGB/A image decoded so far. Returns NULL if output params
342 | // are not initialized yet. The RGB/A output type corresponds to the colorspace
343 | // specified during call to WebPINewDecoder() or WebPINewRGB().
344 | // *last_y is the index of last decoded row in raster scan order. Some pointers
345 | // (*last_y, *width etc.) can be NULL if corresponding information is not
346 | // needed. The values in these pointers are only valid on successful (non-NULL)
347 | // return.
348 | WEBP_EXTERN uint8_t* WebPIDecGetRGB(
349 | const WebPIDecoder* idec, int* last_y,
350 | int* width, int* height, int* stride);
351 |
352 | // Same as above function to get a YUVA image. Returns pointer to the luma
353 | // plane or NULL in case of error. If there is no alpha information
354 | // the alpha pointer '*a' will be returned NULL.
355 | WEBP_EXTERN uint8_t* WebPIDecGetYUVA(
356 | const WebPIDecoder* idec, int* last_y,
357 | uint8_t** u, uint8_t** v, uint8_t** a,
358 | int* width, int* height, int* stride, int* uv_stride, int* a_stride);
359 |
360 | // Deprecated alpha-less version of WebPIDecGetYUVA(): it will ignore the
361 | // alpha information (if present). Kept for backward compatibility.
362 | static WEBP_INLINE uint8_t* WebPIDecGetYUV(
363 | const WebPIDecoder* idec, int* last_y, uint8_t** u, uint8_t** v,
364 | int* width, int* height, int* stride, int* uv_stride) {
365 | return WebPIDecGetYUVA(idec, last_y, u, v, NULL, width, height,
366 | stride, uv_stride, NULL);
367 | }
368 |
369 | // Generic call to retrieve information about the displayable area.
370 | // If non NULL, the left/right/width/height pointers are filled with the visible
371 | // rectangular area so far.
372 | // Returns NULL in case the incremental decoder object is in an invalid state.
373 | // Otherwise returns the pointer to the internal representation. This structure
374 | // is read-only, tied to WebPIDecoder's lifespan and should not be modified.
375 | WEBP_EXTERN const WebPDecBuffer* WebPIDecodedArea(
376 | const WebPIDecoder* idec, int* left, int* top, int* width, int* height);
377 |
378 | //------------------------------------------------------------------------------
379 | // Advanced decoding parametrization
380 | //
381 | // Code sample for using the advanced decoding API
382 | /*
383 | // A) Init a configuration object
384 | WebPDecoderConfig config;
385 | CHECK(WebPInitDecoderConfig(&config));
386 |
387 | // B) optional: retrieve the bitstream's features.
388 | CHECK(WebPGetFeatures(data, data_size, &config.input) == VP8_STATUS_OK);
389 |
390 | // C) Adjust 'config', if needed
391 | config.no_fancy_upsampling = 1;
392 | config.output.colorspace = MODE_BGRA;
393 | // etc.
394 |
395 | // Note that you can also make config.output point to an externally
396 | // supplied memory buffer, provided it's big enough to store the decoded
397 | // picture. Otherwise, config.output will just be used to allocate memory
398 | // and store the decoded picture.
399 |
400 | // D) Decode!
401 | CHECK(WebPDecode(data, data_size, &config) == VP8_STATUS_OK);
402 |
403 | // E) Decoded image is now in config.output (and config.output.u.RGBA)
404 |
405 | // F) Reclaim memory allocated in config's object. It's safe to call
406 | // this function even if the memory is external and wasn't allocated
407 | // by WebPDecode().
408 | WebPFreeDecBuffer(&config.output);
409 | */
410 |
411 | // Features gathered from the bitstream
412 | struct WebPBitstreamFeatures {
413 | int width; // Width in pixels, as read from the bitstream.
414 | int height; // Height in pixels, as read from the bitstream.
415 | int has_alpha; // True if the bitstream contains an alpha channel.
416 | int has_animation; // True if the bitstream is an animation.
417 | int format; // 0 = undefined (/mixed), 1 = lossy, 2 = lossless
418 |
419 | uint32_t pad[5]; // padding for later use
420 | };
421 |
422 | // Internal, version-checked, entry point
423 | WEBP_EXTERN VP8StatusCode WebPGetFeaturesInternal(
424 | const uint8_t*, size_t, WebPBitstreamFeatures*, int);
425 |
426 | // Retrieve features from the bitstream. The *features structure is filled
427 | // with information gathered from the bitstream.
428 | // Returns VP8_STATUS_OK when the features are successfully retrieved. Returns
429 | // VP8_STATUS_NOT_ENOUGH_DATA when more data is needed to retrieve the
430 | // features from headers. Returns error in other cases.
431 | // Note: The following chunk sequences (before the raw VP8/VP8L data) are
432 | // considered valid by this function:
433 | // RIFF + VP8(L)
434 | // RIFF + VP8X + (optional chunks) + VP8(L)
435 | // ALPH + VP8 <-- Not a valid WebP format: only allowed for internal purpose.
436 | // VP8(L) <-- Not a valid WebP format: only allowed for internal purpose.
437 | static WEBP_INLINE VP8StatusCode WebPGetFeatures(
438 | const uint8_t* data, size_t data_size,
439 | WebPBitstreamFeatures* features) {
440 | return WebPGetFeaturesInternal(data, data_size, features,
441 | WEBP_DECODER_ABI_VERSION);
442 | }
443 |
444 | // Decoding options
445 | struct WebPDecoderOptions {
446 | int bypass_filtering; // if true, skip the in-loop filtering
447 | int no_fancy_upsampling; // if true, use faster pointwise upsampler
448 | int use_cropping; // if true, cropping is applied _first_
449 | int crop_left, crop_top; // top-left position for cropping.
450 | // Will be snapped to even values.
451 | int crop_width, crop_height; // dimension of the cropping area
452 | int use_scaling; // if true, scaling is applied _afterward_
453 | int scaled_width, scaled_height; // final resolution
454 | int use_threads; // if true, use multi-threaded decoding
455 | int dithering_strength; // dithering strength (0=Off, 100=full)
456 | int flip; // flip output vertically
457 | int alpha_dithering_strength; // alpha dithering strength in [0..100]
458 |
459 | uint32_t pad[5]; // padding for later use
460 | };
461 |
462 | // Main object storing the configuration for advanced decoding.
463 | struct WebPDecoderConfig {
464 | WebPBitstreamFeatures input; // Immutable bitstream features (optional)
465 | WebPDecBuffer output; // Output buffer (can point to external mem)
466 | WebPDecoderOptions options; // Decoding options
467 | };
468 |
469 | // Internal, version-checked, entry point
470 | WEBP_EXTERN int WebPInitDecoderConfigInternal(WebPDecoderConfig*, int);
471 |
472 | // Initialize the configuration as empty. This function must always be
473 | // called first, unless WebPGetFeatures() is to be called.
474 | // Returns false in case of mismatched version.
475 | static WEBP_INLINE int WebPInitDecoderConfig(WebPDecoderConfig* config) {
476 | return WebPInitDecoderConfigInternal(config, WEBP_DECODER_ABI_VERSION);
477 | }
478 |
479 | // Instantiate a new incremental decoder object with the requested
480 | // configuration. The bitstream can be passed using 'data' and 'data_size'
481 | // parameter, in which case the features will be parsed and stored into
482 | // config->input. Otherwise, 'data' can be NULL and no parsing will occur.
483 | // Note that 'config' can be NULL too, in which case a default configuration
484 | // is used. If 'config' is not NULL, it must outlive the WebPIDecoder object
485 | // as some references to its fields will be used. No internal copy of 'config'
486 | // is made.
487 | // The return WebPIDecoder object must always be deleted calling WebPIDelete().
488 | // Returns NULL in case of error (and config->status will then reflect
489 | // the error condition, if available).
490 | WEBP_EXTERN WebPIDecoder* WebPIDecode(const uint8_t* data, size_t data_size,
491 | WebPDecoderConfig* config);
492 |
493 | // Non-incremental version. This version decodes the full data at once, taking
494 | // 'config' into account. Returns decoding status (which should be VP8_STATUS_OK
495 | // if the decoding was successful). Note that 'config' cannot be NULL.
496 | WEBP_EXTERN VP8StatusCode WebPDecode(const uint8_t* data, size_t data_size,
497 | WebPDecoderConfig* config);
498 |
499 | #ifdef __cplusplus
500 | } // extern "C"
501 | #endif
502 |
503 | #endif // WEBP_WEBP_DECODE_H_
504 |
--------------------------------------------------------------------------------
/__lib__/libwebp-1.1.0-windows-x64/include/webp/demux.h:
--------------------------------------------------------------------------------
1 | // Copyright 2012 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Demux API.
11 | // Enables extraction of image and extended format data from WebP files.
12 |
13 | // Code Example: Demuxing WebP data to extract all the frames, ICC profile
14 | // and EXIF/XMP metadata.
15 | /*
16 | WebPDemuxer* demux = WebPDemux(&webp_data);
17 |
18 | uint32_t width = WebPDemuxGetI(demux, WEBP_FF_CANVAS_WIDTH);
19 | uint32_t height = WebPDemuxGetI(demux, WEBP_FF_CANVAS_HEIGHT);
20 | // ... (Get information about the features present in the WebP file).
21 | uint32_t flags = WebPDemuxGetI(demux, WEBP_FF_FORMAT_FLAGS);
22 |
23 | // ... (Iterate over all frames).
24 | WebPIterator iter;
25 | if (WebPDemuxGetFrame(demux, 1, &iter)) {
26 | do {
27 | // ... (Consume 'iter'; e.g. Decode 'iter.fragment' with WebPDecode(),
28 | // ... and get other frame properties like width, height, offsets etc.
29 | // ... see 'struct WebPIterator' below for more info).
30 | } while (WebPDemuxNextFrame(&iter));
31 | WebPDemuxReleaseIterator(&iter);
32 | }
33 |
34 | // ... (Extract metadata).
35 | WebPChunkIterator chunk_iter;
36 | if (flags & ICCP_FLAG) WebPDemuxGetChunk(demux, "ICCP", 1, &chunk_iter);
37 | // ... (Consume the ICC profile in 'chunk_iter.chunk').
38 | WebPDemuxReleaseChunkIterator(&chunk_iter);
39 | if (flags & EXIF_FLAG) WebPDemuxGetChunk(demux, "EXIF", 1, &chunk_iter);
40 | // ... (Consume the EXIF metadata in 'chunk_iter.chunk').
41 | WebPDemuxReleaseChunkIterator(&chunk_iter);
42 | if (flags & XMP_FLAG) WebPDemuxGetChunk(demux, "XMP ", 1, &chunk_iter);
43 | // ... (Consume the XMP metadata in 'chunk_iter.chunk').
44 | WebPDemuxReleaseChunkIterator(&chunk_iter);
45 | WebPDemuxDelete(demux);
46 | */
47 |
48 | #ifndef WEBP_WEBP_DEMUX_H_
49 | #define WEBP_WEBP_DEMUX_H_
50 |
51 | #include "./decode.h" // for WEBP_CSP_MODE
52 | #include "./mux_types.h"
53 |
54 | #ifdef __cplusplus
55 | extern "C" {
56 | #endif
57 |
58 | #define WEBP_DEMUX_ABI_VERSION 0x0107 // MAJOR(8b) + MINOR(8b)
59 |
60 | // Note: forward declaring enumerations is not allowed in (strict) C and C++,
61 | // the types are left here for reference.
62 | // typedef enum WebPDemuxState WebPDemuxState;
63 | // typedef enum WebPFormatFeature WebPFormatFeature;
64 | typedef struct WebPDemuxer WebPDemuxer;
65 | typedef struct WebPIterator WebPIterator;
66 | typedef struct WebPChunkIterator WebPChunkIterator;
67 | typedef struct WebPAnimInfo WebPAnimInfo;
68 | typedef struct WebPAnimDecoderOptions WebPAnimDecoderOptions;
69 |
70 | //------------------------------------------------------------------------------
71 |
72 | // Returns the version number of the demux library, packed in hexadecimal using
73 | // 8bits for each of major/minor/revision. E.g: v2.5.7 is 0x020507.
74 | WEBP_EXTERN int WebPGetDemuxVersion(void);
75 |
76 | //------------------------------------------------------------------------------
77 | // Life of a Demux object
78 |
79 | typedef enum WebPDemuxState {
80 | WEBP_DEMUX_PARSE_ERROR = -1, // An error occurred while parsing.
81 | WEBP_DEMUX_PARSING_HEADER = 0, // Not enough data to parse full header.
82 | WEBP_DEMUX_PARSED_HEADER = 1, // Header parsing complete,
83 | // data may be available.
84 | WEBP_DEMUX_DONE = 2 // Entire file has been parsed.
85 | } WebPDemuxState;
86 |
87 | // Internal, version-checked, entry point
88 | WEBP_EXTERN WebPDemuxer* WebPDemuxInternal(
89 | const WebPData*, int, WebPDemuxState*, int);
90 |
91 | // Parses the full WebP file given by 'data'. For single images the WebP file
92 | // header alone or the file header and the chunk header may be absent.
93 | // Returns a WebPDemuxer object on successful parse, NULL otherwise.
94 | static WEBP_INLINE WebPDemuxer* WebPDemux(const WebPData* data) {
95 | return WebPDemuxInternal(data, 0, NULL, WEBP_DEMUX_ABI_VERSION);
96 | }
97 |
98 | // Parses the possibly incomplete WebP file given by 'data'.
99 | // If 'state' is non-NULL it will be set to indicate the status of the demuxer.
100 | // Returns NULL in case of error or if there isn't enough data to start parsing;
101 | // and a WebPDemuxer object on successful parse.
102 | // Note that WebPDemuxer keeps internal pointers to 'data' memory segment.
103 | // If this data is volatile, the demuxer object should be deleted (by calling
104 | // WebPDemuxDelete()) and WebPDemuxPartial() called again on the new data.
105 | // This is usually an inexpensive operation.
106 | static WEBP_INLINE WebPDemuxer* WebPDemuxPartial(
107 | const WebPData* data, WebPDemuxState* state) {
108 | return WebPDemuxInternal(data, 1, state, WEBP_DEMUX_ABI_VERSION);
109 | }
110 |
111 | // Frees memory associated with 'dmux'.
112 | WEBP_EXTERN void WebPDemuxDelete(WebPDemuxer* dmux);
113 |
114 | //------------------------------------------------------------------------------
115 | // Data/information extraction.
116 |
117 | typedef enum WebPFormatFeature {
118 | WEBP_FF_FORMAT_FLAGS, // bit-wise combination of WebPFeatureFlags
119 | // corresponding to the 'VP8X' chunk (if present).
120 | WEBP_FF_CANVAS_WIDTH,
121 | WEBP_FF_CANVAS_HEIGHT,
122 | WEBP_FF_LOOP_COUNT, // only relevant for animated file
123 | WEBP_FF_BACKGROUND_COLOR, // idem.
124 | WEBP_FF_FRAME_COUNT // Number of frames present in the demux object.
125 | // In case of a partial demux, this is the number
126 | // of frames seen so far, with the last frame
127 | // possibly being partial.
128 | } WebPFormatFeature;
129 |
130 | // Get the 'feature' value from the 'dmux'.
131 | // NOTE: values are only valid if WebPDemux() was used or WebPDemuxPartial()
132 | // returned a state > WEBP_DEMUX_PARSING_HEADER.
133 | // If 'feature' is WEBP_FF_FORMAT_FLAGS, the returned value is a bit-wise
134 | // combination of WebPFeatureFlags values.
135 | // If 'feature' is WEBP_FF_LOOP_COUNT, WEBP_FF_BACKGROUND_COLOR, the returned
136 | // value is only meaningful if the bitstream is animated.
137 | WEBP_EXTERN uint32_t WebPDemuxGetI(
138 | const WebPDemuxer* dmux, WebPFormatFeature feature);
139 |
140 | //------------------------------------------------------------------------------
141 | // Frame iteration.
142 |
143 | struct WebPIterator {
144 | int frame_num;
145 | int num_frames; // equivalent to WEBP_FF_FRAME_COUNT.
146 | int x_offset, y_offset; // offset relative to the canvas.
147 | int width, height; // dimensions of this frame.
148 | int duration; // display duration in milliseconds.
149 | WebPMuxAnimDispose dispose_method; // dispose method for the frame.
150 | int complete; // true if 'fragment' contains a full frame. partial images
151 | // may still be decoded with the WebP incremental decoder.
152 | WebPData fragment; // The frame given by 'frame_num'. Note for historical
153 | // reasons this is called a fragment.
154 | int has_alpha; // True if the frame contains transparency.
155 | WebPMuxAnimBlend blend_method; // Blend operation for the frame.
156 |
157 | uint32_t pad[2]; // padding for later use.
158 | void* private_; // for internal use only.
159 | };
160 |
161 | // Retrieves frame 'frame_number' from 'dmux'.
162 | // 'iter->fragment' points to the frame on return from this function.
163 | // Setting 'frame_number' equal to 0 will return the last frame of the image.
164 | // Returns false if 'dmux' is NULL or frame 'frame_number' is not present.
165 | // Call WebPDemuxReleaseIterator() when use of the iterator is complete.
166 | // NOTE: 'dmux' must persist for the lifetime of 'iter'.
167 | WEBP_EXTERN int WebPDemuxGetFrame(
168 | const WebPDemuxer* dmux, int frame_number, WebPIterator* iter);
169 |
170 | // Sets 'iter->fragment' to point to the next ('iter->frame_num' + 1) or
171 | // previous ('iter->frame_num' - 1) frame. These functions do not loop.
172 | // Returns true on success, false otherwise.
173 | WEBP_EXTERN int WebPDemuxNextFrame(WebPIterator* iter);
174 | WEBP_EXTERN int WebPDemuxPrevFrame(WebPIterator* iter);
175 |
176 | // Releases any memory associated with 'iter'.
177 | // Must be called before any subsequent calls to WebPDemuxGetChunk() on the same
178 | // iter. Also, must be called before destroying the associated WebPDemuxer with
179 | // WebPDemuxDelete().
180 | WEBP_EXTERN void WebPDemuxReleaseIterator(WebPIterator* iter);
181 |
182 | //------------------------------------------------------------------------------
183 | // Chunk iteration.
184 |
185 | struct WebPChunkIterator {
186 | // The current and total number of chunks with the fourcc given to
187 | // WebPDemuxGetChunk().
188 | int chunk_num;
189 | int num_chunks;
190 | WebPData chunk; // The payload of the chunk.
191 |
192 | uint32_t pad[6]; // padding for later use
193 | void* private_;
194 | };
195 |
196 | // Retrieves the 'chunk_number' instance of the chunk with id 'fourcc' from
197 | // 'dmux'.
198 | // 'fourcc' is a character array containing the fourcc of the chunk to return,
199 | // e.g., "ICCP", "XMP ", "EXIF", etc.
200 | // Setting 'chunk_number' equal to 0 will return the last chunk in a set.
201 | // Returns true if the chunk is found, false otherwise. Image related chunk
202 | // payloads are accessed through WebPDemuxGetFrame() and related functions.
203 | // Call WebPDemuxReleaseChunkIterator() when use of the iterator is complete.
204 | // NOTE: 'dmux' must persist for the lifetime of the iterator.
205 | WEBP_EXTERN int WebPDemuxGetChunk(const WebPDemuxer* dmux,
206 | const char fourcc[4], int chunk_number,
207 | WebPChunkIterator* iter);
208 |
209 | // Sets 'iter->chunk' to point to the next ('iter->chunk_num' + 1) or previous
210 | // ('iter->chunk_num' - 1) chunk. These functions do not loop.
211 | // Returns true on success, false otherwise.
212 | WEBP_EXTERN int WebPDemuxNextChunk(WebPChunkIterator* iter);
213 | WEBP_EXTERN int WebPDemuxPrevChunk(WebPChunkIterator* iter);
214 |
215 | // Releases any memory associated with 'iter'.
216 | // Must be called before destroying the associated WebPDemuxer with
217 | // WebPDemuxDelete().
218 | WEBP_EXTERN void WebPDemuxReleaseChunkIterator(WebPChunkIterator* iter);
219 |
220 | //------------------------------------------------------------------------------
221 | // WebPAnimDecoder API
222 | //
223 | // This API allows decoding (possibly) animated WebP images.
224 | //
225 | // Code Example:
226 | /*
227 | WebPAnimDecoderOptions dec_options;
228 | WebPAnimDecoderOptionsInit(&dec_options);
229 | // Tune 'dec_options' as needed.
230 | WebPAnimDecoder* dec = WebPAnimDecoderNew(webp_data, &dec_options);
231 | WebPAnimInfo anim_info;
232 | WebPAnimDecoderGetInfo(dec, &anim_info);
233 | for (uint32_t i = 0; i < anim_info.loop_count; ++i) {
234 | while (WebPAnimDecoderHasMoreFrames(dec)) {
235 | uint8_t* buf;
236 | int timestamp;
237 | WebPAnimDecoderGetNext(dec, &buf, ×tamp);
238 | // ... (Render 'buf' based on 'timestamp').
239 | // ... (Do NOT free 'buf', as it is owned by 'dec').
240 | }
241 | WebPAnimDecoderReset(dec);
242 | }
243 | const WebPDemuxer* demuxer = WebPAnimDecoderGetDemuxer(dec);
244 | // ... (Do something using 'demuxer'; e.g. get EXIF/XMP/ICC data).
245 | WebPAnimDecoderDelete(dec);
246 | */
247 |
248 | typedef struct WebPAnimDecoder WebPAnimDecoder; // Main opaque object.
249 |
250 | // Global options.
251 | struct WebPAnimDecoderOptions {
252 | // Output colorspace. Only the following modes are supported:
253 | // MODE_RGBA, MODE_BGRA, MODE_rgbA and MODE_bgrA.
254 | WEBP_CSP_MODE color_mode;
255 | int use_threads; // If true, use multi-threaded decoding.
256 | uint32_t padding[7]; // Padding for later use.
257 | };
258 |
259 | // Internal, version-checked, entry point.
260 | WEBP_EXTERN int WebPAnimDecoderOptionsInitInternal(
261 | WebPAnimDecoderOptions*, int);
262 |
263 | // Should always be called, to initialize a fresh WebPAnimDecoderOptions
264 | // structure before modification. Returns false in case of version mismatch.
265 | // WebPAnimDecoderOptionsInit() must have succeeded before using the
266 | // 'dec_options' object.
267 | static WEBP_INLINE int WebPAnimDecoderOptionsInit(
268 | WebPAnimDecoderOptions* dec_options) {
269 | return WebPAnimDecoderOptionsInitInternal(dec_options,
270 | WEBP_DEMUX_ABI_VERSION);
271 | }
272 |
273 | // Internal, version-checked, entry point.
274 | WEBP_EXTERN WebPAnimDecoder* WebPAnimDecoderNewInternal(
275 | const WebPData*, const WebPAnimDecoderOptions*, int);
276 |
277 | // Creates and initializes a WebPAnimDecoder object.
278 | // Parameters:
279 | // webp_data - (in) WebP bitstream. This should remain unchanged during the
280 | // lifetime of the output WebPAnimDecoder object.
281 | // dec_options - (in) decoding options. Can be passed NULL to choose
282 | // reasonable defaults (in particular, color mode MODE_RGBA
283 | // will be picked).
284 | // Returns:
285 | // A pointer to the newly created WebPAnimDecoder object, or NULL in case of
286 | // parsing error, invalid option or memory error.
287 | static WEBP_INLINE WebPAnimDecoder* WebPAnimDecoderNew(
288 | const WebPData* webp_data, const WebPAnimDecoderOptions* dec_options) {
289 | return WebPAnimDecoderNewInternal(webp_data, dec_options,
290 | WEBP_DEMUX_ABI_VERSION);
291 | }
292 |
293 | // Global information about the animation..
294 | struct WebPAnimInfo {
295 | uint32_t canvas_width;
296 | uint32_t canvas_height;
297 | uint32_t loop_count;
298 | uint32_t bgcolor;
299 | uint32_t frame_count;
300 | uint32_t pad[4]; // padding for later use
301 | };
302 |
303 | // Get global information about the animation.
304 | // Parameters:
305 | // dec - (in) decoder instance to get information from.
306 | // info - (out) global information fetched from the animation.
307 | // Returns:
308 | // True on success.
309 | WEBP_EXTERN int WebPAnimDecoderGetInfo(const WebPAnimDecoder* dec,
310 | WebPAnimInfo* info);
311 |
312 | // Fetch the next frame from 'dec' based on options supplied to
313 | // WebPAnimDecoderNew(). This will be a fully reconstructed canvas of size
314 | // 'canvas_width * 4 * canvas_height', and not just the frame sub-rectangle. The
315 | // returned buffer 'buf' is valid only until the next call to
316 | // WebPAnimDecoderGetNext(), WebPAnimDecoderReset() or WebPAnimDecoderDelete().
317 | // Parameters:
318 | // dec - (in/out) decoder instance from which the next frame is to be fetched.
319 | // buf - (out) decoded frame.
320 | // timestamp - (out) timestamp of the frame in milliseconds.
321 | // Returns:
322 | // False if any of the arguments are NULL, or if there is a parsing or
323 | // decoding error, or if there are no more frames. Otherwise, returns true.
324 | WEBP_EXTERN int WebPAnimDecoderGetNext(WebPAnimDecoder* dec,
325 | uint8_t** buf, int* timestamp);
326 |
327 | // Check if there are more frames left to decode.
328 | // Parameters:
329 | // dec - (in) decoder instance to be checked.
330 | // Returns:
331 | // True if 'dec' is not NULL and some frames are yet to be decoded.
332 | // Otherwise, returns false.
333 | WEBP_EXTERN int WebPAnimDecoderHasMoreFrames(const WebPAnimDecoder* dec);
334 |
335 | // Resets the WebPAnimDecoder object, so that next call to
336 | // WebPAnimDecoderGetNext() will restart decoding from 1st frame. This would be
337 | // helpful when all frames need to be decoded multiple times (e.g.
338 | // info.loop_count times) without destroying and recreating the 'dec' object.
339 | // Parameters:
340 | // dec - (in/out) decoder instance to be reset
341 | WEBP_EXTERN void WebPAnimDecoderReset(WebPAnimDecoder* dec);
342 |
343 | // Grab the internal demuxer object.
344 | // Getting the demuxer object can be useful if one wants to use operations only
345 | // available through demuxer; e.g. to get XMP/EXIF/ICC metadata. The returned
346 | // demuxer object is owned by 'dec' and is valid only until the next call to
347 | // WebPAnimDecoderDelete().
348 | //
349 | // Parameters:
350 | // dec - (in) decoder instance from which the demuxer object is to be fetched.
351 | WEBP_EXTERN const WebPDemuxer* WebPAnimDecoderGetDemuxer(
352 | const WebPAnimDecoder* dec);
353 |
354 | // Deletes the WebPAnimDecoder object.
355 | // Parameters:
356 | // dec - (in/out) decoder instance to be deleted
357 | WEBP_EXTERN void WebPAnimDecoderDelete(WebPAnimDecoder* dec);
358 |
359 | #ifdef __cplusplus
360 | } // extern "C"
361 | #endif
362 |
363 | #endif // WEBP_WEBP_DEMUX_H_
364 |
--------------------------------------------------------------------------------
/__lib__/libwebp-1.1.0-windows-x64/include/webp/encode.h:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // WebP encoder: main interface
11 | //
12 | // Author: Skal (pascal.massimino@gmail.com)
13 |
14 | #ifndef WEBP_WEBP_ENCODE_H_
15 | #define WEBP_WEBP_ENCODE_H_
16 |
17 | #include "./types.h"
18 |
19 | #ifdef __cplusplus
20 | extern "C" {
21 | #endif
22 |
23 | #define WEBP_ENCODER_ABI_VERSION 0x020f // MAJOR(8b) + MINOR(8b)
24 |
25 | // Note: forward declaring enumerations is not allowed in (strict) C and C++,
26 | // the types are left here for reference.
27 | // typedef enum WebPImageHint WebPImageHint;
28 | // typedef enum WebPEncCSP WebPEncCSP;
29 | // typedef enum WebPPreset WebPPreset;
30 | // typedef enum WebPEncodingError WebPEncodingError;
31 | typedef struct WebPConfig WebPConfig;
32 | typedef struct WebPPicture WebPPicture; // main structure for I/O
33 | typedef struct WebPAuxStats WebPAuxStats;
34 | typedef struct WebPMemoryWriter WebPMemoryWriter;
35 |
36 | // Return the encoder's version number, packed in hexadecimal using 8bits for
37 | // each of major/minor/revision. E.g: v2.5.7 is 0x020507.
38 | WEBP_EXTERN int WebPGetEncoderVersion(void);
39 |
40 | //------------------------------------------------------------------------------
41 | // One-stop-shop call! No questions asked:
42 |
43 | // Returns the size of the compressed data (pointed to by *output), or 0 if
44 | // an error occurred. The compressed data must be released by the caller
45 | // using the call 'WebPFree(*output)'.
46 | // These functions compress using the lossy format, and the quality_factor
47 | // can go from 0 (smaller output, lower quality) to 100 (best quality,
48 | // larger output).
49 | WEBP_EXTERN size_t WebPEncodeRGB(const uint8_t* rgb,
50 | int width, int height, int stride,
51 | float quality_factor, uint8_t** output);
52 | WEBP_EXTERN size_t WebPEncodeBGR(const uint8_t* bgr,
53 | int width, int height, int stride,
54 | float quality_factor, uint8_t** output);
55 | WEBP_EXTERN size_t WebPEncodeRGBA(const uint8_t* rgba,
56 | int width, int height, int stride,
57 | float quality_factor, uint8_t** output);
58 | WEBP_EXTERN size_t WebPEncodeBGRA(const uint8_t* bgra,
59 | int width, int height, int stride,
60 | float quality_factor, uint8_t** output);
61 |
62 | // These functions are the equivalent of the above, but compressing in a
63 | // lossless manner. Files are usually larger than lossy format, but will
64 | // not suffer any compression loss.
65 | // Note these functions, like the lossy versions, use the library's default
66 | // settings. For lossless this means 'exact' is disabled. RGB values in
67 | // transparent areas will be modified to improve compression. To avoid this,
68 | // use WebPEncode() and set WebPConfig::exact to 1.
69 | WEBP_EXTERN size_t WebPEncodeLosslessRGB(const uint8_t* rgb,
70 | int width, int height, int stride,
71 | uint8_t** output);
72 | WEBP_EXTERN size_t WebPEncodeLosslessBGR(const uint8_t* bgr,
73 | int width, int height, int stride,
74 | uint8_t** output);
75 | WEBP_EXTERN size_t WebPEncodeLosslessRGBA(const uint8_t* rgba,
76 | int width, int height, int stride,
77 | uint8_t** output);
78 | WEBP_EXTERN size_t WebPEncodeLosslessBGRA(const uint8_t* bgra,
79 | int width, int height, int stride,
80 | uint8_t** output);
81 |
82 | //------------------------------------------------------------------------------
83 | // Coding parameters
84 |
85 | // Image characteristics hint for the underlying encoder.
86 | typedef enum WebPImageHint {
87 | WEBP_HINT_DEFAULT = 0, // default preset.
88 | WEBP_HINT_PICTURE, // digital picture, like portrait, inner shot
89 | WEBP_HINT_PHOTO, // outdoor photograph, with natural lighting
90 | WEBP_HINT_GRAPH, // Discrete tone image (graph, map-tile etc).
91 | WEBP_HINT_LAST
92 | } WebPImageHint;
93 |
94 | // Compression parameters.
95 | struct WebPConfig {
96 | int lossless; // Lossless encoding (0=lossy(default), 1=lossless).
97 | float quality; // between 0 and 100. For lossy, 0 gives the smallest
98 | // size and 100 the largest. For lossless, this
99 | // parameter is the amount of effort put into the
100 | // compression: 0 is the fastest but gives larger
101 | // files compared to the slowest, but best, 100.
102 | int method; // quality/speed trade-off (0=fast, 6=slower-better)
103 |
104 | WebPImageHint image_hint; // Hint for image type (lossless only for now).
105 |
106 | int target_size; // if non-zero, set the desired target size in bytes.
107 | // Takes precedence over the 'compression' parameter.
108 | float target_PSNR; // if non-zero, specifies the minimal distortion to
109 | // try to achieve. Takes precedence over target_size.
110 | int segments; // maximum number of segments to use, in [1..4]
111 | int sns_strength; // Spatial Noise Shaping. 0=off, 100=maximum.
112 | int filter_strength; // range: [0 = off .. 100 = strongest]
113 | int filter_sharpness; // range: [0 = off .. 7 = least sharp]
114 | int filter_type; // filtering type: 0 = simple, 1 = strong (only used
115 | // if filter_strength > 0 or autofilter > 0)
116 | int autofilter; // Auto adjust filter's strength [0 = off, 1 = on]
117 | int alpha_compression; // Algorithm for encoding the alpha plane (0 = none,
118 | // 1 = compressed with WebP lossless). Default is 1.
119 | int alpha_filtering; // Predictive filtering method for alpha plane.
120 | // 0: none, 1: fast, 2: best. Default if 1.
121 | int alpha_quality; // Between 0 (smallest size) and 100 (lossless).
122 | // Default is 100.
123 | int pass; // number of entropy-analysis passes (in [1..10]).
124 |
125 | int show_compressed; // if true, export the compressed picture back.
126 | // In-loop filtering is not applied.
127 | int preprocessing; // preprocessing filter:
128 | // 0=none, 1=segment-smooth, 2=pseudo-random dithering
129 | int partitions; // log2(number of token partitions) in [0..3]. Default
130 | // is set to 0 for easier progressive decoding.
131 | int partition_limit; // quality degradation allowed to fit the 512k limit
132 | // on prediction modes coding (0: no degradation,
133 | // 100: maximum possible degradation).
134 | int emulate_jpeg_size; // If true, compression parameters will be remapped
135 | // to better match the expected output size from
136 | // JPEG compression. Generally, the output size will
137 | // be similar but the degradation will be lower.
138 | int thread_level; // If non-zero, try and use multi-threaded encoding.
139 | int low_memory; // If set, reduce memory usage (but increase CPU use).
140 |
141 | int near_lossless; // Near lossless encoding [0 = max loss .. 100 = off
142 | // (default)].
143 | int exact; // if non-zero, preserve the exact RGB values under
144 | // transparent area. Otherwise, discard this invisible
145 | // RGB information for better compression. The default
146 | // value is 0.
147 |
148 | int use_delta_palette; // reserved for future lossless feature
149 | int use_sharp_yuv; // if needed, use sharp (and slow) RGB->YUV conversion
150 |
151 | uint32_t pad[2]; // padding for later use
152 | };
153 |
154 | // Enumerate some predefined settings for WebPConfig, depending on the type
155 | // of source picture. These presets are used when calling WebPConfigPreset().
156 | typedef enum WebPPreset {
157 | WEBP_PRESET_DEFAULT = 0, // default preset.
158 | WEBP_PRESET_PICTURE, // digital picture, like portrait, inner shot
159 | WEBP_PRESET_PHOTO, // outdoor photograph, with natural lighting
160 | WEBP_PRESET_DRAWING, // hand or line drawing, with high-contrast details
161 | WEBP_PRESET_ICON, // small-sized colorful images
162 | WEBP_PRESET_TEXT // text-like
163 | } WebPPreset;
164 |
165 | // Internal, version-checked, entry point
166 | WEBP_EXTERN int WebPConfigInitInternal(WebPConfig*, WebPPreset, float, int);
167 |
168 | // Should always be called, to initialize a fresh WebPConfig structure before
169 | // modification. Returns false in case of version mismatch. WebPConfigInit()
170 | // must have succeeded before using the 'config' object.
171 | // Note that the default values are lossless=0 and quality=75.
172 | static WEBP_INLINE int WebPConfigInit(WebPConfig* config) {
173 | return WebPConfigInitInternal(config, WEBP_PRESET_DEFAULT, 75.f,
174 | WEBP_ENCODER_ABI_VERSION);
175 | }
176 |
177 | // This function will initialize the configuration according to a predefined
178 | // set of parameters (referred to by 'preset') and a given quality factor.
179 | // This function can be called as a replacement to WebPConfigInit(). Will
180 | // return false in case of error.
181 | static WEBP_INLINE int WebPConfigPreset(WebPConfig* config,
182 | WebPPreset preset, float quality) {
183 | return WebPConfigInitInternal(config, preset, quality,
184 | WEBP_ENCODER_ABI_VERSION);
185 | }
186 |
187 | // Activate the lossless compression mode with the desired efficiency level
188 | // between 0 (fastest, lowest compression) and 9 (slower, best compression).
189 | // A good default level is '6', providing a fair tradeoff between compression
190 | // speed and final compressed size.
191 | // This function will overwrite several fields from config: 'method', 'quality'
192 | // and 'lossless'. Returns false in case of parameter error.
193 | WEBP_EXTERN int WebPConfigLosslessPreset(WebPConfig* config, int level);
194 |
195 | // Returns true if 'config' is non-NULL and all configuration parameters are
196 | // within their valid ranges.
197 | WEBP_EXTERN int WebPValidateConfig(const WebPConfig* config);
198 |
199 | //------------------------------------------------------------------------------
200 | // Input / Output
201 | // Structure for storing auxiliary statistics.
202 |
203 | struct WebPAuxStats {
204 | int coded_size; // final size
205 |
206 | float PSNR[5]; // peak-signal-to-noise ratio for Y/U/V/All/Alpha
207 | int block_count[3]; // number of intra4/intra16/skipped macroblocks
208 | int header_bytes[2]; // approximate number of bytes spent for header
209 | // and mode-partition #0
210 | int residual_bytes[3][4]; // approximate number of bytes spent for
211 | // DC/AC/uv coefficients for each (0..3) segments.
212 | int segment_size[4]; // number of macroblocks in each segments
213 | int segment_quant[4]; // quantizer values for each segments
214 | int segment_level[4]; // filtering strength for each segments [0..63]
215 |
216 | int alpha_data_size; // size of the transparency data
217 | int layer_data_size; // size of the enhancement layer data
218 |
219 | // lossless encoder statistics
220 | uint32_t lossless_features; // bit0:predictor bit1:cross-color transform
221 | // bit2:subtract-green bit3:color indexing
222 | int histogram_bits; // number of precision bits of histogram
223 | int transform_bits; // precision bits for transform
224 | int cache_bits; // number of bits for color cache lookup
225 | int palette_size; // number of color in palette, if used
226 | int lossless_size; // final lossless size
227 | int lossless_hdr_size; // lossless header (transform, huffman etc) size
228 | int lossless_data_size; // lossless image data size
229 |
230 | uint32_t pad[2]; // padding for later use
231 | };
232 |
233 | // Signature for output function. Should return true if writing was successful.
234 | // data/data_size is the segment of data to write, and 'picture' is for
235 | // reference (and so one can make use of picture->custom_ptr).
236 | typedef int (*WebPWriterFunction)(const uint8_t* data, size_t data_size,
237 | const WebPPicture* picture);
238 |
239 | // WebPMemoryWrite: a special WebPWriterFunction that writes to memory using
240 | // the following WebPMemoryWriter object (to be set as a custom_ptr).
241 | struct WebPMemoryWriter {
242 | uint8_t* mem; // final buffer (of size 'max_size', larger than 'size').
243 | size_t size; // final size
244 | size_t max_size; // total capacity
245 | uint32_t pad[1]; // padding for later use
246 | };
247 |
248 | // The following must be called first before any use.
249 | WEBP_EXTERN void WebPMemoryWriterInit(WebPMemoryWriter* writer);
250 |
251 | // The following must be called to deallocate writer->mem memory. The 'writer'
252 | // object itself is not deallocated.
253 | WEBP_EXTERN void WebPMemoryWriterClear(WebPMemoryWriter* writer);
254 | // The custom writer to be used with WebPMemoryWriter as custom_ptr. Upon
255 | // completion, writer.mem and writer.size will hold the coded data.
256 | // writer.mem must be freed by calling WebPMemoryWriterClear.
257 | WEBP_EXTERN int WebPMemoryWrite(const uint8_t* data, size_t data_size,
258 | const WebPPicture* picture);
259 |
260 | // Progress hook, called from time to time to report progress. It can return
261 | // false to request an abort of the encoding process, or true otherwise if
262 | // everything is OK.
263 | typedef int (*WebPProgressHook)(int percent, const WebPPicture* picture);
264 |
265 | // Color spaces.
266 | typedef enum WebPEncCSP {
267 | // chroma sampling
268 | WEBP_YUV420 = 0, // 4:2:0
269 | WEBP_YUV420A = 4, // alpha channel variant
270 | WEBP_CSP_UV_MASK = 3, // bit-mask to get the UV sampling factors
271 | WEBP_CSP_ALPHA_BIT = 4 // bit that is set if alpha is present
272 | } WebPEncCSP;
273 |
274 | // Encoding error conditions.
275 | typedef enum WebPEncodingError {
276 | VP8_ENC_OK = 0,
277 | VP8_ENC_ERROR_OUT_OF_MEMORY, // memory error allocating objects
278 | VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY, // memory error while flushing bits
279 | VP8_ENC_ERROR_NULL_PARAMETER, // a pointer parameter is NULL
280 | VP8_ENC_ERROR_INVALID_CONFIGURATION, // configuration is invalid
281 | VP8_ENC_ERROR_BAD_DIMENSION, // picture has invalid width/height
282 | VP8_ENC_ERROR_PARTITION0_OVERFLOW, // partition is bigger than 512k
283 | VP8_ENC_ERROR_PARTITION_OVERFLOW, // partition is bigger than 16M
284 | VP8_ENC_ERROR_BAD_WRITE, // error while flushing bytes
285 | VP8_ENC_ERROR_FILE_TOO_BIG, // file is bigger than 4G
286 | VP8_ENC_ERROR_USER_ABORT, // abort request by user
287 | VP8_ENC_ERROR_LAST // list terminator. always last.
288 | } WebPEncodingError;
289 |
290 | // maximum width/height allowed (inclusive), in pixels
291 | #define WEBP_MAX_DIMENSION 16383
292 |
293 | // Main exchange structure (input samples, output bytes, statistics)
294 | struct WebPPicture {
295 | // INPUT
296 | //////////////
297 | // Main flag for encoder selecting between ARGB or YUV input.
298 | // It is recommended to use ARGB input (*argb, argb_stride) for lossless
299 | // compression, and YUV input (*y, *u, *v, etc.) for lossy compression
300 | // since these are the respective native colorspace for these formats.
301 | int use_argb;
302 |
303 | // YUV input (mostly used for input to lossy compression)
304 | WebPEncCSP colorspace; // colorspace: should be YUV420 for now (=Y'CbCr).
305 | int width, height; // dimensions (less or equal to WEBP_MAX_DIMENSION)
306 | uint8_t* y, *u, *v; // pointers to luma/chroma planes.
307 | int y_stride, uv_stride; // luma/chroma strides.
308 | uint8_t* a; // pointer to the alpha plane
309 | int a_stride; // stride of the alpha plane
310 | uint32_t pad1[2]; // padding for later use
311 |
312 | // ARGB input (mostly used for input to lossless compression)
313 | uint32_t* argb; // Pointer to argb (32 bit) plane.
314 | int argb_stride; // This is stride in pixels units, not bytes.
315 | uint32_t pad2[3]; // padding for later use
316 |
317 | // OUTPUT
318 | ///////////////
319 | // Byte-emission hook, to store compressed bytes as they are ready.
320 | WebPWriterFunction writer; // can be NULL
321 | void* custom_ptr; // can be used by the writer.
322 |
323 | // map for extra information (only for lossy compression mode)
324 | int extra_info_type; // 1: intra type, 2: segment, 3: quant
325 | // 4: intra-16 prediction mode,
326 | // 5: chroma prediction mode,
327 | // 6: bit cost, 7: distortion
328 | uint8_t* extra_info; // if not NULL, points to an array of size
329 | // ((width + 15) / 16) * ((height + 15) / 16) that
330 | // will be filled with a macroblock map, depending
331 | // on extra_info_type.
332 |
333 | // STATS AND REPORTS
334 | ///////////////////////////
335 | // Pointer to side statistics (updated only if not NULL)
336 | WebPAuxStats* stats;
337 |
338 | // Error code for the latest error encountered during encoding
339 | WebPEncodingError error_code;
340 |
341 | // If not NULL, report progress during encoding.
342 | WebPProgressHook progress_hook;
343 |
344 | void* user_data; // this field is free to be set to any value and
345 | // used during callbacks (like progress-report e.g.).
346 |
347 | uint32_t pad3[3]; // padding for later use
348 |
349 | // Unused for now
350 | uint8_t* pad4, *pad5;
351 | uint32_t pad6[8]; // padding for later use
352 |
353 | // PRIVATE FIELDS
354 | ////////////////////
355 | void* memory_; // row chunk of memory for yuva planes
356 | void* memory_argb_; // and for argb too.
357 | void* pad7[2]; // padding for later use
358 | };
359 |
360 | // Internal, version-checked, entry point
361 | WEBP_EXTERN int WebPPictureInitInternal(WebPPicture*, int);
362 |
363 | // Should always be called, to initialize the structure. Returns false in case
364 | // of version mismatch. WebPPictureInit() must have succeeded before using the
365 | // 'picture' object.
366 | // Note that, by default, use_argb is false and colorspace is WEBP_YUV420.
367 | static WEBP_INLINE int WebPPictureInit(WebPPicture* picture) {
368 | return WebPPictureInitInternal(picture, WEBP_ENCODER_ABI_VERSION);
369 | }
370 |
371 | //------------------------------------------------------------------------------
372 | // WebPPicture utils
373 |
374 | // Convenience allocation / deallocation based on picture->width/height:
375 | // Allocate y/u/v buffers as per colorspace/width/height specification.
376 | // Note! This function will free the previous buffer if needed.
377 | // Returns false in case of memory error.
378 | WEBP_EXTERN int WebPPictureAlloc(WebPPicture* picture);
379 |
380 | // Release the memory allocated by WebPPictureAlloc() or WebPPictureImport*().
381 | // Note that this function does _not_ free the memory used by the 'picture'
382 | // object itself.
383 | // Besides memory (which is reclaimed) all other fields of 'picture' are
384 | // preserved.
385 | WEBP_EXTERN void WebPPictureFree(WebPPicture* picture);
386 |
387 | // Copy the pixels of *src into *dst, using WebPPictureAlloc. Upon return, *dst
388 | // will fully own the copied pixels (this is not a view). The 'dst' picture need
389 | // not be initialized as its content is overwritten.
390 | // Returns false in case of memory allocation error.
391 | WEBP_EXTERN int WebPPictureCopy(const WebPPicture* src, WebPPicture* dst);
392 |
393 | // Compute the single distortion for packed planes of samples.
394 | // 'src' will be compared to 'ref', and the raw distortion stored into
395 | // '*distortion'. The refined metric (log(MSE), log(1 - ssim),...' will be
396 | // stored in '*result'.
397 | // 'x_step' is the horizontal stride (in bytes) between samples.
398 | // 'src/ref_stride' is the byte distance between rows.
399 | // Returns false in case of error (bad parameter, memory allocation error, ...).
400 | WEBP_EXTERN int WebPPlaneDistortion(const uint8_t* src, size_t src_stride,
401 | const uint8_t* ref, size_t ref_stride,
402 | int width, int height,
403 | size_t x_step,
404 | int type, // 0 = PSNR, 1 = SSIM, 2 = LSIM
405 | float* distortion, float* result);
406 |
407 | // Compute PSNR, SSIM or LSIM distortion metric between two pictures. Results
408 | // are in dB, stored in result[] in the B/G/R/A/All order. The distortion is
409 | // always performed using ARGB samples. Hence if the input is YUV(A), the
410 | // picture will be internally converted to ARGB (just for the measurement).
411 | // Warning: this function is rather CPU-intensive.
412 | WEBP_EXTERN int WebPPictureDistortion(
413 | const WebPPicture* src, const WebPPicture* ref,
414 | int metric_type, // 0 = PSNR, 1 = SSIM, 2 = LSIM
415 | float result[5]);
416 |
417 | // self-crops a picture to the rectangle defined by top/left/width/height.
418 | // Returns false in case of memory allocation error, or if the rectangle is
419 | // outside of the source picture.
420 | // The rectangle for the view is defined by the top-left corner pixel
421 | // coordinates (left, top) as well as its width and height. This rectangle
422 | // must be fully be comprised inside the 'src' source picture. If the source
423 | // picture uses the YUV420 colorspace, the top and left coordinates will be
424 | // snapped to even values.
425 | WEBP_EXTERN int WebPPictureCrop(WebPPicture* picture,
426 | int left, int top, int width, int height);
427 |
428 | // Extracts a view from 'src' picture into 'dst'. The rectangle for the view
429 | // is defined by the top-left corner pixel coordinates (left, top) as well
430 | // as its width and height. This rectangle must be fully be comprised inside
431 | // the 'src' source picture. If the source picture uses the YUV420 colorspace,
432 | // the top and left coordinates will be snapped to even values.
433 | // Picture 'src' must out-live 'dst' picture. Self-extraction of view is allowed
434 | // ('src' equal to 'dst') as a mean of fast-cropping (but note that doing so,
435 | // the original dimension will be lost). Picture 'dst' need not be initialized
436 | // with WebPPictureInit() if it is different from 'src', since its content will
437 | // be overwritten.
438 | // Returns false in case of memory allocation error or invalid parameters.
439 | WEBP_EXTERN int WebPPictureView(const WebPPicture* src,
440 | int left, int top, int width, int height,
441 | WebPPicture* dst);
442 |
443 | // Returns true if the 'picture' is actually a view and therefore does
444 | // not own the memory for pixels.
445 | WEBP_EXTERN int WebPPictureIsView(const WebPPicture* picture);
446 |
447 | // Rescale a picture to new dimension width x height.
448 | // If either 'width' or 'height' (but not both) is 0 the corresponding
449 | // dimension will be calculated preserving the aspect ratio.
450 | // No gamma correction is applied.
451 | // Returns false in case of error (invalid parameter or insufficient memory).
452 | WEBP_EXTERN int WebPPictureRescale(WebPPicture* pic, int width, int height);
453 |
454 | // Colorspace conversion function to import RGB samples.
455 | // Previous buffer will be free'd, if any.
456 | // *rgb buffer should have a size of at least height * rgb_stride.
457 | // Returns false in case of memory error.
458 | WEBP_EXTERN int WebPPictureImportRGB(
459 | WebPPicture* picture, const uint8_t* rgb, int rgb_stride);
460 | // Same, but for RGBA buffer.
461 | WEBP_EXTERN int WebPPictureImportRGBA(
462 | WebPPicture* picture, const uint8_t* rgba, int rgba_stride);
463 | // Same, but for RGBA buffer. Imports the RGB direct from the 32-bit format
464 | // input buffer ignoring the alpha channel. Avoids needing to copy the data
465 | // to a temporary 24-bit RGB buffer to import the RGB only.
466 | WEBP_EXTERN int WebPPictureImportRGBX(
467 | WebPPicture* picture, const uint8_t* rgbx, int rgbx_stride);
468 |
469 | // Variants of the above, but taking BGR(A|X) input.
470 | WEBP_EXTERN int WebPPictureImportBGR(
471 | WebPPicture* picture, const uint8_t* bgr, int bgr_stride);
472 | WEBP_EXTERN int WebPPictureImportBGRA(
473 | WebPPicture* picture, const uint8_t* bgra, int bgra_stride);
474 | WEBP_EXTERN int WebPPictureImportBGRX(
475 | WebPPicture* picture, const uint8_t* bgrx, int bgrx_stride);
476 |
477 | // Converts picture->argb data to the YUV420A format. The 'colorspace'
478 | // parameter is deprecated and should be equal to WEBP_YUV420.
479 | // Upon return, picture->use_argb is set to false. The presence of real
480 | // non-opaque transparent values is detected, and 'colorspace' will be
481 | // adjusted accordingly. Note that this method is lossy.
482 | // Returns false in case of error.
483 | WEBP_EXTERN int WebPPictureARGBToYUVA(WebPPicture* picture,
484 | WebPEncCSP /*colorspace = WEBP_YUV420*/);
485 |
486 | // Same as WebPPictureARGBToYUVA(), but the conversion is done using
487 | // pseudo-random dithering with a strength 'dithering' between
488 | // 0.0 (no dithering) and 1.0 (maximum dithering). This is useful
489 | // for photographic picture.
490 | WEBP_EXTERN int WebPPictureARGBToYUVADithered(
491 | WebPPicture* picture, WebPEncCSP colorspace, float dithering);
492 |
493 | // Performs 'sharp' RGBA->YUVA420 downsampling and colorspace conversion.
494 | // Downsampling is handled with extra care in case of color clipping. This
495 | // method is roughly 2x slower than WebPPictureARGBToYUVA() but produces better
496 | // and sharper YUV representation.
497 | // Returns false in case of error.
498 | WEBP_EXTERN int WebPPictureSharpARGBToYUVA(WebPPicture* picture);
499 | // kept for backward compatibility:
500 | WEBP_EXTERN int WebPPictureSmartARGBToYUVA(WebPPicture* picture);
501 |
502 | // Converts picture->yuv to picture->argb and sets picture->use_argb to true.
503 | // The input format must be YUV_420 or YUV_420A. The conversion from YUV420 to
504 | // ARGB incurs a small loss too.
505 | // Note that the use of this colorspace is discouraged if one has access to the
506 | // raw ARGB samples, since using YUV420 is comparatively lossy.
507 | // Returns false in case of error.
508 | WEBP_EXTERN int WebPPictureYUVAToARGB(WebPPicture* picture);
509 |
510 | // Helper function: given a width x height plane of RGBA or YUV(A) samples
511 | // clean-up or smoothen the YUV or RGB samples under fully transparent area,
512 | // to help compressibility (no guarantee, though).
513 | WEBP_EXTERN void WebPCleanupTransparentArea(WebPPicture* picture);
514 |
515 | // Scan the picture 'picture' for the presence of non fully opaque alpha values.
516 | // Returns true in such case. Otherwise returns false (indicating that the
517 | // alpha plane can be ignored altogether e.g.).
518 | WEBP_EXTERN int WebPPictureHasTransparency(const WebPPicture* picture);
519 |
520 | // Remove the transparency information (if present) by blending the color with
521 | // the background color 'background_rgb' (specified as 24bit RGB triplet).
522 | // After this call, all alpha values are reset to 0xff.
523 | WEBP_EXTERN void WebPBlendAlpha(WebPPicture* pic, uint32_t background_rgb);
524 |
525 | //------------------------------------------------------------------------------
526 | // Main call
527 |
528 | // Main encoding call, after config and picture have been initialized.
529 | // 'picture' must be less than 16384x16384 in dimension (cf WEBP_MAX_DIMENSION),
530 | // and the 'config' object must be a valid one.
531 | // Returns false in case of error, true otherwise.
532 | // In case of error, picture->error_code is updated accordingly.
533 | // 'picture' can hold the source samples in both YUV(A) or ARGB input, depending
534 | // on the value of 'picture->use_argb'. It is highly recommended to use
535 | // the former for lossy encoding, and the latter for lossless encoding
536 | // (when config.lossless is true). Automatic conversion from one format to
537 | // another is provided but they both incur some loss.
538 | WEBP_EXTERN int WebPEncode(const WebPConfig* config, WebPPicture* picture);
539 |
540 | //------------------------------------------------------------------------------
541 |
542 | #ifdef __cplusplus
543 | } // extern "C"
544 | #endif
545 |
546 | #endif // WEBP_WEBP_ENCODE_H_
547 |
--------------------------------------------------------------------------------
/__lib__/libwebp-1.1.0-windows-x64/include/webp/mux.h:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // RIFF container manipulation and encoding for WebP images.
11 | //
12 | // Authors: Urvang (urvang@google.com)
13 | // Vikas (vikasa@google.com)
14 |
15 | #ifndef WEBP_WEBP_MUX_H_
16 | #define WEBP_WEBP_MUX_H_
17 |
18 | #include "./mux_types.h"
19 |
20 | #ifdef __cplusplus
21 | extern "C" {
22 | #endif
23 |
24 | #define WEBP_MUX_ABI_VERSION 0x0108 // MAJOR(8b) + MINOR(8b)
25 |
26 | //------------------------------------------------------------------------------
27 | // Mux API
28 | //
29 | // This API allows manipulation of WebP container images containing features
30 | // like color profile, metadata, animation.
31 | //
32 | // Code Example#1: Create a WebPMux object with image data, color profile and
33 | // XMP metadata.
34 | /*
35 | int copy_data = 0;
36 | WebPMux* mux = WebPMuxNew();
37 | // ... (Prepare image data).
38 | WebPMuxSetImage(mux, &image, copy_data);
39 | // ... (Prepare ICCP color profile data).
40 | WebPMuxSetChunk(mux, "ICCP", &icc_profile, copy_data);
41 | // ... (Prepare XMP metadata).
42 | WebPMuxSetChunk(mux, "XMP ", &xmp, copy_data);
43 | // Get data from mux in WebP RIFF format.
44 | WebPMuxAssemble(mux, &output_data);
45 | WebPMuxDelete(mux);
46 | // ... (Consume output_data; e.g. write output_data.bytes to file).
47 | WebPDataClear(&output_data);
48 | */
49 |
50 | // Code Example#2: Get image and color profile data from a WebP file.
51 | /*
52 | int copy_data = 0;
53 | // ... (Read data from file).
54 | WebPMux* mux = WebPMuxCreate(&data, copy_data);
55 | WebPMuxGetFrame(mux, 1, &image);
56 | // ... (Consume image; e.g. call WebPDecode() to decode the data).
57 | WebPMuxGetChunk(mux, "ICCP", &icc_profile);
58 | // ... (Consume icc_data).
59 | WebPMuxDelete(mux);
60 | WebPFree(data);
61 | */
62 |
63 | // Note: forward declaring enumerations is not allowed in (strict) C and C++,
64 | // the types are left here for reference.
65 | // typedef enum WebPMuxError WebPMuxError;
66 | // typedef enum WebPChunkId WebPChunkId;
67 | typedef struct WebPMux WebPMux; // main opaque object.
68 | typedef struct WebPMuxFrameInfo WebPMuxFrameInfo;
69 | typedef struct WebPMuxAnimParams WebPMuxAnimParams;
70 | typedef struct WebPAnimEncoderOptions WebPAnimEncoderOptions;
71 |
72 | // Error codes
73 | typedef enum WebPMuxError {
74 | WEBP_MUX_OK = 1,
75 | WEBP_MUX_NOT_FOUND = 0,
76 | WEBP_MUX_INVALID_ARGUMENT = -1,
77 | WEBP_MUX_BAD_DATA = -2,
78 | WEBP_MUX_MEMORY_ERROR = -3,
79 | WEBP_MUX_NOT_ENOUGH_DATA = -4
80 | } WebPMuxError;
81 |
82 | // IDs for different types of chunks.
83 | typedef enum WebPChunkId {
84 | WEBP_CHUNK_VP8X, // VP8X
85 | WEBP_CHUNK_ICCP, // ICCP
86 | WEBP_CHUNK_ANIM, // ANIM
87 | WEBP_CHUNK_ANMF, // ANMF
88 | WEBP_CHUNK_DEPRECATED, // (deprecated from FRGM)
89 | WEBP_CHUNK_ALPHA, // ALPH
90 | WEBP_CHUNK_IMAGE, // VP8/VP8L
91 | WEBP_CHUNK_EXIF, // EXIF
92 | WEBP_CHUNK_XMP, // XMP
93 | WEBP_CHUNK_UNKNOWN, // Other chunks.
94 | WEBP_CHUNK_NIL
95 | } WebPChunkId;
96 |
97 | //------------------------------------------------------------------------------
98 |
99 | // Returns the version number of the mux library, packed in hexadecimal using
100 | // 8bits for each of major/minor/revision. E.g: v2.5.7 is 0x020507.
101 | WEBP_EXTERN int WebPGetMuxVersion(void);
102 |
103 | //------------------------------------------------------------------------------
104 | // Life of a Mux object
105 |
106 | // Internal, version-checked, entry point
107 | WEBP_EXTERN WebPMux* WebPNewInternal(int);
108 |
109 | // Creates an empty mux object.
110 | // Returns:
111 | // A pointer to the newly created empty mux object.
112 | // Or NULL in case of memory error.
113 | static WEBP_INLINE WebPMux* WebPMuxNew(void) {
114 | return WebPNewInternal(WEBP_MUX_ABI_VERSION);
115 | }
116 |
117 | // Deletes the mux object.
118 | // Parameters:
119 | // mux - (in/out) object to be deleted
120 | WEBP_EXTERN void WebPMuxDelete(WebPMux* mux);
121 |
122 | //------------------------------------------------------------------------------
123 | // Mux creation.
124 |
125 | // Internal, version-checked, entry point
126 | WEBP_EXTERN WebPMux* WebPMuxCreateInternal(const WebPData*, int, int);
127 |
128 | // Creates a mux object from raw data given in WebP RIFF format.
129 | // Parameters:
130 | // bitstream - (in) the bitstream data in WebP RIFF format
131 | // copy_data - (in) value 1 indicates given data WILL be copied to the mux
132 | // object and value 0 indicates data will NOT be copied.
133 | // Returns:
134 | // A pointer to the mux object created from given data - on success.
135 | // NULL - In case of invalid data or memory error.
136 | static WEBP_INLINE WebPMux* WebPMuxCreate(const WebPData* bitstream,
137 | int copy_data) {
138 | return WebPMuxCreateInternal(bitstream, copy_data, WEBP_MUX_ABI_VERSION);
139 | }
140 |
141 | //------------------------------------------------------------------------------
142 | // Non-image chunks.
143 |
144 | // Note: Only non-image related chunks should be managed through chunk APIs.
145 | // (Image related chunks are: "ANMF", "VP8 ", "VP8L" and "ALPH").
146 | // To add, get and delete images, use WebPMuxSetImage(), WebPMuxPushFrame(),
147 | // WebPMuxGetFrame() and WebPMuxDeleteFrame().
148 |
149 | // Adds a chunk with id 'fourcc' and data 'chunk_data' in the mux object.
150 | // Any existing chunk(s) with the same id will be removed.
151 | // Parameters:
152 | // mux - (in/out) object to which the chunk is to be added
153 | // fourcc - (in) a character array containing the fourcc of the given chunk;
154 | // e.g., "ICCP", "XMP ", "EXIF" etc.
155 | // chunk_data - (in) the chunk data to be added
156 | // copy_data - (in) value 1 indicates given data WILL be copied to the mux
157 | // object and value 0 indicates data will NOT be copied.
158 | // Returns:
159 | // WEBP_MUX_INVALID_ARGUMENT - if mux, fourcc or chunk_data is NULL
160 | // or if fourcc corresponds to an image chunk.
161 | // WEBP_MUX_MEMORY_ERROR - on memory allocation error.
162 | // WEBP_MUX_OK - on success.
163 | WEBP_EXTERN WebPMuxError WebPMuxSetChunk(
164 | WebPMux* mux, const char fourcc[4], const WebPData* chunk_data,
165 | int copy_data);
166 |
167 | // Gets a reference to the data of the chunk with id 'fourcc' in the mux object.
168 | // The caller should NOT free the returned data.
169 | // Parameters:
170 | // mux - (in) object from which the chunk data is to be fetched
171 | // fourcc - (in) a character array containing the fourcc of the chunk;
172 | // e.g., "ICCP", "XMP ", "EXIF" etc.
173 | // chunk_data - (out) returned chunk data
174 | // Returns:
175 | // WEBP_MUX_INVALID_ARGUMENT - if mux, fourcc or chunk_data is NULL
176 | // or if fourcc corresponds to an image chunk.
177 | // WEBP_MUX_NOT_FOUND - If mux does not contain a chunk with the given id.
178 | // WEBP_MUX_OK - on success.
179 | WEBP_EXTERN WebPMuxError WebPMuxGetChunk(
180 | const WebPMux* mux, const char fourcc[4], WebPData* chunk_data);
181 |
182 | // Deletes the chunk with the given 'fourcc' from the mux object.
183 | // Parameters:
184 | // mux - (in/out) object from which the chunk is to be deleted
185 | // fourcc - (in) a character array containing the fourcc of the chunk;
186 | // e.g., "ICCP", "XMP ", "EXIF" etc.
187 | // Returns:
188 | // WEBP_MUX_INVALID_ARGUMENT - if mux or fourcc is NULL
189 | // or if fourcc corresponds to an image chunk.
190 | // WEBP_MUX_NOT_FOUND - If mux does not contain a chunk with the given fourcc.
191 | // WEBP_MUX_OK - on success.
192 | WEBP_EXTERN WebPMuxError WebPMuxDeleteChunk(
193 | WebPMux* mux, const char fourcc[4]);
194 |
195 | //------------------------------------------------------------------------------
196 | // Images.
197 |
198 | // Encapsulates data about a single frame.
199 | struct WebPMuxFrameInfo {
200 | WebPData bitstream; // image data: can be a raw VP8/VP8L bitstream
201 | // or a single-image WebP file.
202 | int x_offset; // x-offset of the frame.
203 | int y_offset; // y-offset of the frame.
204 | int duration; // duration of the frame (in milliseconds).
205 |
206 | WebPChunkId id; // frame type: should be one of WEBP_CHUNK_ANMF
207 | // or WEBP_CHUNK_IMAGE
208 | WebPMuxAnimDispose dispose_method; // Disposal method for the frame.
209 | WebPMuxAnimBlend blend_method; // Blend operation for the frame.
210 | uint32_t pad[1]; // padding for later use
211 | };
212 |
213 | // Sets the (non-animated) image in the mux object.
214 | // Note: Any existing images (including frames) will be removed.
215 | // Parameters:
216 | // mux - (in/out) object in which the image is to be set
217 | // bitstream - (in) can be a raw VP8/VP8L bitstream or a single-image
218 | // WebP file (non-animated)
219 | // copy_data - (in) value 1 indicates given data WILL be copied to the mux
220 | // object and value 0 indicates data will NOT be copied.
221 | // Returns:
222 | // WEBP_MUX_INVALID_ARGUMENT - if mux is NULL or bitstream is NULL.
223 | // WEBP_MUX_MEMORY_ERROR - on memory allocation error.
224 | // WEBP_MUX_OK - on success.
225 | WEBP_EXTERN WebPMuxError WebPMuxSetImage(
226 | WebPMux* mux, const WebPData* bitstream, int copy_data);
227 |
228 | // Adds a frame at the end of the mux object.
229 | // Notes: (1) frame.id should be WEBP_CHUNK_ANMF
230 | // (2) For setting a non-animated image, use WebPMuxSetImage() instead.
231 | // (3) Type of frame being pushed must be same as the frames in mux.
232 | // (4) As WebP only supports even offsets, any odd offset will be snapped
233 | // to an even location using: offset &= ~1
234 | // Parameters:
235 | // mux - (in/out) object to which the frame is to be added
236 | // frame - (in) frame data.
237 | // copy_data - (in) value 1 indicates given data WILL be copied to the mux
238 | // object and value 0 indicates data will NOT be copied.
239 | // Returns:
240 | // WEBP_MUX_INVALID_ARGUMENT - if mux or frame is NULL
241 | // or if content of 'frame' is invalid.
242 | // WEBP_MUX_MEMORY_ERROR - on memory allocation error.
243 | // WEBP_MUX_OK - on success.
244 | WEBP_EXTERN WebPMuxError WebPMuxPushFrame(
245 | WebPMux* mux, const WebPMuxFrameInfo* frame, int copy_data);
246 |
247 | // Gets the nth frame from the mux object.
248 | // The content of 'frame->bitstream' is allocated using WebPMalloc(), and NOT
249 | // owned by the 'mux' object. It MUST be deallocated by the caller by calling
250 | // WebPDataClear().
251 | // nth=0 has a special meaning - last position.
252 | // Parameters:
253 | // mux - (in) object from which the info is to be fetched
254 | // nth - (in) index of the frame in the mux object
255 | // frame - (out) data of the returned frame
256 | // Returns:
257 | // WEBP_MUX_INVALID_ARGUMENT - if mux or frame is NULL.
258 | // WEBP_MUX_NOT_FOUND - if there are less than nth frames in the mux object.
259 | // WEBP_MUX_BAD_DATA - if nth frame chunk in mux is invalid.
260 | // WEBP_MUX_MEMORY_ERROR - on memory allocation error.
261 | // WEBP_MUX_OK - on success.
262 | WEBP_EXTERN WebPMuxError WebPMuxGetFrame(
263 | const WebPMux* mux, uint32_t nth, WebPMuxFrameInfo* frame);
264 |
265 | // Deletes a frame from the mux object.
266 | // nth=0 has a special meaning - last position.
267 | // Parameters:
268 | // mux - (in/out) object from which a frame is to be deleted
269 | // nth - (in) The position from which the frame is to be deleted
270 | // Returns:
271 | // WEBP_MUX_INVALID_ARGUMENT - if mux is NULL.
272 | // WEBP_MUX_NOT_FOUND - If there are less than nth frames in the mux object
273 | // before deletion.
274 | // WEBP_MUX_OK - on success.
275 | WEBP_EXTERN WebPMuxError WebPMuxDeleteFrame(WebPMux* mux, uint32_t nth);
276 |
277 | //------------------------------------------------------------------------------
278 | // Animation.
279 |
280 | // Animation parameters.
281 | struct WebPMuxAnimParams {
282 | uint32_t bgcolor; // Background color of the canvas stored (in MSB order) as:
283 | // Bits 00 to 07: Alpha.
284 | // Bits 08 to 15: Red.
285 | // Bits 16 to 23: Green.
286 | // Bits 24 to 31: Blue.
287 | int loop_count; // Number of times to repeat the animation [0 = infinite].
288 | };
289 |
290 | // Sets the animation parameters in the mux object. Any existing ANIM chunks
291 | // will be removed.
292 | // Parameters:
293 | // mux - (in/out) object in which ANIM chunk is to be set/added
294 | // params - (in) animation parameters.
295 | // Returns:
296 | // WEBP_MUX_INVALID_ARGUMENT - if mux or params is NULL.
297 | // WEBP_MUX_MEMORY_ERROR - on memory allocation error.
298 | // WEBP_MUX_OK - on success.
299 | WEBP_EXTERN WebPMuxError WebPMuxSetAnimationParams(
300 | WebPMux* mux, const WebPMuxAnimParams* params);
301 |
302 | // Gets the animation parameters from the mux object.
303 | // Parameters:
304 | // mux - (in) object from which the animation parameters to be fetched
305 | // params - (out) animation parameters extracted from the ANIM chunk
306 | // Returns:
307 | // WEBP_MUX_INVALID_ARGUMENT - if mux or params is NULL.
308 | // WEBP_MUX_NOT_FOUND - if ANIM chunk is not present in mux object.
309 | // WEBP_MUX_OK - on success.
310 | WEBP_EXTERN WebPMuxError WebPMuxGetAnimationParams(
311 | const WebPMux* mux, WebPMuxAnimParams* params);
312 |
313 | //------------------------------------------------------------------------------
314 | // Misc Utilities.
315 |
316 | // Sets the canvas size for the mux object. The width and height can be
317 | // specified explicitly or left as zero (0, 0).
318 | // * When width and height are specified explicitly, then this frame bound is
319 | // enforced during subsequent calls to WebPMuxAssemble() and an error is
320 | // reported if any animated frame does not completely fit within the canvas.
321 | // * When unspecified (0, 0), the constructed canvas will get the frame bounds
322 | // from the bounding-box over all frames after calling WebPMuxAssemble().
323 | // Parameters:
324 | // mux - (in) object to which the canvas size is to be set
325 | // width - (in) canvas width
326 | // height - (in) canvas height
327 | // Returns:
328 | // WEBP_MUX_INVALID_ARGUMENT - if mux is NULL; or
329 | // width or height are invalid or out of bounds
330 | // WEBP_MUX_OK - on success.
331 | WEBP_EXTERN WebPMuxError WebPMuxSetCanvasSize(WebPMux* mux,
332 | int width, int height);
333 |
334 | // Gets the canvas size from the mux object.
335 | // Note: This method assumes that the VP8X chunk, if present, is up-to-date.
336 | // That is, the mux object hasn't been modified since the last call to
337 | // WebPMuxAssemble() or WebPMuxCreate().
338 | // Parameters:
339 | // mux - (in) object from which the canvas size is to be fetched
340 | // width - (out) canvas width
341 | // height - (out) canvas height
342 | // Returns:
343 | // WEBP_MUX_INVALID_ARGUMENT - if mux, width or height is NULL.
344 | // WEBP_MUX_BAD_DATA - if VP8X/VP8/VP8L chunk or canvas size is invalid.
345 | // WEBP_MUX_OK - on success.
346 | WEBP_EXTERN WebPMuxError WebPMuxGetCanvasSize(const WebPMux* mux,
347 | int* width, int* height);
348 |
349 | // Gets the feature flags from the mux object.
350 | // Note: This method assumes that the VP8X chunk, if present, is up-to-date.
351 | // That is, the mux object hasn't been modified since the last call to
352 | // WebPMuxAssemble() or WebPMuxCreate().
353 | // Parameters:
354 | // mux - (in) object from which the features are to be fetched
355 | // flags - (out) the flags specifying which features are present in the
356 | // mux object. This will be an OR of various flag values.
357 | // Enum 'WebPFeatureFlags' can be used to test individual flag values.
358 | // Returns:
359 | // WEBP_MUX_INVALID_ARGUMENT - if mux or flags is NULL.
360 | // WEBP_MUX_BAD_DATA - if VP8X/VP8/VP8L chunk or canvas size is invalid.
361 | // WEBP_MUX_OK - on success.
362 | WEBP_EXTERN WebPMuxError WebPMuxGetFeatures(const WebPMux* mux,
363 | uint32_t* flags);
364 |
365 | // Gets number of chunks with the given 'id' in the mux object.
366 | // Parameters:
367 | // mux - (in) object from which the info is to be fetched
368 | // id - (in) chunk id specifying the type of chunk
369 | // num_elements - (out) number of chunks with the given chunk id
370 | // Returns:
371 | // WEBP_MUX_INVALID_ARGUMENT - if mux, or num_elements is NULL.
372 | // WEBP_MUX_OK - on success.
373 | WEBP_EXTERN WebPMuxError WebPMuxNumChunks(const WebPMux* mux,
374 | WebPChunkId id, int* num_elements);
375 |
376 | // Assembles all chunks in WebP RIFF format and returns in 'assembled_data'.
377 | // This function also validates the mux object.
378 | // Note: The content of 'assembled_data' will be ignored and overwritten.
379 | // Also, the content of 'assembled_data' is allocated using WebPMalloc(), and
380 | // NOT owned by the 'mux' object. It MUST be deallocated by the caller by
381 | // calling WebPDataClear(). It's always safe to call WebPDataClear() upon
382 | // return, even in case of error.
383 | // Parameters:
384 | // mux - (in/out) object whose chunks are to be assembled
385 | // assembled_data - (out) assembled WebP data
386 | // Returns:
387 | // WEBP_MUX_BAD_DATA - if mux object is invalid.
388 | // WEBP_MUX_INVALID_ARGUMENT - if mux or assembled_data is NULL.
389 | // WEBP_MUX_MEMORY_ERROR - on memory allocation error.
390 | // WEBP_MUX_OK - on success.
391 | WEBP_EXTERN WebPMuxError WebPMuxAssemble(WebPMux* mux,
392 | WebPData* assembled_data);
393 |
394 | //------------------------------------------------------------------------------
395 | // WebPAnimEncoder API
396 | //
397 | // This API allows encoding (possibly) animated WebP images.
398 | //
399 | // Code Example:
400 | /*
401 | WebPAnimEncoderOptions enc_options;
402 | WebPAnimEncoderOptionsInit(&enc_options);
403 | // Tune 'enc_options' as needed.
404 | WebPAnimEncoder* enc = WebPAnimEncoderNew(width, height, &enc_options);
405 | while() {
406 | WebPConfig config;
407 | WebPConfigInit(&config);
408 | // Tune 'config' as needed.
409 | WebPAnimEncoderAdd(enc, frame, timestamp_ms, &config);
410 | }
411 | WebPAnimEncoderAdd(enc, NULL, timestamp_ms, NULL);
412 | WebPAnimEncoderAssemble(enc, webp_data);
413 | WebPAnimEncoderDelete(enc);
414 | // Write the 'webp_data' to a file, or re-mux it further.
415 | */
416 |
417 | typedef struct WebPAnimEncoder WebPAnimEncoder; // Main opaque object.
418 |
419 | // Forward declarations. Defined in encode.h.
420 | struct WebPPicture;
421 | struct WebPConfig;
422 |
423 | // Global options.
424 | struct WebPAnimEncoderOptions {
425 | WebPMuxAnimParams anim_params; // Animation parameters.
426 | int minimize_size; // If true, minimize the output size (slow). Implicitly
427 | // disables key-frame insertion.
428 | int kmin;
429 | int kmax; // Minimum and maximum distance between consecutive key
430 | // frames in the output. The library may insert some key
431 | // frames as needed to satisfy this criteria.
432 | // Note that these conditions should hold: kmax > kmin
433 | // and kmin >= kmax / 2 + 1. Also, if kmax <= 0, then
434 | // key-frame insertion is disabled; and if kmax == 1,
435 | // then all frames will be key-frames (kmin value does
436 | // not matter for these special cases).
437 | int allow_mixed; // If true, use mixed compression mode; may choose
438 | // either lossy and lossless for each frame.
439 | int verbose; // If true, print info and warning messages to stderr.
440 |
441 | uint32_t padding[4]; // Padding for later use.
442 | };
443 |
444 | // Internal, version-checked, entry point.
445 | WEBP_EXTERN int WebPAnimEncoderOptionsInitInternal(
446 | WebPAnimEncoderOptions*, int);
447 |
448 | // Should always be called, to initialize a fresh WebPAnimEncoderOptions
449 | // structure before modification. Returns false in case of version mismatch.
450 | // WebPAnimEncoderOptionsInit() must have succeeded before using the
451 | // 'enc_options' object.
452 | static WEBP_INLINE int WebPAnimEncoderOptionsInit(
453 | WebPAnimEncoderOptions* enc_options) {
454 | return WebPAnimEncoderOptionsInitInternal(enc_options, WEBP_MUX_ABI_VERSION);
455 | }
456 |
457 | // Internal, version-checked, entry point.
458 | WEBP_EXTERN WebPAnimEncoder* WebPAnimEncoderNewInternal(
459 | int, int, const WebPAnimEncoderOptions*, int);
460 |
461 | // Creates and initializes a WebPAnimEncoder object.
462 | // Parameters:
463 | // width/height - (in) canvas width and height of the animation.
464 | // enc_options - (in) encoding options; can be passed NULL to pick
465 | // reasonable defaults.
466 | // Returns:
467 | // A pointer to the newly created WebPAnimEncoder object.
468 | // Or NULL in case of memory error.
469 | static WEBP_INLINE WebPAnimEncoder* WebPAnimEncoderNew(
470 | int width, int height, const WebPAnimEncoderOptions* enc_options) {
471 | return WebPAnimEncoderNewInternal(width, height, enc_options,
472 | WEBP_MUX_ABI_VERSION);
473 | }
474 |
475 | // Optimize the given frame for WebP, encode it and add it to the
476 | // WebPAnimEncoder object.
477 | // The last call to 'WebPAnimEncoderAdd' should be with frame = NULL, which
478 | // indicates that no more frames are to be added. This call is also used to
479 | // determine the duration of the last frame.
480 | // Parameters:
481 | // enc - (in/out) object to which the frame is to be added.
482 | // frame - (in/out) frame data in ARGB or YUV(A) format. If it is in YUV(A)
483 | // format, it will be converted to ARGB, which incurs a small loss.
484 | // timestamp_ms - (in) timestamp of this frame in milliseconds.
485 | // Duration of a frame would be calculated as
486 | // "timestamp of next frame - timestamp of this frame".
487 | // Hence, timestamps should be in non-decreasing order.
488 | // config - (in) encoding options; can be passed NULL to pick
489 | // reasonable defaults.
490 | // Returns:
491 | // On error, returns false and frame->error_code is set appropriately.
492 | // Otherwise, returns true.
493 | WEBP_EXTERN int WebPAnimEncoderAdd(
494 | WebPAnimEncoder* enc, struct WebPPicture* frame, int timestamp_ms,
495 | const struct WebPConfig* config);
496 |
497 | // Assemble all frames added so far into a WebP bitstream.
498 | // This call should be preceded by a call to 'WebPAnimEncoderAdd' with
499 | // frame = NULL; if not, the duration of the last frame will be internally
500 | // estimated.
501 | // Parameters:
502 | // enc - (in/out) object from which the frames are to be assembled.
503 | // webp_data - (out) generated WebP bitstream.
504 | // Returns:
505 | // True on success.
506 | WEBP_EXTERN int WebPAnimEncoderAssemble(WebPAnimEncoder* enc,
507 | WebPData* webp_data);
508 |
509 | // Get error string corresponding to the most recent call using 'enc'. The
510 | // returned string is owned by 'enc' and is valid only until the next call to
511 | // WebPAnimEncoderAdd() or WebPAnimEncoderAssemble() or WebPAnimEncoderDelete().
512 | // Parameters:
513 | // enc - (in/out) object from which the error string is to be fetched.
514 | // Returns:
515 | // NULL if 'enc' is NULL. Otherwise, returns the error string if the last call
516 | // to 'enc' had an error, or an empty string if the last call was a success.
517 | WEBP_EXTERN const char* WebPAnimEncoderGetError(WebPAnimEncoder* enc);
518 |
519 | // Deletes the WebPAnimEncoder object.
520 | // Parameters:
521 | // enc - (in/out) object to be deleted
522 | WEBP_EXTERN void WebPAnimEncoderDelete(WebPAnimEncoder* enc);
523 |
524 | //------------------------------------------------------------------------------
525 |
526 | #ifdef __cplusplus
527 | } // extern "C"
528 | #endif
529 |
530 | #endif // WEBP_WEBP_MUX_H_
531 |
--------------------------------------------------------------------------------
/__lib__/libwebp-1.1.0-windows-x64/include/webp/mux_types.h:
--------------------------------------------------------------------------------
1 | // Copyright 2012 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Data-types common to the mux and demux libraries.
11 | //
12 | // Author: Urvang (urvang@google.com)
13 |
14 | #ifndef WEBP_WEBP_MUX_TYPES_H_
15 | #define WEBP_WEBP_MUX_TYPES_H_
16 |
17 | #include // memset()
18 | #include "./types.h"
19 |
20 | #ifdef __cplusplus
21 | extern "C" {
22 | #endif
23 |
24 | // Note: forward declaring enumerations is not allowed in (strict) C and C++,
25 | // the types are left here for reference.
26 | // typedef enum WebPFeatureFlags WebPFeatureFlags;
27 | // typedef enum WebPMuxAnimDispose WebPMuxAnimDispose;
28 | // typedef enum WebPMuxAnimBlend WebPMuxAnimBlend;
29 | typedef struct WebPData WebPData;
30 |
31 | // VP8X Feature Flags.
32 | typedef enum WebPFeatureFlags {
33 | ANIMATION_FLAG = 0x00000002,
34 | XMP_FLAG = 0x00000004,
35 | EXIF_FLAG = 0x00000008,
36 | ALPHA_FLAG = 0x00000010,
37 | ICCP_FLAG = 0x00000020,
38 |
39 | ALL_VALID_FLAGS = 0x0000003e
40 | } WebPFeatureFlags;
41 |
42 | // Dispose method (animation only). Indicates how the area used by the current
43 | // frame is to be treated before rendering the next frame on the canvas.
44 | typedef enum WebPMuxAnimDispose {
45 | WEBP_MUX_DISPOSE_NONE, // Do not dispose.
46 | WEBP_MUX_DISPOSE_BACKGROUND // Dispose to background color.
47 | } WebPMuxAnimDispose;
48 |
49 | // Blend operation (animation only). Indicates how transparent pixels of the
50 | // current frame are blended with those of the previous canvas.
51 | typedef enum WebPMuxAnimBlend {
52 | WEBP_MUX_BLEND, // Blend.
53 | WEBP_MUX_NO_BLEND // Do not blend.
54 | } WebPMuxAnimBlend;
55 |
56 | // Data type used to describe 'raw' data, e.g., chunk data
57 | // (ICC profile, metadata) and WebP compressed image data.
58 | // 'bytes' memory must be allocated using WebPMalloc() and such.
59 | struct WebPData {
60 | const uint8_t* bytes;
61 | size_t size;
62 | };
63 |
64 | // Initializes the contents of the 'webp_data' object with default values.
65 | static WEBP_INLINE void WebPDataInit(WebPData* webp_data) {
66 | if (webp_data != NULL) {
67 | memset(webp_data, 0, sizeof(*webp_data));
68 | }
69 | }
70 |
71 | // Clears the contents of the 'webp_data' object by calling WebPFree().
72 | // Does not deallocate the object itself.
73 | static WEBP_INLINE void WebPDataClear(WebPData* webp_data) {
74 | if (webp_data != NULL) {
75 | WebPFree((void*)webp_data->bytes);
76 | WebPDataInit(webp_data);
77 | }
78 | }
79 |
80 | // Allocates necessary storage for 'dst' and copies the contents of 'src'.
81 | // Returns true on success.
82 | static WEBP_INLINE int WebPDataCopy(const WebPData* src, WebPData* dst) {
83 | if (src == NULL || dst == NULL) return 0;
84 | WebPDataInit(dst);
85 | if (src->bytes != NULL && src->size != 0) {
86 | dst->bytes = (uint8_t*)WebPMalloc(src->size);
87 | if (dst->bytes == NULL) return 0;
88 | memcpy((void*)dst->bytes, src->bytes, src->size);
89 | dst->size = src->size;
90 | }
91 | return 1;
92 | }
93 |
94 | #ifdef __cplusplus
95 | } // extern "C"
96 | #endif
97 |
98 | #endif // WEBP_WEBP_MUX_TYPES_H_
99 |
--------------------------------------------------------------------------------
/__lib__/libwebp-1.1.0-windows-x64/include/webp/types.h:
--------------------------------------------------------------------------------
1 | // Copyright 2010 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Common types + memory wrappers
11 | //
12 | // Author: Skal (pascal.massimino@gmail.com)
13 |
14 | #ifndef WEBP_WEBP_TYPES_H_
15 | #define WEBP_WEBP_TYPES_H_
16 |
17 | #include // for size_t
18 |
19 | #ifndef _MSC_VER
20 | #include
21 | #if defined(__cplusplus) || !defined(__STRICT_ANSI__) || \
22 | (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
23 | #define WEBP_INLINE inline
24 | #else
25 | #define WEBP_INLINE
26 | #endif
27 | #else
28 | typedef signed char int8_t;
29 | typedef unsigned char uint8_t;
30 | typedef signed short int16_t;
31 | typedef unsigned short uint16_t;
32 | typedef signed int int32_t;
33 | typedef unsigned int uint32_t;
34 | typedef unsigned long long int uint64_t;
35 | typedef long long int int64_t;
36 | #define WEBP_INLINE __forceinline
37 | #endif /* _MSC_VER */
38 |
39 | #ifndef WEBP_EXTERN
40 | // This explicitly marks library functions and allows for changing the
41 | // signature for e.g., Windows DLL builds.
42 | # if defined(__GNUC__) && __GNUC__ >= 4
43 | # define WEBP_EXTERN extern __attribute__ ((visibility ("default")))
44 | # else
45 | # define WEBP_EXTERN extern
46 | # endif /* __GNUC__ >= 4 */
47 | #endif /* WEBP_EXTERN */
48 |
49 | // Macro to check ABI compatibility (same major revision number)
50 | #define WEBP_ABI_IS_INCOMPATIBLE(a, b) (((a) >> 8) != ((b) >> 8))
51 |
52 | #ifdef __cplusplus
53 | extern "C" {
54 | #endif
55 |
56 | // Allocates 'size' bytes of memory. Returns NULL upon error. Memory
57 | // must be deallocated by calling WebPFree(). This function is made available
58 | // by the core 'libwebp' library.
59 | WEBP_EXTERN void* WebPMalloc(size_t size);
60 |
61 | // Releases memory returned by the WebPDecode*() functions (from decode.h).
62 | WEBP_EXTERN void WebPFree(void* ptr);
63 |
64 | #ifdef __cplusplus
65 | } // extern "C"
66 | #endif
67 |
68 | #endif // WEBP_WEBP_TYPES_H_
69 |
--------------------------------------------------------------------------------
/__lib__/libwebp-1.1.0-windows-x64/lib/libwebp.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/winseros/WebpPreviewForWindowsExplorer/bb8c1bfab7f3d8075657eb7807258802b3062430/__lib__/libwebp-1.1.0-windows-x64/lib/libwebp.lib
--------------------------------------------------------------------------------
/__lib__/libwebp-1.1.0-windows-x64/lib/libwebpdemux.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/winseros/WebpPreviewForWindowsExplorer/bb8c1bfab7f3d8075657eb7807258802b3062430/__lib__/libwebp-1.1.0-windows-x64/lib/libwebpdemux.lib
--------------------------------------------------------------------------------
/__lib__/libwebp-1.1.0-windows-x64/lib/libwebpmux.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/winseros/WebpPreviewForWindowsExplorer/bb8c1bfab7f3d8075657eb7807258802b3062430/__lib__/libwebp-1.1.0-windows-x64/lib/libwebpmux.lib
--------------------------------------------------------------------------------
/__lib__/libwebp-1.1.0-windows-x64/test.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/winseros/WebpPreviewForWindowsExplorer/bb8c1bfab7f3d8075657eb7807258802b3062430/__lib__/libwebp-1.1.0-windows-x64/test.webp
--------------------------------------------------------------------------------
/__lib__/libwebp-1.1.0-windows-x64/test_ref.ppm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/winseros/WebpPreviewForWindowsExplorer/bb8c1bfab7f3d8075657eb7807258802b3062430/__lib__/libwebp-1.1.0-windows-x64/test_ref.ppm
--------------------------------------------------------------------------------
/docs/preview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/winseros/WebpPreviewForWindowsExplorer/bb8c1bfab7f3d8075657eb7807258802b3062430/docs/preview.png
--------------------------------------------------------------------------------
/src/ClassFactory.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #include "ClassFactory.h"
5 | #include "ThumbnailProvider.h"
6 | #include "dllmain.h"
7 |
8 | namespace webpext
9 | {
10 | ClassFactory::ClassFactory(): ref_count_{1}
11 | {
12 | IncreaseDllRefCount();
13 | }
14 |
15 | ClassFactory::~ClassFactory()
16 | {
17 | DecreaseDllRefCount();
18 | }
19 |
20 | #pragma region IUnknown
21 | HRESULT ClassFactory::QueryInterface(const IID& riid, void** ppvObject)
22 | {
23 | static const QITAB qit[]{QITABENT(ClassFactory, IClassFactory), {0}};
24 | return QISearch(this, qit, riid, ppvObject);
25 | }
26 |
27 | ULONG ClassFactory::AddRef()
28 | {
29 | return InterlockedIncrement(&ref_count_);
30 | }
31 |
32 | ULONG ClassFactory::Release()
33 | {
34 | const ULONG ref = InterlockedDecrement(&ref_count_);
35 | if (ref == 0)
36 | delete this;
37 | return ref;
38 | }
39 | #pragma endregion
40 |
41 | #pragma region IClassFactory
42 | HRESULT ClassFactory::LockServer(BOOL fLock)
43 | {
44 | if (fLock)
45 | IncreaseDllRefCount();
46 | else
47 | DecreaseDllRefCount();
48 | return S_OK;
49 | }
50 |
51 | HRESULT ClassFactory::CreateInstance(IUnknown* pUnkOuter, const IID& riid, void** ppvObject)
52 | {
53 | HRESULT hr = CLASS_E_NOAGGREGATION;
54 | if (pUnkOuter == nullptr)
55 | {
56 | hr = E_OUTOFMEMORY;
57 | auto* thp = new (std::nothrow) ThumbnailProvider();
58 | if (thp != nullptr)
59 | {
60 | hr = thp->QueryInterface(riid, ppvObject);
61 | thp->Release();
62 | }
63 | }
64 | return hr;
65 | }
66 | #pragma endregion
67 | }
68 |
--------------------------------------------------------------------------------
/src/ClassFactory.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | namespace webpext
6 | {
7 | class ClassFactory final : public IClassFactory
8 | {
9 | private:
10 | long ref_count_;
11 | ~ClassFactory();
12 | public:
13 | ClassFactory();
14 | ClassFactory(ClassFactory&) = default;
15 | ClassFactory(ClassFactory&&) = default;
16 | ClassFactory& operator=(ClassFactory const&) = default;
17 | ClassFactory& operator=(ClassFactory&&) = default;
18 |
19 | #pragma region IUnknown
20 | HRESULT STDMETHODCALLTYPE QueryInterface(const IID& riid, void** ppvObject) override;
21 | ULONG STDMETHODCALLTYPE AddRef() override;
22 | ULONG STDMETHODCALLTYPE Release() override;
23 | #pragma endregion
24 |
25 | #pragma region IClassFacotory
26 | HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown* pUnkOuter, const IID& riid, void** ppvObject) override;
27 | HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock) override;
28 | #pragma endregion
29 | };
30 | }
31 |
--------------------------------------------------------------------------------
/src/Registry.cpp:
--------------------------------------------------------------------------------
1 | #include "Registry.h"
2 | #include
3 | #include
4 | #include "dllmain.h"
5 |
6 | namespace webpext
7 | {
8 | HRESULT Registry::registerServer(const string& pathToDll)
9 | {
10 | try
11 | {
12 | registerServerImpl(pathToDll);
13 | SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
14 | return S_OK;
15 | }
16 | catch (const RegistryException& ex)
17 | {
18 | return HRESULT_FROM_WIN32(ex.status());
19 | }
20 | }
21 |
22 | HRESULT Registry::unregisterServer()
23 | {
24 | try
25 | {
26 | unregisterServerImpl();
27 | SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
28 | return S_OK;
29 | }
30 | catch (const RegistryException& ex)
31 | {
32 | return HRESULT_FROM_WIN32(ex.status());
33 | }
34 | }
35 |
36 | void Registry::registerServerImpl(const string& pathToDll)
37 | {
38 | setRegistryKeyValue("Software\\Classes\\.webp\\ShellEx\\{e357fccd-a995-4576-b01f-234630154e96}",
39 | WEBP_SHELL_CLSID);
40 |
41 | setRegistryKeyValue("Software\\Classes\\CLSID\\" WEBP_SHELL_CLSID,
42 | WEBP_PROJECT_NAME);
43 | setRegistryKeyValue("Software\\Classes\\CLSID\\" WEBP_SHELL_CLSID "\\InprocServer32",
44 | pathToDll);
45 | setRegistryKeyValue("Software\\Classes\\CLSID\\" WEBP_SHELL_CLSID "\\InprocServer32",
46 | "Apartment",
47 | "ThreadingModel");
48 | }
49 |
50 | void Registry::unregisterServerImpl()
51 | {
52 | removeRegistryKey("Software\\Classes\\CLSID\\" WEBP_SHELL_CLSID);
53 | }
54 |
55 | #define HKEY_CLASS HKEY_CURRENT_USER
56 |
57 | void Registry::setRegistryKeyValue(const string& key, const string& value, const string& name)
58 | {
59 | HKEY reg;
60 | LSTATUS ls = RegCreateKeyEx(HKEY_CLASS,
61 | key.data(),
62 | 0,
63 | NULL,
64 | REG_OPTION_NON_VOLATILE,
65 | KEY_SET_VALUE | KEY_WOW64_64KEY,
66 | NULL,
67 | ®,
68 | NULL);
69 |
70 | if (ls != ERROR_SUCCESS)
71 | throw RegistryException::fromLStatus(key, ls);
72 |
73 | ls = RegSetKeyValue(reg, NULL, name.empty() ? NULL : name.data(), REG_SZ, value.data(),
74 | static_cast(value.length()));
75 | RegCloseKey(reg);
76 |
77 | if (ls != ERROR_SUCCESS)
78 | throw RegistryException::fromLStatus(key, ls);
79 | }
80 |
81 | void Registry::removeRegistryKey(const string& key)
82 | {
83 | const LSTATUS ls = RegDeleteTree(HKEY_CLASS, key.data());
84 |
85 | if (ls != ERROR_SUCCESS)
86 | throw RegistryException::fromLStatus(key, ls);
87 | }
88 |
89 | Registry::RegistryException Registry::RegistryException::fromLStatus(const string& registryKey, LSTATUS status)
90 | {
91 | const string systemError = getSystemMessage(status);
92 | return {registryKey, systemError, status};
93 | }
94 |
95 | Registry::RegistryException::
96 | RegistryException(string registryKey, const string& systemError, LSTATUS status)
97 | : exception(systemError.data()),
98 | registryKey_(std::move(registryKey)),
99 | status_(status)
100 | {
101 | }
102 |
103 | LSTATUS Registry::RegistryException::status() const
104 | {
105 | return status_;
106 | }
107 |
108 | const string& Registry::RegistryException::registryKey() const
109 | {
110 | return registryKey_;
111 | }
112 |
113 | string Registry::RegistryException::getSystemMessage(LSTATUS status)
114 | {
115 | TCHAR buffer[2048];
116 | const DWORD size = sizeof buffer / sizeof TCHAR;
117 |
118 | const DWORD number = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
119 | NULL,
120 | status,
121 | LANG_USER_DEFAULT,
122 | buffer,
123 | size,
124 | NULL);
125 | return {buffer, number};
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/src/Registry.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 | namespace webpext
7 | {
8 | using namespace std;
9 |
10 | class Registry {
11 | public:
12 | static HRESULT registerServer(const string& pathToDll);
13 |
14 | static HRESULT unregisterServer();
15 |
16 | private:
17 | static void registerServerImpl(const string& pathToDll);
18 |
19 | static void unregisterServerImpl();
20 |
21 | static void setRegistryKeyValue(const string& key, const string& value, const string& name = "");
22 |
23 | static void removeRegistryKey(const string& key);
24 |
25 | class RegistryException : public exception {
26 | public:
27 | static RegistryException fromLStatus(const string& registryKey, LSTATUS status);
28 |
29 | RegistryException(string registryKey, const string& systemError, LSTATUS status);
30 |
31 | LSTATUS status() const;
32 |
33 | const string& registryKey() const;
34 |
35 | private:
36 | string registryKey_;
37 | LSTATUS status_;
38 |
39 | static string getSystemMessage(LSTATUS status);
40 | };
41 | };
42 | }
43 |
--------------------------------------------------------------------------------
/src/ThumbnailProvider.cpp:
--------------------------------------------------------------------------------
1 | #include "ThumbnailProvider.h"
2 | #include
3 | #include
4 | #include
5 | #include "WebpReader.h"
6 |
7 | namespace webpext
8 | {
9 | using namespace std;
10 |
11 | ThumbnailProvider::ThumbnailProvider() :
12 | ref_count_{1},
13 | stream_{nullptr}
14 | {
15 | }
16 |
17 | ThumbnailProvider::~ThumbnailProvider()
18 | {
19 | if (stream_)
20 | stream_->Release();
21 | }
22 |
23 | #pragma region IUnknown
24 |
25 | HRESULT ThumbnailProvider::QueryInterface(const IID& riid, void** ppvObject)
26 | {
27 | static const QITAB qit[]{
28 | QITABENT(ThumbnailProvider, IInitializeWithStream),
29 | QITABENT(ThumbnailProvider, IThumbnailProvider),
30 | {0}
31 | };
32 | return QISearch(this, qit, riid, ppvObject);
33 | }
34 |
35 | ULONG ThumbnailProvider::AddRef()
36 | {
37 | return InterlockedIncrement(&ref_count_);
38 | }
39 |
40 | ULONG ThumbnailProvider::Release()
41 | {
42 | const long ref = InterlockedDecrement(&ref_count_);
43 | if (ref == 0)
44 | delete this;
45 | return ref;
46 | }
47 |
48 | #pragma endregion
49 |
50 | #pragma region IThumbnailProvider
51 |
52 | HRESULT ThumbnailProvider::GetThumbnail(UINT cx, HBITMAP* phbmp, WTS_ALPHATYPE* pdwAlpha)
53 | {
54 | STATSTG stat;
55 | HRESULT hr = stream_->Stat(&stat, STATFLAG::STATFLAG_NONAME);
56 | if (SUCCEEDED(hr))
57 | {
58 | const unique_ptr data = make_unique(stat.cbSize.QuadPart);
59 | ULONG bytes_read;
60 | hr = stream_->Read(data.get(), static_cast(stat.cbSize.QuadPart), &bytes_read);
61 | if (SUCCEEDED(hr))
62 | {
63 | const WebpReader reader;
64 | INT webp_width, webp_height;
65 | BOOLEAN webp_alpha;
66 | hr = reader.ReadWebpHeader(data.get(), bytes_read, &webp_width, &webp_height, &webp_alpha);
67 |
68 | INT scaled_width, scaled_height;
69 | CalcScaledBmpSize(webp_width, webp_height, cx, &scaled_width, &scaled_height);
70 |
71 | if (SUCCEEDED(hr))
72 | {
73 | BITMAPINFO bmi;
74 | bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
75 | bmi.bmiHeader.biHeight = -scaled_height;
76 | bmi.bmiHeader.biWidth = scaled_width;
77 | bmi.bmiHeader.biPlanes = 1;
78 | bmi.bmiHeader.biBitCount = 32;
79 | bmi.bmiHeader.biCompression = BI_RGB;
80 | *pdwAlpha = webp_alpha ? WTSAT_ARGB : WTSAT_RGB;
81 |
82 | TBYTE* bytes;
83 | HBITMAP bmp = CreateDIBSection(nullptr, &bmi, DIB_RGB_COLORS,
84 | reinterpret_cast(&bytes),
85 | nullptr, 0);
86 |
87 | hr = bmp ? S_OK : E_OUTOFMEMORY;
88 | if (SUCCEEDED(hr))
89 | {
90 | WebpReadInfo ri
91 | {
92 | data.get(),
93 | bytes_read,
94 | scaled_width,
95 | scaled_height,
96 | bytes
97 | };
98 |
99 | hr = reader.ReadAsBitmap(&ri);
100 | if (SUCCEEDED(hr))
101 | {
102 | *phbmp = bmp;
103 | }
104 | }
105 | }
106 | }
107 | }
108 |
109 | return hr;
110 | }
111 |
112 | void ThumbnailProvider::CalcScaledBmpSize(const INT webp_width, const INT webp_height,
113 | const INT cx, INT* scaled_width, INT* scaled_height) const
114 | {
115 | if (webp_width > cx || webp_height > cx)
116 | {
117 | if (webp_width > webp_height)
118 | {
119 | const double ratio = 1.0 * cx / webp_width;
120 | *scaled_width = cx;
121 | *scaled_height = static_cast(round(ratio * webp_height));
122 | }
123 | else if (webp_height > webp_width)
124 | {
125 | const double ratio = 1.0 * cx / webp_height;
126 | *scaled_width = static_cast(round(ratio * webp_width));
127 | *scaled_height = cx;
128 | }
129 | else
130 | {
131 | *scaled_width = cx;
132 | *scaled_height = cx;
133 | }
134 | }
135 | else
136 | {
137 | *scaled_width = webp_width;
138 | *scaled_height = webp_height;
139 | }
140 | }
141 |
142 | #pragma endregion
143 |
144 | #pragma region IInitializeWithStream
145 |
146 | HRESULT ThumbnailProvider::Initialize(IStream* pstream, DWORD grfMode)
147 | {
148 | HRESULT hr = E_UNEXPECTED;
149 | if (!stream_)
150 | hr = pstream->QueryInterface(&stream_);
151 | return hr;
152 | }
153 |
154 | #pragma endregion
155 | }
156 |
--------------------------------------------------------------------------------
/src/ThumbnailProvider.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 | namespace webpext
7 | {
8 | class ThumbnailProvider final : public IThumbnailProvider, IInitializeWithStream
9 | {
10 | private:
11 | long ref_count_;
12 | IStream* stream_;
13 | ~ThumbnailProvider();
14 | public:
15 | ThumbnailProvider();
16 | #pragma region IUnknown
17 | HRESULT STDMETHODCALLTYPE QueryInterface(const IID& riid, void** ppvObject) override;
18 | ULONG STDMETHODCALLTYPE AddRef() override;
19 | ULONG STDMETHODCALLTYPE Release() override;
20 | #pragma endregion
21 | #pragma region IThumbnailProvider
22 | HRESULT STDMETHODCALLTYPE GetThumbnail(UINT cx, HBITMAP* phbmp, WTS_ALPHATYPE* pdwAlpha) override;
23 | void CalcScaledBmpSize(const INT webp_width, const INT webp_height, const INT cx,
24 | INT* scaled_width,
25 | INT* scaled_height) const;
26 | #pragma endregion
27 | #pragma region IInitializeWithStream
28 | HRESULT Initialize(IStream* pstream, DWORD grfMode) override;
29 | #pragma endregion
30 | };
31 | }
32 |
--------------------------------------------------------------------------------
/src/WebpReader.cpp:
--------------------------------------------------------------------------------
1 | #include "WebpReader.h"
2 | #include
3 | #include
4 |
5 | namespace webpext
6 | {
7 | HRESULT WebpReader::ReadWebpHeader(TBYTE* webp_data, LONG webp_data_size, INT* webp_width, INT* webp_height,
8 | BOOLEAN* webp_alpha) const
9 | {
10 | WebPBitstreamFeatures features;
11 | if (WebPGetFeatures(webp_data, webp_data_size, &features) != VP8_STATUS_OK)
12 | return E_FAIL;
13 |
14 | *webp_width = features.width;
15 | *webp_height = features.height;
16 | *webp_alpha = features.has_alpha == TRUE;
17 |
18 | return S_OK;
19 | }
20 |
21 | HRESULT WebpReader::ReadAsBitmap(WebpReadInfo* webp_read_info) const
22 | {
23 | INT webp_width, webp_height;
24 | WebPGetInfo(webp_read_info->webp_data, webp_read_info->webp_data_size, &webp_width, &webp_height);
25 |
26 | WebPDecoderConfig config;
27 | if (!WebPInitDecoderConfig(&config))
28 | return E_FAIL;
29 |
30 | config.output.colorspace = MODE_BGRA;
31 | if (webp_width > webp_read_info->scaled_width || webp_height > webp_read_info->scaled_height)
32 | {
33 | config.options.use_scaling = 1;
34 | config.options.scaled_width = webp_read_info->scaled_width;
35 | config.options.scaled_height = webp_read_info->scaled_height;
36 | }
37 |
38 | if (WebPDecode(webp_read_info->webp_data, webp_read_info->webp_data_size, &config) != VP8_STATUS_OK)
39 | {
40 | WebPFreeDecBuffer(&config.output);
41 | return E_FAIL;
42 | }
43 |
44 | memcpy(webp_read_info->bmp_data, config.output.u.RGBA.rgba, config.output.u.RGBA.size);
45 | WebPFreeDecBuffer(&config.output);
46 |
47 | return S_OK;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/WebpReader.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | namespace webpext
6 | {
7 | struct WebpReadInfo
8 | {
9 | const TBYTE* webp_data;
10 | const ULONG webp_data_size;
11 | const INT scaled_width;
12 | const INT scaled_height;
13 | TBYTE* bmp_data;
14 | };
15 |
16 | class WebpReader
17 | {
18 | public:
19 | HRESULT ReadWebpHeader(TBYTE* webp_data, LONG webp_data_size, INT* webp_width, INT* webp_height, BOOLEAN* webp_alpha) const;
20 |
21 | HRESULT ReadAsBitmap(WebpReadInfo* webp_read_info) const;
22 | };
23 | }
24 |
--------------------------------------------------------------------------------
/src/dllmain.cpp:
--------------------------------------------------------------------------------
1 | #include "dllmain.h"
2 | #include
3 | #include
4 | #include
5 | #include "ClassFactory.h"
6 | #include "Registry.h"
7 |
8 | namespace webpext
9 | {
10 | long g_dllRefCount = 0;
11 |
12 | void IncreaseDllRefCount()
13 | {
14 | InterlockedIncrement(&g_dllRefCount);
15 | }
16 |
17 | void DecreaseDllRefCount()
18 | {
19 | InterlockedDecrement(&g_dllRefCount);
20 | }
21 | }
22 |
23 | HINSTANCE g_hInstDll = nullptr;
24 |
25 | STDAPI DllMain(
26 | HINSTANCE hInstDll,
27 | DWORD fdwReason,
28 | LPVOID lpReserved)
29 | {
30 | switch (fdwReason)
31 | {
32 | case DLL_PROCESS_ATTACH:
33 | g_hInstDll = hInstDll;
34 | DisableThreadLibraryCalls(hInstDll);
35 | break;
36 | case DLL_PROCESS_DETACH:
37 | g_hInstDll = nullptr;
38 | break;
39 | }
40 | return TRUE;
41 | }
42 |
43 | using namespace webpext;
44 |
45 | STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void** ppv)
46 | {
47 | HRESULT hr = CLASS_E_CLASSNOTAVAILABLE;
48 | if (IsEqualCLSID(CLSID_WebpThumbProvider, rclsid))
49 | {
50 | hr = E_OUTOFMEMORY;
51 | auto* pClassFactory = new(std::nothrow) ClassFactory();
52 | if (pClassFactory)
53 | {
54 | hr = pClassFactory->QueryInterface(riid, ppv);
55 | pClassFactory->Release();
56 | }
57 | }
58 |
59 | return hr;
60 | }
61 |
62 | STDAPI DllCanUnloadNow()
63 | {
64 | return g_dllRefCount > 0 ? S_FALSE : S_OK;
65 | }
66 |
67 | STDAPI DllRegisterServer() {
68 | using namespace std::filesystem;
69 |
70 | HRESULT hr;
71 |
72 | TCHAR buf[MAX_PATH];
73 | if (GetModuleFileName(g_hInstDll, buf, MAX_PATH)) {
74 | const path dllPath(buf);
75 | hr = Registry::registerServer(dllPath.string());
76 | } else {
77 | hr = HRESULT_FROM_WIN32(GetLastError());
78 | }
79 |
80 | return hr;
81 | }
82 |
83 | STDAPI DllUnregisterServer() {
84 | return Registry::unregisterServer();
85 | }
86 |
--------------------------------------------------------------------------------
/src/dllmain.def:
--------------------------------------------------------------------------------
1 | EXPORTS
2 | DllGetClassObject PRIVATE
3 | DllCanUnloadNow PRIVATE
4 | DllRegisterServer PRIVATE
5 | DllUnregisterServer PRIVATE
6 | DllMain PRIVATE
7 |
--------------------------------------------------------------------------------
/src/dllmain.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | namespace webpext
6 | {
7 | extern void IncreaseDllRefCount();
8 |
9 | extern void DecreaseDllRefCount();
10 | }
11 |
12 |
13 | #define WEBP_SHELL_CLSID "{C39D7E2A-FC3C-4DEE-BE80-380065FC2C2A}"
14 | #define WEBP_PROJECT_NAME "Webp Thumbnail Provider"
15 |
16 | static constexpr GUID CLSID_WebpThumbProvider =
17 | {0xc39d7e2a, 0xfc3c, 0x4dee, {0xbe, 0x80, 0x38, 0x0, 0x65, 0xfc, 0x2c, 0x2a}};
18 |
--------------------------------------------------------------------------------