1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 02:32:36 +01:00

Rewrite cellPngDec to use libpng

Improvements made:
* Supports tEXt chunks
* Supports chunk information
* Supports 16-bit depth image packing (fixes #1127)
* Supports fixed alpha values
* And more.
This commit is contained in:
Raul Tambre 2016-01-19 21:24:41 +02:00
parent 303a109286
commit 0c8c13b8b7
12 changed files with 866 additions and 440 deletions

3
.gitmodules vendored
View File

@ -22,3 +22,6 @@
[submodule "GSL"]
path = GSL
url = https://github.com/Microsoft/GSL.git
[submodule "libpng"]
path = libpng
url = https://github.com/RPCS3/libpng

View File

@ -53,7 +53,7 @@ before_install:
fi;
before_script:
- git submodule update --init asmjit ffmpeg rsx_program_decompiler GSL
- git submodule update --init asmjit ffmpeg rsx_program_decompiler GSL libpng
- mkdir build
- cd build
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then cmake ..; else cmake .. -DLLVM_DIR=/usr/local/opt/llvm36/lib/llvm-3.6/share/llvm/cmake; fi

View File

@ -12,6 +12,7 @@ if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
endif()
add_subdirectory( asmjit )
add_subdirectory( libpng )
# TODO: do real installation, including copying directory structure
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${PROJECT_BINARY_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${PROJECT_BINARY_DIR}/bin")

View File

@ -14,7 +14,7 @@ branches:
before_build:
# until git for win 2.5 release with commit checkout
- git submodule update --init ffmpeg asmjit minidx9 rsx_program_decompiler GSL
- git submodule update --init ffmpeg asmjit minidx9 rsx_program_decompiler GSL libpng
- 7z x wxWidgets.7z -aos -oC:\rpcs3\wxWidgets > null
- if %configuration%==Release (cmake -G "Visual Studio 14 Win64")
else (7z x llvmlibs.7z -aos -oC:\rpcs3 > null && cmake -G "Visual Studio 14 Win64" -DLLVM_DIR=C:/rpcs3/llvm_build/share/llvm/cmake)

1
libpng Submodule

@ -0,0 +1 @@
Subproject commit ea77a6fd4983e6c2ab4ef1dee7c819188c2f4f3e

View File

@ -17,6 +17,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rpcs3", "rpcs3\rpcs3.vcxpro
{97FDAB45-9C58-5BC5-A2F4-EE42739EBC63} = {97FDAB45-9C58-5BC5-A2F4-EE42739EBC63}
{A1A8355B-0988-528E-9CC2-B971D6266669} = {A1A8355B-0988-528E-9CC2-B971D6266669}
{09F2F96A-1CC6-5E43-AF1D-956EC2A4888D} = {09F2F96A-1CC6-5E43-AF1D-956EC2A4888D}
{D6973076-9317-4EF2-A0B8-B7A18AC0713E} = {D6973076-9317-4EF2-A0B8-B7A18AC0713E}
{8B867186-A0B5-5479-B824-E176EDD27C40} = {8B867186-A0B5-5479-B824-E176EDD27C40}
{87B42A9C-3F5C-53D7-9017-2B1CAE39457D} = {87B42A9C-3F5C-53D7-9017-2B1CAE39457D}
{8BC303AB-25BE-4276-8E57-73F171B2D672} = {8BC303AB-25BE-4276-8E57-73F171B2D672}
@ -197,6 +198,17 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XAudio", "rpcs3\XAudio.vcxp
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OpenAL", "rpcs3\OpenAL.vcxproj", "{30A05C4D-F5FD-421C-A864-17A64BDEAA75}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libpng", "libpng", "{A17D34F1-7E3E-4841-818D-3B7C6F5AF829}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpng", "libpng\projects\vstudio\libpng\libpng.vcxproj", "{D6973076-9317-4EF2-A0B8-B7A18AC0713E}"
ProjectSection(ProjectDependencies) = postProject
{60F89955-91C6-3A36-8000-13C592FEC2DF} = {60F89955-91C6-3A36-8000-13C592FEC2DF}
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "zlib", "zlib", "{F0C19EFA-EDD0-43F2-97C1-18E865E96B4E}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "libpng\projects\vstudio\zlib\zlib.vcxproj", "{60F89955-91C6-3A36-8000-13C592FEC2DF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug - LLVM|x64 = Debug - LLVM|x64
@ -693,6 +705,34 @@ Global
{30A05C4D-F5FD-421C-A864-17A64BDEAA75}.Release - LLVM|x64.Build.0 = Release - LLVM|x64
{30A05C4D-F5FD-421C-A864-17A64BDEAA75}.Release|x64.ActiveCfg = Release|x64
{30A05C4D-F5FD-421C-A864-17A64BDEAA75}.Release|x64.Build.0 = Release|x64
{D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Debug - LLVM|x64.ActiveCfg = Debug Library|x64
{D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Debug - LLVM|x64.Build.0 = Debug Library|x64
{D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Debug - MemLeak|x64.ActiveCfg = Debug Library|x64
{D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Debug - MemLeak|x64.Build.0 = Debug Library|x64
{D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Debug|x64.ActiveCfg = Debug|x64
{D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Debug|x64.Build.0 = Debug|x64
{D6973076-9317-4EF2-A0B8-B7A18AC0713E}.DLL Debug|x64.ActiveCfg = Debug|x64
{D6973076-9317-4EF2-A0B8-B7A18AC0713E}.DLL Debug|x64.Build.0 = Debug|x64
{D6973076-9317-4EF2-A0B8-B7A18AC0713E}.DLL Release|x64.ActiveCfg = Release|x64
{D6973076-9317-4EF2-A0B8-B7A18AC0713E}.DLL Release|x64.Build.0 = Release|x64
{D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Release - LLVM|x64.ActiveCfg = Release Library|x64
{D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Release - LLVM|x64.Build.0 = Release Library|x64
{D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Release|x64.ActiveCfg = Release|x64
{D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Release|x64.Build.0 = Release|x64
{60F89955-91C6-3A36-8000-13C592FEC2DF}.Debug - LLVM|x64.ActiveCfg = Debug Library|x64
{60F89955-91C6-3A36-8000-13C592FEC2DF}.Debug - LLVM|x64.Build.0 = Debug Library|x64
{60F89955-91C6-3A36-8000-13C592FEC2DF}.Debug - MemLeak|x64.ActiveCfg = Debug Library|x64
{60F89955-91C6-3A36-8000-13C592FEC2DF}.Debug - MemLeak|x64.Build.0 = Debug Library|x64
{60F89955-91C6-3A36-8000-13C592FEC2DF}.Debug|x64.ActiveCfg = Debug Library|x64
{60F89955-91C6-3A36-8000-13C592FEC2DF}.Debug|x64.Build.0 = Debug Library|x64
{60F89955-91C6-3A36-8000-13C592FEC2DF}.DLL Debug|x64.ActiveCfg = Debug Library|x64
{60F89955-91C6-3A36-8000-13C592FEC2DF}.DLL Debug|x64.Build.0 = Debug Library|x64
{60F89955-91C6-3A36-8000-13C592FEC2DF}.DLL Release|x64.ActiveCfg = Release Library|x64
{60F89955-91C6-3A36-8000-13C592FEC2DF}.DLL Release|x64.Build.0 = Release Library|x64
{60F89955-91C6-3A36-8000-13C592FEC2DF}.Release - LLVM|x64.ActiveCfg = Release Library|x64
{60F89955-91C6-3A36-8000-13C592FEC2DF}.Release - LLVM|x64.Build.0 = Release Library|x64
{60F89955-91C6-3A36-8000-13C592FEC2DF}.Release|x64.ActiveCfg = Release Library|x64
{60F89955-91C6-3A36-8000-13C592FEC2DF}.Release|x64.Build.0 = Release Library|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -730,5 +770,7 @@ Global
{7D73447B-3D2D-4DFE-BF62-57E644C1D09F} = {10FBF193-D532-4CCF-B875-4C7091A7F6C2}
{78CB2F39-B809-4A06-8329-8C0A19119D3D} = {10FBF193-D532-4CCF-B875-4C7091A7F6C2}
{30A05C4D-F5FD-421C-A864-17A64BDEAA75} = {10FBF193-D532-4CCF-B875-4C7091A7F6C2}
{D6973076-9317-4EF2-A0B8-B7A18AC0713E} = {A17D34F1-7E3E-4841-818D-3B7C6F5AF829}
{60F89955-91C6-3A36-8000-13C592FEC2DF} = {F0C19EFA-EDD0-43F2-97C1-18E865E96B4E}
EndGlobalSection
EndGlobal

View File

@ -88,6 +88,7 @@ if(NOT MSVC)
endif()
find_package(OpenGL REQUIRED)
find_package(OpenAL REQUIRED)
find_package(PNG REQUIRED)
find_package(LLVM CONFIG)
include("${wxWidgets_USE_FILE}")
@ -104,6 +105,7 @@ include_directories(
${GLEW_INCLUDE_DIR}
${wxWidgets_INCLUDE_DIRS}
${OPENAL_INCLUDE_DIR}
${PNG_INCLUDE_DIRS}
${LLVM_INCLUDE_DIRS}
"${RPCS3_SRC_DIR}/../ffmpeg/${PLATFORM_ARCH}/include"
"${RPCS3_SRC_DIR}"
@ -181,17 +183,17 @@ if(WIN32) # I'm not sure we need all of these libs, but we link them in vs
target_link_libraries(rpcs3 ${LLVM_LIBS})
endif()
if(NOT MSVC)
target_link_libraries(rpcs3 ${OPENGL_LIBRARIES} ${GLEW_LIBRARY} opengl32.lib glu32.lib)
target_link_libraries(rpcs3 ${OPENGL_LIBRARIES} ${PNG_LIBRARIES} ${GLEW_LIBRARY} opengl32.lib glu32.lib)
else()
target_link_libraries(rpcs3 dxgi.lib d2d1.lib dwrite.lib)
endif()
target_link_libraries(rpcs3 asmjit.lib avformat.lib avcodec.lib avutil.lib swresample.lib swscale.lib ${wxWidgets_LIBRARIES} ${OPENAL_LIBRARY} ${ADDITIONAL_LIBS})
else()
if(LLVM_FOUND)
target_link_libraries(rpcs3 asmjit.a ${wxWidgets_LIBRARIES} ${OPENAL_LIBRARY} ${GLEW_LIBRARY} ${OPENGL_LIBRARIES})
target_link_libraries(rpcs3 asmjit.a ${wxWidgets_LIBRARIES} ${OPENAL_LIBRARY} ${GLEW_LIBRARY} ${OPENGL_LIBRARIES} ${PNG_LIBRARIES})
target_link_libraries(rpcs3 libavformat.a libavcodec.a libavutil.a libswresample.a libswscale.a ${ZLIB_LIBRARIES} ${LLVM_LIBS} ${ADDITIONAL_LIBS})
else()
target_link_libraries(rpcs3 asmjit.a ${wxWidgets_LIBRARIES} ${OPENAL_LIBRARY} ${GLEW_LIBRARY} ${OPENGL_LIBRARIES})
target_link_libraries(rpcs3 asmjit.a ${wxWidgets_LIBRARIES} ${OPENAL_LIBRARY} ${GLEW_LIBRARY} ${OPENGL_LIBRARIES} ${PNG_LIBRARIES})
target_link_libraries(rpcs3 libavformat.a libavcodec.a libavutil.a libswresample.a libswscale.a ${ZLIB_LIBRARIES} ${ADDITIONAL_LIBS})
endif()
endif()

View File

@ -9,6 +9,13 @@ enum CellPngTxtType : s32
CELL_PNG_ITXT = 2,
};
enum CellPngUnknownLocation : s32
{
CELL_PNG_BEFORE_PLTE = 1,
CELL_PNG_BEFORE_IDAT = 2,
CELL_PNG_AFTER_IDAT = 8,
};
struct CellPngPLTEentry
{
u8 red;
@ -33,13 +40,6 @@ struct CellPngSPLTentry
be_t<u32> paletteEntriesNumber;
};
enum CellPngUnknownLocation : s32
{
CELL_PNG_BEFORE_PLTE = 1,
CELL_PNG_BEFORE_IDAT = 2,
CELL_PNG_AFTER_IDAT = 8,
};
struct CellPngTextInfo
{
be_t<s32> txtType; // CellPngTxtType

File diff suppressed because it is too large Load Diff

View File

@ -83,9 +83,20 @@ enum CellPngDecDecodeStatus : s32
CELL_PNGDEC_DEC_STATUS_STOP = 1,
};
enum CellPngDecBufferMode : s32
{
CELL_PNGDEC_LINE_MODE = 1,
};
enum CellPngDecSpuMode : s32
{
CELL_PNGDEC_RECEIVE_EVENT = 0,
CELL_PNGDEC_TRYRECEIVE_EVENT = 1,
};
// Callbacks for memory management
using CellPngDecCbControlMalloc = vm::ptr<void>(u32 size, vm::ptr<void> cbCtrlMallocArg);
using CellPngDecCbControlFree = s32(vm::ptr<void> ptr, vm::ptr<void> cbCtrlFreeArg);
using CellPngDecCbControlFree = s32(vm::ptr<void> ptr, vm::ptr<void> cbCtrlFreeArg);
// Structs
struct CellPngDecThreadInParam
@ -179,18 +190,6 @@ struct CellPngDecDataOutInfo
be_t<s32> status; // CellPngDecDecodeStatus
};
// Defines for decoding partial streams
enum CellPngDecBufferMode : s32
{
CELL_PNGDEC_LINE_MODE = 1,
};
enum CellPngDecSpuMode : s32
{
CELL_PNGDEC_RECEIVE_EVENT = 0,
CELL_PNGDEC_TRYRECEIVE_EVENT = 1,
};
// Structs for decoding partial streams
struct CellPngDecStrmInfo
{
@ -248,7 +247,7 @@ struct CellPngDecExtOutParam
// Callbacks for decoding partial streams
using CellPngDecCbControlStream = s32(vm::ptr<CellPngDecStrmInfo> strmInfo, vm::ptr<CellPngDecStrmParam> strmParam, vm::ptr<void> cbCtrlStrmArg);
using CellPngDecCbControlDisp = s32(vm::ptr<CellPngDecDispInfo> dispInfo, vm::ptr<CellPngDecDispParam> dispParam, vm::ptr<void> cbCtrlDispArg);
using CellPngDecCbControlDisp = s32(vm::ptr<CellPngDecDispInfo> dispInfo, vm::ptr<CellPngDecDispParam> dispParam, vm::ptr<void> cbCtrlDispArg);
struct CellPngDecCbCtrlStrm
{
@ -263,7 +262,7 @@ struct CellPngDecCbCtrlDisp
};
// Custom structs
struct PngDecoder
struct PngHandle
{
vm::ptr<CellPngDecCbControlMalloc> malloc;
vm::ptr<void> malloc_arg;
@ -271,17 +270,53 @@ struct PngDecoder
vm::ptr<void> free_arg;
};
// For reading from a buffer using libpng
struct PngBuffer
{
// The cursor location and data pointer for reading from a buffer
size_t cursor;
size_t length;
vm::bptr<void> data;
// The file descriptor, and whether we need to read from a file descriptor
bool file;
u32 fd;
};
struct PngStream
{
vm::ptr<PngDecoder> dec;
// old data:
u32 fd;
u64 fileSize;
// PNG decoding structures
CellPngDecInfo info;
CellPngDecOutParam outParam;
CellPngDecSrc src;
CellPngDecOutParam out_param;
CellPngDecSrc source;
CellPngDecStrmInfo streamInfo;
CellPngDecStrmParam streamParam;
// Fixed alpha value and flag
bool fixed_alpha;
be_t<u32> fixed_alpha_colour;
// Pixel packing value
be_t<s32> packing;
// PNG custom read function structure, for decoding from a buffer
vm::ptr<PngBuffer> buffer;
// libpng structures for reading and decoding the PNG file
png_structp png_ptr;
png_infop info_ptr;
};
// Converts libpng colour type to cellPngDec colour type
static s32 getPngDecColourType(u8 type)
{
switch (type)
{
case PNG_COLOR_TYPE_RGB: return CELL_PNGDEC_RGB;
case PNG_COLOR_TYPE_RGBA: return CELL_PNGDEC_RGBA; // We can't diffrentiate between ARGB and RGBA. Doesn't seem to be exactly important.
case PNG_COLOR_TYPE_PALETTE: return CELL_PNGDEC_PALETTE;
case PNG_COLOR_TYPE_GRAY: return CELL_PNGDEC_GRAYSCALE;
case PNG_COLOR_TYPE_GRAY_ALPHA: return CELL_PNGDEC_GRAYSCALE_ALPHA;
default: throw EXCEPTION("Unknown colour type: %d", type);
}
}

View File

@ -3,7 +3,7 @@
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<IncludePath>.\;..\;..\asmjit\src\asmjit;..\wxWidgets\include\msvc;..\wxWidgets\include;..\ffmpeg\WindowsInclude;..\ffmpeg\Windows\x86_64\Include;$(VC_IncludePath);$(WindowsSDK_IncludePath);..\llvm\include;..\llvm_build\include;$(UniversalCRT_IncludePath);..\minidx12\Include;..\glm;..\GSL\include</IncludePath>
<IncludePath>.\;..\;..\asmjit\src\asmjit;..\wxWidgets\include\msvc;..\wxWidgets\include;..\ffmpeg\WindowsInclude;..\ffmpeg\Windows\x86_64\Include;$(VC_IncludePath);$(WindowsSDK_IncludePath);..\llvm\include;..\llvm_build\include;$(UniversalCRT_IncludePath);..\minidx12\Include;..\glm;..\GSL\include;..\libpng</IncludePath>
<OutDir>$(SolutionDir)lib\$(Configuration)-$(Platform)\</OutDir>
<LibraryPath>$(SolutionDir)lib\$(Configuration)-$(Platform)\;$(UniversalCRT_LibraryPath_x64);$(LibraryPath)</LibraryPath>
<IntDir>$(SolutionDir)tmp\$(ProjectName)-$(Configuration)-$(Platform)\</IntDir>
@ -25,9 +25,9 @@
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>odbc32.lib;odbccp32.lib;comctl32.lib;ws2_32.lib;shlwapi.lib;winmm.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;rpcrt4.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>odbc32.lib;odbccp32.lib;comctl32.lib;ws2_32.lib;shlwapi.lib;winmm.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;rpcrt4.lib;libpng.lib;%(AdditionalDependencies)</AdditionalDependencies>
<DataExecutionPrevention>true</DataExecutionPrevention>
<AdditionalLibraryDirectories>..\wxWidgets\lib\vc_x64_lib;..\ffmpeg\Windows\x86_64\lib</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>..\wxWidgets\lib\vc_x64_lib;..\ffmpeg\Windows\x86_64\lib;..\lib\</AdditionalLibraryDirectories>
<BaseAddress>0x10000</BaseAddress>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
</Link>

45
zlib.props Normal file
View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
* zlib.props - location of zlib source
*
* libpng version 1.6.20 - December 3, 2015
*
* Copyright (c) 1998-2011 Glenn Randers-Pehrson
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
* You must edit this file to record the location of the zlib
* source code.
-->
<Project ToolsVersion="4.0"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<!-- Place the name of the directory containing the source of zlib used for
debugging in this property.
The directory need only contain the '.c' and '.h' files from the
source.
If you use a relative directory name (as below) then it must be
relative to the project directories; these are one level deeper than
the directories containing this file.
If the version of zlib you use does not match that used when the
distribution was built you will get warnings from pngtest that the zlib
versions do not match. The zlib version used in this build is recorded
below:
-->
<ZLibSrcDir>..\..\..\..\wxWidgets\src\zlib\</ZLibSrcDir>
<!-- The following line allows compilation for an ARM target with Visual
Studio 2012. Notice that this is not supported by the Visual Studio
2012 IDE and that the programs that result cannot be run unless they
signed by Microsoft. This is therefore untested; only Microsoft can
test it:
-->
<WindowsSDKDesktopARMSupport>true</WindowsSDKDesktopARMSupport>
</PropertyGroup>
</Project>