Skip to content
This repository was archived by the owner on Oct 31, 2022. It is now read-only.

Commit b4412a6

Browse files
committed
Windows multithreaded decode
1 parent 6b453e2 commit b4412a6

File tree

5 files changed

+103
-25
lines changed

5 files changed

+103
-25
lines changed

Hap Codec Windows/Hap Codec.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ attrib -R "$(TargetDir)$(TargetName).qtx"
121121
<ClCompile Include="..\source\HapCompressor.c" />
122122
<ClCompile Include="..\source\HapDecompressor.c" />
123123
<ClCompile Include="..\source\ImageMath.c" />
124+
<ClCompile Include="..\source\ParallelLoops.cpp" />
124125
<ClCompile Include="..\source\PixelFormats.c" />
125126
<ClCompile Include="..\source\squish-c.cpp" />
126127
<ClCompile Include="..\source\SquishDecoder.c" />
@@ -149,6 +150,7 @@ attrib -R "$(TargetDir)$(TargetName).qtx"
149150
<ClInclude Include="..\source\HapPlatform.h" />
150151
<ClInclude Include="..\source\HapResCommon.h" />
151152
<ClInclude Include="..\source\ImageMath.h" />
153+
<ClInclude Include="..\source\ParallelLoops.h" />
152154
<ClInclude Include="..\source\PixelFormats.h" />
153155
<ClInclude Include="..\source\squish-c.h" />
154156
<ClInclude Include="..\source\SquishDecoder.h" />

Hap Codec Windows/Hap Codec.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@
7777
<ClCompile Include="..\source\DXTBlocksSSSE3.c">
7878
<Filter>DXT</Filter>
7979
</ClCompile>
80+
<ClCompile Include="..\source\ParallelLoops.cpp">
81+
<Filter>Basics</Filter>
82+
</ClCompile>
8083
</ItemGroup>
8184
<ItemGroup>
8285
<ClInclude Include="..\source\HapResCommon.h">
@@ -142,6 +145,9 @@
142145
<ClInclude Include="..\source\DXTBlocks.h">
143146
<Filter>DXT</Filter>
144147
</ClInclude>
148+
<ClInclude Include="..\source\ParallelLoops.h">
149+
<Filter>Basics</Filter>
150+
</ClInclude>
145151
</ItemGroup>
146152
<ItemGroup>
147153
<None Include="..\source\HapAlphaComponent.r">

source/HapDecompressor.c

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "HapCodecSubTypes.h"
4242
#include "hap.h"
4343
#include "Buffers.h"
44+
#include "ParallelLoops.h"
4445
#include "YCoCg.h"
4546
#include "YCoCgDXT.h"
4647

@@ -137,32 +138,9 @@ typedef struct {
137138
Callback for multithreaded Hap decoding
138139
*/
139140

140-
void HapMTDecode(HapDecodeWorkFunction function, void *p, unsigned int count, HapDecompressorGlobals info)
141+
void HapMTDecode(HapDecodeWorkFunction function, void *p, unsigned int count, void *info)
141142
{
142-
#if defined(__APPLE__)
143-
if (info->hapDecodeQueue == NULL)
144-
{
145-
if (dispatch_barrier_async == NULL) // ie before OS 10.7
146-
{
147-
info->hapDecodeQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
148-
}
149-
else
150-
{
151-
info->hapDecodeQueue = dispatch_queue_create("com.vidvox.hap-codec.decode", DISPATCH_QUEUE_CONCURRENT);
152-
}
153-
}
154-
dispatch_apply(count, info->hapDecodeQueue, ^(size_t index) {
155-
function(p, (unsigned int)index);
156-
});
157-
#else
158-
{
159-
// TODO: Windows multithreading
160-
int i;
161-
for (i = 0; i < (int)count; i++) {
162-
function(p, i);
163-
}
164-
}
165-
#endif
143+
HapParallelFor((HapParallelFunction)function, p, count);
166144
}
167145

168146
/* -- This Image Decompressor User the Base Image Decompressor Component --

source/ParallelLoops.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
ParallelLoops.cpp
3+
Hap Codec
4+
5+
Copyright (c) 2012-2014, Tom Butterworth and Vidvox LLC. All rights reserved.
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
12+
* Redistributions in binary form must reproduce the above copyright
13+
notice, this list of conditions and the following disclaimer in the
14+
documentation and/or other materials provided with the distribution.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
*/
27+
28+
#include "ParallelLoops.h"
29+
#if defined(__APPLE__)
30+
#else
31+
#include <ppl.h>
32+
#endif
33+
34+
35+
extern "C" void HapParallelFor(HapParallelFunction function, void *info, unsigned int count)
36+
{
37+
#if defined(__APPLE__)
38+
dispatch_apply(count, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(size_t index) {
39+
function(p, (unsigned int)index);
40+
});
41+
#else
42+
concurrency::parallel_for((unsigned int)0, count, [&](unsigned int i) {
43+
function(info, i);
44+
});
45+
#endif
46+
}

source/ParallelLoops.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
ParallelLoops.h
3+
Hap Codec
4+
5+
Copyright (c) 2012-2014, Tom Butterworth and Vidvox LLC. All rights reserved.
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
12+
* Redistributions in binary form must reproduce the above copyright
13+
notice, this list of conditions and the following disclaimer in the
14+
documentation and/or other materials provided with the distribution.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
*/
27+
28+
/*
29+
Platform code for parallel loops.
30+
*/
31+
32+
#ifndef HapParallelFor_h
33+
#define HapParallelFor_h
34+
35+
#ifdef __cplusplus
36+
extern "C" {
37+
#endif
38+
39+
typedef void (*HapParallelFunction)(void *p, unsigned int index);
40+
41+
void HapParallelFor(HapParallelFunction function, void *info, unsigned int count);
42+
43+
#ifdef __cplusplus
44+
}
45+
#endif
46+
#endif

0 commit comments

Comments
 (0)