diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..6c6da92
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,89 @@
+#sources
+*.c text
+*.cc text
+*.cxx text
+*.cpp text
+*.c++ text
+*.hpp text
+*.h text
+*.h++ text
+*.hh text
+
+# Compiled Object files
+*.slo binary
+*.lo binary
+*.o binary
+*.obj binary
+
+# Precompiled Headers
+*.gch binary
+*.pch binary
+
+# Compiled Dynamic libraries
+*.so binary
+*.dylib binary
+*.dll binary
+
+# Compiled Static libraries
+*.lai binary
+*.la binary
+*.a binary
+*.lib binary
+
+# Executables
+*.exe binary
+*.out binary
+*.app binary
+###############################################################################
+# Set default behavior to automatically normalize line endings.
+###############################################################################
+* text=auto
+
+###############################################################################
+# Set the merge driver for project and solution files
+#
+# Merging from the command prompt will add diff markers to the files if there
+# are conflicts (Merging from VS is not affected by the settings below, in VS
+# the diff markers are never inserted). Diff markers may cause the following
+# file extensions to fail to load in VS. An alternative would be to treat
+# these files as binary and thus will always conflict and require user
+# intervention with every merge. To do so, just comment the entries below and
+# uncomment the group further below
+###############################################################################
+
+*.sln text eol=crlf
+*.csproj text eol=crlf
+*.vbproj text eol=crlf
+*.vcxproj text eol=crlf
+*.vcproj text eol=crlf
+*.dbproj text eol=crlf
+*.fsproj text eol=crlf
+*.lsproj text eol=crlf
+*.wixproj text eol=crlf
+*.modelproj text eol=crlf
+*.sqlproj text eol=crlf
+*.wmaproj text eol=crlf
+
+*.xproj text eol=crlf
+*.props text eol=crlf
+*.filters text eol=crlf
+*.vcxitems text eol=crlf
+
+
+#*.sln merge=binary
+#*.csproj merge=binary
+#*.vbproj merge=binary
+#*.vcxproj merge=binary
+#*.vcproj merge=binary
+#*.dbproj merge=binary
+#*.fsproj merge=binary
+#*.lsproj merge=binary
+#*.wixproj merge=binary
+#*.modelproj merge=binary
+#*.sqlproj merge=binary
+#*.wwaproj merge=binary
+
+#*.xproj merge=binary
+#*.props merge=binary
+#*.filters merge=binary
+#*.vcxitems merge=binary
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..014f9bd
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,33 @@
+##### 1.3.0:
+ Changed `_SARDen`, `_SARNum` to display MPEG-4 PAR. (videoh)
+ Changed `_AspectRatio` type to array int.
+
+##### 1.2.6:
+ Restored previous behavior of frame property `_FieldBased`.
+ Fixed frame properties `_DurationNum` and `_DurationDen`.
+ Added frame properties `_SARDen`, `_SARNum`, `_FieldOrder`, `_FieldOperation`, `_TFF`, `_RFF`, `_Film`, `_ProgressiveFrame`, `_ChromaLocation`, `_AbsoluteTime`. (videoh)
+ Added parameters `nocrop` and `rff`.
+
+##### 1.2.5:
+ Fixed frame property `_FieldBased`.
+
+##### 1.2.4:
+ Fixed regression for relative file paths.
+
+##### 1.2.3:
+ Fixed FFSAR_NUM, FFSAR_DEN, FFSAR.
+
+##### 1.2.2:
+ Fixed values of frame properties _Quants* when info=0.
+
+##### 1.2.1:
+ Added support for path with forward slash (Windows).
+
+##### 1.2.0:
+ Added variables (ffms2 like) - FFSAR_NUM, FFSAR_DEN, FFSAR.
+
+##### 1.1.0:
+ Set frame properties - _DurationNum, _DurationDen, _FieldBased, _AspectRatio, _GOPNumber, _GOPPosition, _GOPClosed, _EncodedFrameTop, _EncodedFrameBottom, _PictType, _Matrix, _QuantsAverage, _QuantsAverage, _QuantsMax.
+
+##### 1.0.0:
+ Renamed the plugin and function to D2VSource.
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..df46bc7
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,67 @@
+cmake_minimum_required(VERSION 3.16)
+
+project(libd2vsource LANGUAGES CXX)
+
+find_package (Git)
+if (GIT_FOUND)
+ execute_process (COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0
+ OUTPUT_VARIABLE ver
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+else ()
+ message (STATUS "GIT not found")
+endif ()
+
+add_library(d2vsource SHARED
+ src/AVISynthAPI.cpp
+ src/color_convert.cpp
+ src/getbit.cpp
+ src/gethdr.cpp
+ src/getpic.cpp
+ src/global.cpp
+ src/idct_ap922_sse2.cpp
+ src/idct_llm_float_avx2.cpp
+ src/idct_llm_float_sse2.cpp
+ src/idct_ref_sse3.cpp
+ src/mc.cpp
+ src/misc.cpp
+ src/MPEG2Decoder.cpp
+ src/store.cpp
+ src/yv12pict.cpp
+)
+
+if (NOT CMAKE_BUILD_TYPE)
+ set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
+endif()
+
+message(STATUS "Build type - ${CMAKE_BUILD_TYPE}")
+
+set_source_files_properties(src/idct_ap922_sse2.cpp PROPERTIES COMPILE_OPTIONS "-mfpmath=sse;-msse2")
+set_source_files_properties(src/idct_llm_float_sse2.cpp PROPERTIES COMPILE_OPTIONS "-mfpmath=sse;-msse2")
+set_source_files_properties(src/idct_ref_sse3.cpp PROPERTIES COMPILE_OPTIONS "-mssse3")
+set_source_files_properties(src/idct_llm_float_avx2.cpp PROPERTIES COMPILE_OPTIONS "-mavx2;-mfma")
+
+target_include_directories(d2vsource PRIVATE
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ /usr/local/include/avisynth
+)
+
+set_target_properties(d2vsource PROPERTIES OUTPUT_NAME "d2vsource.${ver}")
+
+target_compile_features(d2vsource PRIVATE cxx_std_17)
+
+include(GNUInstallDirs)
+
+INSTALL(TARGETS d2vsource
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/avisynth")
+
+# uninstall target
+if(NOT TARGET uninstall)
+ configure_file(
+ "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
+ IMMEDIATE @ONLY)
+
+ add_custom_target(uninstall
+ COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
+endif()
diff --git a/src/dgdecode/COPYING.txt b/COPYING.txt
similarity index 100%
rename from src/dgdecode/COPYING.txt
rename to COPYING.txt
diff --git a/src/dgdecode/History.txt b/History.txt
similarity index 100%
rename from src/dgdecode/History.txt
rename to History.txt
diff --git a/README.md b/README.md
index d90e881..f6c1ab8 100644
--- a/README.md
+++ b/README.md
@@ -1,81 +1,184 @@
-# MPEG2DecPlus
-これはDGDecode.dllをAvisynth+用に改造するプロジェクトです。
+## D2VSource
-###やりたいこと:
- - 改築を重ねた温泉旅館のようなコードをきれいにする。
- - VFAPI用コード、YUY2用コード等、現在では必要ないコードの排除。
- - アセンブラの排除による64bitへの対応、及びSSE2/AVX2でのintrinsicによる最適化。等
+This is a project (previously named as MPEG2DecPlus) to modify DGDecode.dll for AviSynth+.
-###必要なもの:
- - Windows Vista SP2 以降の Windows OS
- - SSE3が使えるCPU(Intel Pentium4(prescott) または AMD Athlon64x2 以降)
- - Avisynth+ r2172以降 またはAvisynth 2.60以降
- - Microsoft VisualC++ Redistributable Package 2015.
+### Requirements:
- ###使い方:
- ```
- MPEG2Source(string "d2v", int "cpu", int "idct", bool "iPP", int "moderate_h", int "moderate_v",
- bool "showQ", bool "fastMC", string "cpu2", int "info", int "upConv", bool "i420", bool "iCC")
- ```
- d2v: dv2ファイルのパス
-
- cpu: 現在使用不可。設定しても何も起こらない。iPP, moderate_h, moderate_v, fastMC, cpu2も同様。
-
- idct: 使用するiDCTアルゴリズム。
- 0: d2vの指定に従う。
- 1,2,3,6,7: AP922整数(SSE2MMXと同じもの)。
- 4: SSE2/AVX2 LLM(単精度浮動小数点、SSE2/AVX2の判定は自動)。
- 5: IEEE 1180 reference(倍精度浮動小数点)。
-
- showQ: マクロブロックの量子化器を表示する。
-
- info: デバッグ情報を出力する。
- 0: 表示しない。(デフォルト)
- 1: 動画フレームにオーバーレイで表示。
- 2: OutputDebugString()で出力。(内容はDebugView.exeで確認)
- 3: hintsをフレーム左上隅の64バイトに埋め込む。
+- AviSynth 2.60 / AviSynth+ 3.4 or later
- upConv: フレームを出力するフォーマット。
- 0: YUV420なソースはYV12で出力、YUV422なソースはYV16で出力。
- 1: YV16で出力。
- 2: YV24で出力。
+- Microsoft VisualC++ Redistributable Package 2022 (can be downloaded from [here](https://github.com/abbodi1406/vcredist/releases))
- i420: trueであればYUV420をi420として出力する。現在ではどちらでもほぼ変わりはない。
+### Usage:
- iCC: upConvにおけるYUV420の取扱いの設定。
- 未設定: フレームフラグに従ってinterlaced/progressiveを切り替える。
- true: 全フレームをinterlacedとして処理する。
- false: 全フレームをprogressiveとして処理する。
-
-```
-Deblock(clip c, int "quant", int "aOffset", int "bOffset")
-```
-H.264式デブロックフィルタ。manao氏のフィルタを取り込んだもの。
-
- clip: Y8, YV12, YV16, YV411, YV24をサポート。
-
- quant: 0~51(デフォルト25)
- デブロックの強さ。
-
- aOffset: 0 ~ 51-quant(デフォルト0)
- ブロック検出の閾値。高いほどブロックと判定されやすくなる。
+ ```
+ D2VSource(string "d2v", int "idct", bool "showQ", int "info", int "upConv", bool "i420", bool "iCC", bool "nocrop", int "rff")
+ ```
- bOffset: 0 ~ 51-quant(デフォルト0)
- デブロックの強さ及び検出率の補正値。
- 高いほどデブロックが強くかかり、ブロックと判定されやすくなる。
+### Parameters:
+
+- d2v\
+ The path of the dv2 file.
+
+- idct\
+ The iDCT algorithm to use.\
+ 0: Follow the d2v specification.\
+ 1,2,3,6,7: AP922 integer (same as SSE2/MMX).\
+ 4: SSE2/AVX2 LLM (single precision floating point, SSE2/AVX2 determination is automatic).\
+ 5: IEEE 1180 reference (double precision floating point).\
+ Default: -1.
+
+- showQ\
+ It displays macroblock quantizers..\
+ Default: False.
+
+- info\
+ It prints debug information.\
+ 0: Do not display.\
+ 1: Overlay on video frame.\
+ 2: Output with OutputDebugString(). (The contents are confirmed by DebugView.exe).\
+ 3: Embed hints in 64 bytes of the frame upper left corner.\
+ Default: 0.
+
+- upConv\
+ The output format.\
+ 0: No conversion. YUV420 output is YV12, YUV422 output is YV16.\
+ 1: Output YV16.\
+ 2: Output YV24.\
+ Default: 0.
+
+- i420\
+ It determinates what is the output of YUV420.\
+ True: The output is i410.\
+ False: The output is YV12.\
+ Default: False.
-```
-LumaYUV(clip c, int "lumoff", int "lumgain")
-```
-入力クリップの輝度をlumoffとlumgainの値によって変更する。出力Y = (入力y * lumgain) + lumoff
+- iCC\
+ It determinates how YUV420 is upscaled when upConv=true.\
+ True: Force field-based upsampling.\
+ False: Forse progressive upsampling.\
+ Default: Auto determination based on the frame flag.
+
+- nocrop\
+ Use direct-rendered buffer, which may need cropping.\
+ It could provide a speedup when you know you need to crop your image anyway, by avoiding extra memcpy calls.\
+ Default: False.
- clip: Y8, YV12, YV16, YV411, YV24をサポート。
+- rff\
+ Changes Field_Operation without the need of editing d2v or rescanning with different Field Operation.\
+ 0: Honor Pulldowns Flags.\
+ 1: Forced Film.\
+ 2: Ignored Pulldowns Flags.\
+ Default: -1 - read the value from d2v.
+
+### Exported variables:
+
+FFSAR_NUM, FFSAR_DEN, FFSAR (these indicate Generic PAR).
+
+### Frame properties
+
+_AbsoluteTime [float]\
+The frame’s absolute timestamp in seconds.
+
+_AspectRatio [int]\
+An array giving the display aspect ratio.
+
+_ChromaLocation [int]\
+Chroma sample position in YUV formats:
+0=left, 1=center, 2=topleft, 3=top, 4=bottomleft, 5=bottom.
+
+_DurationNum [int], _DurationDen [int]\
+The frame’s duration in seconds as a rational number.
+
+_EncodedFrameTop [int], _EncodedFrameBottom [int]\
+Frame number (before pulldown) used to generate this frame's
+top/bottom field.
+
+_FieldBased [int]\
+Describes the composition of the frame:\
+0=frame based (progressive), 1=bottom field first, 2=top field first.\
+Note that the GOP progressive flag is used to determine whether the frame is progressive.
+
+_FieldOperation [int]\
+Describes the field operation option in effect:\
+0=honor pulldown, 1=force film, 2=ignore pulldown.
+
+_FieldOrder [int]\
+Display field order of the frame:\
+0=bottom field first, 1=top field first.
+
+_Film [int]\
+Set if the frame is part of a 3:2 soft pulldown section.\
+Note that this uses the RFF history of several preceding\
+frames, and so is valid only when doing linear access.
+
+_GOPClosed [int]\
+Set if the current GOP is closed.
+
+_GOPNumber [int]\
+The 0-based GOP number that contains the frame. Note that\
+if this is set as the value x, then propShow displays it as\
+[x, y] where y is the 0-based frame number of the first frame\
+in the GOP.
+
+_GOPPosition [int]\
+The GOP position field from the D2V file for the GOP containing\
+the frame.
+
+_Matrix [int]\
+The matrix number field from the D2V file for the GOP containing\
+the frame.
+
+_PictType [data]\
+A single character describing the frame type. It uses the common\
+IPB characters but others may also be used for formats with\
+additional frame types.
+
+_ProgressiveFrame [int]\
+Set if the progress_frame flag is set for this frame.
+
+_QuantsAverage [int]\
+The average quantizer value for the frame.
+
+_QuantsMax [int]\
+The maximum quantizer value for the frame.
+
+_QuantsMin [int]\
+The minimum quantizer value for the frame.
+
+_RFF [int]\
+If _FieldOperation is 2 (ignore pulldown) then _RFF describes whether the stream specifies that a repeat field operation is to be performed on this frame. If _FieldOperation is 0 (honor pulldown) or 1 (force film) then _RFF describes whether the frame was composed with field repetition.
+
+_SARDen [int]
+The denominator of the "pixel size" (MPEG-4 PAR), also called the\
+Sample Aspect Ratio (SAR).
- lumoff: -255 ~ 255 (デフォルト0)
+_SARNum [int]
+The numerator of the "pixel size" (MPEG-4 PAR), also called the\
+Sample Aspect Ratio (SAR).
- lumgain: 0.0 ~ 2.0 (デフォルト1.0)
+_TFF [int]\
+If _FieldOperation is 2 (ignore pulldown) and _RFF is set, then _TFF\
+describes whether the stream specifies that the top field is to be repeated, otherwise the bottom field is to be repeated. If _FieldOperation is 0 (honor pulldown) or 1 (force film) then _TFF is inapplicable and is set to -1.
-###ソースコード
- https://github.com/chikuzen/MPEG2DecPlus/
+### Building:
+- Windows\
+ Use solution files.
+- Linux
+ ```
+ Requirements:
+ - Git
+ - C++17 compiler
+ - CMake >= 3.16
+ ```
+ ```
+ git clone https://github.com/Asd-g/MPEG2DecPlus && \
+ cd MPEG2DecPlus && \
+ mkdir build && \
+ cd build && \
+
+ cmake ..
+ make -j$(nproc)
+ sudo make install
+ ```
diff --git a/README_old.md b/README_old.md
new file mode 100644
index 0000000..69f29fe
--- /dev/null
+++ b/README_old.md
@@ -0,0 +1,65 @@
+# MPEG2DecPlus
+これはDGDecode.dllをAvisynth+用に改造するプロジェクトです。
+
+###やりたいこと:
+ - 改築を重ねた温泉旅館のようなコードをきれいにする。
+ - VFAPI用コード、YUY2用コード等、現在では必要ないコードの排除。
+ - アセンブラの排除による64bitへの対応、及びSSE2/AVX2でのintrinsicによる最適化。等
+
+###必要なもの:
+ - Windows Vista SP2 以降の Windows OS
+ - SSE3が使えるCPU(Intel Pentium4(prescott) または AMD Athlon64x2 以降)
+ - Avisynth+ r2172以降 またはAvisynth 2.60以降
+ - Microsoft VisualC++ Redistributable Package 2019.
+
+ ###使い方:
+ ```
+ MPEG2Source(string "d2v", int "cpu", int "idct", bool "iPP", int "moderate_h", int "moderate_v",
+ bool "showQ", bool "fastMC", string "cpu2", int "info", int "upConv", bool "i420", bool "iCC")
+ ```
+ d2v: dv2ファイルのパス
+
+ cpu: 現在使用不可。設定しても何も起こらない。iPP, moderate_h, moderate_v, fastMC, cpu2も同様。
+
+ idct: 使用するiDCTアルゴリズム。
+ 0: d2vの指定に従う。
+ 1,2,3,6,7: AP922整数(SSE2MMXと同じもの)。
+ 4: SSE2/AVX2 LLM(単精度浮動小数点、SSE2/AVX2の判定は自動)。
+ 5: IEEE 1180 reference(倍精度浮動小数点)。
+
+ showQ: マクロブロックの量子化器を表示する。
+
+ info: デバッグ情報を出力する。
+ 0: 表示しない。(デフォルト)
+ 1: 動画フレームにオーバーレイで表示。
+ 2: OutputDebugString()で出力。(内容はDebugView.exeで確認)
+ 3: hintsをフレーム左上隅の64バイトに埋め込む。
+
+ upConv: フレームを出力するフォーマット。
+ 0: YUV420なソースはYV12で出力、YUV422なソースはYV16で出力。
+ 1: YV16で出力。
+ 2: YV24で出力。
+
+ i420: trueであればYUV420をi420として出力する。現在ではどちらでもほぼ変わりはない。
+
+ iCC: upConvにおけるYUV420の取扱いの設定。
+ 未設定: フレームフラグに従ってinterlaced/progressiveを切り替える。
+ true: 全フレームをinterlacedとして処理する。
+ false: 全フレームをprogressiveとして処理する。
+
+
+```
+LumaYUV(clip c, int "lumoff", int "lumgain")
+```
+入力クリップの輝度をlumoffとlumgainの値によって変更する。出力Y = (入力y * lumgain) + lumoff
+
+ clip: Y8, YV12, YV16, YV411, YV24をサポート。
+
+ lumoff: -255 ~ 255 (デフォルト0)
+
+ lumgain: 0.0 ~ 2.0 (デフォルト1.0)
+
+###ソースコード
+ https://github.com/chikuzen/MPEG2DecPlus/
+
+
diff --git a/bin/.gitkeep b/bin/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/bin/DGIndex.lang.ini b/bin/DGIndex.lang.ini
deleted file mode 100644
index c39cf76..0000000
--- a/bin/DGIndex.lang.ini
+++ /dev/null
@@ -1,275 +0,0 @@
-; DGIndex language settings
-
-[MainMenu]
-00=&File
-01=&Stream
-02=&Video
-03=&Audio
-04=&Options
-05=&Tools
-06=&Help
-
-[SubMenu0]
-00=&Open [F2]
-01=Load Project
-02=&Close [F3]
-03=
-04=&Save Project [F4]
-05=Save Project and Demux Video
-06=Save BMP [F7]
-07=Demux Audio-Only Stream
-08=
-09=Preview [F5]
-10=Play [F6]
-11=Stop [Esc]
-12=Pause/Resume [Space]
-13=
-14=
-15=Exit
-
-[SubMenu1]
-00=Detect PIDs: PAT/PMT
-01=Detect PIDs: PSIP
-02=Detect PIDs: Raw
-03=Set PIDs
-04=Set Margin
-
-[SubMenu2]
-00=iDCT Algorithm
-01=Field Operation
-02=YUV -> RGB
-03=HD Display
-04=
-05=Luminance Filter
-06=Cropping Filter
-07=
-08=Copy frame to clipboard [F8]
-
-[SubMenu2-0]
-00=32-bit MMX
-01=32-bit SSE MMX
-02=32-bit SSE2 MMX
-03=64-bit Floating Point
-04=IEEE-1180 Reference
-05=Skal SSE MMX
-06=Simple MMX
-
-[SubMenu2-1]
-00=Honor Pulldown Flags
-01=Ignore Pulldown Flags
-02=Forced Film
-
-[SubMenu2-2]
-00=PC Scale
-01=TV Scale
-
-[SubMenu2-3]
-00=Full Sized
-01=Shrink by Half
-02=Top Left
-03=Top Right
-04=Bottom Left
-05=Bottom Right
-
-[SubMenu3]
-00=Output Method
-01=Select Track(s)
-02=
-03=Dolby Digital Decode
-04=48 -> 44.1KHz
-05=Normalization
-
-[SubMenu3-0]
-00=Disable
-01=Demux Tracks
-02=Demux All Tracks
-03=Decode AC3 Track to WAV
-
-[SubMenu3-3]
-00=Dynamic Range Control
-01=Dolby Surround Downmix
-02=Pre-Scale Decision [F9]
-
-[SubMenu3-3-0]
-00=Off
-01=
-02=Light
-03=Normal
-04=Heavy
-
-[SubMenu3-4]
-00=Off
-01=
-02=Low
-03=Mid
-04=High
-05=UltraHigh
-
-[SubMenu4]
-00=Loop Playback
-01=Playback Speed
-02=Process Priority
-03=Use Full Paths
-04=Force Fusion-Style Audio
-05=Force Open GOPs in D2V File
-06=Log Quant Matrices
-07=Log Timestamps
-08=AVS Template
-09=BMP Save Path
-10=Enable Info Log
-11=Correct D2V
-
-[SubMenu4-1]
-00=Single Step
-01=Super Slow
-02=Slow
-03=Normal
-04=Fast
-05=Maximum
-
-[SubMenu4-2]
-00=High
-01=Normal
-02=Low
-
-[SubMenu4-11]
-00=Disable
-01=Enable
-
-[SubMenu5]
-00=Analyze Sync
-01=Fix D2V
-02=Parse D2V
-
-[SubMenu6]
-00=Detected SIMD
-01=VFAPI Plug-In
-02=
-03=About DGIndex
-04=DGMPGDec Quick Start Guide
-05=DGIndex User Manual
-06=DGDecode User Manual
-07=
-08=jackei's Web Site
-09=neuron2's Web Site
-
-[SubMenu6-0]
-00=MMX
-01=SSE MMX
-02=SSE2
-03=SSE FPU
-04=3D Now!
-
-[Dialog0]
-;caption=Information
-;font_size=8
-;font_name=Tahoma
-
-[Dialog1]
-caption=Version
-font_size=10
-font_name=Tahoma
-00=OK
-01=DGIndex is an evolution of jackei's original work called DVD2AVI. The name was changed to prevent versioning nightmares and to reflect the significant divergence of functionality.
-02=I am using this About box to permanently record the origins of DGIndex and to acknowledge the original work of jackei, as well as my personal gratitude for his wonderful contribution to our community!"
-
-[Dialog2]
-caption=File List
-font_size=10
-font_name=Tahoma
-00=ADD
-01=UP
-02=DOWN
-03=DEL
-04=DEL ALL
-05=OK
-
-[Dialog3]
-caption=Luminance Filter
-font_size=10
-font_name=Tahoma
-00=Enable Luminance Filter
-01=Offset:
-02=Gammna:
-
-[Dialog4]
-caption=Normalization
-font_size=10
-font_name=Tahoma
-00=Enable Normalization
-01=Volume
-
-[Dialog5]
-caption=Set PIDs
-font_size=10
-font_name=Tahoma
-00=OK
-01=Cancel
-02=Video PID
-03=Audio PID
-04=PCR PID
-05=[Please use hexadecimal values with no leading 0x.]
-
-[Dialog6]
-caption=AVS Template
-font_size=10
-font_name=Tahoma
-00=Don't Use Template
-01=Change Template File
-02=Keep Current Template File
-03=Your current AVS template file is:
-
-[Dialog7]
-caption=BMP Save Path
-font_size=10
-font_name=Tahoma
-00=OK
-01=Cancel
-02=Your current BMP save path is:
-
-[Dialog8]
-caption=Cropping
-font_size=10
-font_name=Tahoma
-00=Enable Cropping Filter
-01=Left
-02=Right
-03=Top
-04=Bottom
-05=Width
-06=Height
-
-[Dialog9]
-caption=Detect PIDs
-font_size=10
-font_name=Tahoma
-00=Set Video
-01=Set Audio
-02=Set PCR
-03=Done
-04=Select a line and use these buttons to set that PID as the audio or video PID.
-
-[Dialog10]
-caption=Select Track(s)
-font_size=10
-font_name=Tahoma
-00=OK
-01=Cancel
-02=List desired audio id's separated by commas
-
-[Dialog11]
-caption=Select Track to Analyze
-font_size=10
-font_name=Tahoma
-00=OK
-01=Cancel
-02=Enter audio id to analyze in hex without the leading 0x
-
-[Dialog12]
-caption=Set Margin
-font_size=10
-font_name=Tahoma
-00=OK
-01=Cancel
-02=Margin:
-03=msec
diff --git a/bin/DGIndex.lang_chi.ini b/bin/DGIndex.lang_chi.ini
deleted file mode 100644
index 62e74dd..0000000
--- a/bin/DGIndex.lang_chi.ini
+++ /dev/null
@@ -1,276 +0,0 @@
-; DGIndex language settings
-; coding: gb2312
-
-[MainMenu]
-00=ļ(&F)
-01=(&S)
-02=Ƶ(&V)
-03=Ƶ(&A)
-04=ѡ(&O)
-05=(&T)
-06=(&H)
-
-[SubMenu0]
-00=(&O) [F2]
-01=Ŀ
-02=ر(&C) [F3]
-03=
-04=Ŀ(&S) [F4]
-05=ĿƵ
-06= BMP [F7]
-07=Ƶ
-08=
-09=Ԥ [F5]
-10= [F6]
-11=ֹͣ [Esc]
-12=ͣ/ָ [Space]
-13=
-14=
-15=˳
-
-[SubMenu1]
-00= PID: PAT/PMT
-01= PID: PSIP
-02= PID: Raw
-03= PID
-04=ü
-
-[SubMenu2]
-00=iDCT 㷨
-01=
-02=YUV -> RGB
-03=ʾ
-04=
-05=˾
-06=ü˾
-07=
-08=֡Ƶ [F8]
-
-[SubMenu2-0]
-00=32-bit MMX
-01=32-bit SSE MMX
-02=32-bit SSE2 MMX
-03=64-bit Floating Point
-04=IEEE-1180 Reference
-05=Skal SSE MMX
-06=Simple MMX
-
-[SubMenu2-1]
-00=ѭ۵
-01=۵
-02=ǿƽƬ֡
-
-[SubMenu2-2]
-00=PC ɫ
-01=TV ɫ
-
-[SubMenu2-3]
-00=ԭʼС
-01=һ
-02=
-03=
-04=
-05=
-
-[SubMenu3]
-00=ʽ
-01=ѡ
-02=
-03=űֽ
-04=48 -> 44.1KHz
-05=
-
-[SubMenu3-0]
-00=
-01=
-02=
-03= AC3 Ϊ WAV
-
-[SubMenu3-3]
-00=̬Χ
-01=űȻ
-02=Pre-Scale Decision [F9]
-
-[SubMenu3-3-0]
-00=ر
-01=
-02=dz
-03=
-04=
-
-[SubMenu3-4]
-00=ر
-01=
-02=
-03=
-04=
-05=ܸ
-
-[SubMenu4]
-00=ѭ
-01=ٶ
-02=ȼ
-03=ʹ·
-04=Force Fusion-Style Audio
-05=Force Open GOPs in D2V File
-06=Log Quant Matrices
-07=¼ʱ
-08=AVS ģ
-09=BMP ·
-10=־
-11= D2V
-
-[SubMenu4-1]
-00=
-01=
-02=
-03=
-04=
-05=
-
-[SubMenu4-2]
-00=
-01=
-02=
-
-[SubMenu4-11]
-00=
-01=
-
-[SubMenu5]
-00=ͬ
-01= D2V
-02= D2V
-
-[SubMenu6]
-00=ͬ
-01=VFAPI
-02=
-03= DGIndex
-04=DGMPGDec ָ
-05=DGIndex ûֲ
-06=DGDecode ûֲ
-07=
-08=jackei վ
-09=neuron2 վ
-
-[SubMenu6-0]
-00=MMX
-01=SSE MMX
-02=SSE2
-03=SSE FPU
-04=3D Now!
-
-[Dialog0]
-;caption=Information
-;font_size=8
-;font_name=Tahoma
-
-[Dialog1]
-caption=汾
-font_size=10
-font_name=Tahoma
-00=ȷ
-01=DGIndex is an evolution of jackei's original work called DVD2AVI. The name was changed to prevent versioning nightmares and to reflect the significant divergence of functionality.
-02=I am using this About box to permanently record the origins of DGIndex and to acknowledge the original work of jackei, as well as my personal gratitude for his wonderful contribution to our community!"
-
-[Dialog2]
-caption=ļб
-font_size=10
-font_name=Tahoma
-00=
-01=
-02=
-03=ɾ
-04=ȫɾ
-05=ȷ
-
-[Dialog3]
-caption=˾
-font_size=10
-font_name=Tahoma
-00=˾
-01=ƫ:
-02=٤:
-
-[Dialog4]
-caption=
-font_size=10
-font_name=Tahoma
-00=
-01=
-
-[Dialog5]
-caption= PID
-font_size=10
-font_name=Tahoma
-00=ȷ
-01=ȡ
-02=Ƶ PID
-03=Ƶ PID
-04=PCR PID
-05=[ʹò '0x'ǰʮֵ]
-
-[Dialog6]
-caption=AVS ģ
-font_size=10
-font_name=Tahoma
-00=ʹģ
-01=ģļ
-02=ֵǰģļ
-03=ǰ AVS ģļΪ:
-
-[Dialog7]
-caption=BMP ·
-font_size=10
-font_name=Tahoma
-00=ȷ
-01=ȡ
-02=ǰ BMP ·Ϊ:
-
-[Dialog8]
-caption=ü
-font_size=10
-font_name=Tahoma
-00=òü˾
-01=
-02=
-03=
-04=
-05=
-06=߶
-
-[Dialog9]
-caption= PID
-font_size=10
-font_name=Tahoma
-00=Ƶ
-01=Ƶ
-02= PCR
-03=
-04=ѡһв PID ΪƵƵ PID
-
-[Dialog10]
-caption=ѡ
-font_size=10
-font_name=Tahoma
-00=ȷ
-01=ȡ
-02=ҪƵ ID (Զŷָ)
-
-[Dialog11]
-caption=ѡҪ
-font_size=10
-font_name=Tahoma
-00=ȷ
-01=ȡ
-02=Ƶ ID ԱʮƷ (Ҫǰ '0x')
-
-[Dialog12]
-caption=
-font_size=10
-font_name=Tahoma
-00=ȷ
-01=ȡ
-02=:
-03=
diff --git a/bin/DGIndex.lang_jpn.ini b/bin/DGIndex.lang_jpn.ini
deleted file mode 100644
index 7633957..0000000
--- a/bin/DGIndex.lang_jpn.ini
+++ /dev/null
@@ -1,276 +0,0 @@
-; DGIndex language settings
-; coding: shift_jis
-
-[MainMenu]
-00=t@C(&F)
-01=Xg[(&S)
-02=f(&V)
-03=(&A)
-04=IvV(&O)
-05=c[(&T)
-06=wv(&H)
-
-[SubMenu0]
-00=J(&O) [F2]
-01=vWFNgJ
-02=(&C) [F3]
-03=
-04=vWFNg̕ۑ(&S) [F4]
-05=vWFNgۑf
-06=BMPt@Cۑ [F7]
-07=̂ݕ
-08=
-09=vr[ [F5]
-10=Đ [F6]
-11=~ [Esc]
-12=ꎞ~ / ĊJ [Space]
-13=
-14=
-15=I
-
-[SubMenu1]
-00=PIĎo: PAT/PMT
-01=PIĎo: PSIP
-02=PIĎo: Raw
-03=PID̐ݒ
-04=}[W̐ݒ
-
-[SubMenu2]
-00=iDCT ASY
-01=tB[h
-02=YUV -> RGB
-03=HD \
-04=
-05=Px
-06=NbsO
-07=
-08=t[Nbv{[hɃRs[ [F8]
-
-[SubMenu2-0]
-00=32-bit MMX
-01=32-bit SSE MMX
-02=32-bit SSE2 MMX
-03=64-bit Floating Point
-04=IEEE-1180 Reference
-05=Skal SSE MMX
-06=Simple MMX
-
-[SubMenu2-1]
-00=v_EtOD悷
-01=v_EtO
-02=tBϊ
-
-[SubMenu2-2]
-00=PCF
-01=TVF
-
-[SubMenu2-3]
-00=tTCY
-01=
-02=㕔
-03=E㕔
-04=
-05=E
-
-[SubMenu3]
-00=o͌`
-01=gbN̑I
-02=
-03=hr[fW^ fR[h
-04=48 -> 44.1KHz ϊ
-05=ʐK
-
-[SubMenu3-0]
-00=o͂Ȃ
-01=
-02=SgbNꊇ
-03=AC3 gbN WAV
-
-[SubMenu3-3]
-00=_Ci~bNWRg[
-01=hr[TEh _E~bNX
-02=vXP[̌ [F9]
-
-[SubMenu3-3-0]
-00=Ȃ
-01=
-02=Cg
-03=m[}
-04=wr[
-
-[SubMenu3-4]
-00=Ȃ
-01=
-02=ቹ
-03=ʏ
-04=
-05=ō
-
-[SubMenu4]
-00=[vĐ
-01=Đx
-02=^XNDx
-03=tpXgp
-04=t[WX^C
-05=IOpen-GOPň
-06=ʎq}gbNX̃O
-07=^CX^ṽO
-08=AVS ev[g
-09=BMP ̕ۑpX
-10=OLɂ
-11=D2V
-
-[SubMenu4-1]
-00=VOXebv
-01=ᑬ
-02=ᑬ
-03=ʏ
-04=
-05=ō
-
-[SubMenu4-2]
-00=
-01=ʏ
-02=Ⴂ
-
-[SubMenu4-11]
-00=
-01=L
-
-[SubMenu5]
-00=̕
-01=D2V ̏C
-02=D2V ̕
-
-[SubMenu6]
-00=Zp
-01=VFAPI vOC
-02=
-03=o[W
-04=DGMPGDec NCbNX^[gKCh
-05=DGIndex [U[}jA
-06=DGDecode [U[}jA
-07=
-08=jackeĩEFuTCg
-09=neuron2̃EFuTCg
-
-[SubMenu6-0]
-00=MMX
-01=SSE MMX
-02=SSE2
-03=SSE FPU
-04=3D Now!
-
-[Dialog0]
-;caption=Information
-;font_size=8
-;font_name=Tahoma
-
-[Dialog1]
-caption=o[W
-font_size=10
-font_name=Tahoma
-00=OK
-01=DGIndex is an evolution of jackei's original work called DVD2AVI. The name was changed to prevent versioning nightmares and to reflect the significant divergence of functionality.
-02=I am using this About box to permanently record the origins of DGIndex and to acknowledge the original work of jackei, as well as my personal gratitude for his wonderful contribution to our community!"
-
-[Dialog2]
-caption=t@CXg
-font_size=10
-font_name=Tahoma
-00=lj
-01=
-02=
-03=폜
-04=Sč폜
-05=OK
-
-[Dialog3]
-caption=Px
-font_size=10
-font_name=Tahoma
-00=PxL
-01=ItZbg:
-02=K}:
-
-[Dialog4]
-caption=ʐK
-font_size=10
-font_name=Tahoma
-00=ʐKL
-01=
-
-[Dialog5]
-caption=PID̐ݒ
-font_size=10
-font_name=Tahoma
-00=OK
-01=LZ
-02=f PID
-03= PID
-04=PCR PID
-05=[0xȂ16i̒lgpĂB]
-
-[Dialog6]
-caption=AVS ev[g
-font_size=10
-font_name=Tahoma
-00=ev[ggpȂ
-01=ev[g̕ύX
-02=݂̃t@Cێ
-03=݂̃ev[gt@C:
-
-[Dialog7]
-caption=BMP Save Path
-font_size=10
-font_name=Tahoma
-00=OK
-01=Cancel
-02=݂ BMP ۑpX:
-
-[Dialog8]
-caption=NbsO
-font_size=10
-font_name=Tahoma
-00=NbsOL
-01=
-02=E
-03=
-04=
-05=
-06=
-
-[Dialog9]
-caption=PIĎo
-font_size=10
-font_name=Tahoma
-00=fZbg
-01=Zbg
-02=PCRZbg
-03=
-04=fPIDƂăZbgɂ́AsIă{^ĂB
-
-[Dialog10]
-caption=gbN̑I
-font_size=10
-font_name=Tahoma
-00=OK
-01=LZ
-02=I[fBIIDR}ŋėĂB
-
-[Dialog11]
-caption=͂gbN̑I
-font_size=10
-font_name=Tahoma
-00=OK
-01=LZ
-02=I[fBIID0xȂ16iŎw肵ĂB
-
-[Dialog12]
-caption=}[W̐ݒ
-font_size=10
-font_name=Tahoma
-00=OK
-01=LZ
-02=}[W:
-03=~b
diff --git a/build/msvcX/DGDecode/DGDecode.vcxproj b/build/msvcX/DGDecode/DGDecode.vcxproj
deleted file mode 100644
index 043587a..0000000
--- a/build/msvcX/DGDecode/DGDecode.vcxproj
+++ /dev/null
@@ -1,205 +0,0 @@
-
-
-
-
- Debug
- Win32
-
-
- Debug
- x64
-
-
- Release
- Win32
-
-
- Release
- x64
-
-
-
- {13BF3FBA-7CD9-4374-83D5-E001E722E3DE}
- Win32Proj
- DGDecode
- 8.1
- MPEG2DecPlus
-
-
-
-
- DynamicLibrary
- true
- MultiByte
-
-
- DynamicLibrary
- true
- MultiByte
-
-
- DynamicLibrary
- false
- true
- MultiByte
- v140
-
-
- DynamicLibrary
- false
- true
- MultiByte
- v140
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
- $(SolutionDir)..\..\bin\msvc$(VisualStudioVersion)\$(Configuration)\
- $(Configuration)\msvc$(VisualStudioVersion)\
-
-
- true
-
-
- false
- $(SolutionDir)..\..\bin\msvc$(VisualStudioVersion)\$(Configuration)\
- $(Configuration)\msvc$(VisualStudioVersion)\
-
-
- false
- $(ProjectName)64
-
-
-
-
-
- Level3
- Disabled
- _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;_USRDLL;DGDECODE_EXPORTS;%(PreprocessorDefinitions)
- C:\my_projects\AviSynthPlus\avs_core\include;..\..\..\src\dgdecode
-
-
- Windows
- true
- shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
-
-
-
-
-
-
- Level3
- Disabled
- _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;_USRDLL;DGDECODE_EXPORTS;%(PreprocessorDefinitions)
- C:\my_projects\AviSynthPlus\avs_core\include;..\..\..\src\dgdecode
-
-
- Windows
- true
- shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
-
-
-
-
- Level3
-
-
- MaxSpeed
- false
- true
- _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;_USRDLL;DGDECODE_EXPORTS;%(PreprocessorDefinitions)
- C:\my_projects\AviSynthPlus\avs_core\include;..\..\..\src\dgdecode
- true
- AnySuitable
- StreamingSIMDExtensions2
- Fast
- true
- Speed
-
-
- Windows
- true
- true
- true
- shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
- false
-
-
-
-
- Level3
-
-
- MaxSpeed
- false
- true
- _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;_USRDLL;DGDECODE_EXPORTS;%(PreprocessorDefinitions)
- C:\my_projects\AviSynthPlus\avs_core\include;..\..\..\src\dgdecode
- true
- AnySuitable
- Speed
- true
- NotSet
- Fast
-
-
- Windows
- true
- true
- true
- shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
- false
-
-
-
-
-
-
-
-
-
-
-
-
- AdvancedVectorExtensions2
- AdvancedVectorExtensions2
- AdvancedVectorExtensions2
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/build/msvcX/DGDecode/DGDecode.vcxproj.filters b/build/msvcX/DGDecode/DGDecode.vcxproj.filters
deleted file mode 100644
index c2790ac..0000000
--- a/build/msvcX/DGDecode/DGDecode.vcxproj.filters
+++ /dev/null
@@ -1,99 +0,0 @@
-
-
-
-
- {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
- cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
-
-
- {93995380-89BD-4b04-88EB-625FBE52EBFB}
- h;hpp;hxx;hm;inl;inc;xsd
-
-
- {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
- rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
-
-
- {b92ffe8f-65a1-47d7-b2eb-8eafdef68fd7}
-
-
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- MPEG2DecPlus
-
-
- MPEG2DecPlus
-
-
- MPEG2DecPlus
-
-
- MPEG2DecPlus
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
-
-
- Header Files
-
-
- MPEG2DecPlus
-
-
- MPEG2DecPlus
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
-
\ No newline at end of file
diff --git a/build/msvcX/DGIndex/DGIndex.vcxproj b/build/msvcX/DGIndex/DGIndex.vcxproj
deleted file mode 100644
index 2181632..0000000
--- a/build/msvcX/DGIndex/DGIndex.vcxproj
+++ /dev/null
@@ -1,256 +0,0 @@
-
-
-
-
- Debug
- Win32
-
-
- Debug
- x64
-
-
- Release
- Win32
-
-
- Release
- x64
-
-
-
- {7BED3DC2-9B7C-446A-997F-9AD4560B1709}
- Win32Proj
- DGIndex
-
-
-
-
- Application
- true
- MultiByte
-
-
- Application
- true
- MultiByte
-
-
- Application
- false
- true
- MultiByte
-
-
- Application
- false
- true
- MultiByte
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
- $(SolutionDir)..\..\bin\msvc$(VisualStudioVersion)\$(Configuration)\
- $(Configuration)\msvc$(VisualStudioVersion)\
-
-
- true
-
-
- false
- $(SolutionDir)..\..\bin\msvc$(VisualStudioVersion)\$(Configuration)\
- $(Configuration)\msvc$(VisualStudioVersion)\
-
-
- false
-
-
-
-
-
- Level3
- Disabled
- _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)
- ..\..\..\src\dgindex
-
-
- Windows
- true
- shlwapi.lib;winmm.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
- 4096000
-
-
-
-
-
-
- Level3
- Disabled
- _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)
- ..\..\..\src\dgindex
-
-
- Windows
- true
- shlwapi.lib;winmm.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
- 4096000
-
-
-
-
- Level3
-
-
- MaxSpeed
- true
- true
- _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)
- ..\..\..\src\dgindex
-
-
- Windows
- true
- true
- true
- shlwapi.lib;winmm.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
- 4096000
- false
-
-
-
-
- Level3
-
-
- MaxSpeed
- true
- true
- _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)
- ..\..\..\src\dgindex
-
-
- Windows
- true
- true
- true
- shlwapi.lib;winmm.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
- 4096000
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ml /c /coff /Cx /nologo /Fo $(IntDir)%(Filename).obj %(FullPath)
-
- ml /c /coff /Cx /nologo /Fo $(IntDir)%(Filename).obj %(FullPath)
-
- $(IntDir)%(Filename).obj;%(Outputs)
- $(IntDir)%(Filename).obj;%(Outputs)
- ml /c /coff /Cx /nologo /Fo $(IntDir)%(Filename).obj %(FullPath)
-
- ml /c /coff /Cx /nologo /Fo $(IntDir)%(Filename).obj %(FullPath)
-
- $(IntDir)%(Filename).obj;%(Outputs)
- $(IntDir)%(Filename).obj;%(Outputs)
-
-
- nasm -f win32 -DPREFIX -DWIN32 -o $(IntDir)%(Filename).obj %(FullPath)
-
- nasm -f win32 -DPREFIX -DWIN32 -o $(IntDir)%(Filename).obj %(FullPath)
-
- $(IntDir)%(Filename).obj;%(Outputs)
- $(IntDir)%(Filename).obj;%(Outputs)
- nasm -f win32 -DPREFIX -DWIN32 -o $(IntDir)%(Filename).obj %(FullPath)
-
- nasm -f win32 -DPREFIX -DWIN32 -o $(IntDir)%(Filename).obj %(FullPath)
-
- $(IntDir)%(Filename).obj;%(Outputs)
- $(IntDir)%(Filename).obj;%(Outputs)
-
-
- %40copy /Y ..\..\..\src\dgdecode\skl_nasm.h .\ >NUL
-nasm -f win32 -DPREFIX -DWIN32 -o $(IntDir)%(Filename).obj %(FullPath)
-%40del /Q .\*.h
-
- %40copy /Y ..\..\..\src\dgdecode\skl_nasm.h .\ >NUL
-nasm -f win32 -DPREFIX -DWIN32 -o $(IntDir)%(Filename).obj %(FullPath)
-%40del /Q .\*.h
-
- $(IntDir)%(Filename).obj;%(Outputs)
- $(IntDir)%(Filename).obj;%(Outputs)
- %40copy /Y ..\..\..\src\dgdecode\skl_nasm.h .\ >NUL
-nasm -f win32 -DPREFIX -DWIN32 -o $(IntDir)%(Filename).obj %(FullPath)
-%40del /Q .\*.h
-
- %40copy /Y ..\..\..\src\dgdecode\skl_nasm.h .\ >NUL
-nasm -f win32 -DPREFIX -DWIN32 -o $(IntDir)%(Filename).obj %(FullPath)
-%40del /Q .\*.h
-
- $(IntDir)%(Filename).obj;%(Outputs)
- $(IntDir)%(Filename).obj;%(Outputs)
-
-
-
-
-
-
\ No newline at end of file
diff --git a/build/msvcX/DGIndex/DGIndex.vcxproj.filters b/build/msvcX/DGIndex/DGIndex.vcxproj.filters
deleted file mode 100644
index 0dce877..0000000
--- a/build/msvcX/DGIndex/DGIndex.vcxproj.filters
+++ /dev/null
@@ -1,156 +0,0 @@
-
-
-
-
- {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
- cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
-
-
- {93995380-89BD-4b04-88EB-625FBE52EBFB}
- h;hpp;hxx;hm;inl;inc;xsd
-
-
- {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
- rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
-
-
- {a1228af4-4725-4835-8ecb-323a1e68029d}
-
-
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- AC3Dec
-
-
- AC3Dec
-
-
- AC3Dec
-
-
- AC3Dec
-
-
- AC3Dec
-
-
- AC3Dec
-
-
- AC3Dec
-
-
- AC3Dec
-
-
- AC3Dec
-
-
- AC3Dec
-
-
- AC3Dec
-
-
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- AC3Dec
-
-
- AC3Dec
-
-
-
-
- Resource Files
-
-
-
-
- Resource Files
-
-
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
-
\ No newline at end of file
diff --git a/build/msvcX/DGMPGDec.sln b/build/msvcX/DGMPGDec.sln
deleted file mode 100644
index 92db205..0000000
--- a/build/msvcX/DGMPGDec.sln
+++ /dev/null
@@ -1,38 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 14
-VisualStudioVersion = 14.0.25420.1
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DGIndex", "DGIndex\DGIndex.vcxproj", "{7BED3DC2-9B7C-446A-997F-9AD4560B1709}"
-EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MPEG2DecPlus", "DGDecode\DGDecode.vcxproj", "{13BF3FBA-7CD9-4374-83D5-E001E722E3DE}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Win32 = Debug|Win32
- Debug|x64 = Debug|x64
- Release|Win32 = Release|Win32
- Release|x64 = Release|x64
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {7BED3DC2-9B7C-446A-997F-9AD4560B1709}.Debug|Win32.ActiveCfg = Debug|Win32
- {7BED3DC2-9B7C-446A-997F-9AD4560B1709}.Debug|Win32.Build.0 = Debug|Win32
- {7BED3DC2-9B7C-446A-997F-9AD4560B1709}.Debug|x64.ActiveCfg = Debug|x64
- {7BED3DC2-9B7C-446A-997F-9AD4560B1709}.Debug|x64.Build.0 = Debug|x64
- {7BED3DC2-9B7C-446A-997F-9AD4560B1709}.Release|Win32.ActiveCfg = Release|Win32
- {7BED3DC2-9B7C-446A-997F-9AD4560B1709}.Release|Win32.Build.0 = Release|Win32
- {7BED3DC2-9B7C-446A-997F-9AD4560B1709}.Release|x64.ActiveCfg = Release|x64
- {7BED3DC2-9B7C-446A-997F-9AD4560B1709}.Release|x64.Build.0 = Release|x64
- {13BF3FBA-7CD9-4374-83D5-E001E722E3DE}.Debug|Win32.ActiveCfg = Debug|Win32
- {13BF3FBA-7CD9-4374-83D5-E001E722E3DE}.Debug|Win32.Build.0 = Debug|Win32
- {13BF3FBA-7CD9-4374-83D5-E001E722E3DE}.Debug|x64.ActiveCfg = Debug|x64
- {13BF3FBA-7CD9-4374-83D5-E001E722E3DE}.Debug|x64.Build.0 = Debug|x64
- {13BF3FBA-7CD9-4374-83D5-E001E722E3DE}.Release|Win32.ActiveCfg = Release|Win32
- {13BF3FBA-7CD9-4374-83D5-E001E722E3DE}.Release|Win32.Build.0 = Release|Win32
- {13BF3FBA-7CD9-4374-83D5-E001E722E3DE}.Release|x64.ActiveCfg = Release|x64
- {13BF3FBA-7CD9-4374-83D5-E001E722E3DE}.Release|x64.Build.0 = Release|x64
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
-EndGlobal
diff --git a/build/msvcX/msvcX.props b/build/msvcX/msvcX.props
deleted file mode 100644
index 2aade2b..0000000
--- a/build/msvcX/msvcX.props
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
- v110_xp
- v120_xp
- v140_xp
-
-
diff --git a/cmake_uninstall.cmake.in b/cmake_uninstall.cmake.in
new file mode 100644
index 0000000..c2d34d4
--- /dev/null
+++ b/cmake_uninstall.cmake.in
@@ -0,0 +1,21 @@
+if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
+ message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
+endif()
+
+file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
+string(REGEX REPLACE "\n" ";" files "${files}")
+foreach(file ${files})
+ message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
+ if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+ exec_program(
+ "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
+ OUTPUT_VARIABLE rm_out
+ RETURN_VALUE rm_retval
+ )
+ if(NOT "${rm_retval}" STREQUAL 0)
+ message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
+ endif()
+ else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+ message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
+ endif()
+endforeach()
diff --git a/config.sh b/config.sh
deleted file mode 100755
index a783c4e..0000000
--- a/config.sh
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/bin/sh
-ERR_EXIT () {
- echo $1; exit 1
-}
-
-cwd="$(cd $(dirname $0); pwd)"
-
-version=''
-clean='no'
-
-config_h="$cwd/src/config.h"
-
-# Parse options
-for opt do
- optarg="${opt#*=}"
- case "$opt" in
- --clean)
- clean='yes'
- ;;
- *)
- ERR_EXIT "Unknown option ... $opt"
- ;;
- esac
-done
-
-# Output config.h
-if [ "$clean" = 'yes' -o ! -d "$cwd/.git" ]; then
- cat > "$config_h" << EOF
-#undef DGMPGDEC_GIT_VERSION
-EOF
-else
- cd "$cwd"
- if [ -n "`git tag`" ]; then
- version="`git describe --tags`"
- echo "$version"
- echo "#define DGMPGDEC_GIT_VERSION \"$version\"" > "$config_h"
- else
- echo "#undef DGMPGDEC_GIT_VERSION" > "$config_h"
- fi
-fi
diff --git a/msvc/D2VSource.sln b/msvc/D2VSource.sln
new file mode 100644
index 0000000..12a3121
--- /dev/null
+++ b/msvc/D2VSource.sln
@@ -0,0 +1,31 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.30204.135
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "D2VSource", "D2VSource.vcxproj", "{BE45DDEC-9C54-4E57-BE8C-3CDE734BEAA6}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {BE45DDEC-9C54-4E57-BE8C-3CDE734BEAA6}.Debug|x64.ActiveCfg = Debug|x64
+ {BE45DDEC-9C54-4E57-BE8C-3CDE734BEAA6}.Debug|x64.Build.0 = Debug|x64
+ {BE45DDEC-9C54-4E57-BE8C-3CDE734BEAA6}.Debug|x86.ActiveCfg = Debug|Win32
+ {BE45DDEC-9C54-4E57-BE8C-3CDE734BEAA6}.Debug|x86.Build.0 = Debug|Win32
+ {BE45DDEC-9C54-4E57-BE8C-3CDE734BEAA6}.Release|x64.ActiveCfg = Release|x64
+ {BE45DDEC-9C54-4E57-BE8C-3CDE734BEAA6}.Release|x64.Build.0 = Release|x64
+ {BE45DDEC-9C54-4E57-BE8C-3CDE734BEAA6}.Release|x86.ActiveCfg = Release|Win32
+ {BE45DDEC-9C54-4E57-BE8C-3CDE734BEAA6}.Release|x86.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {80DFC486-AC15-406C-BBDA-6D722A495010}
+ EndGlobalSection
+EndGlobal
diff --git a/msvc/D2VSource.vcxproj b/msvc/D2VSource.vcxproj
new file mode 100644
index 0000000..3d1ea44
--- /dev/null
+++ b/msvc/D2VSource.vcxproj
@@ -0,0 +1,191 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ 16.0
+ {BE45DDEC-9C54-4E57-BE8C-3CDE734BEAA6}
+ Win32Proj
+ 10.0
+
+
+
+ Application
+ true
+ v142
+
+
+ DynamicLibrary
+ false
+ v142
+
+
+ DynamicLibrary
+ true
+ v142
+
+
+ DynamicLibrary
+ false
+ v142
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+
+
+ false
+ ..\..\AviSynthPlus\avs_core\include;$(IncludePath)
+
+
+ ..\..\AviSynthPlus\avs_core\include;$(IncludePath)
+ false
+
+
+ ..\..\AviSynthPlus\avs_core\include;$(IncludePath)
+
+
+
+ WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)
+ MultiThreadedDebugDLL
+ Level3
+ ProgramDatabase
+ Disabled
+
+
+ MachineX86
+ true
+ Windows
+
+
+
+
+ WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)
+ MultiThreadedDLL
+ Level3
+ ProgramDatabase
+ true
+ AnySuitable
+ true
+ Speed
+ true
+ true
+ Precise
+ stdcpp17
+ true
+
+
+ MachineX86
+ true
+ Windows
+ true
+ true
+ UseLinkTimeCodeGeneration
+
+
+
+
+ true
+ AnySuitable
+ true
+ Speed
+ true
+ true
+ stdcpp17
+ true
+ Precise
+
+
+ true
+
+
+ true
+ UseLinkTimeCodeGeneration
+
+
+
+
+ stdcpp17
+
+
+
+
+
+
+
+
+
+
+ false
+
+
+
+ AdvancedVectorExtensions2
+ AdvancedVectorExtensions2
+ AdvancedVectorExtensions2
+
+
+
+
+
+
+
+
+ false
+
+
+
+
+
+
+ false
+
+
+
+
+
+
+
+ false
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/msvc/D2VSource.vcxproj.filters b/msvc/D2VSource.vcxproj.filters
new file mode 100644
index 0000000..7cad7bd
--- /dev/null
+++ b/msvc/D2VSource.vcxproj.filters
@@ -0,0 +1,98 @@
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
+
+
+ {93995380-89BD-4b04-88EB-625FBE52EBFB}
+ h;hh;hpp;hxx;hm;inl;inc;xsd
+
+
+ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
+ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav
+
+
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+
+
+ Resource Files
+
+
+
\ No newline at end of file
diff --git a/src/AVISynthAPI.cpp b/src/AVISynthAPI.cpp
new file mode 100644
index 0000000..56b652f
--- /dev/null
+++ b/src/AVISynthAPI.cpp
@@ -0,0 +1,656 @@
+/*
+ * Avisynth 2.5 API for MPEG2Dec3
+ *
+ * Changes to fix frame dropping and random frame access are
+ * Copyright (C) 2003-2008 Donald A. Graft
+ *
+ * Copyright (C) 2002-2003 Marc Fauconneau
+ *
+ * based of the intial MPEG2Dec Avisytnh API Copyright (C) Mathias Born - May 2001
+ *
+ * This file is part of DGMPGDec, a free MPEG-2 decoder
+ *
+ * DGMPGDec is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * DGMPGDec is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Make; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "AVISynthAPI.h"
+#include "color_convert.h"
+#include "misc.h"
+#ifndef _WIN32
+#include
+
+#include "win_import_min.h"
+
+#define _MAX_PATH PATH_MAX
+#endif
+
+#define VERSION "D2VSource 1.2.3"
+
+bool PutHintingData(uint8_t* video, uint32_t hint)
+{
+ constexpr uint32_t MAGIC_NUMBER = 0xdeadbeef;
+
+ for (int i = 0; i < 32; ++i) {
+ *video &= ~1;
+ *video++ |= ((MAGIC_NUMBER & (1 << i)) >> i);
+ }
+ for (int i = 0; i < 32; i++) {
+ *video &= ~1;
+ *video++ |= ((hint & (1 << i)) >> i);
+ }
+ return false;
+}
+
+
+static void luminance_filter(uint8_t* luma, const int width, const int height,
+ const int pitch, const uint8_t* table)
+{
+ for (int y = 0; y < height; ++y) {
+ for (int x = 0; x < width; ++x) {
+ luma[x] = table[luma[x]];
+ }
+ luma += pitch;
+ }
+}
+
+
+static void show_info(int n, CMPEG2Decoder& d, PVideoFrame& frame,
+ const VideoInfo& vi, IScriptEnvironment* env)
+{
+ uint32_t raw = std::max(d.FrameList[n].bottom, d.FrameList[n].top);
+ if (raw < d.BadStartingFrames)
+ raw = d.BadStartingFrames;
+
+ uint32_t gop = 0;
+ do {
+ if (raw >= d.GOPList[gop].number)
+ if (raw < d.GOPList[static_cast(gop) + 1].number)
+ break;
+ } while (++gop < d.GOPList.size() - 1);
+
+ const auto& rgop = d.GOPList[gop];
+ const auto& fraw = d.FrameList[raw];
+ const auto& fn = d.FrameList[n];
+
+ int pct = fraw.pct == I_TYPE ? 'I' : fraw.pct == B_TYPE ? 'B' : 'P';
+
+ const char* matrix[8] = {
+ "Forbidden",
+ "ITU-R BT.709",
+ "Unspecified Video",
+ "Reserved",
+ "FCC",
+ "ITU-R BT.470-2 System B, G",
+ "SMPTE 170M",
+ "SMPTE 240M (1987)",
+ };
+
+ if (d.info == 1) {
+ char msg1[1024];
+ sprintf_s(msg1, "%s\n"
+ "---------------------------------------\n"
+ "Source: %s\n"
+ "Frame Rate: %3.6f fps (%u/%u) %s\n"
+ "Field Order: %s\n"
+ "Picture Size: %d x %d\n"
+ "Aspect Ratio: %s\n"
+ "Progr Seq: %s\n"
+ "GOP Number: %u (%u) GOP Pos = %I64d\n"
+ "Closed GOP: %s\n"
+ "Display Frame: %d\n"
+ "Encoded Frame: %d (top) %d (bottom)\n"
+ "Frame Type: %c (%d)\n"
+ "Progr Frame: %s\n"
+ "Colorimetry: %s (%d)\n"
+ "Quants: %d/%d/%d (avg/min/max)\n",
+ VERSION,
+ d.Infilename[rgop.file].c_str(),
+ double(d.VF_FrameRate_Num) / double(d.VF_FrameRate_Den),
+ d.VF_FrameRate_Num,
+ d.VF_FrameRate_Den,
+ (d.VF_FrameRate == 25000 || d.VF_FrameRate == 50000) ? "(PAL)" :
+ d.VF_FrameRate == 29970 ? "(NTSC)" : "",
+ d.Field_Order == 1 ? "Top Field First" : "Bottom Field First",
+ d.getLumaWidth(), d.getLumaHeight(),
+ d.Aspect_Ratio,
+ rgop.progressive ? "True" : "False",
+#ifdef _WIN32
+ gop, rgop.number, rgop.position,
+#else
+ gop, rgop.number, static_cast(rgop.position),
+#endif
+ rgop.closed ? "True" : "False",
+ n,
+ fn.top, fn.bottom,
+ pct, raw,
+ fraw.pf ? "True" : "False",
+ matrix[rgop.matrix], rgop.matrix,
+ d.avgquant, d.minquant, d.maxquant);
+ env->ApplyMessage(&frame, vi, msg1, 150, 0xdfffbf, 0x0, 0x0);
+
+ }
+ else if (d.info == 2) {
+ dprintf(const_cast("MPEG2DecPlus: %s\n"), VERSION);
+ dprintf(const_cast("MPEG2DecPlus: Source: %s\n"), d.Infilename[rgop.file].c_str());
+ dprintf(const_cast("MPEG2DecPlus: Frame Rate: %3.6f fps (%u/%u) %s\n"),
+ double(d.VF_FrameRate_Num) / double(d.VF_FrameRate_Den),
+ d.VF_FrameRate_Num, d.VF_FrameRate_Den,
+ (d.VF_FrameRate == 25000 || d.VF_FrameRate == 50000) ? "(PAL)" : d.VF_FrameRate == 29970 ? "(NTSC)" : "");
+ dprintf(const_cast("MPEG2DecPlus: Field Order: %s\n"), d.Field_Order == 1 ? "Top Field First" : "Bottom Field First");
+ dprintf(const_cast("MPEG2DecPlus: Picture Size: %d x %d\n"), d.getLumaWidth(), d.getLumaHeight());
+ dprintf(const_cast("MPEG2DecPlus: Aspect Ratio: %s\n"), d.Aspect_Ratio);
+ dprintf(const_cast("MPEG2DecPlus: Progressive Seq: %s\n"), rgop.progressive ? "True" : "False");
+ dprintf(const_cast("MPEG2DecPlus: GOP Number: %d (%d) GOP Pos = %I64d\n"), gop, rgop.number, rgop.position);
+ dprintf(const_cast("MPEG2DecPlus: Closed GOP: %s\n"), rgop.closed ? "True" : "False");
+ dprintf(const_cast("MPEG2DecPlus: Display Frame: %d\n"), n);
+ dprintf(const_cast("MPEG2DecPlus: Encoded Frame: %d (top) %d (bottom)\n"), fn.top, fn.bottom);
+ dprintf(const_cast("MPEG2DecPlus: Frame Type: %c (%d)\n"), pct, raw);
+ dprintf(const_cast("MPEG2DecPlus: Progressive Frame: %s\n"), fraw.pf ? "True" : "False");
+ dprintf(const_cast("MPEG2DecPlus: Colorimetry: %s (%d)\n"), matrix[rgop.matrix], rgop.matrix);
+ dprintf(const_cast("MPEG2DecPlus: Quants: %d/%d/%d (avg/min/max)\n"), d.avgquant, d.minquant, d.maxquant);
+
+ }
+ else if (d.info == 3) {
+ constexpr uint32_t PROGRESSIVE = 0x00000001;
+ constexpr int COLORIMETRY_SHIFT = 2;
+
+ uint32_t hint = 0;
+ if (fraw.pf == 1) hint |= PROGRESSIVE;
+ hint |= ((rgop.matrix & 7) << COLORIMETRY_SHIFT);
+ PutHintingData(frame->GetWritePtr(PLANAR_Y), hint);
+ }
+}
+
+
+D2VSource::D2VSource(const char* d2v, int idct, bool showQ,
+ int _info, int _upConv, bool _i420, int iCC, int _rff,
+ IScriptEnvironment* env) :
+ bufY(nullptr), bufU(nullptr), bufV(nullptr), decoder(nullptr)
+{
+ if (_rff < -1 || _rff > 2)
+ env->ThrowError("D2VSource: rff must be set to -1, 0, 1 or 2!");
+
+ if (iCC != -1 && iCC != 0 && iCC != 1)
+ env->ThrowError("D2VSource: iCC must be set to -1, 0, or 1!");
+
+ if (_upConv != 0 && _upConv != 1 && _upConv != 2)
+ env->ThrowError("D2VSource: upConv must be set to 0, 1, or 2!");
+
+ if (idct > 7)
+ env->ThrowError("D2VSource: iDCT invalid (1:MMX,2:SSEMMX,3:SSE2,4:FPU,5:REF,6:Skal's,7:Simple)");
+
+ FILE* f;
+#ifdef _WIN32
+ fopen_s(&f, d2v, "r");
+#else
+ f = fopen(d2v, "r");
+#endif
+ if (f == nullptr)
+ env->ThrowError("D2VSource: unable to load D2V file \"%s\" ", d2v);
+
+ try {
+ decoder = new CMPEG2Decoder(f, d2v, idct, iCC, _upConv, _info, showQ, _i420, _rff, env->GetCPUFlags());
+ }
+ catch (std::runtime_error& e) {
+ if (f) fclose(f);
+ env->ThrowError("D2VSource: %s", e.what());
+ }
+
+ env->AtExit([](void* p, IScriptEnvironment*) { delete reinterpret_cast(p); p = nullptr; }, decoder);
+ auto& d = *decoder;
+
+ int chroma_format = d.getChromaFormat();
+
+ memset(&vi, 0, sizeof(vi));
+ vi.width = d.Clip_Width;
+ vi.height = d.Clip_Height;
+ if (_upConv == 2) vi.pixel_type = VideoInfo::CS_YV24;
+ else if (chroma_format == 2 || _upConv == 1) vi.pixel_type = VideoInfo::CS_YV16;
+ else if (d.i420 == true) vi.pixel_type = VideoInfo::CS_I420;
+ else vi.pixel_type = VideoInfo::CS_YV12;
+
+ vi.SetFPS(d.VF_FrameRate_Num, d.VF_FrameRate_Den);
+ vi.num_frames = static_cast(d.FrameList.size());
+ vi.SetFieldBased(false);
+
+ if (_upConv == 2) {
+ auto free_buf = [](void* p, IScriptEnvironment* e) {
+ _aligned_free(p);
+ p = nullptr;
+ };
+ size_t ysize = ((static_cast(vi.width) + 31) & ~31) * (static_cast(vi.height) + 1);
+ size_t uvsize = ((static_cast(d.getChromaWidth()) + 15) & ~15) * (static_cast(vi.height) + 1);
+ void* ptr = _aligned_malloc(ysize + 2 * uvsize, 32);
+ if (!ptr) {
+ env->ThrowError("D2VSource: malloc failure (bufY, bufU, bufV)!");
+ }
+ env->AtExit(free_buf, ptr);
+ bufY = reinterpret_cast(ptr);
+ bufU = bufY + ysize;
+ bufV = bufU + uvsize;
+ }
+
+ luminanceFlag = (d.lumGamma != 0 || d.lumOffset != 0);
+ if (luminanceFlag) {
+ int lg = d.lumGamma;
+ int lo = d.lumOffset;
+ for (int i = 0; i < 256; ++i) {
+ double value = 255.0 * pow(i / 255.0, pow(2.0, -lg / 128.0)) + lo + 0.5;
+
+ if (value < 0)
+ luminanceTable[i] = 0;
+ else if (value > 255.0)
+ luminanceTable[i] = 255;
+ else
+ luminanceTable[i] = static_cast(value);
+ }
+ }
+
+ has_at_least_v8 = true;
+ try { env->CheckVersion(8); }
+ catch (const AvisynthError&) { has_at_least_v8 = false; }
+
+ std::vector ar;
+ ar.reserve(2);
+ std::stringstream str(d.Aspect_Ratio);
+ int n;
+ char ch;
+ while (str >> n)
+ {
+ if (str >> ch)
+ ar.push_back(n);
+ else
+ ar.push_back(n);
+ }
+
+ const double sar = ar[0] / static_cast(ar[1]) / (static_cast(vi.width) / vi.height);
+ double decimal_part = sar - static_cast(sar);
+
+ std::valarray vec_1{ double(static_cast(sar)), 1 }, vec_2{ 1,0 }, temporary;
+
+ while (decimal_part > 0.005)
+ {
+ const double new_number = 1 / decimal_part;
+ const double whole_part = static_cast(new_number);
+
+ temporary = vec_1;
+ vec_1 = whole_part * vec_1 + vec_2;
+ vec_2 = temporary;
+
+ decimal_part = new_number - whole_part;
+ }
+
+ env->SetVar(env->Sprintf("%s", "FFSAR_NUM"), static_cast(vec_1[0]));
+ env->SetVar(env->Sprintf("%s", "FFSAR_DEN"), static_cast(vec_1[1]));
+
+ if (vec_1[0] > 0 && vec_1[1] > 0)
+ env->SetVar(env->Sprintf("%s", "FFSAR"), sar);
+}
+
+
+unsigned int gcd(unsigned int a, unsigned int b)
+{
+ if (b == 0)
+ return a;
+ return gcd(b, a % b);
+}
+
+
+bool __stdcall D2VSource::GetParity(int)
+{
+ return decoder->Field_Order == 1;
+}
+
+
+PVideoFrame __stdcall D2VSource::GetFrame(int n, IScriptEnvironment* env)
+{
+ auto& d = *decoder;
+ PVideoFrame frame = env->NewVideoFrame(vi, 32);
+ YV12PICT out = (d.upConv != 2) ? YV12PICT(frame) :
+ YV12PICT(bufY, bufU, bufV, vi.width, d.getChromaWidth(), vi.height);
+
+ d.Decode(n, out);
+
+ if (luminanceFlag)
+ luminance_filter(out.y, out.ywidth, out.yheight, out.ypitch, luminanceTable);
+
+ if (d.upConv == 2) { // convert 4:2:2 (planar) to 4:4:4 (planar)
+ env->BitBlt(frame->GetWritePtr(PLANAR_Y), frame->GetPitch(PLANAR_Y),
+ bufY, out.ypitch, vi.width, vi.height);
+ conv422to444(out.u, frame->GetWritePtr(PLANAR_U), out.uvpitch,
+ frame->GetPitch(PLANAR_U), vi.width, vi.height);
+ conv422to444(out.v, frame->GetWritePtr(PLANAR_V), out.uvpitch,
+ frame->GetPitch(PLANAR_V), vi.width, vi.height);
+ }
+
+ if (d.info != 0)
+ show_info(n, d, frame, vi, env);
+
+ if (has_at_least_v8)
+ {
+ AVSMap* props = env->getFramePropsRW(frame);
+
+ /* Sample duration */
+ env->propSetInt(props, "_DurationNum", d.VF_FrameRate_Den, 0);
+ env->propSetInt(props, "_DurationDen", d.VF_FrameRate_Num, 0);
+ /* BFF or TFF */
+ uint32_t raw = std::max(d.FrameList[n].bottom, d.FrameList[n].top);
+ if (raw < d.BadStartingFrames)
+ raw = d.BadStartingFrames;
+
+ uint32_t gop = 0;
+ do {
+ if (raw >= d.GOPList[gop].number)
+ if (raw < d.GOPList[static_cast(gop) + 1].number)
+ break;
+ } while (++gop < d.GOPList.size() - 1);
+
+ const auto& rgop = d.GOPList[gop];
+
+ int field_based = 0;
+ if (!rgop.progressive)
+ field_based = d.Field_Order == 1 ? 2 : 1;
+ env->propSetInt(props, "_FieldBased", field_based, 0);
+ env->propSetInt(props, "_FieldOrder", d.Field_Order, 0);
+ /* AR */
+ int64_t dar[2];
+ static_cast(sscanf(d.Aspect_Ratio, "%lld:%lld", &dar[0], &dar[1]));
+ env->propSetIntArray(props, "_AspectRatio", dar, 2);
+
+ auto par_num = 0;
+ auto par_den = 0;
+ if (d.D2V_Height > 576)
+ {
+ // HD. Use PAR 1:1.
+ par_num = 1;
+ par_den = 1;
+ }
+ else
+ {
+ // SD. We have 4 cases.
+ if (d.aspect_ratio_information == 2 && d.D2V_Height == 480)
+ {
+ par_num = 10;
+ par_den = 11;
+ }
+ else if (d.aspect_ratio_information == 2 && d.D2V_Height == 576)
+ {
+ par_num = 12;
+ par_den = 11;
+ }
+ else if (d.aspect_ratio_information == 3 && d.D2V_Height == 480)
+ {
+ par_num = 40;
+ par_den = 33;
+ }
+ else if (d.aspect_ratio_information == 3 && d.D2V_Height == 576)
+ {
+ par_num = 16;
+ par_den = 11;
+ }
+ else
+ {
+ // Not a standard SD case. Calculate the PAR.
+ switch (d.aspect_ratio_information)
+ {
+ case 0:
+ par_num = 0;
+ par_den = 0;
+ break;
+ case 1:
+ par_num = 1;
+ par_den = 1;
+ break;
+ case 2:
+ par_num = 4 * d.D2V_Height;
+ par_den = 3 * d.D2V_Width;
+ break;
+ case 3:
+ par_num = 16 * d.D2V_Height;
+ par_den = 9 * d.D2V_Width;
+ break;
+ case 4:
+ par_num = 221 * d.D2V_Height;
+ par_den = 100 * d.D2V_Width;
+ break;
+ default:
+ par_num = 0;
+ par_den = 0;
+ break;
+ }
+ int divisor = gcd(par_num, par_den);
+ par_num /= divisor;
+ par_den /= divisor;
+ }
+ }
+ env->propSetInt(props, "_SARNum", par_num, 0);
+ env->propSetInt(props, "_SARDen", par_den, 0);
+ /* GOP */
+ int64_t gop_number[2] = { gop, rgop.number };
+ env->propSetIntArray(props, "_GOPNumber", gop_number, 2);
+ env->propSetInt(props, "_GOPPosition", rgop.position, 0);
+
+ int closed_gop = rgop.closed ? 1 : 0;
+ env->propSetInt(props, "_GOPClosed", closed_gop, 0);
+ /* Encoded frame */
+ const auto& fn = d.FrameList[n];
+
+ env->propSetInt(props, "_EncodedFrameTop", fn.top, 0);
+ env->propSetInt(props, "_EncodedFrameBottom", fn.bottom, 0);
+ /* Picture type */
+ const auto& fraw = d.FrameList[raw];
+ const char* pct = fraw.pct == I_TYPE ? "I" : fraw.pct == B_TYPE ? "B" : "P";
+
+ env->propSetData(props, "_PictType", pct, 1, 0);
+ /* Matrix */
+ env->propSetInt(props, "_Matrix", rgop.matrix, 0);
+ /* Quants */
+ d.has_prop = true;
+ env->propSetInt(props, "_QuantsAverage", d.avgquant, 0);
+ env->propSetInt(props, "_QuantsMin", d.minquant, 0);
+ env->propSetInt(props, "_QuantsMax", d.maxquant, 0);
+ // Pulldown stuff.
+ env->propSetInt(props, "_FieldOperation", d.FO_Flag, 0);
+ if (d.FO_Flag == FO_RAW)
+ {
+ // Ignore pulldown.
+ env->propSetInt(props, "_TFF", (fn.type & 2) == 2, 0);
+ env->propSetInt(props, "_RFF", fn.type & 1, 0);
+ history[0] = history[1];
+ history[1] = history[2];
+ history[2] = history[3];
+ history[3] = fn.type & 1;
+ if ((history[0] == 0 && history[1] == 1 && history[2] == 0 && history[3] == 1) ||
+ (history[0] == 1 && history[1] == 0 && history[2] == 1 && history[3] == 0))
+ env->propSetInt(props, "_Film", 1, 0);
+ else
+ env->propSetInt(props, "_Film", 0, 0);
+ }
+ else
+ {
+ // Honor pulldown or force film.
+ env->propSetInt(props, "_TFF", -1, 0);
+ env->propSetInt(props, "_RFF", fn.top != fn.bottom, 0);
+ history[0] = history[1];
+ history[1] = history[2];
+ history[2] = history[3];
+ history[3] = history[4];
+ history[4] = fn.top != fn.bottom;
+ if ((history[0] == 1 && history[1] == 1 && history[2] == 0 && history[3] == 0 && history[4] == 0) ||
+ (history[0] == 0 && history[1] == 1 && history[2] == 1 && history[3] == 0 && history[4] == 0) ||
+ (history[0] == 0 && history[1] == 0 && history[2] == 1 && history[3] == 1 && history[4] == 0) ||
+ (history[0] == 0 && history[1] == 0 && history[2] == 0 && history[3] == 1 && history[4] == 1) ||
+ (history[0] == 1 && history[1] == 0 && history[2] == 0 && history[3] == 0 && history[4] == 1))
+ env->propSetInt(props, "_Film", 1, 0);
+ else
+ env->propSetInt(props, "_Film", 0, 0);
+ }
+ env->propSetInt(props, "_ProgressiveFrame", fraw.pf, 0);
+ env->propSetInt(props, "_ChromaLocation", d.mpeg_type == IS_MPEG2 ? 0 : 1, 0);
+ env->propSetFloat(props, "_AbsoluteTime", (static_cast(d.VF_FrameRate_Den) * n) / d.VF_FrameRate_Num, 0);
+ }
+
+ return frame;
+}
+
+
+static void set_user_default(FILE* def, char* d2v, int& idct, bool& showq,
+ int& info, int upcnv, bool& i420, int& icc)
+{
+ char buf[512];
+ auto load_str = [&buf](char* var, const char* name, int len) {
+ if (strncmp(buf, name, len) == 0) {
+ std::vector tmp(512, 0);
+ sscanf_s(buf, name, tmp.data());
+ tmp.erase(std::remove(tmp.begin(), tmp.end(), '"'), tmp.end());
+ strncpy_s(var, tmp.size() + 1, tmp.data(), tmp.size());
+ }
+ };
+ auto load_int = [&buf](int& var, const char* name, int len) {
+ if (strncmp(buf, name, len) == 0) {
+ sscanf_s(buf, name, &var);
+ }
+ };
+ auto load_bool = [&buf](bool& var, const char* name, int len) {
+ if (strncmp(buf, name, len) == 0) {
+ char tmp[16];
+ sscanf_s(buf, name, &tmp);
+ var = tmp[0] == 't';
+ }
+ };
+ auto load_bint = [&buf](int& var, const char* name, int len) {
+ if (strncmp(buf, name, len) == 0) {
+ char tmp[16];
+ sscanf_s(buf, name, &tmp);
+ var = tmp[0] == 't' ? 1 : 0;
+ }
+ };
+
+ while (fgets(buf, 511, def) != 0) {
+ load_str(d2v, "d2v=%s", 4);
+ load_int(idct, "idct=%d", 5);
+ load_bool(showq, "showQ=%s", 6);
+ load_int(info, "info=%d", 5);
+ load_int(upcnv, "upConv=%d", 7);
+ load_bool(i420, "i420=%s", 5);
+ load_bint(icc, "iCC=%s", 4);
+ }
+}
+
+
+AVSValue __cdecl D2VSource::create(AVSValue args, void*, IScriptEnvironment* env)
+{
+ char d2v[512];
+ int idct = -1;
+
+ int iCC = args[6].IsBool() ? (args[6].AsBool() ? 1 : 0) : -1;
+
+ bool showQ = false;
+ int info = 0;
+ int upConv = 0;
+ bool i420 = false;
+
+ FILE* def;
+#ifdef _WIN32
+ fopen_s(&def, "MPEG2DecPlus.def", "r");
+#else
+ def = fopen("MPEG2DecPlus.def", "r");
+#endif
+ if (def != nullptr) {
+ set_user_default(def, d2v, idct, showQ, info, upConv, i420, iCC);
+ fclose(def);
+ }
+
+ // check for uninitialised strings
+ if (strlen(d2v) >= _MAX_PATH) d2v[0] = 0;
+
+ D2VSource* dec = new D2VSource(
+ args[0].AsString(d2v),
+ args[1].AsInt(idct),
+ args[2].AsBool(showQ),
+ args[3].AsInt(info),
+ args[4].AsInt(upConv),
+ args[5].AsBool(i420),
+ iCC,
+ args[8].AsInt(-1),
+ env);
+
+ if (!args[7].AsBool(false))
+ {
+ // Only bother invoking crop if we have to.
+ auto& d = *dec->decoder;
+ if (d.Clip_Top || d.Clip_Bottom || d.Clip_Left || d.Clip_Right ||
+ // This is cheap but it works. The intent is to allow the
+ // display size to be different from the encoded size, while
+ // not requiring massive revisions to the code. So we detect the
+ // difference and crop it off.
+ d.vertical_size != d.Clip_Height || d.horizontal_size != d.Clip_Width ||
+ d.vertical_size == 1088)
+ {
+ int vertical;
+ // Special case for 1088 to 1080 as directed by DGIndex.
+ if (d.vertical_size == 1088 && d.D2V_Height == 1080)
+ vertical = 1080;
+ else
+ vertical = d.vertical_size;
+ AVSValue CropArgs[] = {
+ dec,
+ d.Clip_Left,
+ d.Clip_Top,
+ -(d.Clip_Right + (d.Clip_Width - d.horizontal_size)),
+ -(d.Clip_Bottom + (d.Clip_Height - vertical)),
+ true
+ };
+
+ return env->Invoke("crop", AVSValue(CropArgs, 6));
+ }
+ }
+
+ return dec;
+}
+
+const AVS_Linkage* AVS_linkage = nullptr;
+
+extern "C" __declspec(dllexport) const char* __stdcall
+AvisynthPluginInit3(IScriptEnvironment * env, const AVS_Linkage* const vectors)
+{
+ AVS_linkage = vectors;
+
+ const char* msargs =
+ "[d2v]s"
+ "[idct]i"
+ "[showQ]b"
+ "[info]i"
+ "[upConv]i"
+ "[i420]b"
+ "[iCC]b"
+ "[nocrop]b"
+ "[rff]i";
+
+ env->AddFunction("D2VSource", msargs, D2VSource::create, nullptr);
+
+ return VERSION;
+}
+
diff --git a/src/AVISynthAPI.h b/src/AVISynthAPI.h
new file mode 100644
index 0000000..518ad69
--- /dev/null
+++ b/src/AVISynthAPI.h
@@ -0,0 +1,56 @@
+/*
+ * Avisynth 2.5 API for MPEG2Dec3
+ *
+ * Copyright (C) 2002-2003 Marc Fauconneau
+ *
+ * based of the intial MPEG2Dec Avisytnh API Copyright (C) Mathias Born - May 2001
+ *
+ * This file is part of MPEG2Dec3, a free MPEG-2 decoder
+ *
+ * MPEG2Dec3 is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * MPEG2Dec3 is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Make; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#ifndef MPEG2DECPLUS_AVS_API_H
+#define MPEG2DECPLUS_AVS_API_H
+
+#include
+
+#include "avisynth.h"
+#include "MPEG2Decoder.h"
+
+
+class D2VSource : public IClip {
+ VideoInfo vi;
+ //int _PP_MODE;
+ uint8_t* bufY, * bufU, * bufV; // for 4:2:2 input support
+ CMPEG2Decoder* decoder;
+ bool luminanceFlag;
+ uint8_t luminanceTable[256];
+ bool has_at_least_v8;
+ int history[5];
+
+public:
+ D2VSource(const char* d2v, int idct, bool showQ, int _info, int _upConv, bool _i420, int iCC, int _rff, IScriptEnvironment* env);
+ ~D2VSource() {}
+ PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
+ bool __stdcall GetParity(int n);
+ void __stdcall GetAudio(void* buf, int64_t start, int64_t count, IScriptEnvironment* env) {};
+ const VideoInfo& __stdcall GetVideoInfo() { return vi; }
+ int __stdcall SetCacheHints(int hints, int) { return hints == CACHE_GET_MTMODE ? MT_SERIALIZED : 0; };
+ static AVSValue __cdecl create(AVSValue args, void*, IScriptEnvironment* env);
+};
+
+#endif
diff --git a/src/dgdecode/MPEG2Decoder.cpp b/src/MPEG2Decoder.cpp
similarity index 57%
rename from src/dgdecode/MPEG2Decoder.cpp
rename to src/MPEG2Decoder.cpp
index f8f90b9..d5a13a6 100644
--- a/src/dgdecode/MPEG2Decoder.cpp
+++ b/src/MPEG2Decoder.cpp
@@ -20,25 +20,25 @@
*
*/
-/*
- lots of code modified for YV12 / MPEG2Dec3 - MarcFD
-*/
+ /*
+ lots of code modified for YV12 / MPEG2Dec3 - MarcFD
+ */
#include
-#include
+#include
#include
+#include
+
#include "MPEG2Decoder.h"
+#include "idct.h"
#include "mc.h"
#include "misc.h"
-#include "idct.h"
-#include "shlwapi.h"
-static const int ChromaFormat[4] = {
+static constexpr int ChromaFormat[4] = {
0, 6, 8, 12
};
-
static void validate(bool cond, const char* msg)
{
if (cond) throw std::runtime_error(msg);
@@ -46,12 +46,7 @@ static void validate(bool cond, const char* msg)
// Open function modified by Donald Graft as part of fix for dropped frames and random frame access.
// change function to constructor - chikuzen.
-CMPEG2Decoder::CMPEG2Decoder(FILE* d2vf, const char* path, int _idct, int icc,
- int upconv, int _info, bool showq, bool _i420) :
- VF_FrameRate(0),
- VF_FrameRate_Num(0),
- VF_FrameRate_Den(0),
- prev_frame(0xfffffffe),
+CMPEG2Decoder::CMPEG2Decoder(FILE* d2vf, const char* path, int _idct, int icc, int upconv, int _info, bool showq, bool _i420, int _rff, int _cpu_flags) :
Rdmax(nullptr),
CurrentBfr(0),
NextBfr(0),
@@ -71,11 +66,16 @@ CMPEG2Decoder::CMPEG2Decoder(FILE* d2vf, const char* path, int _idct, int icc,
quantizer_scale(0),
auxFrame1(nullptr),
auxFrame2(nullptr),
- upConv(upconv),
+ prev_frame(0xfffffffe),
+ VF_FrameRate(0),
+ VF_FrameRate_Num(0),
+ VF_FrameRate_Den(0),
+ iCC(icc),
showQ(showq),
+ upConv(upconv),
+ i420(_i420),
info(_info),
- iCC(icc),
- i420(_i420)
+ cpu_flags(_cpu_flags)
{
memset(intra_quantizer_matrix, 0, sizeof(intra_quantizer_matrix));
memset(non_intra_quantizer_matrix, 0, sizeof(non_intra_quantizer_matrix));
@@ -93,45 +93,48 @@ CMPEG2Decoder::CMPEG2Decoder(FILE* d2vf, const char* path, int _idct, int icc,
validate(fgets(buf, 2047, d2vf) == nullptr, "Invalid D2V file, it's empty!");
validate(strstr(buf, "DGIndexProjectFile") == nullptr,
- "The input file is not a D2V project file.");
+ "The input file is not a D2V project file.");
validate(strncmp(buf, "DGIndexProjectFile16", 20) != 0,
- "DGIndex/MPEG2DecPlus mismatch. You are picking up\n"
- "a version of MPEG2DecPlus, possibly from your plugins directory,\n"
- "that does not match the version of DGIndex used to make the D2V\n"
- "file. Search your hard disk for all copies of MPEG2DecPlus.dll\n"
- "and delete or rename all of them except for the one that\n"
- "has the same version number as the DGIndex.exe that was used\n"
- "to make the D2V file.");
+ "DGIndex/MPEG2DecPlus mismatch. You are picking up\n"
+ "a version of MPEG2DecPlus, possibly from your plugins directory,\n"
+ "that does not match the version of DGIndex used to make the D2V\n"
+ "file. Search your hard disk for all copies of MPEG2DecPlus.dll\n"
+ "and delete or rename all of them except for the one that\n"
+ "has the same version number as the DGIndex.exe that was used\n"
+ "to make the D2V file.");
create_file_lists(d2vf, path, buf);
- fscanf(d2vf, "\nStream_Type=%d\n", &SystemStream_Flag);
+ fscanf_s(d2vf, "\nStream_Type=%d\n", &SystemStream_Flag);
if (SystemStream_Flag == 2) {
- fscanf(d2vf, "MPEG2_Transport_PID=%x,%x,%x\n",
- &MPEG2_Transport_VideoPID, &MPEG2_Transport_AudioPID, &MPEG2_Transport_PCRPID);
- fscanf(d2vf, "Transport_Packet_Size=%d\n", &TransportPacketSize);
+ fscanf_s(d2vf, "MPEG2_Transport_PID=%x,%x,%x\n",
+ &MPEG2_Transport_VideoPID, &MPEG2_Transport_AudioPID, &MPEG2_Transport_PCRPID);
+ fscanf_s(d2vf, "Transport_Packet_Size=%d\n", &TransportPacketSize);
}
- fscanf(d2vf, "MPEG_Type=%d\n", &mpeg_type);
+ fscanf_s(d2vf, "MPEG_Type=%d\n", &mpeg_type);
int idct;
- fscanf(d2vf, "iDCT_Algorithm=%d\n", &idct);
+ fscanf_s(d2vf, "iDCT_Algorithm=%d\n", &idct);
if (_idct > 0) {
idct = _idct;
}
setIDCT(idct);
- fscanf(d2vf, "YUVRGB_Scale=%d\n", &i);
+ fscanf_s(d2vf, "YUVRGB_Scale=%d\n", &i);
- fscanf(d2vf, "Luminance_Filter=%d,%d\n", &lumGamma, &lumOffset);
+ fscanf_s(d2vf, "Luminance_Filter=%d,%d\n", &lumGamma, &lumOffset);
- fscanf(d2vf, "Clipping=%d,%d,%d,%d\n",
+ fscanf_s(d2vf, "Clipping=%d,%d,%d,%d\n",
&Clip_Left, &Clip_Right, &Clip_Top, &Clip_Bottom);
- fscanf(d2vf, "Aspect_Ratio=%s\n", Aspect_Ratio);
- fscanf(d2vf, "Picture_Size=%dx%d\n", &D2V_Width, &D2V_Height);
- fscanf(d2vf, "Field_Operation=%d\n", &FO_Flag);
- fscanf(d2vf, "Frame_Rate=%d (%u/%u)\n", &(VF_FrameRate), &(VF_FrameRate_Num), &(VF_FrameRate_Den));
- fscanf(d2vf, "Location=%d,%X,%d,%X\n", &i, &j, &i, &j);
+ fscanf_s(d2vf, "Aspect_Ratio=%s\n", Aspect_Ratio, static_cast(sizeof(Aspect_Ratio)));
+ fscanf_s(d2vf, "Picture_Size=%dx%d\n", &D2V_Width, &D2V_Height);
+ fscanf_s(d2vf, "Field_Operation=%d\n", &FO_Flag);
+ fscanf_s(d2vf, "Frame_Rate=%d (%u/%u)\n", &(VF_FrameRate), &(VF_FrameRate_Num), &(VF_FrameRate_Den));
+ fscanf_s(d2vf, "Location=%d,%X,%d,%X\n", &i, &j, &i, &j);
+
+ if (_rff > -1)
+ FO_Flag = _rff;
create_gop_and_frame_lists(d2vf, buf);
fclose(d2vf);
@@ -150,15 +153,18 @@ void CMPEG2Decoder::setIDCT(int idct)
if (idct == IDCT_REF) {
prefetchTables = prefetch_ref;
idctFunction = idct_ref_sse3;
- } else if (idct == IDCT_LLM_FLOAT) {
- if (has_avx2()) {
+ }
+ else if (idct == IDCT_LLM_FLOAT) {
+ if (!!(cpu_flags & CPUF_AVX2)) {
prefetchTables = prefetch_llm_float_avx2;
idctFunction = idct_llm_float_avx2;
- } else {
+ }
+ else {
prefetchTables = prefetch_llm_float_sse2;
idctFunction = idct_llm_float_sse2;
}
- } else {
+ }
+ else {
prefetchTables = prefetch_ap922;
idctFunction = idct_ap922_sse2;
}
@@ -173,13 +179,13 @@ void CMPEG2Decoder::set_clip_properties()
do {
validate(Fault_Flag == OUT_OF_BITS,
- "Could not find a sequence header in the input stream.");
+ "Could not find a sequence header in the input stream.");
Next_Start_Code();
} while (Get_Bits(32) != SEQUENCE_HEADER_CODE);
Sequence_Header();
validate(chroma_format == CHROMA444,
- "currently unsupported input color format (4:4:4)");
+ "currently unsupported input color format (4:4:4)");
mb_width = (horizontal_size + 15) / 16;
mb_height = progressive_sequence ? (vertical_size + 15) / 16 : 2 * ((vertical_size + 31) / 32);
@@ -196,38 +202,43 @@ void CMPEG2Decoder::set_clip_properties()
Clip_Height = Coded_Picture_Height;
}
-
void CMPEG2Decoder::create_file_lists(FILE* d2vf, const char* path, char* buf)
{
int file_limit;
- fscanf(d2vf, "%d\n", &file_limit);
+ fscanf_s(d2vf, "%d\n", &file_limit);
Infile.reserve(file_limit);
Infilename.reserve(file_limit);
while (file_limit-- > 0) {
fgets(buf, 2047, d2vf);
- auto temp = std::string(buf);
+ std::string temp{ std::string(buf) };
temp.pop_back(); // Strip newline.
- if (PathIsRelativeA(temp.c_str())) {
- std::string d2v_stem;
+ if (temp.find('\r') != std::string::npos) {
+ temp.pop_back(); // remove further unwanted char CR...
+ }
- if (PathIsRelativeA(path)) {
- GetCurrentDirectoryA(_MAX_PATH, buf);
- d2v_stem += buf;
- if (d2v_stem.back() != '\\') d2v_stem.push_back('\\');
- }
- d2v_stem += path;
+ const std::filesystem::path p(temp);
- while (d2v_stem.back() != '\\') d2v_stem.pop_back();
- d2v_stem += temp;
- PathCanonicalizeA(buf, d2v_stem.c_str());
- int in = _open(buf, _O_RDONLY | _O_BINARY);
+ if (p.is_relative()) {
+ const std::string d2v_stem{ std::filesystem::canonical(std::filesystem::path(path).parent_path().generic_string() + ((std::filesystem::path(path).has_parent_path()) ? "/" : "") + p.generic_string()).generic_string() };
+#ifdef _WIN32
+ int in;
+ _sopen_s(&in, d2v_stem.c_str(), _O_RDONLY | _O_BINARY, _SH_DENYWR, 0);
+#else
+ int in{ open(d2v_stem.c_str(), O_RDONLY) };
+#endif
validate(in == -1, "Could not open one of the input files.");
Infile.emplace_back(in);
- Infilename.emplace_back(buf);
- } else {
- int in = _open(temp.c_str(), _O_RDONLY | _O_BINARY);
+ Infilename.emplace_back(d2v_stem);
+ }
+ else {
+#ifdef _WIN32
+ int in;
+ _sopen_s(&in, temp.c_str(), _O_RDONLY | _O_BINARY, _SH_DENYWR, 0);
+#else
+ int in{ open(temp.c_str(), O_RDONLY) };
+#endif
validate(in == -1, "Could not open one of the input files.");
Infile.emplace_back(in);
Infilename.emplace_back(temp);
@@ -235,45 +246,44 @@ void CMPEG2Decoder::create_file_lists(FILE* d2vf, const char* path, char* buf)
}
}
-
void CMPEG2Decoder::create_gop_and_frame_lists(FILE* d2vf, char* buf)
{
uint32_t type, tff, rff, film, ntsc, top, bottom, mapping;
int repeat_on, repeat_off, repeat_init;
ntsc = film = top = bottom = mapping = repeat_on = repeat_off = repeat_init = 0;
HaveRFFs = false;
-
+
// These start with sizes of 1000000 (the old fixed default). If it
// turns out that that is too small, the memory spaces are enlarged
// 500000 at a time using realloc. -- tritical May 16, 2005
DirectAccess.reserve(1000000);
FrameList.resize(1000000);
GOPList.reserve(200000);
-
+
fgets(buf, 2047, d2vf);
char* buf_p = buf;
-
+
while (true) {
- sscanf(buf_p, "%x", &type);
+ sscanf_s(buf_p, "%x", &type);
if (type == 0xff)
break;
if (type & 0x800) { // New I-frame line start.
int matrix, file, ic, vob_id, cell_id;
while (*buf_p++ != ' ');
- sscanf(buf_p, "%d", &matrix);
+ sscanf_s(buf_p, "%d", &matrix);
while (*buf_p++ != ' ');
- sscanf(buf_p, "%d", &file);
+ sscanf_s(buf_p, "%d", &file);
while (*buf_p++ != ' ');
int64_t position = _atoi64(buf_p);
while (*buf_p++ != ' ');
- sscanf(buf_p, "%d", &ic);
+ sscanf_s(buf_p, "%d", &ic);
while (*buf_p++ != ' ');
- sscanf(buf_p, "%d %d", &vob_id, &cell_id);
+ sscanf_s(buf_p, "%d %d", &vob_id, &cell_id);
while (*buf_p++ != ' ');
while (*buf_p++ != ' ');
GOPList.emplace_back(film, matrix, file, position, ic, type);
-
- sscanf(buf_p, "%x", &type);
+
+ sscanf_s(buf_p, "%x", &type);
}
tff = (type & 0x2) >> 1;
if (FO_Flag == FO_RAW)
@@ -281,14 +291,14 @@ void CMPEG2Decoder::create_gop_and_frame_lists(FILE* d2vf, char* buf)
else
rff = type & 0x1;
if (FO_Flag != FO_FILM && FO_Flag != FO_RAW && rff) HaveRFFs = true;
-
+
if (!film) {
if (tff)
Field_Order = 1;
else
Field_Order = 0;
}
-
+
size_t listsize = FrameList.size() - 2;
if (mapping >= listsize || ntsc >= listsize || film >= listsize) {
FrameList.resize(listsize + 500002);
@@ -302,26 +312,26 @@ void CMPEG2Decoder::create_gop_and_frame_lists(FILE* d2vf, char* buf)
if (repeat_init)
{
- if (repeat_off-repeat_on == 5)
+ if (repeat_off - repeat_on == 5)
{
repeat_on = repeat_off = 0;
}
else
{
FrameList[mapping].top = FrameList[mapping].bottom = film;
- mapping ++;
+ mapping++;
}
-
- if (repeat_on-repeat_off == 5)
+
+ if (repeat_on - repeat_off == 5)
{
repeat_on = repeat_off = 0;
FrameList[mapping].top = FrameList[mapping].bottom = film;
- mapping ++;
+ mapping++;
}
}
else
{
- if (repeat_off-repeat_on == 3)
+ if (repeat_off - repeat_on == 3)
{
repeat_on = repeat_off = 0;
repeat_init = 1;
@@ -329,15 +339,15 @@ void CMPEG2Decoder::create_gop_and_frame_lists(FILE* d2vf, char* buf)
else
{
FrameList[mapping].top = FrameList[mapping].bottom = film;
- mapping ++;
+ mapping++;
}
- if (repeat_on-repeat_off == 3)
+ if (repeat_on - repeat_off == 3)
{
repeat_on = repeat_off = 0;
repeat_init = 1;
FrameList[mapping].top = FrameList[mapping].bottom = film;
- mapping ++;
+ mapping++;
}
}
}
@@ -393,7 +403,7 @@ void CMPEG2Decoder::create_gop_and_frame_lists(FILE* d2vf, char* buf)
FrameList[ntsc].bottom = film;
bottom = 1;
}
-
+
if (top && bottom)
{
top = bottom = 0;
@@ -405,6 +415,8 @@ void CMPEG2Decoder::create_gop_and_frame_lists(FILE* d2vf, char* buf)
FrameList[film].pct = (unsigned char)((type & 0x30) >> 4);
FrameList[film].pf = (unsigned char)((type & 0x40) >> 6);
+ // This is used only for FO_RAW.
+ FrameList[film].type = type;
// Remember if this encoded frame requires the previous GOP to be decoded.
// The previous GOP is required if DVD2AVI has marked it as such.
@@ -425,12 +437,13 @@ void CMPEG2Decoder::create_gop_and_frame_lists(FILE* d2vf, char* buf)
GOPList.shrink_to_fit();
DirectAccess.shrink_to_fit();
- if (FO_Flag==FO_FILM) {
- while (FrameList[mapping-1].top >= film)
+ if (FO_Flag == FO_FILM) {
+ while (FrameList[mapping - 1].top >= film)
--mapping;
FrameList.resize(mapping);
- } else {
- while ((FrameList[ntsc-1].top >= film) || (FrameList[ntsc-1].bottom >= film))
+ }
+ else {
+ while ((FrameList[ntsc - 1].top >= film) || (FrameList[ntsc - 1].bottom >= film))
--ntsc;
FrameList.resize(ntsc);
}
@@ -468,9 +481,9 @@ void CMPEG2Decoder::destroy()
void CMPEG2Decoder::allocate_buffers()
{
- QP = (int*)_aligned_malloc(sizeof(int)*mb_width*mb_height, 32);
- backwardQP = (int*)_aligned_malloc(sizeof(int)*mb_width*mb_height, 32);
- auxQP = (int*)_aligned_malloc(sizeof(int)*mb_width*mb_height, 32);
+ QP = (int*)_aligned_malloc(sizeof(int) * mb_width * mb_height, 32);
+ backwardQP = (int*)_aligned_malloc(sizeof(int) * mb_width * mb_height, 32);
+ auxQP = (int*)_aligned_malloc(sizeof(int) * mb_width * mb_height, 32);
if (!QP || !backwardQP || !auxQP) {
destroy();
throw std::runtime_error("failed to allocate QP buffers.");
@@ -491,9 +504,9 @@ void CMPEG2Decoder::allocate_buffers()
size_t size;
for (int i = 0; i < 3; i++) {
if (i == 0)
- size = Coded_Picture_Width * Coded_Picture_Height;
+ size = static_cast(Coded_Picture_Width) * Coded_Picture_Height;
else
- size = Chroma_Width * Chroma_Height;
+ size = static_cast(Chroma_Width) * Chroma_Height;
backward_reference_frame[i] = (unsigned char*)_aligned_malloc(2 * size + 4096, 32); //>>> cheap safety bump
forward_reference_frame[i] = (unsigned char*)_aligned_malloc(2 * size + 4096, 32);
@@ -509,7 +522,8 @@ void CMPEG2Decoder::allocate_buffers()
try {
auxFrame1 = new YV12PICT(Coded_Picture_Height, Coded_Picture_Width, cf);
auxFrame2 = new YV12PICT(Coded_Picture_Height, Coded_Picture_Width, cf);
- } catch (std::runtime_error& e) {
+ }
+ catch (std::runtime_error& e) {
destroy();
throw e;
}
@@ -567,187 +581,171 @@ void CMPEG2Decoder::search_bad_starting()
void CMPEG2Decoder::Decode(uint32_t frame, YV12PICT& dst)
{
-__try {
- Fault_Flag = 0;
- Second_Field = 0;
-
- // Skip initial non-decodable frames.
- frame = std::max(frame, BadStartingFrames);
-
- uint32_t requested_frame = frame;
-
- // Decide whether to use random access or linear play to reach the
- // requested frame. If the seek is just a few frames forward, it will
- // be faster to play linearly to get there. This greatly speeds things up
- // when a decimation like SelectEven() follows this filter.
- if (frame && frame > BadStartingFrames && frame > prev_frame
- && frame < prev_frame + SEEK_THRESHOLD) {
- // Use linear play.
- for (frame = prev_frame + 1; frame <= requested_frame; ++frame) {
-
- // If doing force film, we have to skip or repeat a frame as needed.
- // This handles skipping. Repeating is handled below.
- if ((FO_Flag==FO_FILM)
- && (FrameList[frame].bottom == FrameList[frame-1].bottom + 2)
- && (FrameList[frame].top == FrameList[frame-1].top + 2)) {
- if (!Get_Hdr()) {
- // Flush the final frame.
- assembleFrame(backward_reference_frame, pf_backward, dst);
- return;
- }
- Decode_Picture(dst);
- if (Fault_Flag == OUT_OF_BITS) {
- assembleFrame(backward_reference_frame, pf_backward, dst);
- return;
- }
- if (picture_structure != FRAME_PICTURE) {
- Get_Hdr();
+ try {
+ Fault_Flag = 0;
+ Second_Field = 0;
+
+ // Skip initial non-decodable frames.
+ frame = std::max(frame, BadStartingFrames);
+
+ uint32_t requested_frame = frame;
+
+ // Decide whether to use random access or linear play to reach the
+ // requested frame. If the seek is just a few frames forward, it will
+ // be faster to play linearly to get there. This greatly speeds things up
+ // when a decimation like SelectEven() follows this filter.
+ if (frame && frame > BadStartingFrames && frame > prev_frame
+ && frame < prev_frame + SEEK_THRESHOLD) {
+ // Use linear play.
+ for (frame = prev_frame + 1; frame <= requested_frame; ++frame) {
+
+ // If doing force film, we have to skip or repeat a frame as needed.
+ // This handles skipping. Repeating is handled below.
+ if ((FO_Flag == FO_FILM)
+ && (FrameList[frame].bottom == FrameList[frame - 1].bottom + 2)
+ && (FrameList[frame].top == FrameList[frame - 1].top + 2)) {
+ if (!Get_Hdr()) {
+ // Flush the final frame.
+ assembleFrame(backward_reference_frame, pf_backward, dst);
+ return;
+ }
Decode_Picture(dst);
+ if (Fault_Flag == OUT_OF_BITS) {
+ assembleFrame(backward_reference_frame, pf_backward, dst);
+ return;
+ }
+ if (picture_structure != FRAME_PICTURE) {
+ Get_Hdr();
+ Decode_Picture(dst);
+ }
}
- }
- /* When RFFs are present or we are doing FORCE FILM, we may have already decoded
- the frame that we need. So decode the next frame only when we need to. */
- if (std::max(FrameList[frame].top, FrameList[frame].bottom) >
- std::max(FrameList[frame-1].top, FrameList[frame-1].bottom)) {
- if (!Get_Hdr()) {
- assembleFrame(backward_reference_frame, pf_backward, dst);
- return;
- }
- Decode_Picture(dst);
- if (Fault_Flag == OUT_OF_BITS) {
- assembleFrame(backward_reference_frame, pf_backward, dst);
- return;
- }
- if (picture_structure != FRAME_PICTURE) {
- Get_Hdr();
+ /* When RFFs are present or we are doing FORCE FILM, we may have already decoded
+ the frame that we need. So decode the next frame only when we need to. */
+ if (std::max(FrameList[frame].top, FrameList[frame].bottom) >
+ std::max(FrameList[frame - 1].top, FrameList[frame - 1].bottom)) {
+ if (!Get_Hdr()) {
+ assembleFrame(backward_reference_frame, pf_backward, dst);
+ return;
+ }
Decode_Picture(dst);
+ if (Fault_Flag == OUT_OF_BITS) {
+ assembleFrame(backward_reference_frame, pf_backward, dst);
+ return;
+ }
+ if (picture_structure != FRAME_PICTURE) {
+ Get_Hdr();
+ Decode_Picture(dst);
+ }
+ /* If RFFs are present we have to save the decoded frame to
+ be able to pull down from it when we decode the next frame.
+ If we are doing FORCE FILM, then we may need to repeat the
+ frame, so we'll save it for that purpose. */
+ if (FO_Flag == FO_FILM || HaveRFFs) {
+ // Save the current frame without overwriting the last
+ // stored frame.
+ YV12PICT* tmp = saved_active;
+ saved_active = saved_store;
+ saved_store = tmp;
+ copy_all(dst, *saved_store);
+ }
}
- /* If RFFs are present we have to save the decoded frame to
- be able to pull down from it when we decode the next frame.
- If we are doing FORCE FILM, then we may need to repeat the
- frame, so we'll save it for that purpose. */
- if (FO_Flag == FO_FILM || HaveRFFs) {
- // Save the current frame without overwriting the last
- // stored frame.
- YV12PICT* tmp = saved_active;
- saved_active = saved_store;
- saved_store = tmp;
- copy_all(dst, *saved_store);
+ else {
+ // We already decoded the needed frame. Retrieve it.
+ copy_all(*saved_store, dst);
}
- } else {
- // We already decoded the needed frame. Retrieve it.
- copy_all(*saved_store, dst);
- }
- // Perform pulldown if required.
- if (HaveRFFs) {
- if (FrameList[frame].top > FrameList[frame].bottom) {
- copy_bottom(*saved_active, dst);
- } else if (FrameList[frame].top < FrameList[frame].bottom) {
- copy_top(*saved_active, dst);
+ // Perform pulldown if required.
+ if (HaveRFFs) {
+ if (FrameList[frame].top > FrameList[frame].bottom) {
+ copy_bottom(*saved_active, dst);
+ }
+ else if (FrameList[frame].top < FrameList[frame].bottom) {
+ copy_top(*saved_active, dst);
+ }
}
}
+ prev_frame = requested_frame;
+ return;
}
- prev_frame = requested_frame;
- return;
- }
- prev_frame = requested_frame;
- // Have to do random access.
- uint32_t f = std::max(FrameList[frame].top, FrameList[frame].bottom);
-
- // Determine the GOP that the requested frame is in.
- uint32_t gop;
- for (gop = 0; gop < GOPList.size() - 1; ++gop) {
- if (f >= GOPList[gop].number && f < GOPList[gop + 1].number) {
- break;
+ prev_frame = requested_frame;
+ // Have to do random access.
+ uint32_t f = std::max(FrameList[frame].top, FrameList[frame].bottom);
+
+ // Determine the GOP that the requested frame is in.
+ uint32_t gop;
+ for (gop = 0; gop < GOPList.size() - 1; ++gop) {
+ if (f >= GOPList[gop].number && f < GOPList[gop + static_cast(1)].number) {
+ break;
+ }
}
- }
-
- // Back off by one GOP if required. This ensures enough frames will
- // be decoded that the requested frame is guaranteed to be decodable.
- // The direct flag is written by DGIndex, who knows which frames
- // require the previous GOP to be decoded. We also test whether
- // the previous encoded frame requires it, because that one might be pulled
- // down for this frame. This can be improved by actually testing if the
- // previous frame will be pulled down.
- // Obviously we can't decrement gop if it is 0.
- if (gop) {
- if (DirectAccess[f] == 0 || (f && DirectAccess[f - 1] == 0))
- gop--;
- // This covers the special case where a field of the previous GOP is
- // pulled down into the current GOP.
- else if (f == GOPList[gop].number && FrameList[frame].top != FrameList[frame].bottom)
- gop--;
- }
-
- // Calculate how many frames to decode.
- uint32_t count = f - GOPList[gop].number;
- // Seek in the stream to the GOP to start decoding with.
- File_Flag = GOPList[gop].file;
- _lseeki64(Infile[GOPList[gop].file],
- GOPList[gop].position,
- SEEK_SET);
- Initialize_Buffer();
+ // Back off by one GOP if required. This ensures enough frames will
+ // be decoded that the requested frame is guaranteed to be decodable.
+ // The direct flag is written by DGIndex, who knows which frames
+ // require the previous GOP to be decoded. We also test whether
+ // the previous encoded frame requires it, because that one might be pulled
+ // down for this frame. This can be improved by actually testing if the
+ // previous frame will be pulled down.
+ // Obviously we can't decrement gop if it is 0.
+ if (gop) {
+ if (DirectAccess[f] == 0 || (f && DirectAccess[f - 1] == 0))
+ gop--;
+ // This covers the special case where a field of the previous GOP is
+ // pulled down into the current GOP.
+ else if (f == GOPList[gop].number && FrameList[frame].top != FrameList[frame].bottom)
+ gop--;
+ }
- // Start decoding. Stop when the requested frame is decoded.
- // First decode the required I picture of the D2V index line.
- // An indexed unit (especially a pack) can contain multiple I frames.
- // If we did nothing we would have multiple D2V lines with the same position
- // and the navigation code in DGDecode would be confused. We detect this in DGIndex
- // by seeing how many previous lines we have written with the same position.
- // We store that number in the D2V file and DGDecode uses that as the
- // number of I frames to skip before settling on the required one.
- // So, in fact, we are indexing position plus number of I frames to skip.
- for (uint32_t i = 0; i <= GOPList[gop].I_count; ++i) {
- bool HadI = false;
- while (true) {
- if (!Get_Hdr()) {
- // Something is really messed up.
- return;
- }
- Decode_Picture(dst);
- if (picture_coding_type == I_TYPE)
- HadI = true;
- if (picture_structure != FRAME_PICTURE) {
- Get_Hdr();
+ // Calculate how many frames to decode.
+ uint32_t count = f - GOPList[gop].number;
+
+ // Seek in the stream to the GOP to start decoding with.
+ File_Flag = GOPList[gop].file;
+ _lseeki64(Infile[GOPList[gop].file],
+ GOPList[gop].position,
+ SEEK_SET);
+ Initialize_Buffer();
+
+ // Start decoding. Stop when the requested frame is decoded.
+ // First decode the required I picture of the D2V index line.
+ // An indexed unit (especially a pack) can contain multiple I frames.
+ // If we did nothing we would have multiple D2V lines with the same position
+ // and the navigation code in DGDecode would be confused. We detect this in DGIndex
+ // by seeing how many previous lines we have written with the same position.
+ // We store that number in the D2V file and DGDecode uses that as the
+ // number of I frames to skip before settling on the required one.
+ // So, in fact, we are indexing position plus number of I frames to skip.
+ for (uint32_t i = 0; i <= GOPList[gop].I_count; ++i) {
+ bool HadI = false;
+ while (true) {
+ if (!Get_Hdr()) {
+ // Something is really messed up.
+ return;
+ }
Decode_Picture(dst);
if (picture_coding_type == I_TYPE)
HadI = true;
- // The reason for this next test is quite technical. For details
- // refer to the file CodeNote1.txt.
- if (Second_Field == 1) {
+ if (picture_structure != FRAME_PICTURE) {
Get_Hdr();
Decode_Picture(dst);
+ if (picture_coding_type == I_TYPE)
+ HadI = true;
+ // The reason for this next test is quite technical. For details
+ // refer to the file CodeNote1.txt.
+ if (Second_Field == 1) {
+ Get_Hdr();
+ Decode_Picture(dst);
+ }
}
+ if (HadI) break;
}
- if (HadI) break;
}
- }
- Second_Field = 0;
- if (HaveRFFs == true && count == 0) {
- copy_all(dst, *saved_active);
- }
- if (!Get_Hdr()) {
- // Flush the final frame.
- assembleFrame(backward_reference_frame, pf_backward, dst);
- return;
- }
- Decode_Picture(dst);
- if (Fault_Flag == OUT_OF_BITS) {
- assembleFrame(backward_reference_frame, pf_backward, dst);
- return;
- }
- if (picture_structure != FRAME_PICTURE) {
- Get_Hdr();
- Decode_Picture(dst);
- }
- if (HaveRFFs && count == 1) {
- copy_all(dst, *saved_active);
- }
- for (uint32_t i = 0; i < count; ++i) {
+ Second_Field = 0;
+ if (HaveRFFs == true && count == 0) {
+ copy_all(dst, *saved_active);
+ }
if (!Get_Hdr()) {
// Flush the final frame.
assembleFrame(backward_reference_frame, pf_backward, dst);
@@ -762,33 +760,54 @@ __try {
Get_Hdr();
Decode_Picture(dst);
}
- if ((HaveRFFs == true) && (count > 1) && (i == count - 2)) {
+ if (HaveRFFs && count == 1) {
copy_all(dst, *saved_active);
}
- }
+ for (uint32_t i = 0; i < count; ++i) {
+ if (!Get_Hdr()) {
+ // Flush the final frame.
+ assembleFrame(backward_reference_frame, pf_backward, dst);
+ return;
+ }
+ Decode_Picture(dst);
+ if (Fault_Flag == OUT_OF_BITS) {
+ assembleFrame(backward_reference_frame, pf_backward, dst);
+ return;
+ }
+ if (picture_structure != FRAME_PICTURE) {
+ Get_Hdr();
+ Decode_Picture(dst);
+ }
+ if ((HaveRFFs == true) && (count > 1) && (i == count - 2)) {
+ copy_all(dst, *saved_active);
+ }
+ }
- if (HaveRFFs) {
- // Save for transition to non-random mode.
- copy_all(dst, *saved_store);
+ if (HaveRFFs) {
+ // Save for transition to non-random mode.
+ copy_all(dst, *saved_store);
- // Pull down a field if needed.
- if (FrameList[frame].top > FrameList[frame].bottom) {
- copy_bottom(*saved_active, dst);
- } else if (FrameList[frame].top < FrameList[frame].bottom) {
- copy_top(*saved_active, dst);
+ // Pull down a field if needed.
+ if (FrameList[frame].top > FrameList[frame].bottom) {
+ copy_bottom(*saved_active, dst);
+ }
+ else if (FrameList[frame].top < FrameList[frame].bottom) {
+ copy_top(*saved_active, dst);
+ }
}
+ return;
+ }
+ catch (...) {
+ fprintf(stderr, "Exception caught\n");
+ return;
}
- return;
-} __except(EXCEPTION_EXECUTE_HANDLER) {
- return;
-}
}
__forceinline void CMPEG2Decoder::copy_all(YV12PICT& src, YV12PICT& dst)
{
- int t = (upConv > 0 && chroma_format == 1) ? Chroma_Height*2 : Chroma_Height;
- fast_copy(src.y, src.ypitch, dst.y, dst.ypitch, dst.ywidth,Coded_Picture_Height);
+ int t = (upConv > 0 && chroma_format == 1) ? Chroma_Height * 2 : Chroma_Height;
+ fast_copy(src.y, src.ypitch, dst.y, dst.ypitch, dst.ywidth, Coded_Picture_Height);
fast_copy(src.u, src.uvpitch, dst.u, dst.uvpitch, dst.uvwidth, t);
fast_copy(src.v, src.uvpitch, dst.v, dst.uvpitch, dst.uvwidth, t);
}
@@ -825,11 +844,11 @@ copy_oddeven(const uint8_t* odd, const size_t opitch, const uint8_t* even,
} while (--height != 0);
}
-void CMPEG2Decoder::CopyTopBot(YV12PICT *odd, YV12PICT *even, YV12PICT *dst)
+void CMPEG2Decoder::CopyTopBot(YV12PICT* odd, YV12PICT* even, YV12PICT* dst)
{
- int tChroma_Height = (upConv > 0 && chroma_format == 1) ? Chroma_Height*2 : Chroma_Height;
- copy_oddeven(odd->y,odd->ypitch*2,even->y+even->ypitch,even->ypitch*2,dst->y,dst->ypitch,dst->ywidth,Coded_Picture_Height>>1);
- copy_oddeven(odd->u,odd->uvpitch*2,even->u+even->uvpitch,even->uvpitch*2,dst->u,dst->uvpitch,dst->uvwidth,tChroma_Height>>1);
- copy_oddeven(odd->v,odd->uvpitch*2,even->v+even->uvpitch,even->uvpitch*2,dst->v,dst->uvpitch,dst->uvwidth,tChroma_Height>>1);
+ int tChroma_Height = (upConv > 0 && chroma_format == 1) ? Chroma_Height * 2 : Chroma_Height;
+ copy_oddeven(odd->y, odd->ypitch * 2, even->y + even->ypitch, even->ypitch * 2, dst->y, dst->ypitch, dst->ywidth, Coded_Picture_Height >> 1);
+ copy_oddeven(odd->u, odd->uvpitch * 2, even->u + even->uvpitch, even->uvpitch * 2, dst->u, dst->uvpitch, dst->uvwidth, tChroma_Height >> 1);
+ copy_oddeven(odd->v, odd->uvpitch * 2, even->v + even->uvpitch, even->uvpitch * 2, dst->v, dst->uvpitch, dst->uvwidth, tChroma_Height >> 1);
}
#endif
diff --git a/src/dgdecode/MPEG2Decoder.h b/src/MPEG2Decoder.h
similarity index 79%
rename from src/dgdecode/MPEG2Decoder.h
rename to src/MPEG2Decoder.h
index 11bb297..a90cb6c 100644
--- a/src/dgdecode/MPEG2Decoder.h
+++ b/src/MPEG2Decoder.h
@@ -1,53 +1,51 @@
#ifndef MPEG2DECODER_H
#define MPEG2DECODER_H
-
+#include
#include
#include
-#include
+#include
#include
#include
-#include
-#include
-
-#define WIN32_LEAN_AND_MEAN
-#define NOMINMAX
-#include
-#include
#include "yv12pict.h"
+#ifndef _WIN32
+#include "win_import_min.h"
+#else
+#include
+#endif
/* code definition */
enum {
- PICTURE_START_CODE = 0x100,
- SLICE_START_CODE_MIN = 0x101,
- SLICE_START_CODE_MAX = 0x1AF,
- USER_DATA_START_CODE = 0x1B2,
- SEQUENCE_HEADER_CODE = 0x1B3,
- EXTENSION_START_CODE = 0x1B5,
- SEQUENCE_END_CODE = 0x1B7,
- GROUP_START_CODE = 0x1B8,
-
- SYSTEM_END_CODE = 0x1B9,
- PACK_START_CODE = 0x1BA,
- SYSTEM_START_CODE = 0x1BB,
- PRIVATE_STREAM_1 = 0x1BD,
+ PICTURE_START_CODE = 0x100,
+ SLICE_START_CODE_MIN = 0x101,
+ SLICE_START_CODE_MAX = 0x1AF,
+ USER_DATA_START_CODE = 0x1B2,
+ SEQUENCE_HEADER_CODE = 0x1B3,
+ EXTENSION_START_CODE = 0x1B5,
+ SEQUENCE_END_CODE = 0x1B7,
+ GROUP_START_CODE = 0x1B8,
+
+ SYSTEM_END_CODE = 0x1B9,
+ PACK_START_CODE = 0x1BA,
+ SYSTEM_START_CODE = 0x1BB,
+ PRIVATE_STREAM_1 = 0x1BD,
VIDEO_ELEMENTARY_STREAM = 0x1E0,
};
/* extension start code IDs */
enum {
- SEQUENCE_EXTENSION_ID = 1,
+ SEQUENCE_EXTENSION_ID = 1,
SEQUENCE_DISPLAY_EXTENSION_ID = 2,
- QUANT_MATRIX_EXTENSION_ID = 3,
- COPYRIGHT_EXTENSION_ID = 4,
- PICTURE_DISPLAY_EXTENSION_ID = 7,
- PICTURE_CODING_EXTENSION_ID = 8,
+ QUANT_MATRIX_EXTENSION_ID = 3,
+ COPYRIGHT_EXTENSION_ID = 4,
+ PICTURE_DISPLAY_EXTENSION_ID = 7,
+ PICTURE_CODING_EXTENSION_ID = 8,
};
enum {
- ZIG_ZAG = 0,
+ ZIG_ZAG = 0,
MB_WEIGHT = 32,
MB_CLASS4 = 64,
};
@@ -60,16 +58,16 @@ enum {
};
enum {
- TOP_FIELD = 1,
- BOTTOM_FIELD = 2,
+ TOP_FIELD = 1,
+ BOTTOM_FIELD = 2,
FRAME_PICTURE = 3,
};
enum {
MC_FIELD = 1,
MC_FRAME = 2,
- MC_16X8 = 2,
- MC_DMV = 3,
+ MC_16X8 = 2,
+ MC_DMV = 3,
};
enum {
@@ -87,16 +85,22 @@ enum {
enum {
- IDCT_AUTO = 0,
+ IDCT_AUTO = 0,
IDCT_AP922_INT = 3,
IDCT_LLM_FLOAT = 4,
- IDCT_REF = 5,
+ IDCT_REF = 5,
};
enum {
FO_NONE = 0,
FO_FILM = 1,
- FO_RAW = 2,
+ FO_RAW = 2,
+};
+
+enum {
+ IS_NOT_MPEG = 0,
+ IS_MPEG1,
+ IS_MPEG2,
};
// Fault_Flag values
@@ -128,6 +132,7 @@ struct FRAMELIST {
uint32_t bottom;
uint8_t pf;
uint8_t pct;
+ uint8_t type; // Valid only for FO_RAW. Records the TFF/RFF flags.
};
@@ -155,9 +160,9 @@ class CMPEG2Decoder
void Next_Start_Code(void);
std::vector ReadBuffer;
- uint8_t *Rdbfr, *Rdptr, *Rdmax;
+ uint8_t* Rdbfr, * Rdptr, * Rdmax;
uint32_t CurrentBfr, NextBfr, BitsLeft, Val, Read;
- uint8_t *buffer_invalid;
+ uint8_t* buffer_invalid;
// gethdr.cpp
int Get_Hdr(void);
@@ -207,31 +212,30 @@ class CMPEG2Decoder
void form_predictions(int bx, int by, int macroblock_type, int motion_type,
int PMV[2][2][2], int motion_vertical_field_select[2][2], int dmvector[2]);
- void form_prediction(uint8_t *src[], int sfield, uint8_t *dst[], int dfield,
+ void form_prediction(uint8_t* src[], int sfield, uint8_t* dst[], int dfield,
int lx, int lx2, int w, int h, int x, int y, int dx, int dy, int average_flag);
// motion.cpp
void motion_vectors(int PMV[2][2][2], int dmvector[2], int motion_vertical_field_select[2][2],
int s, int motion_vector_count, int mv_format,
int h_r_size, int v_r_size, int dmv, int mvscale);
- void Dual_Prime_Arithmetic(int DMV[][2], int *dmvector, int mvx, int mvy);
+ void Dual_Prime_Arithmetic(int DMV[][2], int* dmvector, int mvx, int mvy);
- void motion_vector(int *PMV, int *dmvector, int h_r_size, int v_r_size,
+ void motion_vector(int* PMV, int* dmvector, int h_r_size, int v_r_size,
int dmv, int mvscale, int full_pel_vector);
- void decode_motion_vector(int *pred, int r_size, int motion_code,
+ void decode_motion_vector(int* pred, int r_size, int motion_code,
int motion_residualesidual, int full_pel_vector);
int Get_motion_code(void);
int Get_dmvector(void);
// store.cpp
- void assembleFrame(uint8_t *src[], int pf, YV12PICT& dst);
+ void assembleFrame(uint8_t* src[], int pf, YV12PICT& dst);
// decoder operation control flags
int Fault_Flag;
int File_Flag;
- int FO_Flag;
- void(__fastcall *idctFunction)(int16_t* block);
- void(__fastcall *prefetchTables)();
+ void(*idctFunction)(int16_t* block);
+ void(*prefetchTables)();
int SystemStream_Flag; // 0 = none, 1=program, 2=Transport 3=PVA
int TransportPacketSize;
@@ -258,17 +262,17 @@ class CMPEG2Decoder
int alternate_scan;
int quantizer_scale;
- short *block[8], *p_block[8];
+ short* block[8], * p_block[8];
int pf_backward, pf_forward, pf_current;
// global values
- uint8_t *backward_reference_frame[3], *forward_reference_frame[3];
- uint8_t *auxframe[3], *current_frame[3];
+ uint8_t* backward_reference_frame[3], * forward_reference_frame[3];
+ uint8_t* auxframe[3], * current_frame[3];
//uint8_t *u422, *v422;
- YV12PICT *auxFrame1;
- YV12PICT *auxFrame2;
- YV12PICT *saved_active;
- YV12PICT *saved_store;
+ YV12PICT* auxFrame1;
+ YV12PICT* auxFrame2;
+ YV12PICT* saved_active;
+ YV12PICT* saved_store;
enum {
ELEMENTARY_STREAM = 0,
@@ -276,13 +280,6 @@ class CMPEG2Decoder
MPEG2_PROGRAM_STREAM,
};
- enum {
- IS_NOT_MPEG = 0,
- IS_MPEG1,
- IS_MPEG2,
- };
-
- int mpeg_type;
int Coded_Picture_Width, Coded_Picture_Height, Chroma_Width, Chroma_Height;
int block_count, Second_Field;
@@ -314,7 +311,7 @@ class CMPEG2Decoder
void copy_top(YV12PICT& src, YV12PICT& dst);
void copy_bottom(YV12PICT& src, YV12PICT& dst);
- int *QP, *backwardQP, *auxQP;
+ int* QP, * backwardQP, * auxQP;
uint32_t prev_frame;
std::vector DirectAccess;
@@ -328,8 +325,7 @@ class CMPEG2Decoder
void destroy();
public:
- CMPEG2Decoder(FILE* file, const char* path, int _idct, int icc, int upconv,
- int info, bool showq, bool _i420);
+ CMPEG2Decoder(FILE* file, const char* path, int _idct, int icc, int upconv, int info, bool showq, bool _i420, int _rff, int _cpu_flags);
~CMPEG2Decoder() { destroy(); }
void Decode(uint32_t frame, YV12PICT& dst);
@@ -344,6 +340,8 @@ class CMPEG2Decoder
std::vector GOPList;
std::vector FrameList;
+ int mpeg_type;
+ int FO_Flag;
int Field_Order;
bool HaveRFFs;
@@ -351,7 +349,7 @@ class CMPEG2Decoder
uint32_t VF_FrameRate_Num;
uint32_t VF_FrameRate_Den;
- int horizontal_size, vertical_size, mb_width, mb_height;
+ int horizontal_size, vertical_size, mb_width, mb_height, aspect_ratio_information;
//int iPP;
int iCC;
bool showQ;
@@ -361,6 +359,7 @@ class CMPEG2Decoder
// info option stuff
int info;
int minquant, maxquant, avgquant;
+ bool has_prop = false;
// Luminance Code
int lumGamma;
@@ -370,6 +369,7 @@ class CMPEG2Decoder
int getChromaWidth() { return Chroma_Width; }
int getLumaWidth() { return Coded_Picture_Width; }
int getLumaHeight() { return Coded_Picture_Height; }
+ int cpu_flags;
};
@@ -377,7 +377,8 @@ __forceinline uint32_t CMPEG2Decoder::Show_Bits(uint32_t N)
{
if (N <= BitsLeft) {
return (CurrentBfr << (32 - BitsLeft)) >> (32 - N);;
- } else {
+ }
+ else {
N -= BitsLeft;
int shift = 32 - BitsLeft;
//return (((CurrentBfr << shift) >> shift) << N) + (NextBfr >> (32 - N));;
@@ -391,7 +392,8 @@ __forceinline uint32_t CMPEG2Decoder::Get_Bits(uint32_t N)
Val = (CurrentBfr << (32 - BitsLeft)) >> (32 - N);
BitsLeft -= N;
return Val;
- } else {
+ }
+ else {
N -= BitsLeft;
int shift = 32 - BitsLeft;
Val = (CurrentBfr << shift) >> shift;
@@ -409,7 +411,8 @@ __forceinline void CMPEG2Decoder::Flush_Buffer(uint32_t N)
{
if (N < BitsLeft) {
BitsLeft -= N;
- } else {
+ }
+ else {
CurrentBfr = NextBfr;
BitsLeft += 32 - N;
Fill_Next();
@@ -435,35 +438,37 @@ __forceinline void CMPEG2Decoder::Fill_Next()
if (Rdptr >= Rdmax)
Next_Packet();
NextBfr |= Get_Byte();
- } else if (Rdptr < Rdbfr + BUFFER_SIZE - 3) {
+ }
+ else if (Rdptr < Rdbfr + BUFFER_SIZE - 3) {
//NextBfr = (*Rdptr << 24) + (*(Rdptr+1) << 16) + (*(Rdptr+2) << 8) + *(Rdptr+3);
NextBfr = _byteswap_ulong(*reinterpret_cast(Rdptr));
Rdptr += 4;
- } else {
+ }
+ else {
switch (Rdbfr + BUFFER_SIZE - Rdptr) {
- case 1:
- NextBfr = *Rdptr++ << 24;
- Fill_Buffer();
- NextBfr |= (Rdptr[0] << 16) | (Rdptr[1] << 8) | Rdptr[2];
- Rdptr += 3;
- break;
- case 2:
- NextBfr = (Rdptr[0] << 24) | (Rdptr[1] << 16);
- Rdptr += 2;
- Fill_Buffer();
- NextBfr |= (Rdptr[0] << 8) | Rdptr[1];
- Rdptr += 2;
- break;
- case 3:
- NextBfr = (Rdptr[0] << 24) | (Rdptr[1] << 16) | (Rdptr[2] << 8);
- Rdptr += 3;
- Fill_Buffer();
- NextBfr |= *Rdptr++;
- break;
- default:
- Fill_Buffer();
- NextBfr = _byteswap_ulong(*reinterpret_cast(Rdptr));
- Rdptr += 4;
+ case 1:
+ NextBfr = *Rdptr++ << 24;
+ Fill_Buffer();
+ NextBfr |= (Rdptr[0] << 16) | (Rdptr[1] << 8) | Rdptr[2];
+ Rdptr += 3;
+ break;
+ case 2:
+ NextBfr = (Rdptr[0] << 24) | (Rdptr[1] << 16);
+ Rdptr += 2;
+ Fill_Buffer();
+ NextBfr |= (Rdptr[0] << 8) | Rdptr[1];
+ Rdptr += 2;
+ break;
+ case 3:
+ NextBfr = (Rdptr[0] << 24) | (Rdptr[1] << 16) | (Rdptr[2] << 8);
+ Rdptr += 3;
+ Fill_Buffer();
+ NextBfr |= *Rdptr++;
+ break;
+ default:
+ Fill_Buffer();
+ NextBfr = _byteswap_ulong(*reinterpret_cast(Rdptr));
+ Rdptr += 4;
}
}
}
@@ -499,7 +504,7 @@ __forceinline uint32_t CMPEG2Decoder::Get_Byte()
__forceinline uint32_t CMPEG2Decoder::Get_Short()
{
uint32_t i = Get_Byte();
- return (i<<8) + Get_Byte();
+ return (i << 8) + Get_Byte();
}
diff --git a/src/dgdecode/color_convert.cpp b/src/color_convert.cpp
similarity index 91%
rename from src/dgdecode/color_convert.cpp
rename to src/color_convert.cpp
index 6cd4c1d..d1f327c 100644
--- a/src/dgdecode/color_convert.cpp
+++ b/src/color_convert.cpp
@@ -17,11 +17,14 @@ MPEG2Dec's colorspace convertions Copyright (C) Chia-chen Kuo - April 2001
#include
#include
#include "color_convert.h"
+#ifndef _WIN32
+#include "win_import_min.h"
+#endif
#if 0
// C implementation
-void conv420to422I_c(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitch, int width, int height)
+void conv420to422I_c(const uint8_t* src, uint8_t* dst, int src_pitch, int dst_pitch, int width, int height)
{
const uint8_t* s0 = src;
const uint8_t* s1 = src + src_pitch;
@@ -82,7 +85,7 @@ avg_weight_3_5(const __m128i& x, const __m128i& y, const __m128i& four)
}
-void conv420to422I(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitch, int width, int height)
+void conv420to422I(const uint8_t* src, uint8_t* dst, int src_pitch, int dst_pitch, int width, int height)
{
const uint8_t* src0 = src;
const uint8_t* src1 = src + src_pitch;
@@ -140,7 +143,7 @@ void conv420to422I(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitc
#if 0
// C implementation
-void conv420to422P_c(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitch,
+void conv420to422P_c(const uint8_t* src, uint8_t* dst, int src_pitch, int dst_pitch,
int width, int height)
{
const uint8_t* s0 = src;
@@ -180,7 +183,7 @@ void conv420to422P_c(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pi
#endif
-void conv420to422P(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitch,
+void conv420to422P(const uint8_t* src, uint8_t* dst, int src_pitch, int dst_pitch,
int width, int height)
{
const uint8_t* s0 = src;
@@ -244,14 +247,14 @@ void conv420to422P(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitc
#if 0
// C implementation
-void conv422to444_c(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitch,
+void conv422to444_c(const uint8_t* src, uint8_t* dst, int src_pitch, int dst_pitch,
int width, int height)
{
width /= 2;
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width - 1; ++x) {
- dst[2 * x] = src[x];
+ dst[2 * x] = src[x];
dst[2 * x + 1] = (src[x] + src[x + 1] + 1) / 2;
}
dst[2 * width - 2] = dst[2 * width - 1] = src[width - 1];
@@ -262,7 +265,7 @@ void conv422to444_c(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pit
#endif
-void conv422to444(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitch,
+void conv422to444(const uint8_t* src, uint8_t* dst, int src_pitch, int dst_pitch,
int width, int height)
{
const int right = width - 1;
@@ -275,8 +278,8 @@ void conv422to444(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitch
s1 = _mm_avg_epu8(s1, s0);
__m128i d0 = _mm_unpacklo_epi8(s0, s1);
__m128i d1 = _mm_unpackhi_epi8(s0, s1);
- _mm_store_si128(reinterpret_cast<__m128i*>(dst + 2 * x), d0);
- _mm_store_si128(reinterpret_cast<__m128i*>(dst + 2 * x + 16), d1);
+ _mm_store_si128(reinterpret_cast<__m128i*>(dst + static_cast(2) * x), d0);
+ _mm_store_si128(reinterpret_cast<__m128i*>(dst + static_cast(2) * x + 16), d1);
}
dst[right] = dst[right - 1];
src += src_pitch;
@@ -289,12 +292,12 @@ void conv422to444(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitch
const int64_t mmmask_0001 = 0x0001000100010001;
const int64_t mmmask_0128 = 0x0080008000800080;
-void conv444toRGB24(const uint8_t *py, const uint8_t *pu, const uint8_t *pv,
- uint8_t *dst, int src_pitchY, int src_pitchUV, int dst_pitch, int width,
+void conv444toRGB24(const uint8_t* py, const uint8_t* pu, const uint8_t* pv,
+ uint8_t* dst, int src_pitchY, int src_pitchUV, int dst_pitch, int width,
int height, int matrix, int pc_scale)
{
- __int64 RGB_Offset, RGB_Scale, RGB_CBU, RGB_CRV, RGB_CGX;
- int dst_modulo = dst_pitch-(3*width);
+ int64_t RGB_Offset, RGB_Scale, RGB_CBU, RGB_CRV, RGB_CGX;
+ int dst_modulo = dst_pitch - (3 * width);
if (pc_scale)
{
@@ -362,15 +365,15 @@ void conv444toRGB24(const uint8_t *py, const uint8_t *pu, const uint8_t *pv,
mov ecx, [pv] // ecx = pv
mov edx, [dst] // edx = dst
mov edi, width // edi = width
- xor esi, esi
+ xor esi, esi
pxor mm0, mm0
- convRGB24:
- movd mm1, [eax+esi]
- movd mm3, [ebx+esi]
+ convRGB24 :
+ movd mm1, [eax + esi]
+ movd mm3, [ebx + esi]
punpcklbw mm1, mm0
punpcklbw mm3, mm0
- movd mm5, [ecx+esi]
+ movd mm5, [ecx + esi]
punpcklbw mm5, mm0
movq mm7, [mmmask_0128]
psubw mm3, mm7
@@ -420,8 +423,8 @@ void conv444toRGB24(const uint8_t *py, const uint8_t *pu, const uint8_t *pv,
por mm3, mm5
por mm4, mm6
- movd mm5, [ebx+esi]
- movd mm6, [ecx+esi]
+ movd mm5, [ebx + esi]
+ movd mm6, [ecx + esi]
punpcklbw mm5, mm0
punpcklbw mm6, mm0
movq mm7, [mmmask_0128]
@@ -456,17 +459,17 @@ void conv444toRGB24(const uint8_t *py, const uint8_t *pu, const uint8_t *pv,
psrlq mm3, 40
psllq mm6, 16
por mm3, mm6
- movd [edx], mm1
+ movd[edx], mm1
psrld mm4, 16
psrlq mm5, 24
por mm5, mm4
- movd [edx+4], mm3
+ movd[edx + 4], mm3
add edx, 0x0c
add esi, 0x04
cmp esi, edi
- movd [edx-4], mm5
+ movd[edx - 4], mm5
jl convRGB24
@@ -474,7 +477,7 @@ void conv444toRGB24(const uint8_t *py, const uint8_t *pu, const uint8_t *pv,
add ebx, src_pitchUV
add ecx, src_pitchUV
add edx, dst_modulo
- xor esi, esi
+ xor esi, esi
dec height
jnz convRGB24
@@ -483,7 +486,7 @@ void conv444toRGB24(const uint8_t *py, const uint8_t *pu, const uint8_t *pv,
}
-void conv422PtoYUY2(const uint8_t *py, uint8_t *pu, uint8_t *pv, uint8_t *dst,
+void conv422PtoYUY2(const uint8_t* py, uint8_t* pu, uint8_t* pv, uint8_t* dst,
int pitch1Y, int pitch1UV, int pitch2, int width, int height)
{
width /= 2;
@@ -507,7 +510,7 @@ void conv422PtoYUY2(const uint8_t *py, uint8_t *pu, uint8_t *pv, uint8_t *dst,
}
-void convYUY2to422P(const uint8_t *src, uint8_t *py, uint8_t *pu, uint8_t *pv,
+void convYUY2to422P(const uint8_t* src, uint8_t* py, uint8_t* pu, uint8_t* pv,
int pitch1, int pitch2y, int pitch2uv, int width, int height)
{
width /= 2;
@@ -540,4 +543,3 @@ void convYUY2to422P(const uint8_t *src, uint8_t *py, uint8_t *pu, uint8_t *pv,
}
}
#endif
-
diff --git a/src/color_convert.h b/src/color_convert.h
new file mode 100644
index 0000000..74a6c16
--- /dev/null
+++ b/src/color_convert.h
@@ -0,0 +1,16 @@
+#ifndef MPEG2DECPLUS_COLOR_CONVERT_H
+#define MPEG2DECPLUS_COLOR_CONVERT_H
+
+#include
+
+void conv420to422P(const uint8_t* src, uint8_t* dst, int src_pitch, int dst_pitch,
+ int width, int height);
+
+void conv420to422I(const uint8_t* src, uint8_t* dst, int src_pitch, int dst_pitch,
+ int width, int height);
+
+void conv422to444(const uint8_t* src, uint8_t* dst, int src_pitch, int dst_pitch,
+ int width, int height);
+
+#endif
+
diff --git a/src/config.h b/src/config.h
deleted file mode 100644
index a70bdc6..0000000
--- a/src/config.h
+++ /dev/null
@@ -1 +0,0 @@
-#undef DGMPGDEC_GIT_VERSION
diff --git a/src/d2vsource.rc b/src/d2vsource.rc
new file mode 100644
index 0000000..63274ab
--- /dev/null
+++ b/src/d2vsource.rc
@@ -0,0 +1,29 @@
+#include
+
+VS_VERSION_INFO VERSIONINFO
+FILEVERSION 1,3,0,0
+PRODUCTVERSION 1,3,0,0
+FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
+FILEFLAGS 0x0L
+FILEOS VOS__WINDOWS32
+FILETYPE VFT_DLL
+FILESUBTYPE VFT2_UNKNOWN
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904E4"
+ BEGIN
+ VALUE "Comments", "Modified DGDecode."
+ VALUE "FileDescription", "D2VSource for AviSynth 2.6 / AviSynth+"
+ VALUE "FileVersion", "1.3.0"
+ VALUE "InternalName", "D2VSource"
+ VALUE "OriginalFilename", "D2VSource.dll"
+ VALUE "ProductName", "D2VSource"
+ VALUE "ProductVersion", "1.3.0"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1252
+ END
+END
diff --git a/src/dgdecode/AVISynthAPI.cpp b/src/dgdecode/AVISynthAPI.cpp
deleted file mode 100644
index f640e54..0000000
--- a/src/dgdecode/AVISynthAPI.cpp
+++ /dev/null
@@ -1,442 +0,0 @@
-/*
- * Avisynth 2.5 API for MPEG2Dec3
- *
- * Changes to fix frame dropping and random frame access are
- * Copyright (C) 2003-2008 Donald A. Graft
- *
- * Copyright (C) 2002-2003 Marc Fauconneau
- *
- * based of the intial MPEG2Dec Avisytnh API Copyright (C) Mathias Born - May 2001
- *
- * This file is part of DGMPGDec, a free MPEG-2 decoder
- *
- * DGMPGDec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * DGMPGDec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include "AvisynthAPI.h"
-#include "postprocess.h"
-#include "color_convert.h"
-#include "misc.h"
-#include "idct.h"
-
-
-#define VERSION "MPEG2DecPlus 0.2.0"
-
-
-bool PutHintingData(uint8_t *video, uint32_t hint)
-{
- constexpr uint32_t MAGIC_NUMBER = 0xdeadbeef;
-
- for (int i = 0; i < 32; ++i) {
- *video &= ~1;
- *video++ |= ((MAGIC_NUMBER & (1 << i)) >> i);
- }
- for (int i = 0; i < 32; i++) {
- *video &= ~1;
- *video++ |= ((hint & (1 << i)) >> i);
- }
- return false;
-}
-
-
-static void luminance_filter(uint8_t* luma, const int width, const int height,
- const int pitch, const uint8_t* table)
-{
- for (int y = 0; y < height; ++y) {
- for (int x = 0; x < width; ++x) {
- luma[x] = table[luma[x]];
- }
- luma += pitch;
- }
-}
-
-
-static void show_info(int n, CMPEG2Decoder& d, PVideoFrame& frame,
- const VideoInfo& vi, IScriptEnvironment* env)
-{
- uint32_t raw = std::max(d.FrameList[n].bottom, d.FrameList[n].top);
- if (raw < d.BadStartingFrames)
- raw = d.BadStartingFrames;
-
- uint32_t gop = 0;
- do {
- if (raw >= d.GOPList[gop].number)
- if (raw < d.GOPList[gop+1].number)
- break;
- } while (++gop < d.GOPList.size() - 1);
-
- const auto& rgop = d.GOPList[gop];
- const auto& fraw = d.FrameList[raw];
- const auto& fn = d.FrameList[n];
-
- int pct = fraw.pct == I_TYPE ? 'I' : fraw.pct == B_TYPE ? 'B' : 'P';
-
- const char* matrix[8] = {
- "Forbidden",
- "ITU-R BT.709",
- "Unspecified Video",
- "Reserved",
- "FCC",
- "ITU-R BT.470-2 System B, G",
- "SMPTE 170M",
- "SMPTE 240M (1987)",
- };
-
- if (d.info == 1) {
- char msg1[1024];
- sprintf(msg1,"%s\n"
- "---------------------------------------\n"
- "Source: %s\n"
- "Frame Rate: %3.6f fps (%u/%u) %s\n"
- "Field Order: %s\n"
- "Picture Size: %d x %d\n"
- "Aspect Ratio: %s\n"
- "Progr Seq: %s\n"
- "GOP Number: %u (%u) GOP Pos = %I64d\n"
- "Closed GOP: %s\n"
- "Display Frame: %d\n"
- "Encoded Frame: %d (top) %d (bottom)\n"
- "Frame Type: %c (%d)\n"
- "Progr Frame: %s\n"
- "Colorimetry: %s (%d)\n"
- "Quants: %d/%d/%d (avg/min/max)\n",
- VERSION,
- d.Infilename[rgop.file].c_str(),
- double(d.VF_FrameRate_Num) / double(d.VF_FrameRate_Den),
- d.VF_FrameRate_Num,
- d.VF_FrameRate_Den,
- (d.VF_FrameRate == 25000 || d.VF_FrameRate == 50000) ? "(PAL)" :
- d.VF_FrameRate == 29970 ? "(NTSC)" : "",
- d.Field_Order == 1 ? "Top Field First" : "Bottom Field First",
- d.getLumaWidth(), d.getLumaHeight(),
- d.Aspect_Ratio,
- rgop.progressive ? "True" : "False",
- gop, rgop.number, rgop.position,
- rgop.closed ? "True" : "False",
- n,
- fn.top, fn.bottom,
- pct, raw,
- fraw.pf ? "True" : "False",
- matrix[rgop.matrix], rgop.matrix,
- d.avgquant, d.minquant, d.maxquant);
- env->ApplyMessage(&frame, vi, msg1, 150, 0xdfffbf, 0x0, 0x0);
-
- } else if (d.info == 2) {
- dprintf("MPEG2DecPlus: %s\n", VERSION);
- dprintf("MPEG2DecPlus: Source: %s\n", d.Infilename[rgop.file]);
- dprintf("MPEG2DecPlus: Frame Rate: %3.6f fps (%u/%u) %s\n",
- double(d.VF_FrameRate_Num) / double(d.VF_FrameRate_Den),
- d.VF_FrameRate_Num, d.VF_FrameRate_Den,
- (d.VF_FrameRate == 25000 || d.VF_FrameRate == 50000) ? "(PAL)" : d.VF_FrameRate == 29970 ? "(NTSC)" : "");
- dprintf("MPEG2DecPlus: Field Order: %s\n", d.Field_Order == 1 ? "Top Field First" : "Bottom Field First");
- dprintf("MPEG2DecPlus: Picture Size: %d x %d\n", d.getLumaWidth(), d.getLumaHeight());
- dprintf("MPEG2DecPlus: Aspect Ratio: %s\n", d.Aspect_Ratio);
- dprintf("MPEG2DecPlus: Progressive Seq: %s\n", rgop.progressive ? "True" : "False");
- dprintf("MPEG2DecPlus: GOP Number: %d (%d) GOP Pos = %I64d\n", gop, rgop.number, rgop.position);
- dprintf("MPEG2DecPlus: Closed GOP: %s\n", rgop.closed ? "True" : "False");
- dprintf("MPEG2DecPlus: Display Frame: %d\n", n);
- dprintf("MPEG2DecPlus: Encoded Frame: %d (top) %d (bottom)\n", fn.top, fn.bottom);
- dprintf("MPEG2DecPlus: Frame Type: %c (%d)\n", pct, raw);
- dprintf("MPEG2DecPlus: Progressive Frame: %s\n", fraw.pf ? "True" : "False");
- dprintf("MPEG2DecPlus: Colorimetry: %s (%d)\n", matrix[rgop.matrix], rgop.matrix);
- dprintf("MPEG2DecPlus: Quants: %d/%d/%d (avg/min/max)\n", d.avgquant, d.minquant, d.maxquant);
-
- } else if (d.info == 3) {
- constexpr uint32_t PROGRESSIVE = 0x00000001;
- constexpr int COLORIMETRY_SHIFT = 2;
-
- uint32_t hint = 0;
- if (fraw.pf == 1) hint |= PROGRESSIVE;
- hint |= ((rgop.matrix & 7) << COLORIMETRY_SHIFT);
- PutHintingData(frame->GetWritePtr(PLANAR_Y), hint);
- }
-}
-
-
-MPEG2Source::MPEG2Source(const char* d2v, int cpu, int idct, int iPP,
- int moderate_h, int moderate_v, bool showQ,
- bool fastMC, const char* _cpu2, int _info,
- int _upConv, bool _i420, int iCC,
- IScriptEnvironment* env) :
- decoder(nullptr), bufY(nullptr), bufU(nullptr), bufV(nullptr)
-{
- //if (iPP != -1 && iPP != 0 && iPP != 1)
- // env->ThrowError("MPEG2Source: iPP must be set to -1, 0, or 1!");
-
- if (iCC != -1 && iCC != 0 && iCC != 1)
- env->ThrowError("MPEG2Source: iCC must be set to -1, 0, or 1!");
-
- if (_upConv != 0 && _upConv != 1 && _upConv != 2)
- env->ThrowError("MPEG2Source: upConv must be set to 0, 1, or 2!");
-
- if (idct > 7)
- env->ThrowError("MPEG2Source: iDCT invalid (1:MMX,2:SSEMMX,3:SSE2,4:FPU,5:REF,6:Skal's,7:Simple)");
-
- FILE *f = fopen(d2v, "r");
- if (f == nullptr)
- env->ThrowError("MPEG2Source: unable to load D2V file \"%s\" ", d2v);
-
- try {
- decoder = new CMPEG2Decoder(f, d2v, idct, iCC, _upConv, _info, showQ, _i420);
- } catch (std::runtime_error& e) {
- if (f) fclose(f);
- env->ThrowError("MPEG2Source: %s", e.what());
- }
-
- env->AtExit([](void* p, IScriptEnvironment*) { delete p; p = nullptr; }, decoder);
- auto& d = *decoder;
-
- int chroma_format = d.getChromaFormat();
-
- memset(&vi, 0, sizeof(vi));
- vi.width = d.Clip_Width;
- vi.height = d.Clip_Height;
- if (_upConv == 2) vi.pixel_type = VideoInfo::CS_YV24;
- else if (chroma_format == 2 || _upConv == 1) vi.pixel_type = VideoInfo::CS_YV16;
- else if (d.i420 == true) vi.pixel_type = VideoInfo::CS_I420;
- else vi.pixel_type = VideoInfo::CS_YV12;
-
- vi.SetFPS(d.VF_FrameRate_Num, d.VF_FrameRate_Den);
- vi.num_frames = static_cast(d.FrameList.size());
- vi.SetFieldBased(false);
-
- if (_upConv == 2) {
- auto free_buf = [](void* p, IScriptEnvironment* e) {
- _aligned_free(p);
- p = nullptr;
- };
- size_t ysize = ((vi.width + 31) & ~31) * (vi.height + 1);
- size_t uvsize = ((d.getChromaWidth() + 15) & ~15) * (vi.height + 1);
- void* ptr = _aligned_malloc(ysize + 2 * uvsize, 32);
- if (!ptr) {
- env->ThrowError("MPEG2Source: malloc failure (bufY, bufU, bufV)!");
- }
- env->AtExit(free_buf, ptr);
- bufY = reinterpret_cast(ptr);
- bufU = bufY + ysize;
- bufV = bufU + uvsize;
- }
-
- luminanceFlag = (d.lumGamma != 0 || d.lumOffset != 0);
- if (luminanceFlag) {
- int lg = d.lumGamma;
- int lo = d.lumOffset;
- for (int i = 0; i < 256; ++i) {
- double value = 255.0 * pow(i / 255.0, pow(2.0, -lg / 128.0)) + lo + 0.5;
-
- if (value < 0)
- luminanceTable[i] = 0;
- else if (value > 255.0)
- luminanceTable[i] = 255;
- else
- luminanceTable[i] = static_cast(value);
- }
- }
-}
-
-
-bool __stdcall MPEG2Source::GetParity(int)
-{
- return decoder->Field_Order == 1;
-}
-
-
-PVideoFrame __stdcall MPEG2Source::GetFrame(int n, IScriptEnvironment* env)
-{
- auto& d = *decoder;
- PVideoFrame frame = env->NewVideoFrame(vi, 32);
- YV12PICT out = (d.upConv != 2) ? YV12PICT(frame) :
- YV12PICT(bufY, bufU, bufV, vi.width, d.getChromaWidth(), vi.height);
-
- d.Decode(n, out);
-
- if (luminanceFlag )
- luminance_filter(out.y, out.ywidth, out.yheight, out.ypitch, luminanceTable);
-
- if (d.upConv == 2) { // convert 4:2:2 (planar) to 4:4:4 (planar)
- env->BitBlt(frame->GetWritePtr(PLANAR_Y), frame->GetPitch(PLANAR_Y),
- bufY, out.ypitch, vi.width, vi.height);
- conv422to444(out.u, frame->GetWritePtr(PLANAR_U), out.uvpitch,
- frame->GetPitch(PLANAR_U), vi.width, vi.height);
- conv422to444(out.v, frame->GetWritePtr(PLANAR_V), out.uvpitch,
- frame->GetPitch(PLANAR_V), vi.width, vi.height);
- }
-
- if (d.info != 0)
- show_info(n, d, frame, vi, env);
-
- return frame;
-}
-
-
-static void set_user_default(FILE* def, char* d2v, int& idct, bool& showq,
- int& info, int upcnv, bool& i420, int& icc)
-{
- char buf[512];
- auto load_str = [&buf](char* var, const char* name, int len) {
- if (strncmp(buf, name, len) == 0) {
- std::vector tmp(512, 0);
- sscanf(buf, name, tmp.data());
- tmp.erase(std::remove(tmp.begin(), tmp.end(), '"'), tmp.end());
- strncpy(var, tmp.data(), tmp.size());
- }
- };
- auto load_int = [&buf](int& var, const char* name, int len) {
- if (strncmp(buf, name, len) == 0) {
- sscanf(buf, name, &var);
- }
- };
- auto load_bool = [&buf](bool& var, const char* name, int len) {
- if (strncmp(buf, name, len) == 0) {
- char tmp[16];
- sscanf(buf, name, &tmp);
- var = tmp[0] == 't';
- }
- };
- auto load_bint = [&buf](int& var, const char* name, int len) {
- if (strncmp(buf, name, len) == 0) {
- char tmp[16];
- sscanf(buf, name, &tmp);
- var = tmp[0] == 't' ? 1 : 0;
- }
- };
-
- while(fgets(buf, 511, def) != 0) {
- load_str(d2v, "d2v=%s", 4);
- load_int(idct, "idct=%d", 5);
- load_bool(showq, "showQ=%s", 6);
- load_int(info, "info=%d", 5);
- load_int(upcnv, "upConv=%d", 7);
- load_bool(i420, "i420=%s", 5);
- load_bint(icc, "iCC=%s", 4);
- }
-}
-
-
-AVSValue __cdecl MPEG2Source::create(AVSValue args, void*, IScriptEnvironment* env)
-{
- char d2v[512];
- int cpu = 0;
- int idct = -1;
-
- // check if iPP is set, if it is use the set value... if not
- // we set iPP to -1 which automatically switches between field
- // and progressive pp based on pf flag -- same for iCC
- int iPP = args[3].IsBool() ? (args[3].AsBool() ? 1 : 0) : -1;
- int iCC = args[12].IsBool() ? (args[12].AsBool() ? 1 : 0) : -1;
-
- int moderate_h = 20;
- int moderate_v = 40;
- bool showQ = false;
- bool fastMC = false;
- char cpu2[255];
- int info = 0;
- int upConv = 0;
- bool i420 = false;
-
- FILE *def = fopen("MPEG2DecPlus.def", "r");
- if (def != nullptr) {
- set_user_default(def, d2v, idct, showQ, info, upConv, i420, iCC);
- fclose(def);
- }
-
- // check for uninitialised strings
- if (strlen(d2v) >= _MAX_PATH) d2v[0] = 0;
- if (strlen(cpu2) >= 255) cpu2[0] = 0;
-
- MPEG2Source *dec = new MPEG2Source( args[0].AsString(d2v),
- args[1].AsInt(cpu),
- args[2].AsInt(idct),
- iPP,
- args[4].AsInt(moderate_h),
- args[5].AsInt(moderate_v),
- args[6].AsBool(showQ),
- args[7].AsBool(fastMC),
- args[8].AsString(cpu2),
- args[9].AsInt(info),
- args[10].AsInt(upConv),
- args[11].AsBool(i420),
- iCC,
- env );
- // Only bother invoking crop if we have to.
- auto& d = *dec->decoder;
- if (d.Clip_Top || d.Clip_Bottom || d.Clip_Left || d.Clip_Right ||
- // This is cheap but it works. The intent is to allow the
- // display size to be different from the encoded size, while
- // not requiring massive revisions to the code. So we detect the
- // difference and crop it off.
- d.vertical_size != d.Clip_Height || d.horizontal_size != d.Clip_Width ||
- d.vertical_size == 1088)
- {
- int vertical;
- // Special case for 1088 to 1080 as directed by DGIndex.
- if (d.vertical_size == 1088 && d.D2V_Height == 1080)
- vertical = 1080;
- else
- vertical = d.vertical_size;
- AVSValue CropArgs[] = {
- dec,
- d.Clip_Left,
- d.Clip_Top,
- -(d.Clip_Right + (d.Clip_Width - d.horizontal_size)),
- -(d.Clip_Bottom + (d.Clip_Height - vertical)),
- true
- };
-
- return env->Invoke("crop", AVSValue(CropArgs, 6));
- }
-
- return dec;
-}
-
-
-const AVS_Linkage* AVS_linkage = nullptr;
-
-
-extern "C" __declspec(dllexport) const char* __stdcall
-AvisynthPluginInit3(IScriptEnvironment* env, const AVS_Linkage* const vectors)
-{
- AVS_linkage = vectors;
-
- const char* msargs =
- "[d2v]s"
- "[cpu]i"
- "[idct]i"
- "[iPP]b"
- "[moderate_h]i"
- "[moderate_v]i"
- "[showQ]b"
- "[fastMC]b"
- "[cpu2]s"
- "[info]i"
- "[upConv]i"
- "[i420]b"
- "[iCC]b";
-
- env->AddFunction("MPEG2Source", msargs, MPEG2Source::create, nullptr);
- env->AddFunction("LumaYUV","c[lumoff]i[lumgain]f", LumaYUV::create, nullptr);
- env->AddFunction("Deblock", "c[quant]i[aOffset]i[bOffset]i", Deblock::create, nullptr);
- // env->AddFunction("BlindPP", "c[quant]i[cpu]i[cpu2]s[iPP]b[moderate_h]i[moderate_v]i", BlindPP::create, nullptr);
-
- return VERSION;
-}
-
diff --git a/src/dgdecode/AvisynthAPI.h b/src/dgdecode/AvisynthAPI.h
deleted file mode 100644
index 8dc4c34..0000000
--- a/src/dgdecode/AvisynthAPI.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Avisynth 2.5 API for MPEG2Dec3
- *
- * Copyright (C) 2002-2003 Marc Fauconneau
- *
- * based of the intial MPEG2Dec Avisytnh API Copyright (C) Mathias Born - May 2001
- *
- * This file is part of MPEG2Dec3, a free MPEG-2 decoder
- *
- * MPEG2Dec3 is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * MPEG2Dec3 is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
-#ifndef MPEG2DECPLUS_AVS_API_H
-#define MPEG2DECPLUS_AVS_API_H
-
-#include
-#include
-#include
-#include "MPEG2Decoder.h"
-
-
-class MPEG2Source: public IClip {
- VideoInfo vi;
- //int _PP_MODE;
- uint8_t *bufY, *bufU, *bufV; // for 4:2:2 input support
- CMPEG2Decoder* decoder;
- bool luminanceFlag;
- uint8_t luminanceTable[256];
-
-public:
- MPEG2Source(const char* d2v, int cpu, int idct, int iPP, int moderate_h, int moderate_v, bool showQ, bool fastMC, const char* _cpu2, int _info, int _upConv, bool _i420, int iCC, IScriptEnvironment* env);
- ~MPEG2Source() {}
- PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
- bool __stdcall GetParity(int n);
- void __stdcall GetAudio(void* buf, __int64 start, __int64 count, IScriptEnvironment* env) {};
- const VideoInfo& __stdcall GetVideoInfo() { return vi; }
- int __stdcall SetCacheHints(int hints, int) { return hints == CACHE_GET_MTMODE ? MT_SERIALIZED : 0; };
- static AVSValue __cdecl create(AVSValue args, void*, IScriptEnvironment* env);
-};
-
-#if 0
-class BlindPP : public GenericVideoFilter {
- int* QP;
- bool iPP;
- int PP_MODE;
- int moderate_h, moderate_v;
-
-public:
- BlindPP(AVSValue args, IScriptEnvironment* env);
- PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
- ~BlindPP() {}
- int __stdcall SetCacheHints(int hints, int) { return hints == CACHE_GET_MTMODE ? MT_NICE_FILTER : 0; }
- static AVSValue __cdecl create(AVSValue args, void*, IScriptEnvironment* env);
-};
-#endif
-
-class Deblock : public GenericVideoFilter {
- int alpha, beta, c0;
- int numPlanes;
-
-public:
- Deblock(PClip _child, int q, int aoff, int boff, IScriptEnvironment* env);
- ~Deblock() {}
- PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
- int __stdcall SetCacheHints(int hints, int) { return hints == CACHE_GET_MTMODE ? MT_NICE_FILTER : 0; }
- static AVSValue __cdecl create(AVSValue args, void*, IScriptEnvironment* env);
-};
-
-
-class LumaYUV : public GenericVideoFilter {
- int16_t* offsetMask;
- int16_t* gainMask;
- int numPlanes;
- void(*mainProc)(
- const uint8_t* srcp, uint8_t* dstp, const int spitch, const int dpitch,
- const int width, const int height, const int16_t* offsets,
- const int16_t* gains);
-
-public:
- LumaYUV(PClip c, int16_t off, int16_t gain, IScriptEnvironment* env);
- ~LumaYUV() {}
- PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
- int __stdcall SetCacheHints(int hints, int) { return hints == CACHE_GET_MTMODE ? MT_NICE_FILTER : 0; }
- static AVSValue __cdecl create(AVSValue args, void*, IScriptEnvironment* env);
-};
-
-
-#endif
diff --git a/src/dgdecode/BlindPP.cpp b/src/dgdecode/BlindPP.cpp
deleted file mode 100644
index 57919f8..0000000
--- a/src/dgdecode/BlindPP.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-#include
-#include "AvisynthAPI.h"
-#include "PostProcess.h"
-#include "color_convert.h"
-
-
-
-
-BlindPP::BlindPP(AVSValue args, IScriptEnvironment* env) : GenericVideoFilter(args[0].AsClip())
-{
- int quant = args[1].AsInt(2);
- if (vi.width%16!=0)
- env->ThrowError("BlindPP : Need mod16 width");
- if (vi.height%16!=0)
- env->ThrowError("BlindPP : Need mod16 height");
- if (!vi.IsYV12() && !vi.IsYV16())
- env->ThrowError("BlindPP : Only YV12 and YV16 supported");
-
- int n = vi.width * vi.height / 256;
- QP = reinterpret_cast(
- static_cast(
- env)->Allocate(n * sizeof(int), 4, AVS_NORMAL_ALLOC));
- if (QP == nullptr)
- env->ThrowError("BlindPP: malloc failure!");
- env->AtExit([](void* p, IScriptEnvironment* e) {
- static_cast(e)->Free(p); p = nullptr; }, QP);
- std::fill_n(QP, n, quant);
-
- switch (args[2].AsInt(6)) {
- case 0 : PP_MODE = 0; break;
- case 1 : PP_MODE = PP_DEBLOCK_Y_H; break;
- case 2 : PP_MODE = PP_DEBLOCK_Y_H | PP_DEBLOCK_Y_V; break;
- case 3 : PP_MODE = PP_DEBLOCK_Y_H | PP_DEBLOCK_Y_V | PP_DEBLOCK_C_H; break;
- case 4 : PP_MODE = PP_DEBLOCK_Y_H | PP_DEBLOCK_Y_V | PP_DEBLOCK_C_H | PP_DEBLOCK_C_V; break;
- case 5 : PP_MODE = PP_DEBLOCK_Y_H | PP_DEBLOCK_Y_V | PP_DEBLOCK_C_H | PP_DEBLOCK_C_V | PP_DERING_Y; break;
- case 6 : PP_MODE = PP_DEBLOCK_Y_H | PP_DEBLOCK_Y_V | PP_DEBLOCK_C_H | PP_DEBLOCK_C_V | PP_DERING_Y | PP_DERING_C; break;
- default : env->ThrowError("BlindPP : cpu level invalid (0 to 6)");
- }
-
- const char* cpu2 = args[3].AsString("");
- if (strlen(cpu2)==6) {
- PP_MODE = 0;
- if (cpu2[0]=='x' || cpu2[0]=='X') { PP_MODE |= PP_DEBLOCK_Y_H; }
- if (cpu2[1]=='x' || cpu2[1]=='X') { PP_MODE |= PP_DEBLOCK_Y_V; }
- if (cpu2[2]=='x' || cpu2[2]=='X') { PP_MODE |= PP_DEBLOCK_C_H; }
- if (cpu2[3]=='x' || cpu2[3]=='X') { PP_MODE |= PP_DEBLOCK_C_V; }
- if (cpu2[4]=='x' || cpu2[4]=='X') { PP_MODE |= PP_DERING_Y; }
- if (cpu2[5]=='x' || cpu2[5]=='X') { PP_MODE |= PP_DERING_C; }
- }
-
- iPP = args[4].AsBool(false);
- moderate_h = args[5].AsInt(20);
- moderate_v = args[6].AsInt(40);
-}
-
-
-PVideoFrame __stdcall BlindPP::GetFrame(int n, IScriptEnvironment* env)
-{
- PVideoFrame dstf = env->NewVideoFrame(vi);
- PVideoFrame cf = child->GetFrame(n, env);
-
- uint8_t* src[3];
- uint8_t* dst[3];
- src[0] = const_cast(cf->GetReadPtr(PLANAR_Y));
- src[1] = const_cast(cf->GetReadPtr(PLANAR_U));
- src[2] = const_cast(cf->GetReadPtr(PLANAR_V));
- dst[0] = dstf->GetWritePtr(PLANAR_Y);
- dst[1] = dstf->GetWritePtr(PLANAR_U);
- dst[2] = dstf->GetWritePtr(PLANAR_V);
- postprocess(src, cf->GetPitch(PLANAR_Y), cf->GetPitch(PLANAR_U),
- dst, dstf->GetPitch(PLANAR_Y), dstf->GetPitch(PLANAR_U),
- vi.width, vi.height, QP, vi.width/16,
- PP_MODE, moderate_h, moderate_v, vi.Is422(), iPP);
-
- return dstf;
-}
-
-
-
-AVSValue __cdecl BlindPP::create(AVSValue args, void*, IScriptEnvironment* env)
-{
- return new BlindPP(args, env);
-}
diff --git a/src/dgdecode/LumaYUV.cpp b/src/dgdecode/LumaYUV.cpp
deleted file mode 100644
index 6344cb8..0000000
--- a/src/dgdecode/LumaYUV.cpp
+++ /dev/null
@@ -1,160 +0,0 @@
-
-// LumaYUV:
-// a rewrite of LumaYV12 to eliminate inline ASM and support all planar 8bit YUV
-// by OKA Motofumi - August 24, 2016
-
-
-
-#include
-#include
-#include "AvisynthAPI.h"
-
-
-#if 0
-// C implementation
-// offset = lumoff, gain = int(lumgain * 128)
-static void
-main_proc_c(const uint8_t* srcp, uint8_t* dstp, const int spitch,
- const int dpitch,const int width, const int height,
- const int offset, const int gain) noexcept
-{
- for (int y = 0; y < height; ++y) {
- for (int x = 0; x < width; ++x) {
- int val = srcp[x] * gain + 64 / 128 + offset;
- dstp[x] = val < 0 ? 0 : val > 255 ? 255 : val;
- }
- srcp += spitch;
- dstp += dpitch;
- }
-}
-#endif
-
-enum {
- NORMAL,
- NO_GAIN_NEGATIVE_OFFSET,
- NO_GAIN_POSITIVE_OFFSET,
-};
-
-
-template
-static void
-main_proc_sse2(const uint8_t* srcp, uint8_t* dstp, const int spitch,
- const int dpitch, const int width, const int height,
- const int16_t* offsets, const int16_t* gains) noexcept
-{
- const __m128i offs = _mm_load_si128(reinterpret_cast(offsets));
-
- __m128i gain, zero, round;
- if (PATTERN == NORMAL) {
- gain = _mm_load_si128(reinterpret_cast(gains));
- round = _mm_set1_epi16(64);
- zero = _mm_setzero_si128();
- }
-
- for (int y = 0; y < height; ++y) {
- for (int x = 0; x < width; x += 16) {
- __m128i s0 = _mm_load_si128(reinterpret_cast(srcp + x));
-
- if (PATTERN == NORMAL) {
- __m128i s1 = _mm_unpackhi_epi8(s0, zero);
- s0 = _mm_unpacklo_epi8(s0, zero);
-
- s0 = _mm_mullo_epi16(s0, gain);
- s1 = _mm_mullo_epi16(s1, gain);
-
- s0 = _mm_adds_epu16(s0, round);
- s1 = _mm_adds_epu16(s1, round);
-
- s0 = _mm_srli_epi16(s0, 7);
- s1 = _mm_srli_epi16(s1, 7);
-
- s0 = _mm_add_epi16(s0, offs);
- s1 = _mm_add_epi16(s1, offs);
-
- s0 = _mm_packus_epi16(s0, s1);
-
- } else if (PATTERN == NO_GAIN_NEGATIVE_OFFSET) {
- s0 = _mm_subs_epu8(s0, offs);
-
- } else {
- s0 = _mm_adds_epu8(s0, offs);
- }
-
- _mm_stream_si128(reinterpret_cast<__m128i*>(dstp + x), s0);
- }
- srcp += spitch;
- dstp += dpitch;
- }
-
-}
-
-
-LumaYUV::LumaYUV(PClip c, int16_t offset, int16_t gain, IScriptEnvironment* env) :
- GenericVideoFilter(c)
-{
- numPlanes = vi.IsY8() ? 1 : vi.IsYUVA() ? 4 : 3;
-
- auto e2 = static_cast(env);
- void* p = e2->Allocate(16 * sizeof(int16_t), 16, AVS_NORMAL_ALLOC);
- if (!p) {
- env->ThrowError("LumaYUV: failed to create masks.");
- }
- env->AtExit(
- [](void* p, IScriptEnvironment* e) {
- static_cast(e)->Free(p);
- p = nullptr;
- }, p);
-
- offsetMask = reinterpret_cast(p);
- gainMask = offsetMask + 8;
-
- if (gain != 128) {
- mainProc = main_proc_sse2;
- std::fill_n(offsetMask, 8, offset);
- std::fill_n(gainMask, 8, gain);
- } else {
- if (offset < 0) {
- offset = -offset;
- mainProc = main_proc_sse2;
- } else {
- mainProc = main_proc_sse2;
- }
- std::fill_n(reinterpret_cast(offsetMask), 16, static_cast(offset));
- }
-}
-
-
-PVideoFrame __stdcall LumaYUV::GetFrame(int n, IScriptEnvironment* env)
-{
- auto src = child->GetFrame(n, env);
- auto dst = env->NewVideoFrame(vi);
-
- static const int planes[] = { PLANAR_U, PLANAR_V, PLANAR_A };
- for (int p = 0; p < numPlanes - 1; ++p) {
- const int plane = planes[p];
- env->BitBlt(dst->GetWritePtr(plane), dst->GetPitch(plane),
- src->GetReadPtr(plane), src->GetPitch(plane),
- dst->GetRowSize(plane), dst->GetHeight(plane));
- }
-
- mainProc(src->GetReadPtr(PLANAR_Y), dst->GetWritePtr(PLANAR_Y),
- src->GetPitch(PLANAR_Y), dst->GetPitch(PLANAR_Y),vi.width,
- vi.height, offsetMask, gainMask);
-
- return dst;
-}
-
-
-AVSValue __cdecl LumaYUV::create(AVSValue args, void*, IScriptEnvironment* env)
-{
- PClip clip = args[0].AsClip();
- const VideoInfo& vi = clip->GetVideoInfo();
- if (!vi.IsPlanar() || vi.IsRGB() || vi.ComponentSize() != 1) {
- env->ThrowError("LumaYUV: unsupported format.");
- }
- int off = std::min(std::max(args[1].AsInt(0), -255), 255);
- float gain = std::min(std::max(args[2].AsFloatf(1.0f), 0.0f), 2.0f);
- gain *= 128;
-
- return new LumaYUV(clip, static_cast(off), static_cast(gain), env);
-}
diff --git a/src/dgdecode/PostProcess.cpp b/src/dgdecode/PostProcess.cpp
deleted file mode 100644
index 8b2f066..0000000
--- a/src/dgdecode/PostProcess.cpp
+++ /dev/null
@@ -1,2235 +0,0 @@
-#include
-#include
-#include
-#include
-#include
-
-#include "PostProcess.h"
-#include "misc.h"
-
-
-//#define DEBUGMODE
-//#define SELFCHECK
-//#define PREFETCH
-
-#ifdef PREFETCH
-#define PREFETCH_AHEAD_V 8
-#define PREFETCH_AHEAD_H 8
-#define PREFETCH_ENABLE
-#endif
-
-#ifdef SELFCHECK
-#define PP_SELF_CHECK
-#define SELF_CHECK
-#endif
-
-#ifdef DEBUGMODE
-#define SHOWDECISIONS_H
-#define SHOW_DECISIONS
-#define SHOWDECISIONS_V
-#endif
-
-#pragma warning( disable : 4799 )
-
-/* entry point for MMX postprocessing */
-void postprocess(unsigned char * src[], int src_stride, int UVsrc_stride,
- unsigned char * dst[], int dst_stride, int UVdst_stride,
- int horizontal_size, int vertical_size,
- QP_STORE_T *QP_store, int QP_stride,
- int mode, int moderate_h, int moderate_v, bool is422, bool iPP)
-{
-
-
- uint8_t *puc_src;
- uint8_t *puc_dst;
- uint8_t *puc_flt;
- QP_STORE_T *QP_ptr;
- int y, i;
-
- if (iPP) vertical_size >>= 1; // field based post-processing
-
- /* this loop is (hopefully) going to improve performance */
- /* loop down the picture, copying and processing in vertical stripes, each four pixels high */
- for (y=0; y>4)*QP_stride]);
- deblock_horiz(puc_flt, horizontal_size, dst_stride, QP_ptr, QP_stride, 0, moderate_h);
- }
- else
- {
- // top field
- puc_flt = &((dst[0])[y*2*dst_stride]);
- QP_ptr = &(QP_store[(y>>4)*2*QP_stride]);
- deblock_horiz(puc_flt, horizontal_size, dst_stride*2, QP_ptr, QP_stride*2, 0, moderate_h);
- // bottom field
- puc_flt = &((dst[0])[(y*2+1)*dst_stride]);
- QP_ptr = &(QP_store[((y>>4)*2+1)*QP_stride]);
- deblock_horiz(puc_flt, horizontal_size, dst_stride*2, QP_ptr, QP_stride*2, 0, moderate_h);
- }
- }
-
- if (mode & PP_DEBLOCK_Y_V)
- {
- if ( (y%8) && (y-4)>5 )
- {
- if (!iPP)
- {
- puc_flt = &((dst[0])[(y-4)*dst_stride]);
- QP_ptr = &(QP_store[(y>>4)*QP_stride]);
- deblock_vert( puc_flt, horizontal_size, dst_stride, QP_ptr, QP_stride, 0, moderate_v);
- }
- else
- {
- // top field
- puc_flt = &((dst[0])[(y-4)*2*dst_stride]);
- QP_ptr = &(QP_store[(y>>4)*2*QP_stride]);
- deblock_vert( puc_flt, horizontal_size, dst_stride*2, QP_ptr, QP_stride*2, 0, moderate_v);
- // bottom field
- puc_flt = &((dst[0])[((y-4)*2+1)*dst_stride]);
- QP_ptr = &(QP_store[((y>>4)*2+1)*QP_stride]);
- deblock_vert( puc_flt, horizontal_size, dst_stride*2, QP_ptr, QP_stride*2, 0, moderate_v);
- }
- }
- }
-
- }
-
- if (mode & PP_DERING_Y)
- {
- if (!iPP) dering(dst[0],horizontal_size,vertical_size,dst_stride,QP_store,QP_stride,0);
- else
- {
- dering(dst[0],horizontal_size,vertical_size,dst_stride*2,QP_store,QP_stride*2,0);
- dering(dst[0]+dst_stride,horizontal_size,vertical_size,dst_stride*2,QP_store+QP_stride,QP_stride*2,0);
- }
- }
-
- // adjust for chroma
- if (!is422) vertical_size >>= 1;
- horizontal_size >>= 1;
- src_stride = UVsrc_stride;
- dst_stride = UVdst_stride;
-
-
- /* loop U then V */
- for (i=1; i<=2; i++)
- {
- for (y=0; y>4)*QP_stride]);
- else QP_ptr = &(QP_store[(y>>3)*QP_stride]);
- deblock_horiz(puc_flt, horizontal_size, dst_stride, QP_ptr, QP_stride, is422 ? 2 : 1, moderate_h);
- }
- else
- {
- // top field
- puc_flt = &((dst[i])[y*2*dst_stride]);
- if (is422) QP_ptr = &(QP_store[(y>>4)*2*QP_stride]);
- else QP_ptr = &(QP_store[(y>>3)*2*QP_stride]);
- deblock_horiz(puc_flt, horizontal_size, dst_stride*2, QP_ptr, QP_stride*2, is422 ? 2 : 1, moderate_h);
- // bottom field
- puc_flt = &((dst[i])[(y*2+1)*dst_stride]);
- if (is422) QP_ptr = &(QP_store[((y>>4)*2+1)*QP_stride]);
- else QP_ptr = &(QP_store[((y>>3)*2+1)*QP_stride]);
- deblock_horiz(puc_flt, horizontal_size, dst_stride*2, QP_ptr, QP_stride*2, is422 ? 2 : 1, moderate_h);
- }
- }
-
- if (mode & PP_DEBLOCK_C_V)
- {
- if ( (y%8) && (y-4)>5 )
- {
- if (!iPP)
- {
- puc_flt = &((dst[i])[(y-4)*dst_stride]);
- if (is422) QP_ptr = &(QP_store[(y>>4)*QP_stride]);
- else QP_ptr = &(QP_store[(y>>3)*QP_stride]);
- deblock_vert( puc_flt, horizontal_size, dst_stride, QP_ptr, QP_stride, is422 ? 2 : 1, moderate_v);
- }
- else
- {
- // top field
- puc_flt = &((dst[i])[(y-4)*2*dst_stride]);
- if (is422) QP_ptr = &(QP_store[(y>>4)*2*QP_stride]);
- else QP_ptr = &(QP_store[(y>>3)*2*QP_stride]);
- deblock_vert( puc_flt, horizontal_size, dst_stride*2, QP_ptr, QP_stride*2, is422 ? 2 : 1, moderate_v);
- // bottom field
- puc_flt = &((dst[i])[((y-4)*2+1)*dst_stride]);
- if (is422) QP_ptr = &(QP_store[((y>>4)*2+1)*QP_stride]);
- else QP_ptr = &(QP_store[((y>>3)*2+1)*QP_stride]);
- deblock_vert( puc_flt, horizontal_size, dst_stride*2, QP_ptr, QP_stride*2, is422 ? 2 : 1, moderate_v);
- }
- }
- }
-
- }
- }
-
- if (mode & PP_DERING_C)
- {
- if (!iPP)
- {
- dering(dst[1],horizontal_size,vertical_size,dst_stride,QP_store,QP_stride,is422 ? 2 : 1);
- dering(dst[2],horizontal_size,vertical_size,dst_stride,QP_store,QP_stride,is422 ? 2 : 1);
- }
- else
- {
- dering(dst[1],horizontal_size,vertical_size,dst_stride*2,QP_store,QP_stride*2,is422 ? 2 : 1);
- dering(dst[1]+dst_stride,horizontal_size,vertical_size,dst_stride*2,QP_store+QP_stride,QP_stride*2,is422 ? 2 : 1);
- dering(dst[2],horizontal_size,vertical_size,dst_stride*2,QP_store,QP_stride*2,is422 ? 2 : 1);
- dering(dst[2]+dst_stride,horizontal_size,vertical_size,dst_stride*2,QP_store+QP_stride,QP_stride*2,is422 ? 2 : 1);
- }
- }
-
- do_emms();
-}
-
-
-/////////////////////////////////////////////////////////////////////////
-// Post Processing Functions (MMX) //
-// //
-/////////////////////////////////////////////////////////////////////////
-
-// Set MMX state back to normal
-static void do_emms()
-{
- __asm emms;
-}
-
-
-/* this is a horizontal deblocking filter - i.e. it will smooth _vertical_ block edges */
-void deblock_horiz(uint8_t *image, int width, int stride, QP_STORE_T *QP_store, int QP_stride, int chromaFlag, int moderate_h)
-{
- /* loop over every block boundary in that row */
- for (int x = 8; x < width; x += 8) {
- int QP ;
- /* extract QP from the decoder's array of QP values */
- if (chromaFlag == 0) {
- QP = QP_store[x / 16];
- } else {
- QP = QP_store[x / 8];
- }
-
- /* v points to pixel v0, in the left-hand block */
- uint8_t* v = image + x - 5;
-
- /* first decide whether to use default or DC offet mode */
- if (deblock_horiz_useDC(v, stride, moderate_h)) {/* use DC offset mode */
- if (deblock_horiz_DC_on(v, stride, QP)) {
- deblock_horiz_lpf9(v, stride, QP);
- }
- } else { /* use default mode */
- deblock_horiz_default_filter(v, stride, QP);
- }
- }
- __asm emms;
-}
-
-/* decide whether the DC filter should be turned on accoding to QP */
-inline int deblock_horiz_DC_on(uint8_t *v, int stride, int QP)
-{
- /* 99% of the time, this test turns out the same as the |max-min| strategy in the standard */
- QP *= 2;
- for (int i = 0; i < 4; ++i) {
- if (std::abs(v[0] - v[5]) >= QP) return false;
- if (std::abs(v[1] - v[8]) >= QP) return false;
- if (std::abs(v[1] - v[4]) >= QP) return false;
- if (std::abs(v[2] - v[7]) >= QP) return false;
- if (std::abs(v[3] - v[6]) >= QP) return false;
- v += stride;
- }
- return true;
-}
-
-/* horizontal deblocking filter used in default (non-DC) mode */
-inline void deblock_horiz_default_filter(uint8_t *v, int stride, int QP)
-{
- for (int y = 0; y < 4; ++y) {
- int q1 = v[4] - v[5];
- int q = q1 / 2;
- if (q != 0) {
- int a3_0 = 2 * (v[3] - v[6]) - 5 * q1;
- int aa3_0 = std::abs(a3_0);
-
- /* apply the 'delta' function first and check there is a difference to avoid wasting time */
- if (aa3_0 < 8 * QP) {
- int a3_1 = std::abs(5 * (v[3] - v[2]) + 2 * (v[1] - v[4]));
- int a3_2 = std::abs(5 * (v[7] - v[8]) + 2 * (v[5] - v[8]));
-
- int d = aa3_0 - std::min(a3_1, a3_2);
-
- if (d > 6) { /* energy across boundary is greater than in one or both of the blocks */
- /* clip d in the range 0 ... q */
- if (q > 0) {
- if (a3_0 < 0) {
- if (d > q) {
- v[4] -= q;
- v[5] += q;
- } else {
- v[4] -= d;
- v[5] += d;
- }
- }
- } else {
- if (a3_0 > 0) {
- if (-d < q) {
- v[4] -= q;
- v[5] += q;
- } else {
- v[4] += d;
- v[5] -= d;
- }
- }
- }
- }
- }
- }
- v += stride;
- }
-}
-
-
-const static uint64_t mm64_0008 = 0x0008000800080008;
-const static uint64_t mm64_0101 = 0x0101010101010101;
-static uint64_t mm64_temp;
-const static uint64_t mm64_coefs[18] = {
- 0x0001000200040006, /* p1 left */ 0x0000000000000001, /* v1 right */
- 0x0001000200020004, /* v1 left */ 0x0000000000010001, /* v2 right */
- 0x0002000200040002, /* v2 left */ 0x0000000100010002, /* v3 right */
- 0x0002000400020002, /* v3 left */ 0x0001000100020002, /* v4 right */
- 0x0004000200020001, /* v4 left */ 0x0001000200020004, /* v5 right */
- 0x0002000200010001, /* v5 left */ 0x0002000200040002, /* v6 right */
- 0x0002000100010000, /* v6 left */ 0x0002000400020002, /* v7 right */
- 0x0001000100000000, /* v7 left */ 0x0004000200020001, /* v8 right */
- 0x0001000000000000, /* v8 left */ 0x0006000400020001 /* p2 right */
-};
-
-
-/* The 9-tap low pass filter used in "DC" regions */
-/* I'm not sure that I like this implementation any more...! */
-inline void deblock_horiz_lpf9(uint8_t *v, int stride, int QP)
-{
- for (int y = 0; y < 4; ++y) {
- int ys = y * stride;
- int p1 = (std::abs(v[0 + ys] - v[1 + ys]) < QP ) ? v[0 + ys] : v[1 + ys];
- int p2 = (std::abs(v[8 + ys] - v[9 + ys]) < QP ) ? v[9 + ys] : v[8 + ys];
-
- uint32_t mm32_p1p2 = 0x0101 * ((p2 << 16) + p1);
-
- uint8_t* pmm1 = v + y * stride - 3; /* this is 64-aligned */
-
- /* mm7 = 0, mm6 is left hand accumulator, mm5 is right hand acc */
- __asm
- {
- push eax
- push ebx
- mov eax, pmm1
- lea ebx, mm64_coefs
-
- #ifdef PREFETCH_ENABLE
- prefetcht0 32[ebx]
- #endif
-
- movd mm0, mm32_p1p2 /* mm0 = ________p2p2p1p1 0w1 2 3 4 5 6 7 */
- punpcklbw mm0, mm0 /* mm0 = p2p2p2p2p1p1p1p1 0m1 2 3 4 5 6 7 */
-
- movq mm2, qword ptr [eax] /* mm2 = v4v3v2v1xxxxxxxx 0 1 2w3 4 5 6 7 */
- pxor mm7, mm7 /* mm7 = 0000000000000000 0 1 2 3 4 5 6 7w */
-
- movq mm6, mm64_0008 /* mm6 = 0008000800080008 0 1 2 3 4 5 6w7 */
- punpckhbw mm2, mm2 /* mm2 = v4__v3__v2__v1__ 0 1 2m3 4 5 6 7 */
-
- movq mm64_temp, mm0 /*temp = p2p2p2p2p1p1p1p1 0r1 2 3 4 5 6 7 */
-
- punpcklbw mm0, mm7 /* mm0 = __p1__p1__p1__p1 0m1 2 3 4 5 6 7 */
- movq mm5, mm6 /* mm5 = 0008000800080008 0 1 2 3 4 5w6r7 */
-
- pmullw mm0, [ebx] /* mm0 *= mm64_coefs[0] 0m1 2 3 4 5 6 7 */
-
- movq mm1, mm2 /* mm1 = v4v4v3v3v2v2v1v1 0 1w2r3 4 5 6 7 */
- punpcklbw mm2, mm2 /* mm2 = v2v2v2v2v1v1v1v1 0 1 2m3 4 5 6 7 */
-
- punpckhbw mm1, mm1 /* mm1 = v4v4v4v4v3v3v3v3 0 1m2 3 4 5 6 7 */
-
- #ifdef PREFETCH_ENABLE
- prefetcht0 32[ebx]
- #endif
-
- movq mm3, mm2 /* mm3 = v2v2v2v2v1v1v1v1 0 1 2r3w4 5 6 7 */
- punpcklbw mm2, mm7 /* mm2 = __v1__v1__v1__v1 0 1 2m3 4 5 6 7 */
-
- punpckhbw mm3, mm7 /* mm3 = __v2__v2__v2__v2 0 1 2 3m4 5 6 7 */
- paddw mm6, mm0 /* mm6 += mm0 0r1 2 3 4 5 6m7 */
-
- movq mm0, mm2 /* mm0 = __v1__v1__v1__v1 0w1 2r3 4 5 6 7 */
-
- pmullw mm0, 8[ebx] /* mm2 *= mm64_coefs[1] 0m1 2 3 4 5 6 7 */
- movq mm4, mm3 /* mm4 = __v2__v2__v2__v2 0 1 2 3r4w5 6 7 */
-
- pmullw mm2, 16[ebx] /* mm2 *= mm64_coefs[2] 0 1 2m3 4 5 6 7 */
-
- pmullw mm3, 32[ebx] /* mm3 *= mm64_coefs[4] 0 1 2 3m4 5 6 7 */
-
- pmullw mm4, 24[ebx] /* mm3 *= mm64_coefs[3] 0 1 2 3 4m5 6 7 */
- paddw mm5, mm0 /* mm5 += mm0 0r1 2 3 4 5m6 7 */
-
- paddw mm6, mm2 /* mm6 += mm2 0 1 2r3 4 5 6m7 */
- movq mm2, mm1 /* mm2 = v4v4v4v4v3v3v3v3 0 1 2 3 4 5 6 7 */
-
- punpckhbw mm2, mm7 /* mm2 = __v4__v4__v4__v4 0 1 2m3 4 5 6 7r */
- paddw mm5, mm4 /* mm5 += mm4 0 1 2 3 4r5m6 7 */
-
- punpcklbw mm1, mm7 /* mm1 = __v3__v3__v3__v3 0 1m2 3 4 5 6 7r */
- paddw mm6, mm3 /* mm6 += mm3 0 1 2 3r4 5 6m7 */
-
- #ifdef PREFETCH_ENABLE
- prefetcht0 64[ebx]
- #endif
- movq mm0, mm1 /* mm0 = __v3__v3__v3__v3 0w1 2 3 4 5 6 7 */
-
- pmullw mm1, 48[ebx] /* mm1 *= mm64_coefs[6] 0 1m2 3 4 5 6 7 */
-
- pmullw mm0, 40[ebx] /* mm0 *= mm64_coefs[5] 0m1 2 3 4 5 6 7 */
- movq mm4, mm2 /* mm4 = __v4__v4__v4__v4 0 1 2r3 4w5 6 7 */
-
- pmullw mm2, 64[ebx] /* mm2 *= mm64_coefs[8] 0 1 2 3 4 5 6 7 */
- paddw mm6, mm1 /* mm6 += mm1 0 1 2 3 4 5 6 7 */
-
- pmullw mm4, 56[ebx] /* mm4 *= mm64_coefs[7] 0 1 2 3 4m5 6 7 */
- pxor mm3, mm3 /* mm3 = 0000000000000000 0 1 2 3w4 5 6 7 */
-
- movq mm1, 8[eax] /* mm1 = xxxxxxxxv8v7v6v5 0 1w2 3 4 5 6 7 */
- paddw mm5, mm0 /* mm5 += mm0 0r1 2 3 4 5 6 7 */
-
- punpcklbw mm1, mm1 /* mm1 = v8v8v7v7v6v6v5v5 0 1m2 3m4 5 6 7 */
- paddw mm6, mm2 /* mm6 += mm2 0 1 2r3 4 5 6 7 */
-
- #ifdef PREFETCH_ENABLE
- prefetcht0 96[ebx]
- #endif
-
- movq mm2, mm1 /* mm2 = v8v8v7v7v6v6v5v5 0 1r2w3 4 5 6 7 */
- paddw mm5, mm4 /* mm5 += mm4 0 1 2 3 4r5 6 7 */
-
- punpcklbw mm2, mm2 /* mm2 = v6v6v6v6v5v5v5v5 0 1 2m3 4 5 6 7 */
- punpckhbw mm1, mm1 /* mm1 = v8v8v8v8v7v7v7v7 0 1m2 3 4 5 6 7 */
-
- movq mm3, mm2 /* mm3 = v6v6v6v6v5v5v5v5 0 1 2r3w4 5 6 7 */
- punpcklbw mm2, mm7 /* mm2 = __v5__v5__v5__v5 0 1 2m3 4 5 6 7r */
-
- punpckhbw mm3, mm7 /* mm3 = __v6__v6__v6__v6 0 1 2 3m4 5 6 7r */
- movq mm0, mm2 /* mm0 = __v5__v5__v5__v5 0w1 2b3 4 5 6 7 */
-
- pmullw mm0, 72[ebx] /* mm0 *= mm64_coefs[9] 0m1 2 3 4 5 6 7 */
- movq mm4, mm3 /* mm4 = __v6__v6__v6__v6 0 1 2 3 4w5 6 7 */
-
- pmullw mm2, 80[ebx] /* mm2 *= mm64_coefs[10] 0 1 2m3 4 5 6 7 */
-
- pmullw mm3, 96[ebx] /* mm3 *= mm64_coefs[12] 0 1 2 3m4 5 6 7 */
-
- pmullw mm4, 88[ebx] /* mm4 *= mm64_coefs[11] 0 1 2 3 4m5 6 7 */
- paddw mm5, mm0 /* mm5 += mm0 0r1 2 3 4 5 6 7 */
-
- paddw mm6, mm2 /* mm6 += mm2 0 1 2r3 4 5 6 7 */
- movq mm2, mm1 /* mm2 = v8v8v8v8v7v7v7v7 0 1r2w3 4 5 6 7 */
-
- paddw mm6, mm3 /* mm6 += mm3 0 1 2 3r4 5 6 7 */
- punpcklbw mm1, mm7 /* mm1 = __v7__v7__v7__v7 0 1m2 3 4 5 6 7r */
-
- paddw mm5, mm4 /* mm5 += mm4 0 1 2 3 4r5 6 7 */
- punpckhbw mm2, mm7 /* mm2 = __v8__v8__v8__v8 0 1 2m3 4 5 6 7 */
-
- #ifdef PREFETCH_ENABLE
- prefetcht0 128[ebx]
- #endif
-
- movq mm3, mm64_temp /* mm0 = p2p2p2p2p1p1p1p1 0 1 2 3w4 5 6 7 */
- movq mm0, mm1 /* mm0 = __v7__v7__v7__v7 0w1r2 3 4 5 6 7 */
-
- pmullw mm0, 104[ebx] /* mm0 *= mm64_coefs[13] 0m1b2 3 4 5 6 7 */
- movq mm4, mm2 /* mm4 = __v8__v8__v8__v8 0 1 2r3 4w5 6 7 */
-
- pmullw mm1, 112[ebx] /* mm1 *= mm64_coefs[14] 0 1w2 3 4 5 6 7 */
- punpckhbw mm3, mm7 /* mm0 = __p2__p2__p2__p2 0 1 2 3 4 5 6 7 */
-
- pmullw mm2, 128[ebx] /* mm2 *= mm64_coefs[16] 0 1b2m3 4 5 6 7 */
-
- pmullw mm4, 120[ebx] /* mm4 *= mm64_coefs[15] 0 1b2 3 4m5 6 7 */
- paddw mm5, mm0 /* mm5 += mm0 0r1 2 3 4 5m6 7 */
-
- pmullw mm3, 136[ebx] /* mm0 *= mm64_coefs[17] 0 1 2 3m4 5 6 7 */
- paddw mm6, mm1 /* mm6 += mm1 0 1w2 3 4 5 6m7 */
-
- paddw mm6, mm2 /* mm6 += mm2 0 1 2r3 4 5 6m7 */
-
- paddw mm5, mm4 /* mm5 += mm4 0 1 2 3 4r5m6 7 */
- psrlw mm6, 4 /* mm6 /= 16 0 1 2 3 4 5 6m7 */
-
- paddw mm5, mm3 /* mm6 += mm0 0 1 2 3r4 5m6 7 */
-
- psrlw mm5, 4 /* mm5 /= 16 0 1 2 3 4 5m6 7 */
-
- packuswb mm6, mm5 /* pack result into mm6 0 1 2 3 4 5r6m7 */
-
- movq 4[eax], mm6 /* v[] = mm6 0 1 2 3 4 5 6r7 */
-
- pop ebx
- pop eax
- };
- }
-}
-
-/* decide DC mode or default mode for the horizontal filter */
-inline int deblock_horiz_useDC(uint8_t *v, int stride, int moderate_h)
-{
- const uint64_t mm64_mask = 0x00fefefefefefefe;
- uint32_t mm32_result;
- uint64_t *pmm1;
- int eq_cnt, useDC;
-
- pmm1 = (uint64_t *)(&(v[1])); /* this is a 32-bit aligned pointer, not 64-aligned */
-
- __asm
- {
- push eax
- mov eax, pmm1
-
- /* first load some constants into mm4, mm5, mm6, mm7 */
- movq mm6, mm64_mask /*mm6 = 0x00fefefefefefefe */
- pxor mm4, mm4 /*mm4 = 0x0000000000000000 */
-
- movq mm1, qword ptr [eax] /* mm1 = *pmm 0 1 2 3 4 5 6 7 */
- add eax, stride /* eax += stride/8 0 1 2 3 4 5 6 7 */
-
- movq mm5, mm1 /* mm5 = mm1 0 1 2 3 4 5 6 7 */
- psrlq mm1, 8 /* mm1 >>= 8 0 1 2 3 4 5 6 7 */
-
- movq mm2, mm5 /* mm2 = mm5 0 1 2 3 4 5 6 7 */
- psubusb mm5, mm1 /* mm5 -= mm1 0 1 2 3 4 5 6 7 */
-
- movq mm3, qword ptr [eax] /* mm3 = *pmm 0 1 2 3 4 5 6 7 */
- psubusb mm1, mm2 /* mm1 -= mm2 0 1 2 3 4 5 6 7 */
-
- add eax, stride /* eax += stride/8 0 1 2 3 4 5 6 7 */
- por mm5, mm1 /* mm5 |= mm1 0 1 2 3 4 5 6 7 */
-
- movq mm0, mm3 /* mm0 = mm3 0 1 2 3 4 5 6 7 */
- pand mm5, mm6 /* mm5 &= 0xfefefefefefefefe */
-
- pxor mm7, mm7 /*mm7 = 0x0000000000000000 */
- pcmpeqb mm5, mm4 /* are the bytes of mm5 == 0 ? */
-
- movq mm1, qword ptr [eax] /* mm3 = *pmm 0 1 2 3 4 5 6 7 */
- psubb mm7, mm5 /* mm7 has running total of eqcnts */
-
- psrlq mm3, 8 /* mm3 >>= 8 0 1 2 3 4 5 6 7 */
- movq mm5, mm0 /* mm5 = mm0 0 1 2 3 4 5 6 7 */
-
- psubusb mm0, mm3 /* mm0 -= mm3 0 1 2 3 4 5 6 7 */
-
- add eax, stride /* eax += stride/8 0 1 2 3 4 5 6 7 */
- psubusb mm3, mm5 /* mm3 -= mm5 0 1 2 3 4 5 6 7 */
-
- movq mm5, qword ptr [eax] /* mm5 = *pmm 0 1 2 3 4 5 6 7 */
- por mm0, mm3 /* mm0 |= mm3 0 1 2 3 4 5 6 7 */
-
- movq mm3, mm1 /* mm3 = mm1 0 1 2 3 4 5 6 7 */
- pand mm0, mm6 /* mm0 &= 0xfefefefefefefefe */
-
- psrlq mm1, 8 /* mm1 >>= 8 0 1 2 3 4 5 6 7 */
- pcmpeqb mm0, mm4 /* are the bytes of mm0 == 0 ? */
-
- movq mm2, mm3 /* mm2 = mm3 0 1 2 3 4 5 6 7 */
- psubb mm7, mm0 /* mm7 has running total of eqcnts */
-
- psubusb mm3, mm1 /* mm3 -= mm1 0 1 2 3 4 5 6 7 */
-
- psubusb mm1, mm2 /* mm1 -= mm2 0 1 2 3 4 5 6 7 */
-
- por mm3, mm1 /* mm3 |= mm1 0 1 2 3 4 5 6 7 */
- movq mm1, mm5 /* mm1 = mm5 0 1 2 3 4 5 6 7 */
-
- pand mm3, mm6 /* mm3 &= 0xfefefefefefefefe */
- psrlq mm5, 8 /* mm5 >>= 8 0 1 2 3 4 5 6 7 */
-
- pcmpeqb mm3, mm4 /* are the bytes of mm3 == 0 ? */
- movq mm0, mm1 /* mm0 = mm1 0 1 2 3 4 5 6 7 */
-
- psubb mm7, mm3 /* mm7 has running total of eqcnts */
- psubusb mm1, mm5 /* mm1 -= mm5 0 1 2 3 4 5 6 7 */
-
- psubusb mm5, mm0 /* mm5 -= mm0 0 1 2 3 4 5 6 7 */
- por mm1, mm5 /* mm1 |= mm5 0 1 2 3 4 5 6 7 */
-
- pand mm1, mm6 /* mm1 &= 0xfefefefefefefefe */
-
- pcmpeqb mm1, mm4 /* are the bytes of mm1 == 0 ? */
-
- psubb mm7, mm1 /* mm7 has running total of eqcnts */
-
- movq mm1, mm7 /* mm1 = mm7 0 1w2 3 4 5 6 7r */
- psllq mm7, 8 /* mm7 >>= 24 0 1 2 3 4 5 6 7m */
-
- psrlq mm1, 24 /* mm7 >>= 24 0 1 2 3 4 5 6 7m */
-
- paddb mm7, mm1 /* mm7 has running total of eqcnts */
-
- movq mm1, mm7 /* mm1 = mm7 0 1w2 3 4 5 6 7r */
- psrlq mm7, 16 /* mm7 >>= 16 0 1 2 3 4 5 6 7m */
-
- paddb mm7, mm1 /* mm7 has running total of eqcnts */
-
- movq mm1, mm7 /* mm1 = mm7 0 1w2 3 4 5 6 7r */
- psrlq mm7, 8 /* mm7 >>= 8 0 1 2 3 4 5 6 7m */
-
- paddb mm7, mm1 /* mm7 has running total of eqcnts */
-
- movd mm32_result, mm7
-
- pop eax
- };
-
- eq_cnt = mm32_result & 0xff;
-
- useDC = eq_cnt >= moderate_h;
-
- return useDC;
-}
-
-/* this is a vertical deblocking filter - i.e. it will smooth _horizontal_ block edges */
-void deblock_vert( uint8_t *image, int width, int stride, QP_STORE_T *QP_store, int QP_stride, int chromaFlag, int moderate_v)
-{
- uint64_t v_local[20];
- uint64_t p1p2[4];
- int Bx, x, y;
- int QP, QPx16;
- uint8_t *v;
- int useDC, DC_on;
-
- y = 0;
-
- /* loop over image's block boundary rows */
-// for (y=8; y= QP) return false;
- if (std::abs(v[i + 1 * stride] - v[i + 4 * stride]) >= QP) return false;
- if (std::abs(v[i + 1 * stride] - v[i + 8 * stride]) >= QP) return false;
- if (std::abs(v[i + 2 * stride] - v[i + 7 * stride]) >= QP) return false;
- if (std::abs(v[i + 3 * stride] - v[i + 6 * stride]) >= QP) return false;
- }
- return true;
-}
-
-
-/* Vertical deblocking filter for use in non-flat picture regions */
-inline void deblock_vert_default_filter(uint8_t *v, int stride, int QP)
-{
- uint64_t *pmm1;
- const uint64_t mm_0020 = 0x0020002000200020;
- uint64_t mm_8_x_QP;
- int i;
-
- ((uint32_t *)&mm_8_x_QP)[0] = ((uint32_t *)&mm_8_x_QP)[1] = 0x00080008 * QP;
-
- /* working in 4-pixel wide columns, left to right */
- /*i=0 in left, i=1 in right */
- for (i=0; i<2; i++)
- {
- /* v should be 64-bit aligned here */
- pmm1 = (uint64_t *)(&(v[4*i]));
- /* pmm1 will be 32-bit aligned but this doesn't matter as we'll use movd not movq */
-
- __asm
- {
- push ecx
- mov ecx, pmm1
-
- pxor mm7, mm7 /* mm7 = 0000000000000000 0 1 2 3 4 5 6 7w */
- add ecx, stride /* %0 += stride 0 1 2 3 4 5 6 7 */
-
- movd mm0, [ecx] /* mm0 = v1v1v1v1v1v1v1v1 0w1 2 3 4 5 6 7 */
- punpcklbw mm0, mm7 /* mm0 = __v1__v1__v1__v1 L 0m1 2 3 4 5 6 7r */
-
- add ecx, stride /* ecx += stride 0 1 2 3 4 5 6 7 */
- movd mm1, [ecx] /* mm1 = v2v2v2v2v2v2v2v2 0 1w2 3 4 5 6 7 */
-
- add ecx, stride /* ecx += stride 0 1 2 3 4 5 6 7 */
- punpcklbw mm1, mm7 /* mm1 = __v2__v2__v2__v2 L 0 1m2 3 4 5 6 7r */
-
- movd mm2, [ecx] /* mm2 = v3v3v3v3v3v3v3v3 0 1 2w3 4 5 6 7 */
- add ecx, stride /* ecx += stride 0 1 2 3 4 5 6 7 */
-
- punpcklbw mm2, mm7 /* mm2 = __v3__v3__v3__v3 L 0 1 2m3 4 5 6 7r */
-
- movd mm3, [ecx] /* mm3 = v4v4v4v4v4v4v4v4 0 1 2 3w4 5 6 7 */
-
- punpcklbw mm3, mm7 /* mm3 = __v4__v4__v4__v4 L 0 1 2 3m4 5 6 7r */
-
- psubw mm1, mm2 /* mm1 = v2 - v3 L 0 1m2r3 4 5 6 7 */
-
- movq mm4, mm1 /* mm4 = v2 - v3 L 0 1r2 3 4w5 6 7 */
- psllw mm1, 2 /* mm1 = 4 * (v2 - v3) L 0 1m2 3 4 5 6 7 */
-
- paddw mm1, mm4 /* mm1 = 5 * (v2 - v3) L 0 1m2 3 4r5 6 7 */
- psubw mm0, mm3 /* mm0 = v1 - v4 L 0m1 2 3r4 5 6 7 */
-
- psllw mm0, 1 /* mm0 = 2 * (v1 - v4) L 0m1 2 3 4 5 6 7 */
-
- psubw mm0, mm1 /* mm0 = a3_1 L 0m1r2 3 4 5 6 7 */
-
- pxor mm1, mm1 /* mm1 = 0000000000000000 0 1w2 3 4 5 6 7 */
-
- pcmpgtw mm1, mm0 /* is 0 > a3_1 ? L 0r1m2 3 4 5 6 7 */
-
- add ecx, stride /* ecx += stride 0 1 2 3 4 5 6 7 */
- pxor mm0, mm1 /* mm0 = ABS(a3_1) step 1 L 0m1r2 3 4 5 6 7 */
-
- psubw mm0, mm1 /* mm0 = ABS(a3_1) step 2 L 0m1r2 3 4 5 6 7 */
-
- movd mm1, [ecx] /* mm1 = v5v5v5v5v5v5v5v5 0 1w2 3 4 5 6 7 */
-
- punpcklbw mm1, mm7 /* mm1 = __v5__v5__v5__v5 L 0 1m2 3 4 5 6 7r */
-
-
- add ecx, stride /* ecx += stride 0 1 2 3 4 5 6 7 */
- psubw mm3, mm1 /* mm3 = v4 - v5 L 0 1r2 3m4 5 6 7 */
-
- movd mm4, [ecx] /* mm4 = v6v6v6v6v6v6v6v6 0 1 2 3 4w5 6 7 */
-
- punpcklbw mm4, mm7 /* mm4 = __v6__v6__v6__v6 L 0 1 2 3 4m5 6 7r */
-
- add ecx, stride /* ecx += stride 0 1 2 3 4 5 6 7 */
-
- movd mm5, [ecx] /* mm5 = v7v7v7v7v7v7v7v7 0 1 2 3 4 5w6 7 */
- psubw mm2, mm4 /* mm2 = v3 - v6 L 0 1 2m3 4r5 6 7 */
-
- punpcklbw mm5, mm7 /* mm5 = __v7__v7__v7__v7 L 0 1 2 3 4 5m6 7r */
-
- add ecx, stride /* ecx += stride 0 1 2 3 4 5 6 7 */
- psubw mm5, mm4 /* mm5 = v7 - v6 L 0 1 2 3 4r5m6 7 */
-
- movq mm4, mm5 /* mm4 = v7 - v6 L 0 1 2 3 4w5r6 7 */
-
- psllw mm4, 2 /* mm4 = 4 * (v7 - v6) L 0 1 2 3 4 5m6 7 */
-
- paddw mm5, mm4 /* mm5 = 5 * (v7 - v6) L 0 1 2 3 4r5m6 7 */
-
- movd mm4, [ecx] /* mm4 = v8v8v8v8v8v8v8v8 0 1 2 3 4w5 6 7 */
-
- punpcklbw mm4, mm7 /* mm4 = __v8__v8__v8__v8 L 0 1 2 3 4m5 6 7r */
-
- psubw mm1, mm4 /* mm1 = v5 - v8 L 0 1m2 3 4r5 6 7 */
-
- pxor mm4, mm4 /* mm4 = 0000000000000000 0 1 2 3 4w5 6 7 */
- psllw mm1, 1 /* mm1 = 2 * (v5 - v8) L 0 1m2 3 4 5 6 7 */
-
- paddw mm1, mm5 /* mm1 = a3_2 L 0 1m2 3 4 5r6 7 */
-
- pcmpgtw mm4, mm1 /* is 0 > a3_2 ? L 0 1r2 3 4m5 6 7 */
-
- pxor mm1, mm4 /* mm1 = ABS(a3_2) step 1 L 0 1m2 3 4r5 6 7 */
-
- psubw mm1, mm4 /* mm1 = ABS(a3_2) step 2 L 0 1m2 3 4r5 6 7 */
-
- /* at this point, mm0 = ABS(a3_1), mm1 = ABS(a3_2), mm2 = v3 - v6, mm3 = v4 - v5 */
- movq mm4, mm1 /* mm4 = ABS(a3_2) L 0 1r2 3 4w5 6 7 */
-
- pcmpgtw mm1, mm0 /* is ABS(a3_2) > ABS(a3_1) 0r1m2 3 4 5 6 7 */
-
- pand mm0, mm1 /* min() step 1 L 0m1r2 3 4 5 6 7 */
-
- pandn mm1, mm4 /* min() step 2 L 0 1m2 3 4r5 6 7 */
-
- por mm0, mm1 /* min() step 3 L 0m1r2 3 4 5 6 7 */
-
- /* at this point, mm0 = MIN( ABS(a3_1), ABS(a3_2), mm2 = v3 - v6, mm3 = v4 - v5 */
- movq mm1, mm3 /* mm1 = v4 - v5 L 0 1w2 3r4 5 6 7 */
- psllw mm3, 2 /* mm3 = 4 * (v4 - v5) L 0 1 2 3m4 5 6 7 */
-
- paddw mm3, mm1 /* mm3 = 5 * (v4 - v5) L 0 1r2 3m4 5 6 7 */
- psllw mm2, 1 /* mm2 = 2 * (v3 - v6) L 0 1 2m3 4 5 6 7 */
-
- psubw mm2, mm3 /* mm2 = a3_0 L 0 1 2m3r4 5 6 7 */
-
- /* at this point, mm0 = MIN( ABS(a3_1), ABS(a3_2), mm1 = v4 - v5, mm2 = a3_0 */
- movq mm4, mm2 /* mm4 = a3_0 L 0 1 2r3 4w5 6 7 */
- pxor mm3, mm3 /* mm3 = 0000000000000000 0 1 2 3w4 5 6 7 */
-
- pcmpgtw mm3, mm2 /* is 0 > a3_0 ? L 0 1 2r3m4 5 6 7 */
-
- movq mm2, mm_8_x_QP /* mm4 = 8*QP 0 1 2w3 4 5 6 7 */
- pxor mm4, mm3 /* mm4 = ABS(a3_0) step 1 L 0 1 2 3r4m5 6 7 */
-
- psubw mm4, mm3 /* mm4 = ABS(a3_0) step 2 L 0 1 2 3r4m5 6 7 */
-
- /* compare a3_0 against 8*QP */
- pcmpgtw mm2, mm4 /* is 8*QP > ABS(d) ? L 0 1 2m3 4r5 6 7 */
-
- pand mm2, mm4 /* if no, d = 0 L 0 1 2m3 4r5 6 7 */
-
- movq mm4, mm2 /* mm2 = a3_0 L 0 1 2r3 4w5 6 7 */
-
- /* at this point, mm0 = MIN( ABS(a3_1), ABS(a3_2), mm1 = v4 - v5, mm2 = a3_0 , mm3 = SGN(a3_0), mm4 = ABS(a3_0) */
- psubusw mm4, mm0 /* mm0 = (A3_0 - a3_0) L 0r1 2 3 4m5 6 7 */
-
- movq mm0, mm4 /* mm0=ABS(d) L 0w1 2 3 4r5 6 7 */
-
- psllw mm0, 2 /* mm0 = 4 * (A3_0-a3_0) L 0m1 2 3 4 5 6 7 */
-
- paddw mm0, mm4 /* mm0 = 5 * (A3_0-a3_0) L 0m1 2 3 4r5 6 7 */
-
- paddw mm0, mm_0020 /* mm0 += 32 L 0m1 2 3 4 5 6 7 */
-
- psraw mm0, 6 /* mm0 >>= 6 L 0m1 2 3 4 5 6 7 */
-
- /* at this point, mm0 = ABS(d), mm1 = v4 - v5, mm3 = SGN(a3_0) */
- pxor mm2, mm2 /* mm2 = 0000000000000000 0 1 2w3 4 5 6 7 */
-
- pcmpgtw mm2, mm1 /* is 0 > (v4 - v5) ? L 0 1r2m3 4 5 6 7 */
-
- pxor mm1, mm2 /* mm1 = ABS(mm1) step 1 L 0 1m2r3 4 5 6 7 */
-
- psubw mm1, mm2 /* mm1 = ABS(mm1) step 2 L 0 1m2r3 4 5 6 7 */
-
- psraw mm1, 1 /* mm1 >>= 2 L 0 1m2 3 4 5 6 7 */
-
- /* OK at this point, mm0 = ABS(d), mm1 = ABS(q), mm2 = SGN(q), mm3 = SGN(-d) */
- movq mm4, mm2 /* mm4 = SGN(q) L 0 1 2r3 4w5 6 7 */
-
- pxor mm4, mm3 /* mm4 = SGN(q) ^ SGN(-d) L 0 1 2 3r4m5 6 7 */
-
- movq mm5, mm0 /* mm5 = ABS(d) L 0r1 2 3 4 5w6 7 */
-
- pcmpgtw mm5, mm1 /* is ABS(d) > ABS(q) ? L 0 1r2 3 4 5m6 7 */
-
- pand mm1, mm5 /* min() step 1 L 0m1 2 3 4 5r6 7 */
-
- pandn mm5, mm0 /* min() step 2 L 0 1r2 3 4 5m6 7 */
-
- por mm1, mm5 /* min() step 3 L 0m1 2 3 4 5r6 7 */
-
- pand mm1, mm4 /* if signs differ, set 0 L 0m1 2 3 4r5 6 7 */
-
- pxor mm1, mm2 /* Apply sign step 1 L 0m1 2r3 4 5 6 7 */
-
- psubw mm1, mm2 /* Apply sign step 2 L 0m1 2r3 4 5 6 7 */
-
- /* at this point we have d in mm1 */
- pop ecx
- };
-
- if (i==0)
- {
- __asm movq mm6, mm1;
- }
-
- }
-
- /* add d to rows l4 and l5 in memory... */
- pmm1 = (uint64_t *)(&(v[4*stride]));
- __asm
- {
- push ecx
- mov ecx, pmm1
- packsswb mm6, mm1
- movq mm0, [ecx]
- psubb mm0, mm6
- movq [ecx], mm0
- add ecx, stride /* %0 += stride 0 1 2 3 4 5 6 7 */
- paddb mm6, [ecx]
- movq [ecx], mm6
- pop ecx
- };
-}
-
-const static uint64_t mm_fours = 0x0004000400040004;
-
-
-/* Vertical 9-tap low-pass filter for use in "DC" regions of the picture */
-inline void deblock_vert_lpf9(uint64_t *v_local, uint64_t *p1p2, uint8_t *v, int stride)
-{
- /* vertical DC filter in MMX
- mm2 - p1/2 left
- mm3 - p1/2 right
- mm4 - psum left
- mm5 - psum right */
- /* alternate between using mm0/mm1 and mm6/mm7 to accumlate left/right */
-
- __asm
- {
- push eax
- push ebx
- push ecx
-
- mov eax, p1p2
- mov ebx, v_local
- mov ecx, v
-
- /* load p1 left into mm2 and p1 right into mm3 */
- movq mm2, [eax] /* mm2 = p1p2[0] 0 1 2w3 4 5 6 7 */
- add ecx, stride /* ecx points at v[1*stride] 0 1 2 3 4 5 6 7 */
-
- movq mm3, 8[eax] /* mm3 = p1p2[1] 0 1 2 3w4 5 6 7 */
-
- movq mm4, mm_fours /* mm4 = 0x0004000400040004 0 1 2 3 4w5 6 7 */
-
- /* psum = p1 + p1 + p1 + vv[1] + vv[2] + vv[3] + vv[4] + 4 */
- /* psum left will be in mm4, right in mm5 */
-
- movq mm5, mm4 /* mm5 = 0x0004000400040004 0 1 2 3 4 5w6 7 */
-
- paddsw mm4, 16[ebx] /* mm4 += vv[1] left 0 1 2 3 4m5 6 7 */
- paddw mm5, mm3 /* mm5 += p2 left 0 1 2 3r4 5m6 7 */
-
- paddsw mm4, 32[ebx] /* mm4 += vv[2] left 0 1 2 3 4m5 6 7 */
- paddw mm5, mm3 /* mm5 += p2 left 0 1 2 3r4 5m6 7 */
-
- paddsw mm4, 48[ebx] /* mm4 += vv[3] left 0 1 2 3 4m5 6 7 */
- paddw mm5, mm3 /* mm5 += p2 left 0 1 2 3r4 5m6 7 */
-
- paddsw mm5, 24[ebx] /* mm5 += vv[1] right 0 1 2 3 4 5m6 7 */
- paddw mm4, mm2 /* mm4 += p1 left 0 1 2r3 4m5 6 7 */
-
- paddsw mm5, 40[ebx] /* mm5 += vv[2] right 0 1 2 3 4 5m6 7 */
- paddw mm4, mm2 /* mm4 += p1 left 0 1 2r3 4m5 6 7 */
-
- paddsw mm5, 56[ebx] /* mm5 += vv[3] right 0 1 2 3 4 5m6 7 */
- paddw mm4, mm2 /* mm4 += p1 left 0 1 2r3 4m5 6 7 */
-
- paddsw mm4, 64[ebx] /* mm4 += vv[4] left 0 1 2 3 4m5 6 7 */
-
- paddsw mm5, 72[ebx] /* mm5 += vv[4] right 0 1 2 3 4 5m6 7 */
-
- /* v[1] = (((psum + vv[1]) << 1) - (vv[4] - vv[5])) >> 4 */
- /* compute this in mm0 (left) and mm1 (right) */
-
- movq mm0, mm4 /* mm0 = psum left 0w1 2 3 4 5 6 7 */
-
- paddsw mm0, 16[ebx] /* mm0 += vv[1] left 0m1 2 3 4 5 6 7 */
- movq mm1, mm5 /* mm1 = psum right 0 1w2 3 4 5r6 7 */
-
- paddsw mm1, 24[ebx] /* mm1 += vv[1] right 0 1 2 3 4 5 6 7 */
- psllw mm0, 1 /* mm0 <<= 1 0m1 2 3 4 5 6 7 */
-
- psubsw mm0, 64[ebx] /* mm0 -= vv[4] left 0m1 2 3 4 5 6 7 */
- psllw mm1, 1 /* mm1 <<= 1 0 1 2 3 4 5 6 7 */
-
- psubsw mm1, 72[ebx] /* mm1 -= vv[4] right 0 1m2 3 4 5 6 7 */
-
- paddsw mm0, 80[ebx] /* mm0 += vv[5] left 0m1 2 3 4 5 6 7 */
-
- paddsw mm1, 88[ebx] /* mm1 += vv[5] right 0 1m2 3 4 5 6 7 */
- psrlw mm0, 4 /* mm0 >>= 4 0m1 2 3 4 5 6 7 */
-
- /* psum += vv[5] - p1 */
- paddsw mm4, 80[ebx] /* mm4 += vv[5] left 0 1 2 3 4m5 6 7 */
- psrlw mm1, 4 /* mm1 >>= 4 0 1m2 3 4 5 6 7 */
-
- paddsw mm5, 88[ebx] /* mm5 += vv[5] right 0 1 2 3 4 5 6 7 */
- psubsw mm4, [eax] /* mm4 -= p1 left 0 1 2 3 4 5 6 7 */
-
- packuswb mm0, mm1 /* pack mm1, mm0 to mm0 0m1 2 3 4 5 6 7 */
- psubsw mm5, 8[eax] /* mm5 -= p1 right 0 1 2 3 4 5 6 7 */
-
- /* v[2] = (((psum + vv[2]) << 1) - (vv[5] - vv[6])) >> 4 */
- /* compute this in mm6 (left) and mm7 (right) */
- movq mm6, mm4 /* mm6 = psum left 0 1 2 3 4 5 6 7 */
-
- paddsw mm6, 32[ebx] /* mm6 += vv[2] left 0 1 2 3 4 5 6 7 */
- movq mm7, mm5 /* mm7 = psum right 0 1 2 3 4 5 6 7 */
-
- paddsw mm7, 40[ebx] /* mm7 += vv[2] right 0 1 2 3 4 5 6 7 */
- psllw mm6, 1 /* mm6 <<= 1 0 1 2 3 4 5 6 7 */
-
- psubsw mm6, 80[ebx] /* mm6 -= vv[5] left 0 1 2 3 4 5 6 7 */
- psllw mm7, 1 /* mm7 <<= 1 0 1 2 3 4 5 6 7 */
-
- psubsw mm7, 88[ebx] /* mm7 -= vv[5] right 0 1 2 3 4 5 6 7 */
-
- movq [ecx], mm0 /* v[1*stride] = mm0 0 1 2 3 4 5 6 7 */
-
- paddsw mm6, 96[ebx] /* mm6 += vv[6] left 0 1 2 3 4 5 6 7 */
- add ecx, stride /* ecx points at v[2*stride] 0 1 2 3 4 5 6 7 */
-
- paddsw mm7, 104[ebx] /* mm7 += vv[6] right 0 1 2 3 4 5 6 7 */
-
- /* psum += vv[6] - p1 */
-
- paddsw mm4, 96[ebx] /* mm4 += vv[6] left 0 1 2 3 4 5 6 7 */
- psrlw mm6, 4 /* mm6 >>= 4 0 1 2 3 4 5 6 7 */
-
- paddsw mm5, 104[ebx] /* mm5 += vv[6] right 0 1 2 3 4 5 6 7 */
- psrlw mm7, 4 /* mm7 >>= 4 0 1 2 3 4 5 6 7 */
-
- psubsw mm4, [eax] /* mm4 -= p1 left 0 1 2 3 4 5 6 7 */
- packuswb mm6, mm7 /* pack mm7, mm6 to mm6 0 1 2 3 4 5 6 7 */
-
- psubsw mm5, 8[eax] /* mm5 -= p1 right 0 1 2 3 4 5 6 7 */
-
- /* v[3] = (((psum + vv[3]) << 1) - (vv[6] - vv[7])) >> 4 */
- /* compute this in mm0 (left) and mm1 (right) */
-
- movq mm0, mm4 /* mm0 = psum left 0 1 2 3 4 5 6 7 */
-
- paddsw mm0, 48[ebx] /* mm0 += vv[3] left 0 1 2 3 4 5 6 7 */
- movq mm1, mm5 /* mm1 = psum right 0 1 2 3 4 5 6 7 */
-
- paddsw mm1, 56[ebx] /* mm1 += vv[3] right 0 1 2 3 4 5 6 7 */
- psllw mm0, 1 /* mm0 <<= 1 0 1 2 3 4 5 6 7 */
-
- psubsw mm0, 96[ebx] /* mm0 -= vv[6] left 0 1 2 3 4 5 6 7 */
- psllw mm1, 1 /* mm1 <<= 1 0 1 2 3 4 5 6 7 */
-
- psubsw mm1, 104[ebx] /* mm1 -= vv[6] right 0 1 2 3 4 5 6 7 */
-
- movq [ecx], mm6 /* v[2*stride] = mm6 0 1 2 3 4 5 6 7 */
- paddsw mm0, 112[ebx] /* mm0 += vv[7] left 0 1 2 3 4 5 6 7 */
-
- paddsw mm1, 120[ebx] /* mm1 += vv[7] right 0 1 2 3 4 5 6 7 */
- add ecx, stride /* ecx points at v[3*stride] 0 1 2 3 4 5 6 7 */
-
- /* psum += vv[7] - p1 */
- paddsw mm4, 112[ebx] /* mm4 += vv[5] left 0 1 2 3 4 5 6 7 */
- psrlw mm0, 4 /* mm0 >>= 4 0 1 2 3 4 5 6 7 */
-
- paddsw mm5, 120[ebx] /* mm5 += vv[5] right 0 1 2 3 4 5 6 7 */
- psrlw mm1, 4 /* mm1 >>= 4 0 1 2 3 4 5 6 7 */
-
- psubsw mm4, [eax] /* mm4 -= p1 left 0 1 2 3 4 5 6 7 */
- packuswb mm0, mm1 /* pack mm1, mm0 to mm0 0 1 2 3 4 5 6 7 */
-
- psubsw mm5, 8[eax] /* mm5 -= p1 right 0 1 2 3 4 5 6 7 */
-
- /* v[4] = (((psum + vv[4]) << 1) + p1 - vv[1] - (vv[7] - vv[8])) >> 4 */
- /* compute this in mm6 (left) and mm7 (right) */
- movq [ecx], mm0 /* v[3*stride] = mm0 0 1 2 3 4 5 6 7 */
- movq mm6, mm4 /* mm6 = psum left 0 1 2 3 4 5 6 7 */
-
- paddsw mm6, 64[ebx] /* mm6 += vv[4] left 0 1 2 3 4 5 6 7 */
- movq mm7, mm5 /* mm7 = psum right 0 1 2 3 4 5 6 7 */
-
- paddsw mm7, 72[ebx] /* mm7 += vv[4] right 0 1 2 3 4 5 6 7 */
- psllw mm6, 1 /* mm6 <<= 1 0 1 2 3 4 5 6 7 */
-
- paddsw mm6, [eax] /* mm6 += p1 left 0 1 2 3 4 5 6 7 */
- psllw mm7, 1 /* mm7 <<= 1 0 1 2 3 4 5 6 7 */
-
- paddsw mm7, 8[eax] /* mm7 += p1 right 0 1 2 3 4 5 6 7 */
-
- psubsw mm6, 16[ebx] /* mm6 -= vv[1] left 0 1 2 3 4 5 6 7 */
-
- psubsw mm7, 24[ebx] /* mm7 -= vv[1] right 0 1 2 3 4 5 6 7 */
-
- psubsw mm6, 112[ebx] /* mm6 -= vv[7] left 0 1 2 3 4 5 6 7 */
-
- psubsw mm7, 120[ebx] /* mm7 -= vv[7] right 0 1 2 3 4 5 6 7 */
-
- paddsw mm6, 128[ebx] /* mm6 += vv[8] left 0 1 2 3 4 5 6 7 */
- add ecx, stride /* ecx points at v[4*stride] 0 1 2 3 4 5 6 7 */
-
- paddsw mm7, 136[ebx] /* mm7 += vv[8] right 0 1 2 3 4 5 6 7 */
- /* psum += vv[8] - vv[1] */
-
- paddsw mm4, 128[ebx] /* mm4 += vv[5] left 0 1 2 3 4 5 6 7 */
- psrlw mm6, 4 /* mm6 >>= 4 0 1 2 3 4 5 6 7 */
-
- paddsw mm5, 136[ebx] /* mm5 += vv[5] right 0 1 2 3 4 5 6 7 */
- psrlw mm7, 4 /* mm7 >>= 4 0 1 2 3 4 5 6 7 */
-
- psubsw mm4, 16[ebx] /* mm4 -= vv[1] left 0 1 2 3 4 5 6 7 */
- packuswb mm6, mm7 /* pack mm7, mm6 to mm6 0 1 2 3 4 5 6 7 */
-
- psubsw mm5, 24[ebx] /* mm5 -= vv[1] right 0 1 2 3 4 5 6 7 */
-
- /* v[5] = (((psum + vv[5]) << 1) + (vv[1] - vv[2]) - vv[8] + p2) >> 4 */
- /* compute this in mm0 (left) and mm1 (right) */
- movq mm0, mm4 /* mm0 = psum left 0 1 2 3 4 5 6 7 */
-
- paddsw mm0, 80[ebx] /* mm0 += vv[5] left 0 1 2 3 4 5 6 7 */
- movq mm1, mm5 /* mm1 = psum right 0 1 2 3 4 5 6 7 */
-
- paddsw mm1, 88[ebx] /* mm1 += vv[5] right 0 1 2 3 4 5 6 7 */
- psllw mm0, 1 /* mm0 <<= 1 0 1 2 3 4 5 6 7 */
-
- paddsw mm0, 16[eax] /* mm0 += p2 left 0 1 2 3 4 5 6 7 */
- psllw mm1, 1 /* mm1 <<= 1 0 1 2 3 4 5 6 7 */
-
- paddsw mm1, 24[eax] /* mm1 += p2 right 0 1 2 3 4 5 6 7 */
-
- paddsw mm0, 16[ebx] /* mm0 += vv[1] left 0 1 2 3 4 5 6 7 */
- movq [ecx], mm6 /* v[4*stride] = mm6 0 1 2 3 4 5 6 7 */
-
- paddsw mm1, 24[ebx] /* mm1 += vv[1] right 0 1 2 3 4 5 6 7 */
-
- psubsw mm0, 32[ebx] /* mm0 -= vv[2] left 0 1 2 3 4 5 6 7 */
-
- psubsw mm1, 40[ebx] /* mm1 -= vv[2] right 0 1 2 3 4 5 6 7 */
-
- psubsw mm0, 128[ebx] /* mm0 -= vv[8] left 0 1 2 3 4 5 6 7 */
-
- psubsw mm1, 136[ebx] /* mm1 -= vv[8] right 0 1 2 3 4 5 6 7 */
-
- /* psum += p2 - vv[2] */
- paddsw mm4, 16[eax] /* mm4 += p2 left 0 1 2 3 4 5 6 7 */
- add ecx, stride /* ecx points at v[5*stride] 0 1 2 3 4 5 6 7 */
-
- paddsw mm5, 24[eax] /* mm5 += p2 right 0 1 2 3 4 5 6 7 */
-
- psubsw mm4, 32[ebx] /* mm4 -= vv[2] left 0 1 2 3 4 5 6 7 */
-
- psubsw mm5, 40[ebx] /* mm5 -= vv[2] right 0 1 2 3 4 5 6 7 */
-
- /* v[6] = (((psum + vv[6]) << 1) + (vv[2] - vv[3])) >> 4 */
- /* compute this in mm6 (left) and mm7 (right) */
-
- movq mm6, mm4 /* mm6 = psum left 0 1 2 3 4 5 6 7 */
-
- paddsw mm6, 96[ebx] /* mm6 += vv[6] left 0 1 2 3 4 5 6 7 */
- movq mm7, mm5 /* mm7 = psum right 0 1 2 3 4 5 6 7 */
-
- paddsw mm7, 104[ebx] /* mm7 += vv[6] right 0 1 2 3 4 5 6 7 */
- psllw mm6, 1 /* mm6 <<= 1 0 1 2 3 4 5 6 7 */
-
- paddsw mm6, 32[ebx] /* mm6 += vv[2] left 0 1 2 3 4 5 6 7 */
- psllw mm7, 1 /* mm7 <<= 1 0 1 2 3 4 5 6 7 */
-
- paddsw mm7, 40[ebx] /* mm7 += vv[2] right 0 1 2 3 4 5 6 7 */
- psrlw mm0, 4 /* mm0 >>= 4 0 1 2 3 4 5 6 7 */
-
- psubsw mm6, 48[ebx] /* mm6 -= vv[3] left 0 1 2 3 4 5 6 7 */
- psrlw mm1, 4 /* mm1 >>= 4 0 1 2 3 4 5 6 7 */
-
- psubsw mm7, 56[ebx] /* mm7 -= vv[3] right 0 1 2 3 4 5 6 7 */
- packuswb mm0, mm1 /* pack mm1, mm0 to mm0 0 1 2 3 4 5 6 7 */
-
- movq [ecx], mm0 /* v[5*stride] = mm0 0 1 2 3 4 5 6 7 */
-
- /* psum += p2 - vv[3] */
-
- paddsw mm4, 16[eax] /* mm4 += p2 left 0 1 2 3 4 5 6 7 */
- psrlw mm6, 4 /* mm6 >>= 4 0 1 2 3 4 5 6 7 */
-
- paddsw mm5, 24[eax] /* mm5 += p2 right 0 1 2 3 4 5 6 7 */
- psrlw mm7, 4 /* mm7 >>= 4 0 1 2 3 4 5 6 7 */
-
- psubsw mm4, 48[ebx] /* mm4 -= vv[3] left 0 1 2 3 4 5 6 7 */
- add ecx, stride /* ecx points at v[6*stride] 0 1 2 3 4 5 6 7 */
-
- psubsw mm5, 56[ebx] /* mm5 -= vv[3] right 0 1 2 3 4 5 6 7 */
-
- /* v[7] = (((psum + vv[7]) << 1) + (vv[3] - vv[4])) >> 4 */
- /* compute this in mm0 (left) and mm1 (right) */
-
- movq mm0, mm4 /* mm0 = psum left 0 1 2 3 4 5 6 7 */
-
- paddsw mm0, 112[ebx] /* mm0 += vv[7] left 0 1 2 3 4 5 6 7 */
- movq mm1, mm5 /* mm1 = psum right 0 1 2 3 4 5 6 7 */
-
- paddsw mm1, 120[ebx] /* mm1 += vv[7] right 0 1 2 3 4 5 6 7 */
- psllw mm0, 1 /* mm0 <<= 1 0 1 2 3 4 5 6 7 */
-
- paddsw mm0, 48[ebx] /* mm0 += vv[3] left 0 1 2 3 4 5 6 7 */
- psllw mm1, 1 /* mm1 <<= 1 0 1 2 3 4 5 6 7 */
-
- paddsw mm1, 56[ebx] /* mm1 += vv[3] right 0 1 2 3 4 5 6 7 */
- packuswb mm6, mm7 /* pack mm7, mm6 to mm6 0 1 2 3 4 5 6 7 */
-
- psubsw mm0, 64[ebx] /* mm0 -= vv[4] left 0 1 2 3 4 5 6 7 */
-
- psubsw mm1, 72[ebx] /* mm1 -= vv[4] right 0 1 2 3 4 5 6 7 */
- psrlw mm0, 4 /* mm0 >>= 4 0 1 2 3 4 5 6 7 */
-
- movq [ecx], mm6 /* v[6*stride] = mm6 0 1 2 3 4 5 6 7 */
-
- /* psum += p2 - vv[4] */
-
- paddsw mm4, 16[eax] /* mm4 += p2 left 0 1 2 3 4 5 6 7 */
-
- paddsw mm5, 24[eax] /* mm5 += p2 right 0 1 2 3 4 5 6 7 */
- add ecx, stride /* ecx points at v[7*stride] 0 1 2 3 4 5 6 7 */
-
- psubsw mm4, 64[ebx] /* mm4 -= vv[4] left 0 1 2 3 4 5 6 7 */
- psrlw mm1, 4 /* mm1 >>= 4 0 1 2 3 4 5 6 7 */
-
- psubsw mm5, 72[ebx] /* mm5 -= vv[4] right 0 1 2 3 4 5 6 7 */
-
- /* v[8] = (((psum + vv[8]) << 1) + (vv[4] - vv[5])) >> 4 */
- /* compute this in mm6 (left) and mm7 (right) */
-
- movq mm6, mm4 /* mm6 = psum left 0 1 2 3 4 5 6 7 */
-
- paddsw mm6, 128[ebx] /* mm6 += vv[8] left 0 1 2 3 4 5 6 7 */
- movq mm7, mm5 /* mm7 = psum right 0 1 2 3 4 5 6 7 */
-
- paddsw mm7, 136[ebx] /* mm7 += vv[8] right 0 1 2 3 4 5 6 7 */
- psllw mm6, 1 /* mm6 <<= 1 0 1 2 3 4 5 6 7 */
-
- paddsw mm6, 64[ebx] /* mm6 += vv[4] left 0 1 2 3 4 5 6 7 */
- psllw mm7, 1 /* mm7 <<= 1 0 1 2 3 4 5 6 7 */
-
- paddsw mm7, 72[ebx] /* mm7 += vv[4] right 0 1 2 3 4 5 6 7 */
- packuswb mm0, mm1 /* pack mm1, mm0 to mm0 0 1 2 3 4 5 6 7 */
-
- psubsw mm6, 80[ebx] /* mm6 -= vv[5] left 0 1 2 3 4 5 6 7 */
-
- psubsw mm7, 88[ebx] /* mm7 -= vv[5] right 0 1 2 3 4 5 6 7 */
- psrlw mm6, 4 /* mm6 >>= 4 0 1 2 3 4 5 6 7 */
-
- movq [ecx], mm0 /* v[7*stride] = mm0 0 1 2 3 4 5 6 7 */
- psrlw mm7, 4 /* mm7 >>= 4 0 1 2 3 4 5 6 7 */
-
- packuswb mm6, mm7 /* pack mm7, mm6 to mm6 0 1 2 3 4 5 6 7 */
-
- add ecx, stride /* ecx points at v[8*stride] 0 1 2 3 4 5 6 7 */
-
- nop /* 0 1 2 3 4 5 6 7 */
-
- movq [ecx], mm6 /* v[8*stride] = mm6 0 1 2 3 4 5 6 7 */
-
- pop ecx
- pop ebx
- pop eax
- };
-}
-
-/* decide DC mode or default mode in assembler */
-inline int deblock_vert_useDC(uint8_t *v, int stride, int moderate_v)
-{
- const uint64_t mask = 0xfefefefefefefefe;
- uint32_t mm_data1;
- uint64_t *pmm1;
- int eq_cnt, useDC;
-
- /* starting pointer is at v[stride] == v1 in mpeg4 notation */
- pmm1 = (uint64_t *)(&(v[stride]));
-
- /* first load some constants into mm4, mm6, mm7 */
- __asm
- {
- push eax
- mov eax, pmm1
-
- movq mm6, mask /*mm6 = 0xfefefefefefefefe */
- pxor mm7, mm7 /*mm7 = 0x0000000000000000 */
-
- movq mm2, [eax] /* mm2 = *p_data */
- pxor mm4, mm4 /*mm4 = 0x0000000000000000 */
-
- add eax, stride /* p_data += stride */
- movq mm3, mm2 /* mm3 = *p_data */
- };
-
- __asm
- {
- movq mm2, [eax] /* mm2 = *p_data */
- movq mm0, mm3 /* mm0 = mm3 */
-
- movq mm3, mm2 /* mm3 = *p_data */
- movq mm1, mm0 /* mm1 = mm0 */
-
- psubusb mm0, mm2 /* mm0 -= mm2 */
- add eax, stride /* p_data += stride */
-
- psubusb mm2, mm1 /* mm2 -= mm1 */
- por mm0, mm2 /* mm0 |= mm2 */
-
- pand mm0, mm6 /* mm0 &= 0xfefefefefefefefe */
- pcmpeqb mm0, mm4 /* is mm0 == 0 ? */
-
- movq mm2, [eax] /* mm2 = *p_data */
- psubb mm7, mm0 /* mm7 has running total of eqcnts */
-
- movq mm5, mm3 /* mm5 = mm3 */
- movq mm3, mm2 /* mm3 = *p_data */
-
- movq mm1, mm5 /* mm1 = mm5 */
- psubusb mm5, mm2 /* mm5 -= mm2 */
-
- psubusb mm2, mm1 /* mm2 -= mm1 */
- por mm5, mm2 /* mm5 |= mm2 */
-
- add eax, stride /* p_data += stride */
- pand mm5, mm6 /* mm5 &= 0xfefefefefefefefe */
-
- pcmpeqb mm5, mm4 /* is mm0 == 0 ? */
- psubb mm7, mm5 /* mm7 has running total of eqcnts */
-
- movq mm2, [eax] /* mm2 = *p_data */
- movq mm0, mm3 /* mm0 = mm3 */
-
- movq mm3, mm2 /* mm3 = *p_data */
- movq mm1, mm0 /* mm1 = mm0 */
-
- psubusb mm0, mm2 /* mm0 -= mm2 */
- add eax, stride /* p_data += stride */
-
- psubusb mm2, mm1 /* mm2 -= mm1 */
- por mm0, mm2 /* mm0 |= mm2 */
-
- pand mm0, mm6 /* mm0 &= 0xfefefefefefefefe */
- pcmpeqb mm0, mm4 /* is mm0 == 0 ? */
-
- movq mm2, [eax] /* mm2 = *p_data */
- psubb mm7, mm0 /* mm7 has running total of eqcnts */
-
- movq mm5, mm3 /* mm5 = mm3 */
- movq mm3, mm2 /* mm3 = *p_data */
-
- movq mm1, mm5 /* mm1 = mm5 */
- psubusb mm5, mm2 /* mm5 -= mm2 */
-
- psubusb mm2, mm1 /* mm2 -= mm1 */
- por mm5, mm2 /* mm5 |= mm2 */
-
- add eax, stride /* p_data += stride */
- pand mm5, mm6 /* mm5 &= 0xfefefefefefefefe */
-
- pcmpeqb mm5, mm4 /* is mm0 == 0 ? */
- psubb mm7, mm5 /* mm7 has running total of eqcnts */
-
- movq mm2, [eax] /* mm2 = *p_data */
- movq mm0, mm3 /* mm0 = mm3 */
-
- movq mm3, mm2 /* mm3 = *p_data */
- movq mm1, mm0 /* mm1 = mm0 */
-
- psubusb mm0, mm2 /* mm0 -= mm2 */
- add eax, stride /* p_data += stride */
-
- psubusb mm2, mm1 /* mm2 -= mm1 */
- por mm0, mm2 /* mm0 |= mm2 */
-
- pand mm0, mm6 /* mm0 &= 0xfefefefefefefefe */
- pcmpeqb mm0, mm4 /* is mm0 == 0 ? */
-
- movq mm2, [eax] /* mm2 = *p_data */
- psubb mm7, mm0 /* mm7 has running total of eqcnts */
-
- movq mm5, mm3 /* mm5 = mm3 */
- movq mm3, mm2 /* mm3 = *p_data */
-
- movq mm1, mm5 /* mm1 = mm5 */
- psubusb mm5, mm2 /* mm5 -= mm2 */
-
- psubusb mm2, mm1 /* mm2 -= mm1 */
- por mm5, mm2 /* mm5 |= mm2 */
-
- add eax, stride /* p_data += stride */
- pand mm5, mm6 /* mm5 &= 0xfefefefefefefefe */
-
- pcmpeqb mm5, mm4 /* is mm0 == 0 ? */
- psubb mm7, mm5 /* mm7 has running total of eqcnts */
-
- movq mm2, [eax] /* mm2 = *p_data */
- movq mm0, mm3 /* mm0 = mm3 */
-
- movq mm3, mm2 /* mm3 = *p_data */
- movq mm1, mm0 /* mm1 = mm0 */
-
- psubusb mm0, mm2 /* mm0 -= mm2 */
- add eax, stride /* p_data += stride */
-
- psubusb mm2, mm1 /* mm2 -= mm1 */
- por mm0, mm2 /* mm0 |= mm2 */
-
- pand mm0, mm6 /* mm0 &= 0xfefefefefefefefe */
- pcmpeqb mm0, mm4 /* is mm0 == 0 ? */
-
- psubb mm7, mm0 /* mm7 has running total of eqcnts */
-
- pop eax
- };
-
- /* now mm7 contains negative eq_cnt for all 8-columns */
- /* copy this to mm_data1 */
- /* sum all 8 bytes in mm7 */
- __asm
- {
- movq mm1, mm7 /* mm1 = mm7 0 1w2 3 4 5 6 7r */
- psrlq mm7, 32 /* mm7 >>= 32 0 1 2 3 4 5 6 7m */
-
- paddb mm7, mm1 /* mm7 has running total of eqcnts */
-
- movq mm1, mm7 /* mm1 = mm7 0 1w2 3 4 5 6 7r */
- psrlq mm7, 16 /* mm7 >>= 16 0 1 2 3 4 5 6 7m */
-
- paddb mm1, mm7 /* mm7 has running total of eqcnts */
-
- movq mm7, mm1 /* mm1 = mm7 0 1w2 3 4 5 6 7r */
- psrlq mm7, 8 /* mm7 >>= 8 0 1 2 3 4 5 6 7m */
-
- paddb mm7, mm1 /* mm7 has running total of eqcnts */
-
- movd mm_data1, mm7 /* mm_data1 = mm7 */
- };
-
- eq_cnt = mm_data1 & 0xff;
-
- useDC = (eq_cnt > moderate_v);
-
-#ifdef PP_SELF_CHECK
- if (useDC != useDC2) dprintf("ERROR: MMX version of useDC is incorrect\n");
-#endif
-
- return useDC;
-}
-
-
-/* this is the deringing filter */
-// new MMXSSE version - trbarry 3/15/2002
-
-void dering( uint8_t *image, int width, int height, int stride, QP_STORE_T *QP_store, int QP_stride, int chroma)
-{
- int x, y;
- uint8_t *b8x8, *b10x10;
- uint8_t b8x8filtered[64];
- int QP, max_diff;
- uint8_t min, max, thr, range;
- uint8_t max_diffq[8]; // a qword value of max_diff
-
- /* loop over all the 8x8 blocks in the image... */
- /* don't process outer row of blocks for the time being. */
- for (y=8; y>3)*QP_stride+(x>>3)] // Nick: QP_store[y/8*QP_stride+x/8]
- : chroma == 0 ? QP_store[(y>>4)*QP_stride+(x>>4)] //Nick: QP_store[y/16*QP_stride+x/16];
- : QP_store[(y>>4)*QP_stride+(x>>3)];
-
- /* pointer to the top left pixel in 8x8 block */
- b8x8 = &(image[stride*y + x]);
-
- /* pointer to the top left pixel in 10x10 block */
- b10x10 = &(image[stride*(y-1) + (x-1)]);
-
- // Threshold determination - find min and max grey levels in the block
- // but remove loop thru 64 bytes. trbarry 03/13/2002
-
- __asm
- {
- mov esi, b8x8 // the block addr
- mov eax, stride // offset to next qword in block
-
- movq mm0, qword ptr[esi] // row 0, 1st qword is our min
- movq mm1, mm0 // .. and our max
-
- pminub mm0, qword ptr[esi+eax] // row 1
- pmaxub mm1, qword ptr[esi+eax]
-
- lea esi, [esi+2*eax] // bump for next 2
- pminub mm0, qword ptr[esi] // row 2
- pmaxub mm1, qword ptr[esi]
-
- pminub mm0, qword ptr[esi+eax] // row 3
- pmaxub mm1, qword ptr[esi+eax]
-
- lea esi, [esi+2*eax] // bump for next 2
- pminub mm0, qword ptr[esi] // row 4
- pmaxub mm1, qword ptr[esi]
-
- pminub mm0, qword ptr[esi+eax] // row 5
- pmaxub mm1, qword ptr[esi+eax]
-
- lea esi, [esi+2*eax] // bump for next 2
- pminub mm0, qword ptr[esi] // row 6
- pmaxub mm1, qword ptr[esi]
-
- pminub mm0, qword ptr[esi+eax] // row 7
- pmaxub mm1, qword ptr[esi+eax]
-
- // get min of 8 bytes in mm0
- pshufw mm2, mm0, (3 << 2) + 2 // words 3,2 into low words of mm2
- pminub mm0, mm2 // now 4 min bytes in low half of mm0
- pshufw mm2, mm0, 1 // get word 1 of mm0 in low word of mm2
- pminub mm0, mm2 // got it down to 2 bytes
- movq mm2, mm0
- psrlq mm2, 8 // byte 1 to low byte
- pminub mm0, mm2 // our answer in low order byte
- movd eax, mm0
- mov min, al // save answer
-
- // get max of 8 bytes in mm1
- pshufw mm2, mm1, (3 << 2) + 2 // words 3,2 into low words of mm2
- pmaxub mm1, mm2 // now 4 max bytes in low half of mm1
- pshufw mm2, mm1, 1 // get word 1 of mm1 in low word of mm2
- pmaxub mm1, mm2 // got it down to 2 bytes
- movq mm2, mm1
- psrlq mm2, 8 // byte 1 to low byte
- pmaxub mm1, mm2 // our answer in low order byte
- movd eax, mm1
- mov max, al // save answer
-
- emms;
- }
-
- /* Threshold detirmination - compute threshold and dynamic range */
- thr = (max + min + 1) >> 1; // Nick / 2 changed to >> 1
- range = max - min;
-
- max_diff = QP>>1;
- max_diffq[0] = max_diffq[1] = max_diffq[2] = max_diffq[3]
- = max_diffq[4] = max_diffq[5] = max_diffq[6] = max_diffq[7]
- = max_diff;
-
- /* To opimize in MMX it's better to always fill in the b8x8filtered[] array
-
- b8x8filtered[8*v + h] = ( 8
- + 1 * b10x10[stride*(v+0) + (h+0)] + 2 * b10x10[stride*(v+0) + (h+1)]
- + 1 * b10x10[stride*(v+0) + (h+2)]
- + 2 * b10x10[stride*(v+1) + (h+0)] + 4 * b10x10[stride*(v+1) + (h+1)]
- + 2 * b10x10[stride*(v+1) + (h+2)]
- + 1 * b10x10[stride*(v+2) + (h+0)] + 2 * b10x10[stride*(v+2) + (h+1)]
- + 1 * b10x10[stride*(v+2) + (h+2)]
- >> 4; // Nick / 16 changed to >> 4
-
- Note - As near as I can see, (a + 2*b + c)/4 = avg( avg(a,c), b) and likewise vertical. So since
- there is a nice pavgb MMX instruction that gives a rounded vector average we may as well use it.
- */
- // Fill in b10x10 array completely with 2 dim center weighted average
- // This section now also includes the clipping step.
- // trbarry 03/14/2002
-
- _asm
- {
- mov esi, b10x10 // ptr to 10x10 source array
- lea edi, b8x8filtered // ptr to 8x8 output array
- mov eax, stride // amt to bump source ptr for next row
-
- movq mm7, qword ptr[esi] // this is really line -1
- pavgb mm7, qword ptr[esi+2] // avg( b[v,h], b[v,h+2] }
- pavgb mm7, qword ptr[esi+1] // center weighted avg of 3 pixels w=1,2,1
-
- lea esi, [esi+eax] // bump src ptr to point at line 0
- movq mm0, qword ptr[esi] // really line 0
- pavgb mm0, qword ptr[esi+2]
- movq mm2, qword ptr[esi+1] // save orig line 0 vals for later clip
- pavgb mm0, mm2
-
- movq mm1, qword ptr[esi+eax] // get line 1
- pavgb mm1, qword ptr[esi+eax+2]
- movq mm3, qword ptr[esi+eax+1] // save orig line 1 vals for later clip
- pavgb mm1, mm3
-
- // 0
- pavgb mm7, mm1 // avg lines surrounding line 0
- pavgb mm7, mm0 // center weighted avg of lines -1,0,1
-
- movq mm4, mm2 // value for clip min
- psubusb mm4, max_diffq // min
- pmaxub mm7, mm4 // must be at least min
- paddusb mm2, max_diffq // max
- pminub mm7, mm2 // but no greater than max
-
- movq qword ptr[edi], mm7
-
- lea esi, [esi+2*eax] // bump source ptr 2 lines
- movq mm2, qword ptr[esi] // get line 2
- pavgb mm2, qword ptr[esi+2]
- movq mm4, qword ptr[esi+1] // save orig line 2 vals for later clip
- pavgb mm2, mm4
-
- // 1
- pavgb mm0, mm2 // avg lines surrounding line 1
- pavgb mm0, mm1 // center weighted avg of lines 0,1,2
-
- movq mm5, mm3 // value for clip min
- psubusb mm5, max_diffq // min
- pmaxub mm0, mm5 // must be at least min
- paddusb mm3, max_diffq // max
- pminub mm0, mm3 // but no greater than max
-
- movq qword ptr[edi+8], mm0
-
- movq mm3, qword ptr[esi+eax] // get line 3
- pavgb mm3, qword ptr[esi+eax+2]
- movq mm5, qword ptr[esi+eax+1] // save orig line 3 vals for later clip
- pavgb mm3, mm5
-
- // 2
- pavgb mm1, mm3 // avg lines surrounding line 2
- pavgb mm1, mm2 // center weighted avg of lines 1,2,3
-
- movq mm6, mm4 // value for clip min
- psubusb mm6, max_diffq // min
- pmaxub mm1, mm6 // must be at least min
- paddusb mm4, max_diffq // max
- pminub mm1, mm4 // but no greater than max
-
- movq qword ptr[edi+16], mm1
-
- lea esi, [esi+2*eax] // bump source ptr 2 lines
- movq mm4, qword ptr[esi] // get line 4
- pavgb mm4, qword ptr[esi+2]
- movq mm6, qword ptr[esi+1] // save orig line 4 vals for later clip
- pavgb mm4, mm6
-
- // 3
- pavgb mm2, mm4 // avg lines surrounding line 3
- pavgb mm2, mm3 // center weighted avg of lines 2,3,4
-
- movq mm7, mm5 // save value for clip min
- psubusb mm7, max_diffq // min
- pmaxub mm2, mm7 // must be at least min
- paddusb mm5, max_diffq // max
- pminub mm2, mm5 // but no greater than max
-
- movq qword ptr[edi+24], mm2
-
- movq mm5, qword ptr[esi+eax] // get line 5
- pavgb mm5, qword ptr[esi+eax+2]
- movq mm7, qword ptr[esi+eax+1] // save orig line 5 vals for later clip
- pavgb mm5, mm7
-
- // 4
- pavgb mm3, mm5 // avg lines surrounding line 4
- pavgb mm3, mm4 // center weighted avg of lines 3,4,5
-
- movq mm0, mm6 // save value for clip min
- psubusb mm0, max_diffq // min
- pmaxub mm3, mm0 // must be at least min
- paddusb mm6, max_diffq // max
- pminub mm3, mm6 // but no greater than max
-
- movq qword ptr[edi+32], mm3
-
- lea esi, [esi+2*eax] // bump source ptr 2 lines
- movq mm6, qword ptr[esi] // get line 6
- pavgb mm6, qword ptr[esi+2]
- movq mm0, qword ptr[esi+1] // save orig line 6 vals for later clip
- pavgb mm6, mm0
-
- // 5
- pavgb mm4, mm6 // avg lines surrounding line 5
- pavgb mm4, mm5 // center weighted avg of lines 4,5,6
-
- movq mm1, mm7 // save value for clip min
- psubusb mm1, max_diffq // min
- pmaxub mm4, mm1 // must be at least min
- paddusb mm7, max_diffq // max
- pminub mm4, mm7 // but no greater than max
-
- movq qword ptr[edi+40], mm4
-
- movq mm7, qword ptr[esi+eax] // get line 7
- pavgb mm7, qword ptr[esi+eax+2]
- movq mm1, qword ptr[esi+eax+1] // save orig line 7 vals for later clip
- pavgb mm7, mm1
-
- // 6
- pavgb mm5, mm7 // avg lines surrounding line 6
- pavgb mm5, mm6 // center weighted avg of lines 5,6,7
-
- movq mm2, mm0 // save value for clip min
- psubusb mm2, max_diffq // min
- pmaxub mm5, mm2 // must be at least min
- paddusb mm0, max_diffq // max
- pminub mm5, mm0 // but no greater than max
-
- movq qword ptr[edi+48], mm5
-
- movq mm0, qword ptr[esi+2*eax] // get line 8
- pavgb mm0, qword ptr[esi+2*eax+2]
- pavgb mm0, qword ptr[esi+2*eax+1]
-
- // 7
- pavgb mm6, mm0 // avg lines surrounding line 7
- pavgb mm6, mm7 // center weighted avg of lines 6,7,8
-
- movq mm3, mm1 // save value for clip min
- psubusb mm3, max_diffq // min
- pmaxub mm6, mm3 // must be at least min
- paddusb mm1, max_diffq // max
- pminub mm6, mm1 // but no greater than max
-
- movq qword ptr[edi+56], mm6
-
- emms
- }
-
- // trbarry 03-15-2002
- // If I (hopefully) understand all this correctly then we are supposed to only use the filtered
- // pixels created above in the case where the orig pixel and all its 8 surrounding neighbors
- // are either all above or all below the threashold. Since a mmx compare sets the mmx reg
- // bytes to either 00 or ff we will just check a lopside average of all 9 of these to see
- // if it is still 00 or ff.
- // register notes:
- // esi b10x10
- // edi b8x8filtered
- // eax stride
- // mm0 line 0, 3, or 6 compare average
- // mm1 line 1, 4, or 7 "
- // mm2 line 2, 5, 8, or -1 "
- // mm3 odd line original pixel value
- // mm4 even line original pixel value
- // mm5
- // mm6 8 00's
- // mm7 8 copies of threshold
-
- _asm
- {
- mov esi, b10x10 // ptr to 10x10 source array
- lea edi, b8x8filtered // ptr to 8x8 output array
- mov eax, stride // amt to bump source ptr for next row
- mov bh, thr
- mov bl, thr
- psubusb mm6, mm6 // all 00
- movd mm7, ebx
- pshufw mm7, mm7, 0 // low word to all words
-
- // get compare avg of row -1
- movq mm3, qword ptr[esi+1] // save center pixels of line -1
-
- movq mm2, mm7
- psubusb mm2, qword ptr[esi] // left pixels >= threshold?
- pcmpeqb mm2, mm6 // ff if >= else 00
-
- movq mm5, mm7
- psubusb mm5, mm3 // center pixels >= threshold?
- pcmpeqb mm5, mm6
- pavgb mm2, mm5 // combine answers
-
- movq mm5, mm7
- psubusb mm5, qword ptr[esi+2] // right pixels >= threshold?
- pcmpeqb mm5, mm6
- pavgb mm2, mm5 // combine answers
-
- lea esi, [esi+eax] // &row 0
-
- // get compare avg of row 0
- movq mm4, qword ptr[esi+1] // save center pixels
-
- movq mm0, mm7
- psubusb mm0, qword ptr[esi] // left pixels >= threshold?
- pcmpeqb mm0, mm6 // ff if >= else 00
-
- movq mm5, mm7
- psubusb mm5, mm4 // center pixels >= threshold?
- pcmpeqb mm5, mm6
- pavgb mm0, mm5 // combine answers
-
- movq mm5, mm7
- psubusb mm5, qword ptr[esi+2] // right pixels >= threshold?
- pcmpeqb mm5, mm6
- pavgb mm0, mm5 // combine answers
-
- // get compare avg of row 1
-
- movq mm3, qword ptr[esi+eax+1] // save center pixels
-
- movq mm1, mm7
- psubusb mm1, qword ptr[esi+eax] // left pixels >= threshold?
- pcmpeqb mm1, mm6 // ff if >= else 00
-
- movq mm5, mm7
- psubusb mm5, mm3 // center pixels >= threshold?
- pcmpeqb mm5, mm6
- pavgb mm1, mm5 // combine answers
-
- movq mm5, mm7
- psubusb mm5, qword ptr[esi+eax+2] // right pixels >= threshold?
- pcmpeqb mm5, mm6
- pavgb mm1, mm5 // combine answers
-
- // decide whether to move filtered or orig pixels to row 0, move them
-
- pavgb mm2, mm0
- pavgb mm2, mm1
- pcmpeqb mm5, mm5 // all ff
- pcmpeqb mm5, mm2 // 00 or ff
- pcmpeqb mm5, mm2 // mm2 = ff or 00 ? ff : 00
- psubusb mm2, mm2 // 00
- pcmpeqb mm2, mm5 // opposite of mm5
- pand mm2, mm4 // use orig vales if thresh's diff, else 00
- pand mm5, qword ptr[edi] // use filterd vales if thresh's same, else 00
- por mm5, mm2 // one of them hsa a value
- movq qword ptr[esi+1], mm5 // and store 8 pixels
-
- lea esi, [esi+eax] // &row 1
-
- // get compare avg of row 2
-
- movq mm4, qword ptr[esi+eax+1] // save center pixels
-
- movq mm2, mm7
- psubusb mm2, qword ptr[esi+eax] // left pixels >= threshold?
- pcmpeqb mm2, mm6 // ff if >= else 00
-
- movq mm5, mm7
- psubusb mm5, mm4 // center pixels >= threshold?
- pcmpeqb mm5, mm6
- pavgb mm2, mm5 // combine answers
-
- movq mm5, mm7
- psubusb mm5, qword ptr[esi+eax+2] // right pixels >= threshold?
- pcmpeqb mm5, mm6
- pavgb mm2, mm5 // combine answers
-
- // decide whether to move filtered or orig pixels to row 1, move them
-
- pavgb mm0, mm1
- pavgb mm0, mm2
- pcmpeqb mm5, mm5 // all ff
- pcmpeqb mm5, mm0 // 00 or ff
- pcmpeqb mm5, mm0 // mm2 = ff or 00 ? ff : 00
- psubusb mm0, mm0 // 00
- pcmpeqb mm0, mm5 // opposite of mm5
- pand mm0, mm3 // use orig vales if thresh's diff, else 00
- pand mm5, qword ptr[edi+1*8] // use filterd vales if thresh's same, else 00
- por mm5, mm0 // one of them hsa a value
- movq qword ptr[esi+1], mm5 // and store 8 pixels
-
- lea esi, [esi+eax] // &row 2
-
- // get compare avg of row 3
-
- movq mm3, qword ptr[esi+eax+1] // save center pixels
-
- movq mm0, mm7
- psubusb mm0, qword ptr[esi+eax] // left pixels >= threshold?
- pcmpeqb mm0, mm6 // ff if >= else 00
-
- movq mm5, mm7
- psubusb mm5, mm3 // center pixels >= threshold?
- pcmpeqb mm5, mm6
- pavgb mm0, mm5 // combine answers
-
- movq mm5, mm7
- psubusb mm5, qword ptr[esi+eax+2] // right pixels >= threshold?
- pcmpeqb mm5, mm6
- pavgb mm0, mm5 // combine answers
-
- // decide whether to move filtered or orig pixels to row 2, move them
-
- pavgb mm1, mm0
- pavgb mm1, mm2
- pcmpeqb mm5, mm5 // all ff
- pcmpeqb mm5, mm1 // 00 or ff
- pcmpeqb mm5, mm1 // mm2 = ff or 00 ? ff : 00
- psubusb mm1, mm1 // 00
- pcmpeqb mm1, mm5 // opposite of mm5
- pand mm1, mm4 // use orig vales if thresh's diff, else 00
- pand mm5, qword ptr[edi+2*8] // use filterd vales if thresh's same, else 00
- por mm5, mm1 // one of them hsa a value
- movq qword ptr[esi+1], mm5 // and store 8 pixels
-
- lea esi, [esi+eax] // &row 3
-
- // get compare avg of row 4
-
- movq mm4, qword ptr[esi+eax+1] // save center pixels
-
- movq mm1, mm7
- psubusb mm1, qword ptr[esi+eax] // left pixels >= threshold?
- pcmpeqb mm1, mm6 // ff if >= else 00
-
- movq mm5, mm7
- psubusb mm5, mm4 // center pixels >= threshold?
- pcmpeqb mm5, mm6
- pavgb mm1, mm5 // combine answers
-
- movq mm5, mm7
- psubusb mm5, qword ptr[esi+eax+2] // right pixels >= threshold?
- pcmpeqb mm5, mm6
- pavgb mm1, mm5 // combine answers
-
- // decide whether to move filtered or orig pixels to row 3, move them
-
- pavgb mm2, mm0
- pavgb mm2, mm1
- pcmpeqb mm5, mm5 // all ff
- pcmpeqb mm5, mm2 // 00 or ff
- pcmpeqb mm5, mm2 // mm2 = ff or 00 ? ff : 00
- psubusb mm2, mm2 // 00
- pcmpeqb mm2, mm5 // opposite of mm5
- pand mm2, mm3 // use orig vales if thresh's diff, else 00
- pand mm5, qword ptr[edi+3*8] // use filterd vales if thresh's same, else 00
- por mm5, mm2 // one of them hsa a value
- movq qword ptr[esi+1], mm5 // and store 8 pixels
-
- lea esi, [esi+eax] // &row 4
-
- // get compare avg of row 5
-
- movq mm3, qword ptr[esi+eax+1] // save center pixels
-
- movq mm2, mm7
- psubusb mm2, qword ptr[esi+eax] // left pixels >= threshold?
- pcmpeqb mm2, mm6 // ff if >= else 00
-
- movq mm5, mm7
- psubusb mm5, mm3 // center pixels >= threshold?
- pcmpeqb mm5, mm6
- pavgb mm2, mm5 // combine answers
-
- movq mm5, mm7
- psubusb mm5, qword ptr[esi+eax+2] // right pixels >= threshold?
- pcmpeqb mm5, mm6
- pavgb mm2, mm5 // combine answers
-
- // decide whether to move filtered or orig pixels to row 4, move them
-
- pavgb mm0, mm2
- pavgb mm0, mm1
- pcmpeqb mm5, mm5 // all ff
- pcmpeqb mm5, mm0 // 00 or ff
- pcmpeqb mm5, mm0 // mm2 = ff or 00 ? ff : 00
- psubusb mm0, mm0 // 00
- pcmpeqb mm0, mm5 // opposite of mm5
- pand mm0, mm4 // use orig vales if thresh's diff, else 00
- pand mm5, qword ptr[edi+4*8] // use filterd vales if thresh's same, else 00
- por mm5, mm0 // one of them hsa a value
- movq qword ptr[esi+1], mm5 // and store 8 pixels
-
- lea esi, [esi+eax] // &row 5
-
- // get compare avg of row 6
-
- movq mm4, qword ptr[esi+eax+1] // save center pixels
-
- movq mm0, mm7
- psubusb mm0, qword ptr[esi+eax] // left pixels >= threshold?
- pcmpeqb mm0, mm6 // ff if >= else 00
-
- movq mm5, mm7
- psubusb mm5, mm4 // center pixels >= threshold?
- pcmpeqb mm5, mm6
- pavgb mm0, mm5 // combine answers
-
- movq mm5, mm7
- psubusb mm5, qword ptr[esi+eax+2] // right pixels >= threshold?
- pcmpeqb mm5, mm6
- pavgb mm0, mm5 // combine answers
-
- // decide whether to move filtered or orig pixels to row 5, move them
-
- pavgb mm1, mm0
- pavgb mm1, mm2
- pcmpeqb mm5, mm5 // all ff
- pcmpeqb mm5, mm1 // 00 or ff
- pcmpeqb mm5, mm1 // mm2 = ff or 00 ? ff : 00
- psubusb mm1, mm1 // 00
- pcmpeqb mm1, mm5 // opposite of mm5
- pand mm1, mm3 // use orig vales if thresh's diff, else 00
- pand mm5, qword ptr[edi+5*8] // use filterd vales if thresh's same, else 00
- por mm5, mm1 // one of them hsa a value
- movq qword ptr[esi+1], mm5 // and store 8 pixels
-
- lea esi, [esi+eax] // &row 6
-
- // get compare avg of row 7
-
- movq mm3, qword ptr[esi+eax+1] // save center pixels
-
- movq mm1, mm7
- psubusb mm1, qword ptr[esi+eax] // left pixels >= threshold?
- pcmpeqb mm1, mm6 // ff if >= else 00
-
- movq mm5, mm7
- psubusb mm5, mm3 // center pixels >= threshold?
- pcmpeqb mm5, mm6
- pavgb mm1, mm5 // combine answers
-
- movq mm5, mm7
- psubusb mm5, qword ptr[esi+eax+2] // right pixels >= threshold?
- pcmpeqb mm5, mm6
- pavgb mm1, mm5 // combine answers
-
- // decide whether to move filtered or orig pixels to row 6, move them
-
- pavgb mm2, mm0
- pavgb mm2, mm1
- pcmpeqb mm5, mm5 // all ff
- pcmpeqb mm5, mm2 // 00 or ff
- pcmpeqb mm5, mm2 // mm2 = ff or 00 ? ff : 00
- psubusb mm2, mm2 // 00
- pcmpeqb mm2, mm5 // opposite of mm5
- pand mm2, mm4 // use orig vales if thresh's diff, else 00
- pand mm5, qword ptr[edi+6*8] // use filterd vales if thresh's same, else 00
- por mm5, mm2 // one of them hsa a value
- movq qword ptr[esi+1], mm5 // and store 8 pixels
-
- lea esi, [esi+eax] // &row 7
-
- // get compare avg of row 8
-
- movq mm4, qword ptr[esi+eax+1] // save center pixels
-
- movq mm2, mm7
- psubusb mm2, qword ptr[esi+eax] // left pixels >= threshold?
- pcmpeqb mm2, mm6 // ff if >= else 00
-
- movq mm5, mm7
- psubusb mm5, mm4 // center pixels >= threshold?
- pcmpeqb mm5, mm6
- pavgb mm2, mm5 // combine answers
-
- movq mm5, mm7
- psubusb mm5, qword ptr[esi+eax+2] // right pixels >= threshold?
- pcmpeqb mm5, mm6
- pavgb mm2, mm5 // combine answers
-
- // decide whether to move filtered or orig pixels to row 7, move them
-
- pavgb mm0, mm1
- pavgb mm0, mm2
- pcmpeqb mm5, mm5 // all ff
- pcmpeqb mm5, mm0 // 00 or ff
- pcmpeqb mm5, mm0 // mm2 = ff or 00 ? ff : 00
- psubusb mm0, mm0 // 00
- pcmpeqb mm0, mm5 // opposite of mm5
- pand mm0, mm3 // use orig vales if thresh's diff, else 00
- pand mm5, qword ptr[edi+7*8] // use filterd vales if thresh's same, else 00
- por mm5, mm0 // one of them hsa a value
- movq qword ptr[esi+1], mm5 // and store 8 pixels
-
- emms
- }
- }
- }
-}
-
diff --git a/src/dgdecode/PostProcess.h b/src/dgdecode/PostProcess.h
deleted file mode 100644
index f87d0b5..0000000
--- a/src/dgdecode/PostProcess.h
+++ /dev/null
@@ -1,55 +0,0 @@
-#ifndef _POSTPROCESS_H
-#define _POSTPROCESS_H
-
-#include
-
-#define DEC_MBC 45+300
-#define DEC_MBR 36+300
-
-/**** mode flags to control postprocessing actions ****/
-#define PP_DEBLOCK_Y_H 0x00000001 /* Luma horizontal deblocking */
-#define PP_DEBLOCK_Y_V 0x00000002 /* Luma vertical deblocking */
-#define PP_DEBLOCK_C_H 0x00000004 /* Chroma horizontal deblocking */
-#define PP_DEBLOCK_C_V 0x00000008 /* Chroma vertical deblocking */
-#define PP_DERING_Y 0x00000010 /* Luma deringing */
-#define PP_DERING_C 0x00000020 /* Chroma deringing */
-#define PP_DONT_COPY 0x10000000 /* Postprocessor will not copy src -> dst */
- /* instead, it will operate on dst only */
-
-/******************* general, useful macros ****************/
-#define SIGN(a) ( (a)<0 ? -1 : 1 )
-
-typedef int QP_STORE_T;
-
-/******************** component function prototypes **************/
-int deblock_horiz_useDC(uint8_t *v, int stride, int moderate_h);
-int deblock_horiz_DC_on(uint8_t *v, int stride, int QP);
-void deblock_horiz_lpf9(uint8_t *v, int stride, int QP);
-void deblock_horiz_default_filter(uint8_t *v, int stride, int QP);
-void deblock_horiz(uint8_t *image, int width, int stride, QP_STORE_T *QP_store, int QP_stride, int chromaFlag, int moderate_h);
-int deblock_vert_useDC(uint8_t *v, int stride, int moderate_v);
-int deblock_vert_DC_on(uint8_t *v, int stride, int QP);
-void deblock_vert_copy_and_unpack(int stride, uint8_t *source, uint64_t *dest, int n);
-void deblock_vert_choose_p1p2(uint8_t *v, int stride, uint64_t *p1p2, int QP);
-void deblock_vert_lpf9(uint64_t *v_local, uint64_t *p1p2, uint8_t *v, int stride);
-void deblock_vert_default_filter(uint8_t *v, int stride, int QP);
-void deblock_vert( uint8_t *image, int width, int stride, QP_STORE_T *QP_store, int QP_stride, int chromaFlag, int moderate_v);
-void dering( uint8_t *image, int width, int height, int stride, int *QP_store, int QP_stride, int chroma);
-
-void postprocess(uint8_t * src[], int src_stride, int UVsrc_stride,
- uint8_t * dst[], int dst_stride, int UVdst_stride,
-
- int horizontal_size, int vertical_size,
- QP_STORE_T *QP_store, int QP_stride,
- int mode, int moderate_h, int moderate_v, bool is422, bool iPP);
-void do_emms();
-
-// New Deringing Algo:
-struct DERING_INFO
-{
- uint8_t *rangearray;
- uint8_t *thrarray;
-};
-
-
-#endif
diff --git a/src/dgdecode/color_convert.h b/src/dgdecode/color_convert.h
deleted file mode 100644
index 7b09d47..0000000
--- a/src/dgdecode/color_convert.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#ifndef MPEG2DECPLUS_COLOR_CONVERT_H
-#define MPEG2DECPLUS_COLOR_CONVERT_H
-
-#include
-
-
-void conv420to422P(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitch,
- int width, int height);
-
-void conv420to422I(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitch,
- int width, int height);
-
-void conv422to444(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitch,
- int width, int height);
-#if 0
-void conv444toRGB24(const uint8_t *py, const uint8_t *pu, const uint8_t *pv,
- uint8_t *dst, int src_pitchY, int src_pitchUV, int dst_pitch, int width,
- int height, int matrix, int pc_scale);
-
-void convYUY2to422P(const uint8_t *src, uint8_t *py, uint8_t *pu, uint8_t *pv,
- int pitch1, int pitch2y, int pitch2uv, int width, int height);
-
-void conv422PtoYUY2(const uint8_t *py, uint8_t *pu, uint8_t *pv, uint8_t *dst,
- int pitch1Y, int pitch1UV, int pitch2, int width, int height);
-#endif
-
-#endif
-
diff --git a/src/dgdecode/deblock.cpp b/src/dgdecode/deblock.cpp
deleted file mode 100644
index 47a570a..0000000
--- a/src/dgdecode/deblock.cpp
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
-A rewite of Deblock filter for support all planar 8bit YUV.
-Almost same as tp7's version.
-*/
-
-#include "AvisynthAPI.h"
-
-
-static inline int sat(int x, int min, int max)
-{
- return (x < min) ? min : ((x > max) ? max : x);
-}
-
-
-static inline int absdiff(int x, int y)
-{
- return x > y ? x - y : y - x;
-}
-
-
-static const int alphas[52] = {
- 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 4, 4,
- 5, 6, 7, 8, 9, 10,
- 12, 13, 15, 17, 20,
- 22, 25, 28, 32, 36,
- 40, 45, 50, 56, 63,
- 71, 80, 90, 101, 113,
- 127, 144, 162, 182,
- 203, 226, 255, 255
-};
-
-static const int betas[52] = {
- 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 2, 2,
- 2, 3, 3, 3, 3, 4,
- 4, 4, 6, 6,
- 7, 7, 8, 8, 9, 9,
- 10, 10, 11, 11, 12,
- 12, 13, 13, 14, 14,
- 15, 15, 16, 16, 17,
- 17, 18, 18
-};
-
-static const int cs[52] = {
- 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 1, 1, 1,
- 1, 1, 1, 1, 1, 1,
- 1, 2, 2, 2, 2, 3,
- 3, 3, 4, 4, 5, 5,
- 6, 7, 8, 8, 10,
- 11, 12, 13, 15, 17
-};
-
-
-static void deblock_h_edge(uint8_t *srcp, int srcPitch, const int alpha, const int beta, const int c0)
-{
- uint8_t *sq0 = srcp;
- uint8_t *sq1 = srcp + srcPitch;
- uint8_t *sq2 = srcp + 2 * srcPitch;
- uint8_t *sp0 = srcp - srcPitch;
- uint8_t *sp1 = srcp - 2 * srcPitch;
- uint8_t *sp2 = srcp - 3 * srcPitch;
-
- for (int i = 0; i < 4; ++i) {
- if ((absdiff(sp0[i], sq0[i]) < alpha)
- && (absdiff(sp1[i], sp0[i]) < beta)
- && (absdiff(sq0[i], sq1[i]) < beta)) {
- int ap = absdiff(sp2[i], sp0[i]);
- int aq = absdiff(sq2[i], sq0[i]);
-
- int c = c0;
- if (aq < beta) ++c;
- if (ap < beta) ++c;
-
- int delta = sat((((sq0[i] - sp0[i]) * 4) + (sp1[i] - sq1[i]) + 4) >> 3, -c, c);
- int avg = (sp0[i] + sq0[i] + 1) / 2;
- int deltap1 = sat((sp2[i] + avg - sp1[i] * 2) / 2, -c0, c0);
- int deltaq1 = sat((sq2[i] + avg - sq1[i] * 2) / 2, -c0, c0);
-
- if (ap < beta) sp1[i] = sp1[i] + deltap1;
- sp0[i] = sat(sp0[i] + delta, 0, 255);
- sq0[i] = sat(sq0[i] - delta, 0, 255);
- if (aq < beta) sq1[i] = sq1[i] + deltaq1;
- }
- }
-}
-
-
-static void deblock_v_edge(uint8_t *s, int srcPitch, const int alpha, const int beta, const int c0)
-{
- for (int i = 0; i < 4; ++i) {
- if ((absdiff(s[0], s[-1]) < alpha)
- && (absdiff(s[0], s[1]) < beta)
- && (absdiff(s[-1], s[-2]) < beta)) {
- int ap = absdiff(s[0], s[2]);
- int aq = absdiff(s[-3], s[-1]);
-
- int c = c0;
- if (aq < beta) ++c;
- if (ap < beta) ++c;
-
- int delta = sat((((s[0] - s[-1]) * 4) + (s[-2] - s[1]) + 4) / 8, -c, c);
- int avg = (s[0] + s[-1] + 1) / 2;
- int deltaq1 = sat((s[2] + avg - s[1] * 2) / 2, -c0, c0);
- int deltap1 = sat((s[-3] + avg - s[-2] * 2) / 2, -c0, c0);
-
- if (aq < beta) s[-2] = (s[-2] + deltap1);
- s[-1] = sat(s[-1] + delta, 0, 255);
- s[0] = sat(s[0] - delta, 0, 255);
- if (ap < beta) s[1] = (s[1] + deltaq1);
- }
- s += srcPitch;
- }
-}
-
-
-static void deblock_picture(uint8_t *srcp, int srcPitch, int w, int h,
- const int alpha, const int beta, const int c0)
-{
- for (int j = 0; j < h; j += 4 ) {
- for (int i = 0; i < w; i += 4) {
- if ( j > 0 )
- deblock_h_edge(srcp + i, srcPitch, alpha, beta, c0);
- if ( i > 0 )
- deblock_v_edge(srcp + i, srcPitch, alpha, beta, c0);
- }
- srcp += 4 * srcPitch;
- }
-}
-
-
-Deblock::Deblock(PClip _child, int q, int aoff, int boff, IScriptEnvironment* env) :
- GenericVideoFilter(_child)
-{
- q = sat(q, 0, 51);
- int a = sat(q + aoff, 0, 51);
- int b = sat(q + boff, 0, 51);
- alpha = alphas[a];
- beta = betas[b];
- c0 = cs[a];
-
- if (!vi.IsPlanar() || !vi.IsYUV())
- env->ThrowError("Deblock: need planar yuv input.");
- if (vi.IsYUVA()) {
- env->ThrowError("Deblock: alpha is not supported.");
- }
- if ((vi.width & 7) || (vi.height & 7))
- env->ThrowError("Deblock : width and height must be mod 8");
-
- numPlanes = vi.IsY8() ? 1 : 3;
-}
-
-
-PVideoFrame __stdcall Deblock::GetFrame(int n, IScriptEnvironment *env)
-{
- PVideoFrame src = child->GetFrame(n, env);
- env->MakeWritable(&src);
-
- static const int planes[] = { PLANAR_Y, PLANAR_U, PLANAR_V };
- for (int p = 0; p < numPlanes; ++p) {
- const int plane = planes[p];
- deblock_picture(src->GetWritePtr(plane), src->GetPitch(plane),
- src->GetRowSize(plane), src->GetHeight(plane),
- alpha, beta, c0);
- }
-
- return src;
-}
-
-
-AVSValue __cdecl Deblock::create(AVSValue args, void* user_data, IScriptEnvironment* env)
-{
- int quant = args[1].AsInt(25);
- int aoffset = args[2].AsInt(0);
- int boffset = args[3].AsInt(0);
- return new Deblock(args[0].AsClip(), quant, aoffset, boffset, env);
-}
diff --git a/src/dgdecode/idct.h b/src/dgdecode/idct.h
deleted file mode 100644
index c71d72f..0000000
--- a/src/dgdecode/idct.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef MPEG2DECPLUS_IDCT_H
-#define MPEG2DECPLUS_IDCT_H
-
-#include
-
-void __fastcall idct_ref_sse3(int16_t* block) noexcept;
-
-void __fastcall prefetch_ref() noexcept;
-
-void __fastcall idct_ap922_sse2(int16_t* block) noexcept;
-
-void __fastcall prefetch_ap922() noexcept;
-
-void __fastcall idct_llm_float_sse2(int16_t* block) noexcept;
-
-void __fastcall idct_llm_float_avx2(int16_t* block) noexcept;
-
-void __fastcall prefetch_llm_float_sse2() noexcept;
-
-void __fastcall prefetch_llm_float_avx2() noexcept;
-
-#endif
diff --git a/src/dgdecode/misc.cpp b/src/dgdecode/misc.cpp
deleted file mode 100644
index 5b19b41..0000000
--- a/src/dgdecode/misc.cpp
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * Misc Stuff for MPEG2Dec3
- *
- * Copyright (C) 2002-2003 Marc Fauconneau
- *
- * This file is part of MPEG2Dec3, a free MPEG-2 decoder
- *
- * MPEG2Dec3 is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * MPEG2Dec3 is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
-
-#include
-#include
-#define WIN32_LEAN_AND_MEAN
-#define NOMINMAX
-#include
-
-#include "misc.h"
-
-
-size_t __cdecl dprintf(char* fmt, ...)
-{
- char printString[1024];
-
- va_list argp;
-
- va_start(argp, fmt);
- vsprintf(printString, fmt, argp);
- va_end(argp);
- OutputDebugString(printString);
- return strlen(printString);
-}
-
-
-void __stdcall
-fast_copy(const uint8_t* src, const int src_stride, uint8_t* dst,
- const int dst_stride, const int horizontal_size, int vertical_size) noexcept
-{
- if (vertical_size == 0) {
- return;
- } else if (horizontal_size == src_stride && src_stride == dst_stride) {
- memcpy(dst, src, horizontal_size * vertical_size);
- } else {
- do {
- memcpy(dst, src, horizontal_size);
- dst += dst_stride;
- src += src_stride;
- } while (--vertical_size != 0);
- }
-}
-
-
-enum {
- CPU_NO_X86_SIMD = 0x000000,
- CPU_SSE2_SUPPORT = 0x000001,
- CPU_SSE3_SUPPORT = 0x000002,
- CPU_SSSE3_SUPPORT = 0x000004,
- CPU_SSE4_1_SUPPORT = 0x000008,
- CPU_SSE4_2_SUPPORT = 0x000010,
- CPU_SSE4_A_SUPPORT = 0x000020,
- CPU_FMA4_SUPPORT = 0x000040,
- CPU_FMA3_SUPPORT = 0x000080,
- CPU_AVX_SUPPORT = 0x000100,
- CPU_AVX2_SUPPORT = 0x000200,
- CPU_AVX512F_SUPPORT = 0x000400,
- CPU_AVX512DQ_SUPPORT = 0x000800,
- CPU_AVX512IFMA52_SUPPORT = 0x001000,
- CPU_AVX512PF_SUPPORT = 0x002000,
- CPU_AVX512ER_SUPPORT = 0x004000,
- CPU_AVX512CD_SUPPORT = 0x008000,
- CPU_AVX512BW_SUPPORT = 0x010000,
- CPU_AVX512VL_SUPPORT = 0x020000,
- CPU_AVX512VBMI_SUPPORT = 0x040000,
-};
-
-
-static __forceinline bool is_bit_set(int bitfield, int bit) noexcept
-{
- return (bitfield & (1 << bit)) != 0;
-}
-
-static uint32_t get_simd_support_info(void) noexcept
-{
- uint32_t ret = 0;
- int regs[4] = {0};
-
- __cpuid(regs, 0x00000001);
- if (is_bit_set(regs[3], 26)) {
- ret |= CPU_SSE2_SUPPORT;
- }
- if (is_bit_set(regs[2], 0)) {
- ret |= CPU_SSE3_SUPPORT;
- }
- if (is_bit_set(regs[2], 9)) {
- ret |= CPU_SSSE3_SUPPORT;
- }
- if (is_bit_set(regs[2], 19)) {
- ret |= CPU_SSE4_1_SUPPORT;
- }
- if (is_bit_set(regs[2], 26)) {
- ret |= CPU_SSE4_2_SUPPORT;
- }
- if (is_bit_set(regs[2], 27)) {
- if (is_bit_set(regs[2], 28)) {
- ret |= CPU_AVX_SUPPORT;
- }
- if (is_bit_set(regs[2], 12)) {
- ret |= CPU_FMA3_SUPPORT;
- }
- }
-
- regs[3] = 0;
- __cpuid(regs, 0x80000001);
- if (is_bit_set(regs[3], 6)) {
- ret |= CPU_SSE4_A_SUPPORT;
- }
- if (is_bit_set(regs[3], 16)) {
- ret |= CPU_FMA4_SUPPORT;
- }
-
- __cpuid(regs, 0x00000000);
- if (regs[0] < 7) {
- return ret;
- }
-
- __cpuidex(regs, 0x00000007, 0);
- if (is_bit_set(regs[1], 5)) {
- ret |= CPU_AVX2_SUPPORT;
- }
- if (!is_bit_set(regs[1], 16)) {
- return ret;
- }
-
- ret |= CPU_AVX512F_SUPPORT;
- if (is_bit_set(regs[1], 17)) {
- ret |= CPU_AVX512DQ_SUPPORT;
- }
- if (is_bit_set(regs[1], 21)) {
- ret |= CPU_AVX512IFMA52_SUPPORT;
- }
- if (is_bit_set(regs[1], 26)) {
- ret |= CPU_AVX512PF_SUPPORT;
- }
- if (is_bit_set(regs[1], 27)) {
- ret |= CPU_AVX512ER_SUPPORT;
- }
- if (is_bit_set(regs[1], 28)) {
- ret |= CPU_AVX512CD_SUPPORT;
- }
- if (is_bit_set(regs[1], 30)) {
- ret |= CPU_AVX512BW_SUPPORT;
- }
- if (is_bit_set(regs[1], 31)) {
- ret |= CPU_AVX512VL_SUPPORT;
- }
- if (is_bit_set(regs[2], 1)) {
- ret |= CPU_AVX512VBMI_SUPPORT;
- }
-
- return ret;
-}
-
-bool has_sse2() noexcept
-{
- return (get_simd_support_info() & CPU_SSE2_SUPPORT) != 0;
-}
-
-bool has_sse3() noexcept
-{
- return (get_simd_support_info() & CPU_SSE4_1_SUPPORT) != 0;
-}
-
-bool has_avx2() noexcept
-{
- uint32_t flags = CPU_AVX2_SUPPORT | CPU_FMA3_SUPPORT;
- return (get_simd_support_info() & flags) == flags;
-}
-
diff --git a/src/dgindex/AC3Dec/ac3.h b/src/dgindex/AC3Dec/ac3.h
deleted file mode 100644
index eff4af8..0000000
--- a/src/dgindex/AC3Dec/ac3.h
+++ /dev/null
@@ -1,356 +0,0 @@
-/*
- * Copyright (C) Aaron Holtzman - May 1999
- *
- * This file is part of ac3dec, a free Dolby AC-3 stream decoder.
- *
- * ac3dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * ac3dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
-#include
-
-#ifdef AC3_GLOBAL
-#define AXTN
-#else
-#define AXTN extern
-#endif
-
-typedef unsigned int uint_32;
-typedef unsigned short uint_16;
-typedef unsigned char uint_8;
-
-typedef signed int sint_32;
-typedef signed short sint_16;
-typedef signed char sint_8;
-
-uint_32 ac3_decode_data(uint_8 *data_start, uint_32 length, uint_32 start);
-
-/* Exponent strategy constants */
-#define EXP_REUSE (0)
-#define EXP_D15 (1)
-#define EXP_D25 (2)
-#define EXP_D45 (3)
-
-/* Delta bit allocation constants */
-#define DELTA_BIT_REUSE (0)
-#define DELTA_BIT_NEW (1)
-#define DELTA_BIT_NONE (2)
-#define DELTA_BIT_RESERVED (3)
-
-/* samples work structure */
-typedef double stream_samples_t[6][256];
-
-typedef struct syncinfo_s
-{
- /* Sync word == 0x0B77 */
- uint_16 syncword;
- /* crc for the first 5/8 of the sync block */
- /* uint_16 crc1; */
- /* Stream Sampling Rate (kHz) 0 = 48, 1 = 44.1, 2 = 32, 3 = reserved */
- uint_16 fscod;
- /* Frame size code */
- uint_16 frmsizecod;
-
- /* Information not in the AC-3 bitstream, but derived */
- /* Frame size in 16 bit words */
- uint_16 frame_size;
- /* Bit rate in kilobits */
- uint_16 bit_rate;
- /* sampling rate in hertz */
- uint_32 sampling_rate;
-} syncinfo_t;
-
-typedef struct bsi_s
-{
- /* Bit stream identification == 0x8 */
- uint_16 bsid;
- /* Bit stream mode */
- uint_16 bsmod;
- /* Audio coding mode */
- uint_16 acmod;
- /* If we're using the centre channel then */
- /* centre mix level */
- uint_16 cmixlev;
- /* If we're using the surround channel then */
- /* surround mix level */
- uint_16 surmixlev;
- /* If we're in 2/0 mode then */
- /* Dolby surround mix level - NOT USED - */
- uint_16 dsurmod;
- /* Low frequency effects on */
- uint_16 lfeon;
- /* Dialogue Normalization level */
- uint_16 dialnorm;
- /* Compression exists */
- uint_16 compre;
- /* Compression level */
- uint_16 compr;
- /* Language code exists */
- uint_16 langcode;
- /* Language code */
- uint_16 langcod;
- /* Audio production info exists*/
- uint_16 audprodie;
- uint_16 mixlevel;
- uint_16 roomtyp;
- /* If we're in dual mono mode (acmod == 0) then extra stuff */
- uint_16 dialnorm2;
- uint_16 compr2e;
- uint_16 compr2;
- uint_16 langcod2e;
- uint_16 langcod2;
- uint_16 audprodi2e;
- uint_16 mixlevel2;
- uint_16 roomtyp2;
- /* Copyright bit */
- uint_16 copyrightb;
- /* Original bit */
- uint_16 origbs;
- /* Timecode 1 exists */
- uint_16 timecod1e;
- /* Timecode 1 */
- uint_16 timecod1;
- /* Timecode 2 exists */
- uint_16 timecod2e;
- /* Timecode 2 */
- uint_16 timecod2;
- /* Additional bit stream info exists */
- uint_16 addbsie;
- /* Additional bit stream length - 1 (in bytes) */
- uint_16 addbsil;
- /* Additional bit stream information (max 64 bytes) */
- uint_8 addbsi[64];
-
- /* Information not in the AC-3 bitstream, but derived */
- /* Number of channels (excluding LFE)
- * Derived from acmod */
- uint_16 nfchans;
-} bsi_t;
-
-/* more pain */
-typedef struct audblk_s
-{
- /* block switch bit indexed by channel num */
- uint_16 blksw[5];
- /* dither enable bit indexed by channel num */
- uint_16 dithflag[5];
- /* dynamic range gain exists */
- uint_16 dynrnge;
- /* dynamic range gain */
- uint_16 dynrng;
- /* if acmod==0 then */
- /* dynamic range 2 gain exists */
- uint_16 dynrng2e;
- /* dynamic range 2 gain */
- uint_16 dynrng2;
- /* coupling strategy exists */
- uint_16 cplstre;
- /* coupling in use */
- uint_16 cplinu;
- /* channel coupled */
- uint_16 chincpl[5];
- /* if acmod==2 then */
- /* Phase flags in use */
- uint_16 phsflginu;
- /* coupling begin frequency code */
- uint_16 cplbegf;
- /* coupling end frequency code */
- uint_16 cplendf;
- /* coupling band structure bits */
- uint_16 cplbndstrc[18];
- /* Do coupling co-ords exist for this channel? */
- uint_16 cplcoe[5];
- /* Master coupling co-ordinate */
- uint_16 mstrcplco[5];
- /* Per coupling band coupling co-ordinates */
- uint_16 cplcoexp[5][18];
- uint_16 cplcomant[5][18];
- /* Phase flags for dual mono */
- uint_16 phsflg[18];
- /* Is there a rematrixing strategy */
- uint_16 rematstr;
- /* Rematrixing bits */
- uint_16 rematflg[4];
- /* Coupling exponent strategy */
- uint_16 cplexpstr;
- /* Exponent strategy for full bandwidth channels */
- uint_16 chexpstr[5];
- /* Exponent strategy for lfe channel */
- uint_16 lfeexpstr;
- /* Channel bandwidth for independent channels */
- uint_16 chbwcod[5];
- /* The absolute coupling exponent */
- uint_16 cplabsexp;
- /* Coupling channel exponents (D15 mode gives 18 * 12 /3 encoded exponents */
- uint_16 cplexps[18 * 12 / 3];
-
- /* fbw channel exponents */
- uint_16 exps[5][252 / 3];
- /* channel gain range */
- uint_16 gainrng[5];
- /* low frequency exponents */
- uint_16 lfeexps[3];
-
- /* Bit allocation info */
- uint_16 baie;
- /* Slow decay code */
- uint_16 sdcycod;
- /* Fast decay code */
- uint_16 fdcycod;
- /* Slow gain code */
- uint_16 sgaincod;
- /* dB per bit code */
- uint_16 dbpbcod;
- /* masking floor code */
- uint_16 floorcod;
-
- /* SNR offset info */
- uint_16 snroffste;
- /* coarse SNR offset */
- uint_16 csnroffst;
- /* coupling fine SNR offset */
- uint_16 cplfsnroffst;
- /* coupling fast gain code */
- uint_16 cplfgaincod;
- /* fbw fine SNR offset */
- uint_16 fsnroffst[5];
- /* fbw fast gain code */
- uint_16 fgaincod[5];
- /* lfe fine SNR offset */
- uint_16 lfefsnroffst;
- /* lfe fast gain code */
- uint_16 lfefgaincod;
-
- /* Coupling leak info */
- uint_16 cplleake;
- /* coupling fast leak initialization */
- uint_16 cplfleak;
- /* coupling slow leak initialization */
- uint_16 cplsleak;
-
- /* delta bit allocation info */
- uint_16 deltbaie;
- /* coupling delta bit allocation exists */
- uint_16 cpldeltbae;
- /* fbw delta bit allocation exists */
- uint_16 deltbae[5];
- /* number of cpl delta bit segments */
- uint_16 cpldeltnseg;
- /* coupling delta bit allocation offset */
- uint_16 cpldeltoffst[8];
- /* coupling delta bit allocation length */
- uint_16 cpldeltlen[8];
- /* coupling delta bit allocation length */
- uint_16 cpldeltba[8];
- /* number of delta bit segments */
- uint_16 deltnseg[5];
- /* fbw delta bit allocation offset */
- uint_16 deltoffst[5][8];
- /* fbw delta bit allocation length */
- uint_16 deltlen[5][8];
- /* fbw delta bit allocation length */
- uint_16 deltba[5][8];
-
- /* skip length exists */
- uint_16 skiple;
- /* skip length */
- uint_16 skipl;
-
- //Removed Feb 2000 -ah
- /* channel mantissas */
- //sint_16 chmant[5][256];
-
- /* coupling mantissas */
- sint_16 cplmant[256];
-
- //Removed Feb 2000 -ah
- /* coupling mantissas */
- //sint_16 lfemant[7];
-
- /* Number of coupling sub-bands */
- uint_16 ncplsubnd;
-
- /* Number of combined coupling sub-bands
- * Derived from ncplsubnd and cplbndstrc */
- uint_16 ncplbnd;
-
- /* Number of exponent groups by channel
- * Derived from strmant, endmant */
- uint_16 nchgrps[5];
-
- /* Number of coupling exponent groups
- * Derived from cplbegf, cplendf, cplexpstr */
- uint_16 ncplgrps;
-
- /* End mantissa numbers of fbw channels */
- uint_16 endmant[5];
-
- /* Start and end mantissa numbers for the coupling channel */
- uint_16 cplstrtmant;
- uint_16 cplendmant;
-
- /* Decoded exponent info */
- uint_16 fbw_exp[5][256];
- uint_16 cpl_exp[256];
- uint_16 lfe_exp[7];
-
- /* Bit allocation pointer results */
- uint_16 fbw_bap[5][256];
- uint_16 cpl_bap[256];
- uint_16 lfe_bap[7];
-} audblk_t;
-
-/* coeff */
-void mantissa_init(void);
-void coeff_unpack(bsi_t *bsi, audblk_t *audblk, stream_samples_t samples);
-
-/* crc */
-int crc_process_frame(uint_8 *data,uint_32 num_bytes);
-
-/* downmix */
-void drc_init(void);
-void downmix(audblk_t *audblk, bsi_t* bsi, stream_samples_t stream_samples, sint_16 *s16_samples);
-
-/* exponent */
-#define UNPACK_FBW 1
-#define UNPACK_CPL 2
-#define UNPACK_LFE 4
-
-void exponent_init(void);
-void exponent_unpack( bsi_t *bsi, audblk_t *audblk);
-
-/* imdct */
-void imdct(bsi_t *bsi,audblk_t *audblk, stream_samples_t samples);
-void imdct_init(void);
-
-/* parse */
-void parse_syncinfo(syncinfo_t *syncinfo,uint_8 *data);
-void parse_audblk(bsi_t *bsi,audblk_t *audblk);
-void parse_bsi(bsi_t *bsi);
-
-/* rematrix */
-void rematrix(audblk_t *audblk, stream_samples_t samples);
-
-/* sanity check */
-void sanity_check(bsi_t *bsi, audblk_t *audblk);
-
-void InitialAC3(void);
-AXTN unsigned char AC3Dec_Buffer[49152]; // 48KB/frame for 64~448 Kbps
-
-AXTN uint_32 error_flag;
-
-AXTN uint_8 *buffer_start;
-AXTN uint_32 bits_left;
-AXTN uint_32 current_word;
diff --git a/src/dgindex/AC3Dec/bit_allocate.cpp b/src/dgindex/AC3Dec/bit_allocate.cpp
deleted file mode 100644
index 2b75a9f..0000000
--- a/src/dgindex/AC3Dec/bit_allocate.cpp
+++ /dev/null
@@ -1,458 +0,0 @@
-/*
- * Copyright (C) Aaron Holtzman - May 1999
- *
- * This file is part of ac3dec, a free Dolby AC-3 stream decoder.
- *
- * ac3dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * ac3dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
-#define AC3_GLOBAL
-#include "ac3.h"
-
-#define maxvalue(a, b) (a > b ? a : b)
-#define minvalue(a, b) (a < b ? a : b)
-
-static sint_16 calc_lowcomp(sint_16 a,sint_16 b0,sint_16 b1,sint_16 bin);
-static void ba_compute_psd(sint_16 start, sint_16 end, sint_16 exps[],
- sint_16 psd[], sint_16 bndpsd[]);
-static void ba_compute_excitation(sint_16 start, sint_16 end,sint_16 fgain,
- sint_16 fastleak, sint_16 slowleak, sint_16 bndpsd[], sint_16 excite[]);
-static void ba_compute_mask(sint_16 start, sint_16 end, uint_16 fscod,
- uint_16 deltbae, uint_16 deltnseg, uint_16 deltoffst[], uint_16 deltba[],
- uint_16 deltlen[], sint_16 excite[], sint_16 mask[]);
-static void ba_compute_bap(sint_16 start, sint_16 end, sint_16 snroffset,
- sint_16 psd[], sint_16 mask[], sint_16 bap[]);
-
-/* Misc LUTs for bit allocation process */
-static sint_16 slowdec[] = { 0x0f, 0x11, 0x13, 0x15 };
-static sint_16 fastdec[] = { 0x3f, 0x53, 0x67, 0x7b };
-static sint_16 slowgain[] = { 0x540, 0x4d8, 0x478, 0x410 };
-static sint_16 dbpbtab[] = { 0x000, 0x700, 0x900, 0xb00 };
-
-static uint_16 floortab[] = { 0x2f0, 0x2b0, 0x270, 0x230, 0x1f0, 0x170, 0x0f0, 0xf800 };
-static sint_16 fastgain[] = { 0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, 0x400 };
-
-static sint_16 bndtab[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
- 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
- 20, 21, 22, 23, 24, 25, 26, 27, 28, 31,
- 34, 37, 40, 43, 46, 49, 55, 61, 67, 73,
- 79, 85, 97, 109, 121, 133, 157, 181, 205, 229 };
-
-static sint_16 bndsz[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 3, 3,
- 3, 3, 3, 3, 3, 6, 6, 6, 6, 6,
- 6, 12, 12, 12, 12, 24, 24, 24, 24, 24 };
-
-static sint_16 masktab[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 28, 28, 29,
- 29, 29, 30, 30, 30, 31, 31, 31, 32, 32, 32, 33, 33, 33, 34, 34,
- 34, 35, 35, 35, 35, 35, 35, 36, 36, 36, 36, 36, 36, 37, 37, 37,
- 37, 37, 37, 38, 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, 39, 40,
- 40, 40, 40, 40, 40, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
- 41, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 43, 43, 43,
- 43, 43, 43, 43, 43, 43, 43, 43, 43, 44, 44, 44, 44, 44, 44, 44,
- 44, 44, 44, 44, 44, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 46, 46, 46,
- 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
- 46, 46, 46, 46, 46, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
- 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 48, 48, 48,
- 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
- 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
- 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 0, 0, 0 };
-
-
-static sint_16 latab[] = { 0x0040, 0x003f, 0x003e, 0x003d, 0x003c, 0x003b, 0x003a, 0x0039,
- 0x0038, 0x0037, 0x0036, 0x0035, 0x0034, 0x0034, 0x0033, 0x0032,
- 0x0031, 0x0030, 0x002f, 0x002f, 0x002e, 0x002d, 0x002c, 0x002c,
- 0x002b, 0x002a, 0x0029, 0x0029, 0x0028, 0x0027, 0x0026, 0x0026,
- 0x0025, 0x0024, 0x0024, 0x0023, 0x0023, 0x0022, 0x0021, 0x0021,
- 0x0020, 0x0020, 0x001f, 0x001e, 0x001e, 0x001d, 0x001d, 0x001c,
- 0x001c, 0x001b, 0x001b, 0x001a, 0x001a, 0x0019, 0x0019, 0x0018,
- 0x0018, 0x0017, 0x0017, 0x0016, 0x0016, 0x0015, 0x0015, 0x0015,
- 0x0014, 0x0014, 0x0013, 0x0013, 0x0013, 0x0012, 0x0012, 0x0012,
- 0x0011, 0x0011, 0x0011, 0x0010, 0x0010, 0x0010, 0x000f, 0x000f,
- 0x000f, 0x000e, 0x000e, 0x000e, 0x000d, 0x000d, 0x000d, 0x000d,
- 0x000c, 0x000c, 0x000c, 0x000c, 0x000b, 0x000b, 0x000b, 0x000b,
- 0x000a, 0x000a, 0x000a, 0x000a, 0x000a, 0x0009, 0x0009, 0x0009,
- 0x0009, 0x0009, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
- 0x0007, 0x0007, 0x0007, 0x0007, 0x0007, 0x0007, 0x0006, 0x0006,
- 0x0006, 0x0006, 0x0006, 0x0006, 0x0006, 0x0006, 0x0005, 0x0005,
- 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0004, 0x0004,
- 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004,
- 0x0004, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003,
- 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0002,
- 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
- 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
- 0x0002, 0x0002, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001,
- 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001,
- 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001,
- 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001,
- 0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000};
-
-static sint_16 hth[][50] = {{ 0x04d0, 0x04d0, 0x0440, 0x0400, 0x03e0, 0x03c0, 0x03b0, 0x03b0,
- 0x03a0, 0x03a0, 0x03a0, 0x03a0, 0x03a0, 0x0390, 0x0390, 0x0390,
- 0x0380, 0x0380, 0x0370, 0x0370, 0x0360, 0x0360, 0x0350, 0x0350,
- 0x0340, 0x0340, 0x0330, 0x0320, 0x0310, 0x0300, 0x02f0, 0x02f0,
- 0x02f0, 0x02f0, 0x0300, 0x0310, 0x0340, 0x0390, 0x03e0, 0x0420,
- 0x0460, 0x0490, 0x04a0, 0x0460, 0x0440, 0x0440, 0x0520, 0x0800,
- 0x0840, 0x0840 },
-
- { 0x04f0, 0x04f0, 0x0460, 0x0410, 0x03e0, 0x03d0, 0x03c0, 0x03b0,
- 0x03b0, 0x03a0, 0x03a0, 0x03a0, 0x03a0, 0x03a0, 0x0390, 0x0390,
- 0x0390, 0x0380, 0x0380, 0x0380, 0x0370, 0x0370, 0x0360, 0x0360,
- 0x0350, 0x0350, 0x0340, 0x0340, 0x0320, 0x0310, 0x0300, 0x02f0,
- 0x02f0, 0x02f0, 0x02f0, 0x0300, 0x0320, 0x0350, 0x0390, 0x03e0,
- 0x0420, 0x0450, 0x04a0, 0x0490, 0x0460, 0x0440, 0x0480, 0x0630,
- 0x0840, 0x0840 },
-
- { 0x0580, 0x0580, 0x04b0, 0x0450, 0x0420, 0x03f0, 0x03e0, 0x03d0,
- 0x03c0, 0x03b0, 0x03b0, 0x03b0, 0x03a0, 0x03a0, 0x03a0, 0x03a0,
- 0x03a0, 0x03a0, 0x03a0, 0x03a0, 0x0390, 0x0390, 0x0390, 0x0390,
- 0x0380, 0x0380, 0x0380, 0x0370, 0x0360, 0x0350, 0x0340, 0x0330,
- 0x0320, 0x0310, 0x0300, 0x02f0, 0x02f0, 0x02f0, 0x0300, 0x0310,
- 0x0330, 0x0350, 0x03c0, 0x0410, 0x0470, 0x04a0, 0x0460, 0x0440,
- 0x0450, 0x04e0 }};
-
-static sint_16 baptab[] = { 0, 1, 1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6,
- 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10,
- 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 14,
- 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15 };
-
-static sint_16 sdecay;
-static sint_16 fdecay;
-static sint_16 sgain;
-static sint_16 dbknee;
-static sint_16 floor;
-static sint_16 psd[256];
-static sint_16 bndpsd[256];
-static sint_16 excite[256];
-static sint_16 mask[256];
-
-__forceinline static sint_16 logadd(sint_16 a, sint_16 b)
-{
- if (a >= b)
- return a + latab[minvalue((a - b)>>1, 255)];
- else
- return b + latab[minvalue((b - a)>>1, 255)];
-}
-
-void bit_allocate(uint_16 fscod, bsi_t *bsi, audblk_t *audblk)
-{
- uint_16 i;
- sint_16 fgain;
- sint_16 snroffset;
- sint_16 start;
- sint_16 end;
- sint_16 fastleak;
- sint_16 slowleak;
-
- /* Only perform bit_allocation if the exponents have changed or we
- * have new sideband information */
- if (audblk->chexpstr[0] == 0 && audblk->chexpstr[1] == 0 &&
- audblk->chexpstr[2] == 0 && audblk->chexpstr[3] == 0 &&
- audblk->chexpstr[4] == 0 && audblk->cplexpstr == 0 &&
- audblk->lfeexpstr == 0 && audblk->baie == 0 &&
- audblk->snroffste == 0 && audblk->deltbaie == 0)
- return;
-
- /* Do some setup before we do the bit alloc */
- sdecay = slowdec[audblk->sdcycod];
- fdecay = fastdec[audblk->fdcycod];
- sgain = slowgain[audblk->sgaincod];
- dbknee = dbpbtab[audblk->dbpbcod];
- floor = floortab[audblk->floorcod];
-
- /* if all the SNR offset constants are zero then the whole block is zero */
- if(!audblk->csnroffst && !audblk->fsnroffst[0] &&
- !audblk->fsnroffst[1] && !audblk->fsnroffst[2] &&
- !audblk->fsnroffst[3] && !audblk->fsnroffst[4] &&
- !audblk->cplfsnroffst && !audblk->lfefsnroffst)
- {
- ZeroMemory(audblk->fbw_bap, sizeof(uint_16) * 256 * 5);
- ZeroMemory(audblk->cpl_bap, sizeof(uint_16) * 256);
- ZeroMemory(audblk->lfe_bap, sizeof(uint_16) * 7);
- return;
- }
-
- for(i = 0; i < bsi->nfchans; i++)
- {
- start = 0;
- end = audblk->endmant[i] ;
- fgain = fastgain[audblk->fgaincod[i]];
- snroffset = (((audblk->csnroffst - 15) << 4) + audblk->fsnroffst[i]) << 2 ;
- fastleak = 0;
- slowleak = 0;
-
- ba_compute_psd(start, end, (short *) audblk->fbw_exp[i], psd, bndpsd);
-
- ba_compute_excitation(start, end, fgain, fastleak, slowleak, bndpsd, excite);
-
- ba_compute_mask(start, end, fscod, audblk->deltbae[i], audblk->deltnseg[i],
- audblk->deltoffst[i], audblk->deltba[i], audblk->deltlen[i], excite, mask);
-
- ba_compute_bap(start, end, snroffset, psd, mask, (short *) audblk->fbw_bap[i]);
- }
-
- if(audblk->cplinu)
- {
- start = audblk->cplstrtmant;
- end = audblk->cplendmant;
- fgain = fastgain[audblk->cplfgaincod];
- snroffset = (((audblk->csnroffst - 15) << 4) + audblk->cplfsnroffst) << 2 ;
- fastleak = (audblk->cplfleak << 8) + 768;
- slowleak = (audblk->cplsleak << 8) + 768;
-
- ba_compute_psd(start, end, (short *)audblk->cpl_exp, psd, bndpsd);
-
- ba_compute_excitation(start, end , fgain, fastleak, slowleak, bndpsd, excite);
-
- ba_compute_mask(start, end, fscod, audblk->cpldeltbae, audblk->cpldeltnseg,
- audblk->cpldeltoffst, audblk->cpldeltba, audblk->cpldeltlen, excite, mask);
-
- ba_compute_bap(start, end, snroffset, psd, mask, (short *)audblk->cpl_bap);
- }
-
- if(bsi->lfeon)
- {
- start = 0;
- end = 7;
- fgain = fastgain[audblk->lfefgaincod];
- snroffset = (((audblk->csnroffst - 15) << 4) + audblk->lfefsnroffst) << 2 ;
- fastleak = 0;
- slowleak = 0;
-
- ba_compute_psd(start, end, (short *)audblk->lfe_exp, psd, bndpsd);
-
- ba_compute_excitation(start, end , fgain, fastleak, slowleak, bndpsd, excite);
-
- /* Perform no delta bit allocation for lfe */
- ba_compute_mask(start, end, fscod, 2, 0, 0, 0, 0, excite, mask);
-
- ba_compute_bap(start, end, snroffset, psd, mask, (short *)audblk->lfe_bap);
- }
-}
-
-static void ba_compute_psd(sint_16 start, sint_16 end, sint_16 exps[],
- sint_16 psd[], sint_16 bndpsd[])
-{
- int bin, i, j, k;
- sint_16 lastbin = 0;
-
- /* Map the exponents into dBs */
- for (bin=start; bin lastbin);
-}
-
-static void ba_compute_excitation(sint_16 start, sint_16 end, sint_16 fgain,
- sint_16 fastleak, sint_16 slowleak,
- sint_16 bndpsd[], sint_16 excite[])
-{
- int bin;
- sint_16 bndstrt;
- sint_16 bndend;
- sint_16 lowcomp = 0;
- sint_16 begin = 0;
-
- /* Compute excitation function */
- bndstrt = masktab[start];
- bndend = masktab[end - 1] + 1;
-
- if (bndstrt == 0) /* For fbw and lfe channels */
- {
- lowcomp = calc_lowcomp(lowcomp, bndpsd[0], bndpsd[1], 0);
- excite[0] = bndpsd[0] - fgain - lowcomp;
- lowcomp = calc_lowcomp(lowcomp, bndpsd[1], bndpsd[2], 1);
- excite[1] = bndpsd[1] - fgain - lowcomp;
- begin = 7 ;
-
- /* Note: Do not call calc_lowcomp() for the last band of the lfe channel, (bin = 6) */
- for (bin = 2; bin < 7; bin++)
- {
- if (bndend!= 7 || bin!=6)
- lowcomp = calc_lowcomp(lowcomp, bndpsd[bin], bndpsd[bin+1], bin);
- fastleak = bndpsd[bin] - fgain;
- slowleak = bndpsd[bin] - sgain;
- excite[bin] = fastleak - lowcomp;
-
- if (bndend!= 7 || bin!=6)
- {
- if (bndpsd[bin] <= bndpsd[bin+1])
- {
- begin = bin + 1 ;
- break;
- }
- }
- }
-
- for (bin = begin; bin < minvalue(bndend, 22); bin++)
- {
- if (bndend!= 7 || bin!=6)
- lowcomp = calc_lowcomp(lowcomp, bndpsd[bin], bndpsd[bin+1], bin);
- fastleak -= fdecay ;
- fastleak = maxvalue(fastleak, bndpsd[bin] - fgain);
- slowleak -= sdecay ;
- slowleak = maxvalue(slowleak, bndpsd[bin] - sgain);
- excite[bin] = maxvalue(fastleak - lowcomp, slowleak);
- }
- begin = 22;
- }
- else /* For coupling channel */
- {
- begin = bndstrt;
- }
-
- for (bin = begin; bin < bndend; bin++)
- {
- fastleak -= fdecay;
- fastleak = maxvalue(fastleak, bndpsd[bin] - fgain);
- slowleak -= sdecay;
- slowleak = maxvalue(slowleak, bndpsd[bin] - sgain);
- excite[bin] = maxvalue(fastleak, slowleak) ;
- }
-}
-
-static void ba_compute_mask(sint_16 start, sint_16 end, uint_16 fscod,
- uint_16 deltbae, uint_16 deltnseg, uint_16 deltoffst[], uint_16 deltba[],
- uint_16 deltlen[], sint_16 excite[], sint_16 mask[])
-{
- int bin,k;
- sint_16 bndstrt;
- sint_16 bndend;
- sint_16 delta;
-
- bndstrt = masktab[start];
- bndend = masktab[end - 1] + 1;
-
- /* Compute the masking curve */
-
- for (bin = bndstrt; bin < bndend; bin++)
- {
- if (bndpsd[bin] < dbknee)
- {
- excite[bin] += ((dbknee - bndpsd[bin]) >> 2);
- }
- mask[bin] = maxvalue(excite[bin], hth[fscod][bin]);
- }
-
- /* Perform delta bit modulation if necessary */
- if ((deltbae == DELTA_BIT_REUSE) || (deltbae == DELTA_BIT_NEW))
- {
- sint_16 band = 0;
- sint_16 seg = 0;
-
- for (seg = 0; seg < deltnseg+1; seg++)
- {
- band += deltoffst[seg];
- if (deltba[seg] >= 4)
- {
- delta = (deltba[seg] - 3) << 7;
- }
- else
- {
- delta = (deltba[seg] - 4) << 7;
- }
-
- for (k = 0; k < deltlen[seg]; k++)
- {
- mask[band] += delta;
- band++;
- }
- }
- }
-}
-
-static void ba_compute_bap(sint_16 start, sint_16 end, sint_16 snroffset,
- sint_16 psd[], sint_16 mask[], sint_16 bap[])
-{
- int i,j,k;
- sint_16 lastbin = 0;
- sint_16 address = 0;
-
- /* Compute the bit allocation pointer for each bin */
- i = start;
- j = masktab[start];
-
- do
- {
- lastbin = minvalue(bndtab[j] + bndsz[j], end);
- mask[j] -= snroffset;
- mask[j] -= floor;
-
- if (mask[j] < 0)
- mask[j] = 0;
-
- mask[j] &= 0x1fe0;
- mask[j] += floor;
- for (k = i; k < lastbin; k++)
- {
- address = (psd[i] - mask[j]) >> 5;
- address = minvalue(63, maxvalue(0, address));
- bap[i] = baptab[address];
- i++;
- }
- j++;
- } while (end > lastbin);
-}
-
-static sint_16 calc_lowcomp(sint_16 a, sint_16 b0, sint_16 b1, sint_16 bin)
-{
- if (bin < 7)
- {
- if ((b0 + 256) == b1)
- a = 384;
- else if (b0 > b1)
- a = maxvalue(0, a - 64);
- }
- else if (bin < 20)
- {
- if ((b0 + 256) == b1)
- a = 320;
- else if (b0 > b1)
- a = maxvalue(0, a - 64) ;
- }
- else
- a = maxvalue(0, a - 128);
-
- return a;
-}
diff --git a/src/dgindex/AC3Dec/bitstream.cpp b/src/dgindex/AC3Dec/bitstream.cpp
deleted file mode 100644
index d0d3d40..0000000
--- a/src/dgindex/AC3Dec/bitstream.cpp
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) Aaron Holtzman - May 1999
- *
- * This file is part of ac3dec, a free Dolby AC-3 stream decoder.
- *
- * ac3dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * ac3dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
-#include "ac3.h"
-#include "bitstream.h"
-
-uint_32 bitstream_get_bh(uint_32 num_bits)
-{
- uint_32 result;
-
- num_bits -= bits_left;
- result = (current_word << (32 - bits_left)) >> (32 - bits_left);
-
- current_word = (*buffer_start << 24) + (*(buffer_start+1) << 16) + (*(buffer_start+2) << 8) + *(buffer_start+3);
- buffer_start +=4;
-
- if(num_bits != 0)
- result = (result << num_bits) + (current_word >> (32 - num_bits));
-
- bits_left = 32 - num_bits;
-
- return result;
-}
-
-void bitstream_init(uint_8 *start)
-{
- // initialize the start of the buffer
- buffer_start = start;
- bits_left = 0;
-}
diff --git a/src/dgindex/AC3Dec/bitstream.h b/src/dgindex/AC3Dec/bitstream.h
deleted file mode 100644
index 7b2ecf8..0000000
--- a/src/dgindex/AC3Dec/bitstream.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) Aaron Holtzman - May 1999
- *
- * This file is part of ac3dec, a free Dolby AC-3 stream decoder.
- *
- * ac3dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * ac3dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
-void bitstream_init(uint_8 *start);
-uint_32 bitstream_get_bh(uint_32 num_bits);
-
-__forceinline static uint_32 bitstream_get(uint_32 num_bits)
-{
- uint_32 result;
-
- if (num_bits < bits_left)
- {
- result = (current_word << (32 - bits_left)) >> (32 - num_bits);
- bits_left -= num_bits;
- return result;
- }
-
- return bitstream_get_bh(num_bits);
-}
diff --git a/src/dgindex/AC3Dec/coeff.cpp b/src/dgindex/AC3Dec/coeff.cpp
deleted file mode 100644
index 39f4d74..0000000
--- a/src/dgindex/AC3Dec/coeff.cpp
+++ /dev/null
@@ -1,311 +0,0 @@
-/*
- * Copyright (C) Aaron Holtzman - May 1999
- *
- * This file is part of ac3dec, a free Dolby AC-3 stream decoder.
- *
- * ac3dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * ac3dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
-#include "ac3.h"
-#include "bitstream.h"
-
-// Lookup tables of 0.15 two's complement quantization values
-static const sint_16 q_1[3] =
-{
- ( -2 << 15)/3, 0,( 2 << 15)/3
-};
-
-static const sint_16 q_2[5] =
-{
- ( -4 << 15)/5,( -2 << 15)/5, 0,
- ( 2 << 15)/5,( 4 << 15)/5
-};
-
-static const sint_16 q_3[7] =
-{
- ( -6 << 15)/7,( -4 << 15)/7,( -2 << 15)/7, 0,
- ( 2 << 15)/7,( 4 << 15)/7,( 6 << 15)/7
-};
-
-static const sint_16 q_4[11] =
-{
- (-10 << 15)/11,(-8 << 15)/11,(-6 << 15)/11, ( -4 << 15)/11,(-2 << 15)/11, 0,
- ( 2 << 15)/11,( 4 << 15)/11,( 6 << 15)/11, ( 8 << 15)/11,(10 << 15)/11
-};
-
-static const sint_16 q_5[15] =
-{
- (-14 << 15)/15,(-12 << 15)/15,(-10 << 15)/15,
- ( -8 << 15)/15,( -6 << 15)/15,( -4 << 15)/15,
- ( -2 << 15)/15, 0 ,( 2 << 15)/15,
- ( 4 << 15)/15,( 6 << 15)/15,( 8 << 15)/15,
- ( 10 << 15)/15,( 12 << 15)/15,( 14 << 15)/15
-};
-
-// Scale factors for convert_to_double
-static const uint_32 u32_scale_factors[25] =
-{
- 0x38000000, //2 ^ -(0 + 15)
- 0x37800000, //2 ^ -(1 + 15)
- 0x37000000, //2 ^ -(2 + 15)
- 0x36800000, //2 ^ -(3 + 15)
- 0x36000000, //2 ^ -(4 + 15)
- 0x35800000, //2 ^ -(5 + 15)
- 0x35000000, //2 ^ -(6 + 15)
- 0x34800000, //2 ^ -(7 + 15)
- 0x34000000, //2 ^ -(8 + 15)
- 0x33800000, //2 ^ -(9 + 15)
- 0x33000000, //2 ^ -(10 + 15)
- 0x32800000, //2 ^ -(11 + 15)
- 0x32000000, //2 ^ -(12 + 15)
- 0x31800000, //2 ^ -(13 + 15)
- 0x31000000, //2 ^ -(14 + 15)
- 0x30800000, //2 ^ -(15 + 15)
- 0x30000000, //2 ^ -(16 + 15)
- 0x2f800000, //2 ^ -(17 + 15)
- 0x2f000000, //2 ^ -(18 + 15)
- 0x2e800000, //2 ^ -(19 + 15)
- 0x2e000000, //2 ^ -(20 + 15)
- 0x2d800000, //2 ^ -(21 + 15)
- 0x2d000000, //2 ^ -(22 + 15)
- 0x2c800000, //2 ^ -(23 + 15)
- 0x2c000000 //2 ^ -(24 + 15)
-};
-
-static float *scale_factor = (float*)u32_scale_factors;
-
-// These store the persistent state of the packed mantissas
-static sint_16 m_1_pointer;
-static sint_16 m_2_pointer;
-static sint_16 m_4_pointer;
-
-static sint_16 M_1[27][3];
-static sint_16 M_2[125][3];
-static sint_16 M_4[121][2];
-
-// Conversion from bap to number of bits in the mantissas
-static uint_16 qnttztab[16] = { 0, 0, 0, 3, 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16 };
-
-static sint_16 coeff_get_mantissa(uint_16 bap, uint_16 dithflag);
-static void coeff_uncouple_ch(double samples[], bsi_t *bsi, audblk_t *audblk, uint_32 ch);
-
-void mantissa_init()
-{
- int i;
-
- for (i=0; i<27; i++)
- {
- M_1[i][0] = i / 9;
- M_1[i][1] = (i % 9) / 3;
- M_1[i][2] = (i % 9) % 3;
- }
-
- for (i=0; i<125; i++)
- {
- M_2[i][0] = i / 25;
- M_2[i][1] = (i % 25) / 5;
- M_2[i][2] = (i % 25) % 5;
- }
-
- for (i=0; i<121; i++)
- {
- M_4[i][0] = i / 11;
- M_4[i][1] = i % 11;
- }
-}
-
-void coeff_unpack(bsi_t *bsi, audblk_t *audblk, stream_samples_t samples)
-{
- uint_16 i,j;
- uint_32 done_cpl = 0;
- sint_16 mantissa;
-
- m_1_pointer = m_2_pointer = m_4_pointer = 3;
-
- for(i=0; infchans; i++)
- {
- for(j=0; jendmant[i]; j++)
- {
- mantissa = coeff_get_mantissa(audblk->fbw_bap[i][j], audblk->dithflag[i]);
- samples[i][j] = mantissa * scale_factor[audblk->fbw_exp[i][j]];
- }
-
- if(audblk->cplinu && audblk->chincpl[i] && !done_cpl)
- {
- // ncplmant is equal to 12 * ncplsubnd
- // Don't dither coupling channel until channel separation so that
- // interchannel noise is uncorrelated
- for(j=audblk->cplstrtmant; jcplendmant; j++)
- audblk->cplmant[j] = coeff_get_mantissa(audblk->cpl_bap[j], 0);
- done_cpl = 1;
- }
- }
-
- // uncouple the channel if necessary
- if(audblk->cplinu)
- {
- for(i=0; infchans; i++)
- {
- if(audblk->chincpl[i])
- coeff_uncouple_ch(samples[i], bsi, audblk, i);
- }
- }
-
- if(bsi->lfeon)
- {
- // There are always 7 mantissas for lfe, no dither for lfe
- for(j=0; j<7; j++)
- {
- mantissa = coeff_get_mantissa(audblk->lfe_bap[j], 0);
- samples[5][j] = mantissa * scale_factor[audblk->lfe_exp[j]];
- }
- }
-}
-
-// Fetch a mantissa from the bitstream
-// The mantissa returned is a signed 0.15 fixed point number
-static sint_16 coeff_get_mantissa(uint_16 bap, uint_16 dithflag)
-{
- sint_16 mantissa;
- uint_16 group_code;
- static sint_16 *m_1, *m_2, *m_4;
-
- switch(bap)
- {
- case 0:
- if (dithflag)
- mantissa = (uint_16)(46340.0 * rand() / RAND_MAX) - 23170;
- else
- mantissa = 0;
- break;
-
- case 1:
- if(m_1_pointer > 2)
- {
- group_code = bitstream_get(5);
-
- if (group_code > 26)
- goto error;
-
- m_1 = &M_1[group_code][0];
- m_1_pointer = 0;
- }
- mantissa = m_1[m_1_pointer++];
- mantissa = q_1[mantissa];
- break;
-
- case 2:
- if(m_2_pointer > 2)
- {
- group_code = bitstream_get(7);
-
- if (group_code > 124)
- goto error;
-
- m_2 = &M_2[group_code][0];
- m_2_pointer = 0;
- }
- mantissa = m_2[m_2_pointer++];
- mantissa = q_2[mantissa];
- break;
-
- case 3:
- mantissa = bitstream_get(3);
-
- if(mantissa > 6)
- goto error;
-
- mantissa = q_3[mantissa];
- break;
-
- case 4:
- if(m_4_pointer > 1)
- {
- group_code = bitstream_get(7);
-
- if (group_code > 120)
- goto error;
-
- m_4 = &M_4[group_code][0];
- m_4_pointer = 0;
- }
- mantissa = m_4[m_4_pointer++];
- mantissa = q_4[mantissa];
- break;
-
- case 5:
- mantissa = bitstream_get(4);
-
- if(mantissa > 14)
- goto error;
-
- mantissa = q_5[mantissa];
- break;
-
- default:
- mantissa = bitstream_get(qnttztab[bap]);
- mantissa <<= 16 - qnttztab[bap];
- }
-
- return mantissa;
-
-error:
- error_flag = 1;
- return 0;
-}
-
-// Uncouple the coupling channel into a fbw channel
-static void coeff_uncouple_ch(double samples[], bsi_t *bsi,audblk_t *audblk, uint_32 ch)
-{
- uint_32 bnd = 0;
- uint_32 sub_bnd = 0;
- uint_32 i, j;
- double cpl_coord = 1.0;
- uint_32 cpl_mant_tmp;
- sint_16 mantissa;
-
- for (i=audblk->cplstrtmant; icplendmant;)
- {
- if (!audblk->cplbndstrc[sub_bnd++])
- {
- if (audblk->cplcoexp[ch][bnd] == 15)
- cpl_mant_tmp = (audblk->cplcomant[ch][bnd]) << 11;
- else
- cpl_mant_tmp = (16 + audblk->cplcomant[ch][bnd]) << 10;
-
- cpl_coord = (cpl_mant_tmp * scale_factor[audblk->cplcoexp[ch][bnd] + 3 * audblk->mstrcplco[ch]]) * 8.0;
-
- // Invert the phase for the right channel if necessary
- if (bsi->acmod==0x2 && audblk->phsflginu && ch==1 && audblk->phsflg[bnd])
- cpl_coord = -cpl_coord;
-
- bnd++;
- }
-
- for (j=0; j<12; j++)
- {
- // Get new dither values for each channel if necessary
- if(audblk->dithflag[ch] && audblk->cpl_bap[i]==0)
- mantissa = (uint_16)(46340.0 * rand() / RAND_MAX) - 23170;
- else
- mantissa = audblk->cplmant[i];
-
- samples[i] = (mantissa * scale_factor[audblk->cpl_exp[i]]) * cpl_coord;
-
- i++;
- }
- }
-}
diff --git a/src/dgindex/AC3Dec/crc.cpp b/src/dgindex/AC3Dec/crc.cpp
deleted file mode 100644
index 01c6d34..0000000
--- a/src/dgindex/AC3Dec/crc.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) Aaron Holtzman - May 1999
- *
- * This file is part of ac3dec, a free Dolby AC-3 stream decoder.
- *
- * ac3dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * ac3dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
-#include "ac3.h"
-
-static const uint_16 crc_lut[256] =
-{
- 0x0000,0x8005,0x800f,0x000a,0x801b,0x001e,0x0014,0x8011,
- 0x8033,0x0036,0x003c,0x8039,0x0028,0x802d,0x8027,0x0022,
- 0x8063,0x0066,0x006c,0x8069,0x0078,0x807d,0x8077,0x0072,
- 0x0050,0x8055,0x805f,0x005a,0x804b,0x004e,0x0044,0x8041,
- 0x80c3,0x00c6,0x00cc,0x80c9,0x00d8,0x80dd,0x80d7,0x00d2,
- 0x00f0,0x80f5,0x80ff,0x00fa,0x80eb,0x00ee,0x00e4,0x80e1,
- 0x00a0,0x80a5,0x80af,0x00aa,0x80bb,0x00be,0x00b4,0x80b1,
- 0x8093,0x0096,0x009c,0x8099,0x0088,0x808d,0x8087,0x0082,
- 0x8183,0x0186,0x018c,0x8189,0x0198,0x819d,0x8197,0x0192,
- 0x01b0,0x81b5,0x81bf,0x01ba,0x81ab,0x01ae,0x01a4,0x81a1,
- 0x01e0,0x81e5,0x81ef,0x01ea,0x81fb,0x01fe,0x01f4,0x81f1,
- 0x81d3,0x01d6,0x01dc,0x81d9,0x01c8,0x81cd,0x81c7,0x01c2,
- 0x0140,0x8145,0x814f,0x014a,0x815b,0x015e,0x0154,0x8151,
- 0x8173,0x0176,0x017c,0x8179,0x0168,0x816d,0x8167,0x0162,
- 0x8123,0x0126,0x012c,0x8129,0x0138,0x813d,0x8137,0x0132,
- 0x0110,0x8115,0x811f,0x011a,0x810b,0x010e,0x0104,0x8101,
- 0x8303,0x0306,0x030c,0x8309,0x0318,0x831d,0x8317,0x0312,
- 0x0330,0x8335,0x833f,0x033a,0x832b,0x032e,0x0324,0x8321,
- 0x0360,0x8365,0x836f,0x036a,0x837b,0x037e,0x0374,0x8371,
- 0x8353,0x0356,0x035c,0x8359,0x0348,0x834d,0x8347,0x0342,
- 0x03c0,0x83c5,0x83cf,0x03ca,0x83db,0x03de,0x03d4,0x83d1,
- 0x83f3,0x03f6,0x03fc,0x83f9,0x03e8,0x83ed,0x83e7,0x03e2,
- 0x83a3,0x03a6,0x03ac,0x83a9,0x03b8,0x83bd,0x83b7,0x03b2,
- 0x0390,0x8395,0x839f,0x039a,0x838b,0x038e,0x0384,0x8381,
- 0x0280,0x8285,0x828f,0x028a,0x829b,0x029e,0x0294,0x8291,
- 0x82b3,0x02b6,0x02bc,0x82b9,0x02a8,0x82ad,0x82a7,0x02a2,
- 0x82e3,0x02e6,0x02ec,0x82e9,0x02f8,0x82fd,0x82f7,0x02f2,
- 0x02d0,0x82d5,0x82df,0x02da,0x82cb,0x02ce,0x02c4,0x82c1,
- 0x8243,0x0246,0x024c,0x8249,0x0258,0x825d,0x8257,0x0252,
- 0x0270,0x8275,0x827f,0x027a,0x826b,0x026e,0x0264,0x8261,
- 0x0220,0x8225,0x822f,0x022a,0x823b,0x023e,0x0234,0x8231,
- 0x8213,0x0216,0x021c,0x8219,0x0208,0x820d,0x8207,0x0202
-};
-
-int crc_process_frame(uint_8 *data, uint_32 num_bytes)
-{
- uint_16 state = 0;
- uint_32 i;
-
- for(i=0; i>8)] ^ (state<<8);
-
- return state;
-}
diff --git a/src/dgindex/AC3Dec/decode.cpp b/src/dgindex/AC3Dec/decode.cpp
deleted file mode 100644
index 550d6ba..0000000
--- a/src/dgindex/AC3Dec/decode.cpp
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * Copyright (C) Aaron Holtzman - May 1999
- *
- * This file is part of ac3dec, a free Dolby AC-3 stream decoder.
- *
- * ac3dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * ac3dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
-#include "../global.h"
-#include "ac3.h"
-#include "bitstream.h"
-
-void bit_allocate(uint_16 fscod, bsi_t *bsi, audblk_t *audblk);
-
-static audblk_t audblk;
-static bsi_t bsi;
-static syncinfo_t syncinfo;
-
-// the floating point samples for one audblk
-static stream_samples_t samples;
-
-// the integer samples for the entire frame (with enough space for 2 ch out)
-// if this size change, be sure to change the size when muting
-static sint_16 s16_samples[2 * 6 * 256];
-static short *ptrAC3Dec_Buffer = (short*)AC3Dec_Buffer;
-
-// storage for the syncframe
-#define BUFFER_MAX_SIZE 4096
-static uint_8 buffer[BUFFER_MAX_SIZE];
-static sint_32 buffer_size;
-
-uint_32 decode_buffer_syncframe(syncinfo_t *syncinfo, uint_8 **start, uint_8 *end)
-{
- uint_8 *cur = *start;
- uint_16 syncword = syncinfo->syncword;
- uint_32 ret = 0;
-
- // find an ac3 sync frame
-resync:
- while(syncword != 0x0b77)
- {
- if(cur >= end)
- goto done;
- syncword = (syncword << 8) + *cur++;
- }
-
- // need the next 3 bytes to decide how big the frame is
- while(buffer_size < 3)
- {
- if(cur >= end)
- goto done;
-
- buffer[buffer_size++] = *cur++;
- }
-
- parse_syncinfo(syncinfo, buffer);
-
- if (syncinfo->frame_size==0) // CRITICAL CONDITION
- goto done;
-
- while (buffer_size < (syncinfo->frame_size<<1) - 2)
- {
- if(cur >= end)
- goto done;
-
- buffer[buffer_size++] = *cur++;
- }
-
- // check the crc over the entire frame
- if (crc_process_frame(buffer, (syncinfo->frame_size<<1) - 2))
- {
- SetDlgItemText(hDlg, IDC_INFO, "audio error");
-
- syncword = 0xffff;
- buffer_size = 0;
- goto resync;
- }
-
- // if we got to this point, we found a valid ac3 frame to decode
- bitstream_init(buffer);
- // get rid of the syncinfo struct as we already parsed it
- bitstream_get(24);
-
- // reset the syncword for next time
- syncword = 0xffff;
- buffer_size = 0;
- ret = 1;
-
-done:
- syncinfo->syncword = syncword;
- *start = cur;
- return ret;
-}
-
-uint_32 ac3_decode_data(uint_8 *data_start, uint_32 length, uint_32 start)
-{
- uint_8 *data_end = data_start + length;
- uint_32 i, j = start;
-
- while (decode_buffer_syncframe(&syncinfo, &data_start, data_end))
- {
- if (error_flag)
- {
- SetDlgItemText(hDlg, IDC_INFO, "audio error");
- ZeroMemory(s16_samples, sizeof(sint_16) * 256 * 2 * 6);
- error_flag = 0;
- continue;
- }
-
- parse_bsi(&bsi);
-
- for (i=0; i<6; i++)
- {
- ZeroMemory(samples, sizeof(double) * 256 * (bsi.nfchans + bsi.lfeon));
-
- parse_audblk(&bsi, &audblk);
-
- exponent_unpack(&bsi, &audblk);
- if (error_flag)
- goto error;
-
- bit_allocate(syncinfo.fscod, &bsi, &audblk);
-
- coeff_unpack(&bsi, &audblk, samples);
- if (error_flag)
- goto error;
-
- if (bsi.acmod == 0x2)
- rematrix(&audblk, samples);
-
- imdct(&bsi, &audblk, samples);
-
- downmix(&audblk, &bsi, samples, &s16_samples[i * 512]);
-
- sanity_check(&bsi, &audblk);
- if (error_flag)
- goto error;
- }
-
- memcpy(&AC3Dec_Buffer[start], s16_samples, 6144);
- start += 6144;
-error:
- ;
- }
-
- if (Decision_Flag || (!SRC_Flag && Norm_Flag))
- for (i=(j>>1); i<(start>>1); i++)
- if (Sound_Max < abs(ptrAC3Dec_Buffer[i]))
- {
- Sound_Max = abs(ptrAC3Dec_Buffer[i]);
-
- if (Decision_Flag && Sound_Max > Norm_Ratio)
- {
- sprintf(szBuffer, "%.2f", 327.68 * Norm_Ratio / Sound_Max);
- SetDlgItemText(hDlg, IDC_INFO, szBuffer);
- }
- }
-
- return start;
-}
-
-void InitialAC3()
-{
- int i, count;
-
- if (AudioOnly_Flag)
- {
- MessageBox(hWnd, "The \'Demux Audio Only\' feature is intended for demuxing, not decoding.\nDeselect \'Decode AC3 Track to WAV\' in Audio/Output Method.", NULL, MB_OK | MB_ICONERROR);
- ThreadKill(MISC_KILL);
- }
- for (i = 0x80, count = 0; i < 0x88; i++)
- {
- if (audio[i].selected_for_demux)
- count++;
- }
- if (count > 1)
- {
- MessageBox(hWnd, "Cannot decode multiple AC3 streams at the same time.\nMake sure only one track is selected.", NULL, MB_OK | MB_ICONERROR);
- ThreadKill(MISC_KILL);
- }
-
- error_flag = buffer_size = 0;
-
- ZeroMemory(&syncinfo, sizeof(syncinfo));
- ZeroMemory(&bsi, sizeof(bsi));
- ZeroMemory(&audblk, sizeof(audblk));
-
- drc_init();
- imdct_init();
- exponent_init();
- mantissa_init();
-
- srand(0);
-}
diff --git a/src/dgindex/AC3Dec/downmix.cpp b/src/dgindex/AC3Dec/downmix.cpp
deleted file mode 100644
index 02fb798..0000000
--- a/src/dgindex/AC3Dec/downmix.cpp
+++ /dev/null
@@ -1,420 +0,0 @@
-/*
- * Copyright (C) Aaron Holtzman - May 1999
- *
- * This file is part of ac3dec, a free Dolby AC-3 stream decoder.
- *
- * ac3dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * ac3dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
-#include
-#include "../global.h"
-#include "ac3.h"
-
-static double drc[256];
-static double DRCScale[4] = { 1.0, 1.5, 2.0, 4.0 };
-static double ds_x1, ds_x2, ds_y1, ds_y2;
-
-__forceinline short SaturateRound(double flt)
-{
- int tmp;
-
- __asm
- {
- fld [flt]
- fistp [tmp]
- }
-
- return (tmp<-32768) ? -32768 : ((tmp>32767) ? 32767 : tmp);
-}
-
-void drc_init()
-{
- int i;
-
- for (i=0; i<128; i++)
- drc[i] = pow(DRCScale[DRC_Flag], i/32.0);
-
- for (i=128; i<256; i++)
- drc[i] = pow(DRCScale[DRC_Flag], (i-256)/32.0);
-
- ds_x1 = ds_x2 = ds_y1 = ds_y2 = 0;
-}
-
-static double cmixlev_lut[4] = { 0.2928, 0.2468, 0.2071, 0.2468 };
-static double smixlev_lut[4] = { 0.2928, 0.2071, 0.0 , 0.2071 };
-
-static void downmix_3f_2r_to_2ch(double gain, bsi_t* bsi, stream_samples_t samples, sint_16 *s16_samples)
-{
- uint_32 j;
- double tmp, clev, slev;
- double *centre = 0, *left = 0, *right = 0, *left_sur = 0, *right_sur = 0, *lfe = 0;
-
- left = samples[0];
- centre = samples[1];
- right = samples[2];
- left_sur = samples[3];
- right_sur = samples[4];
-
- if (bsi->lfeon)
- lfe = samples[5];
-
- clev = cmixlev_lut[bsi->cmixlev];
- slev = smixlev_lut[bsi->surmixlev];
-
- if (bsi->lfeon)
- for (j = 0; j < 512; j += 2)
- {
- tmp = (0.4143 * (*left++ + *lfe) + clev * *centre + slev * *left_sur++) * gain;
- s16_samples[j] = SaturateRound(tmp);
-
- tmp = (0.4143 * (*right++ + *lfe++) + clev * *centre++ + slev * *right_sur++) * gain;
- s16_samples[j+1] = SaturateRound(tmp);
- }
- else
- for (j = 0; j < 512; j += 2)
- {
- tmp = (0.4143 * *left++ + clev * *centre + slev * *left_sur++) * gain;
- s16_samples[j] = SaturateRound(tmp);
-
- tmp = (0.4143 * *right++ + clev * *centre++ + slev * *right_sur++) * gain;
- s16_samples[j+1] = SaturateRound(tmp);
- }
-}
-
-static void downmix_2f_2r_to_2ch(double gain, bsi_t* bsi, stream_samples_t samples, sint_16 *s16_samples)
-{
- uint_32 j;
- double tmp, slev;
- double *left = 0, *right = 0, *left_sur = 0, *right_sur = 0;
-
- left = samples[0];
- right = samples[1];
- left_sur = samples[2];
- right_sur = samples[3];
-
- slev = smixlev_lut[bsi->surmixlev];
-
- for (j = 0; j < 512; j += 2)
- {
- tmp = (0.4143 * *left++ + slev * *left_sur++) * gain;
- s16_samples[j] = SaturateRound(tmp);
-
- tmp = (0.4143 * *right++ + slev * *right_sur++) * gain;
- s16_samples[j+1] = SaturateRound(tmp);
- }
-}
-
-static void downmix_3f_1r_to_2ch(double gain, bsi_t* bsi, stream_samples_t samples, sint_16 *s16_samples)
-{
- uint_32 j;
- double tmp, clev, slev;
- double *centre = 0, *left = 0, *right = 0, *sur = 0;
-
- left = samples[0];
- centre = samples[1];
- right = samples[2];
- sur = samples[3];
-
- clev = cmixlev_lut[bsi->cmixlev];
- slev = smixlev_lut[bsi->surmixlev];
-
- for (j = 0; j < 512; j += 2)
- {
- tmp = (0.4143 * *left++ + clev * *centre + slev * *sur) * gain;
- s16_samples[j] = SaturateRound(tmp);
-
- tmp = (0.4143 * *right++ + clev * *centre++ + slev * *sur++) * gain;
- s16_samples[j+1] = SaturateRound(tmp);
- }
-}
-
-static void downmix_2f_1r_to_2ch(double gain, bsi_t* bsi, stream_samples_t samples, sint_16 *s16_samples)
-{
- uint_32 j;
- double tmp, slev;
- double *left = 0, *right = 0, *sur = 0;
-
- left = samples[0];
- right = samples[1];
- sur = samples[2];
-
- slev = smixlev_lut[bsi->surmixlev];
-
- for (j = 0; j < 512; j += 2)
- {
- tmp = (0.4143 * *left++ + slev * *sur) * gain;
- s16_samples[j] = SaturateRound(tmp);
-
- tmp = (0.4143 * *right++ + slev * *sur++) * gain;
- s16_samples[j+1] = SaturateRound(tmp);
- }
-}
-
-static void downmix_3f_0r_to_2ch(double gain, bsi_t* bsi, stream_samples_t samples, sint_16 *s16_samples)
-{
- uint_32 j;
- double tmp, clev;
- double *centre = 0, *left = 0, *right = 0;
-
- left = samples[0];
- centre = samples[1];
- right = samples[2];
-
- clev = cmixlev_lut[bsi->cmixlev];
-
- for (j = 0; j < 512; j += 2)
- {
- tmp = (0.4143 * *left++ + clev * *centre) * gain;
- s16_samples[j] = SaturateRound(tmp);
-
- tmp = (0.4143 * *right++ + clev * *centre++) * gain;
- s16_samples[j+1] = SaturateRound(tmp);
- }
-}
-
-static void downmix_2f_0r_to_2ch(double gain, stream_samples_t samples, sint_16 *s16_samples)
-{
- uint_32 j;
- double tmp;
- double *left = 0, *right = 0;
-
- left = samples[0];
- right = samples[1];
-
- for (j = 0; j < 512; j += 2)
- {
- tmp = *left++ * gain;
- s16_samples[j] = SaturateRound(tmp);
-
- tmp = *right++ * gain;
- s16_samples[j+1] = SaturateRound(tmp);
- }
-}
-
-static void downmix_1f_0r_to_2ch(double gain, double *centre, sint_16 *s16_samples)
-{
- uint_32 j;
- double tmp;
-
- for (j = 0; j < 512; j += 2)
- {
- tmp = 0.7071 * *centre++ * gain;
-
- s16_samples[j] = SaturateRound(tmp);
- s16_samples[j+1] = SaturateRound(tmp);
- }
-}
-
-static void downmix_3f_2r_to_2ch_dolby(double gain, bsi_t* bsi, stream_samples_t samples, sint_16 *s16_samples)
-{
- uint_32 j;
- double tmp, ds_sur;
- double *centre = 0, *left = 0, *right = 0, *left_sur = 0, *right_sur = 0, *lfe = 0;
-
- left = samples[0];
- centre = samples[1];
- right = samples[2];
- left_sur = samples[3];
- right_sur = samples[4];
-
- if (bsi->lfeon)
- {
- lfe = samples[5];
-
- for (j = 0; j < 512; j += 2)
- {
- ds_sur = (ds_x2 + ds_x1 * 2.0 + *left_sur + *right_sur) * 0.12531781 +
- ds_y1 * 0.77997062 - ds_y2 * 0.28124186;
-
- ds_x2 = ds_x1;
- ds_x1 = *left_sur++ + *right_sur++;
- ds_y2 = ds_y1;
- ds_y1 = ds_sur;
-
- tmp = (0.3204 * (*left++ + *lfe) + 0.2265 * (*centre - ds_sur)) * gain;
- s16_samples[j] = SaturateRound(tmp);
-
- tmp = (0.3204 * (*right++ + *lfe++) + 0.2265 * (*centre++ + ds_sur)) * gain;
- s16_samples[j+1] = SaturateRound(tmp);
- }
- }
- else
- {
- for (j = 0; j < 512; j += 2)
- {
- ds_sur = (ds_x2 + ds_x1 * 2.0 + *left_sur + *right_sur) * 0.12531781 +
- ds_y1 * 0.77997062 - ds_y2 * 0.28124186;
-
- ds_x2 = ds_x1;
- ds_x1 = *left_sur++ + *right_sur++;
- ds_y2 = ds_y1;
- ds_y1 = ds_sur;
-
- tmp = (0.3204 * *left++ + 0.2265 * (*centre - ds_sur)) * gain;
- s16_samples[j] = SaturateRound(tmp);
-
- tmp = (0.3204 * *right++ + 0.2265 * (*centre++ + ds_sur)) * gain;
- s16_samples[j+1] = SaturateRound(tmp);
- }
- }
-}
-
-static void downmix_2f_2r_to_2ch_dolby(double gain, stream_samples_t samples, sint_16 *s16_samples)
-{
- uint_32 j;
- double tmp, ds_sur;
- double *left = 0, *right = 0, *left_sur = 0, *right_sur = 0;
-
- left = samples[0];
- right = samples[1];
- left_sur = samples[2];
- right_sur = samples[3];
-
- for (j = 0; j < 512; j += 2)
- {
- ds_sur = (ds_x2 + ds_x1 * 2.0 + *left_sur + *right_sur) * 0.12531781 +
- ds_y1 * 0.77997062 - ds_y2 * 0.28124186;
-
- ds_x2 = ds_x1;
- ds_x1 = *left_sur++ + *right_sur++;
- ds_y2 = ds_y1;
- ds_y1 = ds_sur;
-
- tmp = (0.4143 * *left++ - 0.2928 * ds_sur) * gain;
- s16_samples[j] = SaturateRound(tmp);
-
- tmp = (0.4143 * *right++ + 0.2928 * ds_sur) * gain;
- s16_samples[j+1] = SaturateRound(tmp);
- }
-}
-
-static void downmix_3f_1r_to_2ch_dolby(double gain, stream_samples_t samples, sint_16 *s16_samples)
-{
- uint_32 j;
- double tmp, ds_sur;
- double *centre = 0, *left = 0, *right = 0, *sur = 0;
-
- left = samples[0];
- centre = samples[1];
- right = samples[2];
- sur = samples[3];
-
- for (j = 0; j < 512; j += 2)
- {
- ds_sur = (ds_x2 + ds_x1 * 2.0 + *sur) * 0.12531781 +
- ds_y1 * 0.77997062 - ds_y2 * 0.28124186;
-
- ds_x2 = ds_x1;
- ds_x1 = *sur++;
- ds_y2 = ds_y1;
- ds_y1 = ds_sur;
-
- tmp = (0.4143 * *left++ + 0.2928 * (*centre - ds_sur)) * gain;
- s16_samples[j] = SaturateRound(tmp);
-
- tmp = (0.4143 * *right++ + 0.2928 * (*centre++ + ds_sur)) * gain;
- s16_samples[j+1] = SaturateRound(tmp);
- }
-}
-
-static void downmix_2f_1r_to_2ch_dolby(double gain, stream_samples_t samples, sint_16 *s16_samples)
-{
- uint_32 j;
- double tmp, ds_sur;
- double *left = 0, *right = 0, *sur = 0;
-
- left = samples[0];
- right = samples[1];
- sur = samples[2];
-
- for (j = 0; j < 512; j += 2)
- {
- ds_sur = (ds_x2 + ds_x1 * 2.0 + *sur) * 0.12531781 +
- ds_y1 * 0.77997062 - ds_y2 * 0.28124186;
-
- ds_x2 = ds_x1;
- ds_x1 = *sur++;
- ds_y2 = ds_y1;
- ds_y1 = ds_sur;
-
- tmp = (0.5857 * *left++ - 0.4143 * ds_sur) * gain;
- s16_samples[j] = SaturateRound(tmp);
-
- tmp = (0.5857 * *right++ + 0.4143 * ds_sur) * gain;
- s16_samples[j+1] = SaturateRound(tmp);
- }
-}
-
-void downmix(audblk_t *audblk, bsi_t* bsi, stream_samples_t samples, sint_16 *s16_samples)
-{
- double gain;
-
- if (DRC_Flag>2)
- gain = 32768.0 * drc[bsi->compr] * PreScale_Ratio;
- else
- gain = 32768.0 * drc[audblk->dynrng] * PreScale_Ratio;
-
- switch (bsi->acmod)
- {
- // 3/2
- case 7:
- if (DSDown_Flag)
- downmix_3f_2r_to_2ch_dolby(gain, bsi, samples, s16_samples);
- else
- downmix_3f_2r_to_2ch(gain, bsi, samples, s16_samples);
- break;
-
- // 2/2
- case 6:
- if (DSDown_Flag)
- downmix_2f_2r_to_2ch_dolby(gain, samples, s16_samples);
- else
- downmix_2f_2r_to_2ch(gain, bsi, samples, s16_samples);
- break;
-
- // 3/1
- case 5:
- if (DSDown_Flag)
- downmix_3f_1r_to_2ch_dolby(gain, samples, s16_samples);
- else
- downmix_3f_1r_to_2ch(gain, bsi, samples, s16_samples);
- break;
-
- // 2/1
- case 4:
- if (DSDown_Flag)
- downmix_2f_1r_to_2ch_dolby(gain, samples, s16_samples);
- else
- downmix_2f_1r_to_2ch(gain, bsi, samples, s16_samples);
- break;
-
- // 3/0
- case 3:
- downmix_3f_0r_to_2ch(gain, bsi, samples, s16_samples);
- break;
-
- // 2/0
- case 2:
- downmix_2f_0r_to_2ch(gain, samples, s16_samples);
- break;
-
- // 1/0, 1+1, discard dynrng2 :p
- case 1:
- case 0:
- downmix_1f_0r_to_2ch(gain, samples[0], s16_samples);
- break;
- }
-}
diff --git a/src/dgindex/AC3Dec/exponent.cpp b/src/dgindex/AC3Dec/exponent.cpp
deleted file mode 100644
index 33b1639..0000000
--- a/src/dgindex/AC3Dec/exponent.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright (C) Aaron Holtzman - May 1999
- *
- * This file is part of ac3dec, a free Dolby AC-3 stream decoder.
- *
- * ac3dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * ac3dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
-#include "ac3.h"
-
-static sint_16 EXPT[125][3];
-
-static void exp_unpack_ch(uint_16 type,uint_16 expstr,uint_16 ngrps,uint_16 initial_exp, uint_16 exps[], uint_16 *dest);
-
-void exponent_init()
-{
- int i;
-
- for (i=0; i<125; i++)
- {
- EXPT[i][0] = i / 25;
- EXPT[i][1] = (i - EXPT[i][0] * 25) / 5;
- EXPT[i][2] = i - EXPT[i][0] * 25 - EXPT[i][1] * 5;
- EXPT[i][0] -= 2;
- EXPT[i][1] -= 2;
- EXPT[i][2] -= 2;
- }
-}
-
-void exponent_unpack( bsi_t *bsi, audblk_t *audblk)
-{
- uint_16 i;
-
- for(i=0; i< bsi->nfchans; i++)
- exp_unpack_ch(UNPACK_FBW, audblk->chexpstr[i], audblk->nchgrps[i], audblk->exps[i][0],
- &audblk->exps[i][1], audblk->fbw_exp[i]);
-
- if(audblk->cplinu)
- exp_unpack_ch(UNPACK_CPL, audblk->cplexpstr, audblk->ncplgrps, audblk->cplabsexp << 1,
- audblk->cplexps, &audblk->cpl_exp[audblk->cplstrtmant]);
-
- if(bsi->lfeon)
- exp_unpack_ch(UNPACK_LFE, audblk->lfeexpstr, 2, audblk->lfeexps[0],
- &audblk->lfeexps[1], audblk->lfe_exp);
-}
-
-
-static void exp_unpack_ch(uint_16 type,uint_16 expstr,uint_16 ngrps,uint_16 initial_exp,
- uint_16 exps[], uint_16 *dest)
-{
- uint_16 i,j;
- sint_16 exp_acc;
-
- if(expstr == EXP_REUSE)
- return;
-
- /* Handle the initial absolute exponent */
- exp_acc = initial_exp;
- j = 0;
-
- /* In the case of a fbw channel then the initial absolute values is
- * also an exponent */
- if(type != UNPACK_CPL)
- dest[j++] = exp_acc;
-
- /* Loop through the groups and fill the dest array appropriately */
- for(i=0; i 124)
- {
- error_flag = 1;
- return;
- }
-
- exp_acc += EXPT[exps[i]][0];
-
- switch (expstr)
- {
- case EXP_D45:
- dest[j++] = exp_acc;
- dest[j++] = exp_acc;
- case EXP_D25:
- dest[j++] = exp_acc;
- case EXP_D15:
- dest[j++] = exp_acc;
- }
-
- exp_acc += EXPT[exps[i]][1];
-
- switch (expstr)
- {
- case EXP_D45:
- dest[j++] = exp_acc;
- dest[j++] = exp_acc;
- case EXP_D25:
- dest[j++] = exp_acc;
- case EXP_D15:
- dest[j++] = exp_acc;
- }
-
- exp_acc += EXPT[exps[i]][2];
-
- switch (expstr)
- {
- case EXP_D45:
- dest[j++] = exp_acc;
- dest[j++] = exp_acc;
- case EXP_D25:
- dest[j++] = exp_acc;
- case EXP_D15:
- dest[j++] = exp_acc;
- }
- }
-}
diff --git a/src/dgindex/AC3Dec/imdct.cpp b/src/dgindex/AC3Dec/imdct.cpp
deleted file mode 100644
index 088a22e..0000000
--- a/src/dgindex/AC3Dec/imdct.cpp
+++ /dev/null
@@ -1,414 +0,0 @@
-/*
- * Copyright (C) Aaron Holtzman - May 1999
- *
- * This file is part of ac3dec, a free Dolby AC-3 stream decoder.
- *
- * ac3dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * ac3dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
-#include
-#include "ac3.h"
-
-#define M_PI 3.1415926535897932384626433832795
-#define N 512
-
-void imdct_do_256(double data[], double delay[]);
-void imdct_do_512(double data[], double delay[]);
-
-typedef struct complex_s
-{
- double real;
- double imag;
-} complex_t;
-
-static uint_8 bit_reverse_512[128] = {
- 0x00, 0x40, 0x20, 0x60, 0x10, 0x50, 0x30, 0x70,
- 0x08, 0x48, 0x28, 0x68, 0x18, 0x58, 0x38, 0x78,
- 0x04, 0x44, 0x24, 0x64, 0x14, 0x54, 0x34, 0x74,
- 0x0c, 0x4c, 0x2c, 0x6c, 0x1c, 0x5c, 0x3c, 0x7c,
- 0x02, 0x42, 0x22, 0x62, 0x12, 0x52, 0x32, 0x72,
- 0x0a, 0x4a, 0x2a, 0x6a, 0x1a, 0x5a, 0x3a, 0x7a,
- 0x06, 0x46, 0x26, 0x66, 0x16, 0x56, 0x36, 0x76,
- 0x0e, 0x4e, 0x2e, 0x6e, 0x1e, 0x5e, 0x3e, 0x7e,
- 0x01, 0x41, 0x21, 0x61, 0x11, 0x51, 0x31, 0x71,
- 0x09, 0x49, 0x29, 0x69, 0x19, 0x59, 0x39, 0x79,
- 0x05, 0x45, 0x25, 0x65, 0x15, 0x55, 0x35, 0x75,
- 0x0d, 0x4d, 0x2d, 0x6d, 0x1d, 0x5d, 0x3d, 0x7d,
- 0x03, 0x43, 0x23, 0x63, 0x13, 0x53, 0x33, 0x73,
- 0x0b, 0x4b, 0x2b, 0x6b, 0x1b, 0x5b, 0x3b, 0x7b,
- 0x07, 0x47, 0x27, 0x67, 0x17, 0x57, 0x37, 0x77,
- 0x0f, 0x4f, 0x2f, 0x6f, 0x1f, 0x5f, 0x3f, 0x7f};
-
-static uint_8 bit_reverse_256[64] = {
- 0x00, 0x20, 0x10, 0x30, 0x08, 0x28, 0x18, 0x38,
- 0x04, 0x24, 0x14, 0x34, 0x0c, 0x2c, 0x1c, 0x3c,
- 0x02, 0x22, 0x12, 0x32, 0x0a, 0x2a, 0x1a, 0x3a,
- 0x06, 0x26, 0x16, 0x36, 0x0e, 0x2e, 0x1e, 0x3e,
- 0x01, 0x21, 0x11, 0x31, 0x09, 0x29, 0x19, 0x39,
- 0x05, 0x25, 0x15, 0x35, 0x0d, 0x2d, 0x1d, 0x3d,
- 0x03, 0x23, 0x13, 0x33, 0x0b, 0x2b, 0x1b, 0x3b,
- 0x07, 0x27, 0x17, 0x37, 0x0f, 0x2f, 0x1f, 0x3f};
-
-static complex_t buf[128];
-
-/* Twiddle factor LUT */
-static complex_t *w[7];
-static complex_t w_1[1];
-static complex_t w_2[2];
-static complex_t w_4[4];
-static complex_t w_8[8];
-static complex_t w_16[16];
-static complex_t w_32[32];
-static complex_t w_64[64];
-
-/* Twiddle factors for IMDCT */
-static double xcos1[128];
-static double xsin1[128];
-static double xcos2[64];
-static double xsin2[64];
-
-/* Delay buffer for time domain interleaving */
-static double delay[6][256];
-
-/* Windowing function for Modified DCT */
-static double window[] = {
- 0.00014, 0.00024, 0.00037, 0.00051, 0.00067, 0.00086, 0.00107, 0.00130,
- 0.00157, 0.00187, 0.00220, 0.00256, 0.00297, 0.00341, 0.00390, 0.00443,
- 0.00501, 0.00564, 0.00632, 0.00706, 0.00785, 0.00871, 0.00962, 0.01061,
- 0.01166, 0.01279, 0.01399, 0.01526, 0.01662, 0.01806, 0.01959, 0.02121,
- 0.02292, 0.02472, 0.02662, 0.02863, 0.03073, 0.03294, 0.03527, 0.03770,
- 0.04025, 0.04292, 0.04571, 0.04862, 0.05165, 0.05481, 0.05810, 0.06153,
- 0.06508, 0.06878, 0.07261, 0.07658, 0.08069, 0.08495, 0.08935, 0.09389,
- 0.09859, 0.10343, 0.10842, 0.11356, 0.11885, 0.12429, 0.12988, 0.13563,
- 0.14152, 0.14757, 0.15376, 0.16011, 0.16661, 0.17325, 0.18005, 0.18699,
- 0.19407, 0.20130, 0.20867, 0.21618, 0.22382, 0.23161, 0.23952, 0.24757,
- 0.25574, 0.26404, 0.27246, 0.28100, 0.28965, 0.29841, 0.30729, 0.31626,
- 0.32533, 0.33450, 0.34376, 0.35311, 0.36253, 0.37204, 0.38161, 0.39126,
- 0.40096, 0.41072, 0.42054, 0.43040, 0.44030, 0.45023, 0.46020, 0.47019,
- 0.48020, 0.49022, 0.50025, 0.51028, 0.52031, 0.53033, 0.54033, 0.55031,
- 0.56026, 0.57019, 0.58007, 0.58991, 0.59970, 0.60944, 0.61912, 0.62873,
- 0.63827, 0.64774, 0.65713, 0.66643, 0.67564, 0.68476, 0.69377, 0.70269,
- 0.71150, 0.72019, 0.72877, 0.73723, 0.74557, 0.75378, 0.76186, 0.76981,
- 0.77762, 0.78530, 0.79283, 0.80022, 0.80747, 0.81457, 0.82151, 0.82831,
- 0.83496, 0.84145, 0.84779, 0.85398, 0.86001, 0.86588, 0.87160, 0.87716,
- 0.88257, 0.88782, 0.89291, 0.89785, 0.90264, 0.90728, 0.91176, 0.91610,
- 0.92028, 0.92432, 0.92822, 0.93197, 0.93558, 0.93906, 0.94240, 0.94560,
- 0.94867, 0.95162, 0.95444, 0.95713, 0.95971, 0.96217, 0.96451, 0.96674,
- 0.96887, 0.97089, 0.97281, 0.97463, 0.97635, 0.97799, 0.97953, 0.98099,
- 0.98236, 0.98366, 0.98488, 0.98602, 0.98710, 0.98811, 0.98905, 0.98994,
- 0.99076, 0.99153, 0.99225, 0.99291, 0.99353, 0.99411, 0.99464, 0.99513,
- 0.99558, 0.99600, 0.99639, 0.99674, 0.99706, 0.99736, 0.99763, 0.99788,
- 0.99811, 0.99831, 0.99850, 0.99867, 0.99882, 0.99895, 0.99908, 0.99919,
- 0.99929, 0.99938, 0.99946, 0.99953, 0.99959, 0.99965, 0.99969, 0.99974,
- 0.99978, 0.99981, 0.99984, 0.99986, 0.99988, 0.99990, 0.99992, 0.99993,
- 0.99994, 0.99995, 0.99996, 0.99997, 0.99998, 0.99998, 0.99998, 0.99999,
- 0.99999, 0.99999, 0.99999, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000,
- 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000 };
-
-static complex_t cmplx_mult(complex_t a, complex_t b)
-{
- complex_t ret;
-
- ret.real = a.real * b.real - a.imag * b.imag;
- ret.imag = a.real * b.imag + a.imag * b.real;
-
- return ret;
-}
-
-void imdct_init()
-{
- int i, k;
- complex_t angle_step;
- complex_t current_angle;
-
- /* Twiddle factors to turn IFFT into IMDCT */
- for(i=0; i<128; i++)
- {
- xcos1[i] = cos(2.0 * M_PI * (8*i+1)/(8*N));
- xsin1[i] = sin(2.0 * M_PI * (8*i+1)/(8*N));
- }
-
- /* More twiddle factors to turn IFFT into IMDCT */
- for(i=0; i<64; i++)
- {
- xcos2[i] = cos(2.0 * M_PI * (8*i+1)/(4*N));
- xsin2[i] = sin(2.0 * M_PI * (8*i+1)/(4*N));
- }
-
- /* Canonical twiddle factors for FFT */
- w[0] = w_1;
- w[1] = w_2;
- w[2] = w_4;
- w[3] = w_8;
- w[4] = w_16;
- w[5] = w_32;
- w[6] = w_64;
-
- for( i = 0; i < 7; i++)
- {
- angle_step.real = cos(-2.0 * M_PI / (1 << (i+1)));
- angle_step.imag = sin(-2.0 * M_PI / (1 << (i+1)));
-
- current_angle.real = 1.0;
- current_angle.imag = 0.0;
-
- for (k = 0; k < 1 << i; k++)
- {
- w[i][k] = current_angle;
- current_angle = cmplx_mult(current_angle, angle_step);
- }
- }
-
- ZeroMemory(&delay, sizeof(delay));
-}
-
-void imdct_do_512(double data[], double delay[])
-{
- int i, k;
- int p, q;
- int m;
- int two_m;
- int two_m_plus_one;
-
- double tmp_a_i, tmp_a_r, tmp_b_i, tmp_b_r;
- double *data_ptr, *delay_ptr, *window_ptr;
-
- // Pre IFFT complex multiply plus IFFT cmplx conjugate and bit reverse permutation
- for(i=0; i < 128; i++)
- {
- k = bit_reverse_512[i];
-
- /* z[i] = (X[256-2*i-1] + j * X[2*i]) * (xcos1[i] + j * xsin1[i]) ; */
- buf[k].real = data[255 - (i<<1)] * xcos1[i] - data[i<<1] * xsin1[i];
- buf[k].imag = - data[i<<1] * xcos1[i] - data[255 - (i<<1)] * xsin1[i];
- }
-
- // FFT Merge
- for (m=0; m<7; m++)
- {
- if (m)
- two_m = 1<nfchans; i++)
- {
- if(audblk->blksw[i])
- imdct_do_256(samples[i], delay[i]);
- else
- imdct_do_512(samples[i], delay[i]);
- }
-
- if (bsi->lfeon)
- imdct_do_512(samples[5], delay[5]);
-}
diff --git a/src/dgindex/AC3Dec/parse.cpp b/src/dgindex/AC3Dec/parse.cpp
deleted file mode 100644
index 38ff64b..0000000
--- a/src/dgindex/AC3Dec/parse.cpp
+++ /dev/null
@@ -1,532 +0,0 @@
-/*
- * Copyright (C) Aaron Holtzman - May 1999
- *
- * This file is part of ac3dec, a free Dolby AC-3 stream decoder.
- *
- * ac3dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * ac3dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
-#include "ac3.h"
-#include "bitstream.h"
-
-/* Misc LUT */
-static const uint_16 nfchans[8] = {2,1,2,3,3,4,4,5};
-
-struct frmsize_s
-{
- uint_16 bit_rate;
- uint_16 frm_size[3];
-};
-
-static const struct frmsize_s frmsizecod_tbl[64] =
-{
- { 32 ,{64 ,69 ,96 } },
- { 32 ,{64 ,70 ,96 } },
- { 40 ,{80 ,87 ,120 } },
- { 40 ,{80 ,88 ,120 } },
- { 48 ,{96 ,104 ,144 } },
- { 48 ,{96 ,105 ,144 } },
- { 56 ,{112 ,121 ,168 } },
- { 56 ,{112 ,122 ,168 } },
- { 64 ,{128 ,139 ,192 } },
- { 64 ,{128 ,140 ,192 } },
- { 80 ,{160 ,174 ,240 } },
- { 80 ,{160 ,175 ,240 } },
- { 96 ,{192 ,208 ,288 } },
- { 96 ,{192 ,209 ,288 } },
- { 112 ,{224 ,243 ,336 } },
- { 112 ,{224 ,244 ,336 } },
- { 128 ,{256 ,278 ,384 } },
- { 128 ,{256 ,279 ,384 } },
- { 160 ,{320 ,348 ,480 } },
- { 160 ,{320 ,349 ,480 } },
- { 192 ,{384 ,417 ,576 } },
- { 192 ,{384 ,418 ,576 } },
- { 224 ,{448 ,487 ,672 } },
- { 224 ,{448 ,488 ,672 } },
- { 256 ,{512 ,557 ,768 } },
- { 256 ,{512 ,558 ,768 } },
- { 320 ,{640 ,696 ,960 } },
- { 320 ,{640 ,697 ,960 } },
- { 384 ,{768 ,835 ,1152 } },
- { 384 ,{768 ,836 ,1152 } },
- { 448 ,{896 ,975 ,1344 } },
- { 448 ,{896 ,976 ,1344 } },
- { 512 ,{1024 ,1114 ,1536 } },
- { 512 ,{1024 ,1115 ,1536 } },
- { 576 ,{1152 ,1253 ,1728 } },
- { 576 ,{1152 ,1254 ,1728 } },
- { 640 ,{1280 ,1393 ,1920 } },
- { 640 ,{1280 ,1394 ,1920 } }
-};
-
-/* Parse a syncinfo structure, minus the sync word */
-void parse_syncinfo(syncinfo_t *syncinfo,uint_8 *data)
-{
- //
- // We need to read in the entire syncinfo struct (0x0b77 + 24 bits)
- // in order to determine how big the frame is
- //
-
- // Get the sampling rate
- syncinfo->fscod = (data[2] >> 6) & 0x03;
-
- switch (syncinfo->fscod)
- {
- case 0:
- syncinfo->sampling_rate = 48000;
- break;
-
- case 1:
- syncinfo->sampling_rate = 44100;
- break;
-
- case 2:
- syncinfo->sampling_rate = 32000;
- break;
-
- default:
- error_flag = 1;
- return;
- }
-
- // Get the frame size code
- syncinfo->frmsizecod = data[2] & 0x3f;
-
- // Calculate the frame size and bitrate
- syncinfo->frame_size = frmsizecod_tbl[syncinfo->frmsizecod].frm_size[syncinfo->fscod];
- syncinfo->bit_rate = frmsizecod_tbl[syncinfo->frmsizecod].bit_rate;
-}
-
-/*
- * This routine fills a bsi struct from the AC3 stream
- */
-
-void parse_bsi(bsi_t *bsi)
-{
- sint_32 i;
-
- /* Check the AC-3 version number */
- bsi->bsid = bitstream_get(5);
-
- /* Get the audio service provided by the steram */
- bsi->bsmod = bitstream_get(3);
-
- /* Get the audio coding mode (ie how many channels)*/
- bsi->acmod = bitstream_get(3);
- /* Predecode the number of full bandwidth channels as we use this
- * number a lot */
- bsi->nfchans = nfchans[bsi->acmod];
-
- /* If it is in use, get the centre channel mix level */
- if ((bsi->acmod & 0x1) && bsi->acmod!=0x1)
- bsi->cmixlev = bitstream_get(2);
-
- /* If it is in use, get the surround channel mix level */
- if (bsi->acmod & 0x4)
- bsi->surmixlev = bitstream_get(2);
-
- /* Get the dolby surround mode if in 2/0 mode */
- if(bsi->acmod == 0x2)
- bsi->dsurmod= bitstream_get(2);
-
- /* Is the low frequency effects channel on? */
- bsi->lfeon = bitstream_get(1);
-
- /* Get the dialogue normalization level */
- bsi->dialnorm = bitstream_get(5);
-
- /* Does compression gain exist? */
- bsi->compre = bitstream_get(1);
- if (bsi->compre)
- {
- /* Get compression gain */
- bsi->compr = bitstream_get(8);
- }
-
- /* Does language code exist? */
- bsi->langcode = bitstream_get(1);
- if (bsi->langcode)
- {
- /* Get langauge code */
- bsi->langcod = bitstream_get(8);
- }
-
- /* Does audio production info exist? */
- bsi->audprodie = bitstream_get(1);
- if (bsi->audprodie)
- {
- /* Get mix level */
- bsi->mixlevel = bitstream_get(5);
-
- /* Get room type */
- bsi->roomtyp = bitstream_get(2);
- }
-
- /* If we're in dual mono mode then get some extra info */
- if (bsi->acmod ==0)
- {
- /* Get the dialogue normalization level two */
- bsi->dialnorm2 = bitstream_get(5);
-
- /* Does compression gain two exist? */
- bsi->compr2e = bitstream_get(1);
- if (bsi->compr2e)
- {
- /* Get compression gain two */
- bsi->compr2 = bitstream_get(8);
- }
-
- /* Does language code two exist? */
- bsi->langcod2e = bitstream_get(1);
- if (bsi->langcod2e)
- {
- /* Get langauge code two */
- bsi->langcod2 = bitstream_get(8);
- }
-
- /* Does audio production info two exist? */
- bsi->audprodi2e = bitstream_get(1);
- if (bsi->audprodi2e)
- {
- /* Get mix level two */
- bsi->mixlevel2 = bitstream_get(5);
-
- /* Get room type two */
- bsi->roomtyp2 = bitstream_get(2);
- }
- }
-
- /* Get the copyright bit */
- bsi->copyrightb = bitstream_get(1);
-
- /* Get the original bit */
- bsi->origbs = bitstream_get(1);
-
- /* Does timecode one exist? */
- bsi->timecod1e = bitstream_get(1);
-
- if(bsi->timecod1e)
- bsi->timecod1 = bitstream_get(14);
-
- /* Does timecode two exist? */
- bsi->timecod2e = bitstream_get(1);
-
- if(bsi->timecod2e)
- bsi->timecod2 = bitstream_get(14);
-
- /* Does addition info exist? */
- bsi->addbsie = bitstream_get(1);
-
- if(bsi->addbsie)
- {
- /* Get how much info is there */
- bsi->addbsil = bitstream_get(6);
-
- /* Get the additional info */
- for(i=0; i<(bsi->addbsil+1); i++)
- bsi->addbsi[i] = bitstream_get(8);
- }
-}
-
-/* More pain inducing parsing */
-void parse_audblk(bsi_t *bsi,audblk_t *audblk)
-{
- int i,j;
-
- for (i=0; infchans; i++)
- {
- /* Is this channel an interleaved 256 + 256 block ? */
- audblk->blksw[i] = bitstream_get(1);
- }
-
- for (i=0; infchans; i++)
- {
- /* Should we dither this channel? */
- audblk->dithflag[i] = bitstream_get(1);
- }
-
- /* Does dynamic range control exist? */
- audblk->dynrnge = bitstream_get(1);
- if (audblk->dynrnge)
- {
- /* Get dynamic range info */
- audblk->dynrng = bitstream_get(8);
- }
-
- /* If we're in dual mono mode then get the second channel DR info */
- if (bsi->acmod == 0)
- {
- /* Does dynamic range control two exist? */
- audblk->dynrng2e = bitstream_get(1);
- if (audblk->dynrng2e)
- {
- /* Get dynamic range info */
- audblk->dynrng2 = bitstream_get(8);
- }
- }
-
- /* Does coupling strategy exist? */
- audblk->cplstre = bitstream_get(1);
- if (audblk->cplstre)
- {
- /* Is coupling turned on? */
- audblk->cplinu = bitstream_get(1);
- if(audblk->cplinu)
- {
- for(i=0;i < bsi->nfchans; i++)
- audblk->chincpl[i] = bitstream_get(1);
- if(bsi->acmod == 0x2)
- audblk->phsflginu = bitstream_get(1);
- audblk->cplbegf = bitstream_get(4);
- audblk->cplendf = bitstream_get(4);
- audblk->ncplsubnd = (audblk->cplendf + 2) - audblk->cplbegf + 1;
-
- /* Calculate the start and end bins of the coupling channel */
- audblk->cplstrtmant = (audblk->cplbegf * 12) + 37 ;
- audblk->cplendmant = ((audblk->cplendf + 3) * 12) + 37;
-
- /* The number of combined subbands is ncplsubnd minus each combined band */
- audblk->ncplbnd = audblk->ncplsubnd;
-
- for(i=1; incplsubnd; i++)
- {
- audblk->cplbndstrc[i] = bitstream_get(1);
- audblk->ncplbnd -= audblk->cplbndstrc[i];
- }
- }
- }
-
- if(audblk->cplinu)
- {
- /* Loop through all the channels and get their coupling co-ords */
- for(i=0; infchans;i++)
- {
- if(!audblk->chincpl[i])
- continue;
-
- /* Is there new coupling co-ordinate info? */
- audblk->cplcoe[i] = bitstream_get(1);
-
- if(audblk->cplcoe[i])
- {
- audblk->mstrcplco[i] = bitstream_get(2);
- for(j=0;j < audblk->ncplbnd; j++)
- {
- audblk->cplcoexp[i][j] = bitstream_get(4);
- audblk->cplcomant[i][j] = bitstream_get(4);
- }
- }
- }
-
- /* If we're in dual mono mode, there's going to be some phase info */
- if(bsi->acmod== 0x2 && audblk->phsflginu && (audblk->cplcoe[0] || audblk->cplcoe[1]))
- {
- for(j=0;j < audblk->ncplbnd; j++)
- audblk->phsflg[j] = bitstream_get(1);
- }
- }
-
- /* If we're in dual mono mode, there may be a rematrix strategy */
- if(bsi->acmod == 0x2)
- {
- audblk->rematstr = bitstream_get(1);
- if(audblk->rematstr)
- {
- if (audblk->cplinu == 0)
- {
- for(i = 0; i < 4; i++)
- audblk->rematflg[i] = bitstream_get(1);
- }
- if(audblk->cplbegf>2 && audblk->cplinu)
- {
- for(i = 0; i < 4; i++)
- audblk->rematflg[i] = bitstream_get(1);
- }
- if(audblk->cplbegf<=2 && audblk->cplinu)
- {
- for(i = 0; i < 3; i++)
- audblk->rematflg[i] = bitstream_get(1);
- }
- if(audblk->cplbegf==0 && audblk->cplinu)
- for(i = 0; i < 2; i++)
- audblk->rematflg[i] = bitstream_get(1);
- }
- }
-
- if (audblk->cplinu)
- {
- /* Get the coupling channel exponent strategy */
- audblk->cplexpstr = bitstream_get(2);
- audblk->ncplgrps = (audblk->cplendmant - audblk->cplstrtmant) /
- (3 << (audblk->cplexpstr-1));
- }
-
- for(i = 0; i < bsi->nfchans; i++)
- audblk->chexpstr[i] = bitstream_get(2);
-
- /* Get the exponent strategy for lfe channel */
- if(bsi->lfeon)
- audblk->lfeexpstr = bitstream_get(1);
-
- /* Determine the bandwidths of all the fbw channels */
- for(i = 0; i < bsi->nfchans; i++)
- {
- uint_16 grp_size;
-
- if(audblk->chexpstr[i] != EXP_REUSE)
- {
- if (audblk->cplinu && audblk->chincpl[i])
- {
- audblk->endmant[i] = audblk->cplstrtmant;
- }
- else
- {
- audblk->chbwcod[i] = bitstream_get(6);
- audblk->endmant[i] = ((audblk->chbwcod[i] + 12) * 3) + 37;
- }
-
- /* Calculate the number of exponent groups to fetch */
- grp_size = 3 * (1 << (audblk->chexpstr[i] - 1));
- audblk->nchgrps[i] = (audblk->endmant[i] - 1 + (grp_size - 3)) / grp_size;
- }
- }
-
- /* Get the coupling exponents if they exist */
- if(audblk->cplinu && audblk->cplexpstr!=EXP_REUSE)
- {
- audblk->cplabsexp = bitstream_get(4);
- for(i=0;i< audblk->ncplgrps;i++)
- audblk->cplexps[i] = bitstream_get(7);
- }
-
- /* Get the fwb channel exponents */
- for(i=0;i < bsi->nfchans; i++)
- {
- if(audblk->chexpstr[i] != EXP_REUSE)
- {
- audblk->exps[i][0] = bitstream_get(4);
- for(j=1;j<=audblk->nchgrps[i];j++)
- audblk->exps[i][j] = bitstream_get(7);
- audblk->gainrng[i] = bitstream_get(2);
- }
- }
-
- /* Get the lfe channel exponents */
- if(bsi->lfeon && audblk->lfeexpstr!=EXP_REUSE)
- {
- audblk->lfeexps[0] = bitstream_get(4);
- audblk->lfeexps[1] = bitstream_get(7);
- audblk->lfeexps[2] = bitstream_get(7);
- }
-
- /* Get the parametric bit allocation parameters */
- audblk->baie = bitstream_get(1);
-
- if(audblk->baie)
- {
- audblk->sdcycod = bitstream_get(2);
- audblk->fdcycod = bitstream_get(2);
- audblk->sgaincod = bitstream_get(2);
- audblk->dbpbcod = bitstream_get(2);
- audblk->floorcod = bitstream_get(3);
- }
-
- /* Get the SNR off set info if it exists */
- audblk->snroffste = bitstream_get(1);
-
- if(audblk->snroffste)
- {
- audblk->csnroffst = bitstream_get(6);
-
- if(audblk->cplinu)
- {
- audblk->cplfsnroffst = bitstream_get(4);
- audblk->cplfgaincod = bitstream_get(3);
- }
-
- for(i=0; infchans; i++)
- {
- audblk->fsnroffst[i] = bitstream_get(4);
- audblk->fgaincod[i] = bitstream_get(3);
- }
- if(bsi->lfeon)
- {
- audblk->lfefsnroffst = bitstream_get(4);
- audblk->lfefgaincod = bitstream_get(3);
- }
- }
-
- /* Get coupling leakage info if it exists */
- if(audblk->cplinu)
- {
- audblk->cplleake = bitstream_get(1);
-
- if(audblk->cplleake)
- {
- audblk->cplfleak = bitstream_get(3);
- audblk->cplsleak = bitstream_get(3);
- }
- }
-
- /* Get the delta bit alloaction info */
- audblk->deltbaie = bitstream_get(1);
-
- if(audblk->deltbaie)
- {
- if(audblk->cplinu)
- audblk->cpldeltbae = bitstream_get(2);
-
- for(i = 0;i < bsi->nfchans; i++)
- audblk->deltbae[i] = bitstream_get(2);
-
- if (audblk->cplinu && audblk->cpldeltbae==DELTA_BIT_NEW)
- {
- audblk->cpldeltnseg = bitstream_get(3);
- for(i = 0;i < audblk->cpldeltnseg + 1; i++)
- {
- audblk->cpldeltoffst[i] = bitstream_get(5);
- audblk->cpldeltlen[i] = bitstream_get(4);
- audblk->cpldeltba[i] = bitstream_get(3);
- }
- }
-
- for(i = 0;i < bsi->nfchans; i++)
- {
- if (audblk->deltbae[i] == DELTA_BIT_NEW)
- {
- audblk->deltnseg[i] = bitstream_get(3);
- for(j = 0; j < audblk->deltnseg[i] + 1; j++)
- {
- audblk->deltoffst[i][j] = bitstream_get(5);
- audblk->deltlen[i][j] = bitstream_get(4);
- audblk->deltba[i][j] = bitstream_get(3);
- }
- }
- }
- }
-
- /* Check to see if there's any dummy info to get */
- if((audblk->skiple = bitstream_get(1)))
- {
- uint_16 skip_data;
-
- audblk->skipl = bitstream_get(9);
-
- for(i = 0; i < audblk->skipl ; i++)
- skip_data = bitstream_get(8);
- }
-}
diff --git a/src/dgindex/AC3Dec/rematrix.cpp b/src/dgindex/AC3Dec/rematrix.cpp
deleted file mode 100644
index 25b95f7..0000000
--- a/src/dgindex/AC3Dec/rematrix.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (C) Aaron Holtzman - May 1999
- *
- * This file is part of ac3dec, a free Dolby AC-3 stream decoder.
- *
- * ac3dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * ac3dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
-#include "ac3.h"
-
-struct rematrix_band_s
-{
- uint_32 start;
- uint_32 end;
-};
-
-static struct rematrix_band_s rematrix_band[] = {{13,24}, {25,36}, {37,60}, {61,252}};
-
-/* This routine simply does stereo rematixing for the 2 channel stereo mode */
-void rematrix(audblk_t *audblk, stream_samples_t samples)
-{
- uint_32 num_bands;
- uint_32 start;
- uint_32 end;
- uint_32 i, j;
- double left, right;
-
- if(!audblk->cplinu || audblk->cplbegf > 2)
- num_bands = 4;
- else if (audblk->cplbegf > 0)
- num_bands = 3;
- else
- num_bands = 2;
-
- for(i=0; irematflg[i])
- continue;
-
- start = rematrix_band[i].start;
-
- if (i==num_bands-1 && audblk->cplinu)
- end = 12 * audblk->cplbegf + 36;
- else
- end = rematrix_band[i].end;
-
- for (j=start; j<=end; j++)
- {
- left = samples[0][j] + samples[1][j];
- right = samples[0][j] - samples[1][j];
- samples[0][j] = left;
- samples[1][j] = right;
- }
- }
-}
diff --git a/src/dgindex/AC3Dec/sanity_check.cpp b/src/dgindex/AC3Dec/sanity_check.cpp
deleted file mode 100644
index 42ab042..0000000
--- a/src/dgindex/AC3Dec/sanity_check.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) Aaron Holtzman - May 1999
- *
- * This file is part of ac3dec, a free Dolby AC-3 stream decoder.
- *
- * ac3dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * ac3dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
-#include "ac3.h"
-
-void sanity_check(bsi_t *bsi, audblk_t *audblk)
-{
- int i;
-
- for(i=0; i<5 ; i++)
- {
- if (audblk->fbw_exp[i][255] !=0 || audblk->fbw_exp[i][254] !=0 || audblk->fbw_exp[i][253] !=0)
- error_flag = 1;
-
- if (audblk->fbw_bap[i][255] !=0 || audblk->fbw_bap[i][254] !=0 || audblk->fbw_bap[i][253] !=0)
- error_flag = 1;
- }
-
- if (audblk->cpl_exp[255] !=0 || audblk->cpl_exp[254] !=0 || audblk->cpl_exp[253] !=0)
- error_flag = 1;
-
- if (audblk->cpl_bap[255] !=0 || audblk->cpl_bap[254] !=0 || audblk->cpl_bap[253] !=0)
- error_flag = 1;
-
- if (audblk->cplmant[255] !=0 || audblk->cplmant[254] !=0 || audblk->cplmant[253] !=0)
- error_flag = 1;
-
- for(i=0; i < bsi->nfchans; i++)
- if(audblk->chincpl[i]==0 && audblk->chbwcod[i]>60)
- error_flag = 1;
-}
diff --git a/src/dgindex/COPYING.txt b/src/dgindex/COPYING.txt
deleted file mode 100644
index bee9f8d..0000000
--- a/src/dgindex/COPYING.txt
+++ /dev/null
@@ -1,340 +0,0 @@
- GNU GENERAL PUBLIC LICENSE
- Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users. This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it. (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.) You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
- To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. You must make sure that they, too, receive or can get the
-source code. And you must show them these terms so they know their
-rights.
-
- We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
- Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
- Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary. To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- GNU GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License. The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language. (Hereinafter, translation is included without limitation in
-the term "modification".) Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
- 1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
- 2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) You must cause the modified files to carry prominent notices
- stating that you changed the files and the date of any change.
-
- b) You must cause any work that you distribute or publish, that in
- whole or in part contains or is derived from the Program or any
- part thereof, to be licensed as a whole at no charge to all third
- parties under the terms of this License.
-
- c) If the modified program normally reads commands interactively
- when run, you must cause it, when started running for such
- interactive use in the most ordinary way, to print or display an
- announcement including an appropriate copyright notice and a
- notice that there is no warranty (or else, saying that you provide
- a warranty) and that users may redistribute the program under
- these conditions, and telling the user how to view a copy of this
- License. (Exception: if the Program itself is interactive but
- does not normally print such an announcement, your work based on
- the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
- a) Accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of Sections
- 1 and 2 above on a medium customarily used for software interchange; or,
-
- b) Accompany it with a written offer, valid for at least three
- years, to give any third party, for a charge no more than your
- cost of physically performing source distribution, a complete
- machine-readable copy of the corresponding source code, to be
- distributed under the terms of Sections 1 and 2 above on a medium
- customarily used for software interchange; or,
-
- c) Accompany it with the information you received as to the offer
- to distribute corresponding source code. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form with such
- an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it. For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable. However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License. Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
- 5. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Program or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
- 6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
- 7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all. For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded. In such case, this License incorporates
-the limitation as if written in the body of this License.
-
- 9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
- 10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
- NO WARRANTY
-
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-
- Copyright (C)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
- Gnomovision version 69, Copyright (C) year name of author
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
- , 1 April 1989
- Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs. If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library. If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/src/dgindex/d2vparse.cpp b/src/dgindex/d2vparse.cpp
deleted file mode 100644
index 28b4ee8..0000000
--- a/src/dgindex/d2vparse.cpp
+++ /dev/null
@@ -1,525 +0,0 @@
-// ParseD2V by Donald A. Graft
-// Released under the Gnu Public Licence (GPL)
-
-#include
-#include
-#include
-#include "global.h"
-
-int parse_d2v(HWND hWnd, char *szInput)
-{
- FILE *fp, *wfp;
- char line[2048], *p;
- int i, fill, val, prev_val = -1, ndx = 0, count = 0, fdom = -1;
- int D2Vformat = 0;
- int vob, cell;
- unsigned int gop_field, field_operation, frame_rate, hour, min;
- double sec;
- char render[128], temp[20];
- int type;
-
- // Open the D2V file to be parsed.
- fp = fopen(szInput, "r");
- if (fp == 0)
- {
- MessageBox(hWnd, "Cannot open the D2V file!", NULL, MB_OK | MB_ICONERROR);
- return 0;
- }
- // Mutate the file name to the output text file to receive the parsed data.
- p = &szInput[strlen(szInput)];
- while (*p != '.') p--;
- p[1] = 0;
- strcat(p, "parse.txt");
- // Open the output file.
- wfp = fopen(szInput, "w");
- if (wfp == 0)
- {
- MessageBox(hWnd, "Cannot create the parse output file!", NULL, MB_OK | MB_ICONERROR);
- return 0;
- }
-
- fprintf(wfp, "D2V Parse Output\n\n");
- // Pick up the D2V format number
- fgets(line, 2048, fp);
- if (strncmp(line, "DGIndexProjectFile", 18) != 0)
- {
- MessageBox(hWnd, "The file is not a DGIndex project file!", NULL, MB_OK | MB_ICONERROR);
- fclose(fp);
- fclose(wfp);
- return 0;
- }
- sscanf(line, "DGIndexProjectFile%d", &D2Vformat);
- if (D2Vformat != D2V_FILE_VERSION)
- {
- MessageBox(hWnd, "Obsolete D2V file.\nRecreate it with this version of DGIndex.", NULL, MB_OK | MB_ICONERROR);
- fclose(fp);
- fclose(wfp);
- return 0;
- }
- fprintf(wfp, "Encoded Frame: Display Frames....Flags Byte (* means in 3:2 pattern)\n");
- fprintf(wfp, "--------------------------------------------------------------------\n\n");
- // Get the field operation flag.
- while (fgets(line, 2048, fp) != 0)
- {
- if (strncmp(line, "Field_Operation", 8) == 0) break;
- }
- sscanf(line, "Field_Operation=%d", &field_operation);
- if (field_operation == 1)
- fprintf(wfp, "[Forced Film, ignoring flags]\n");
- else if (field_operation == 2)
- fprintf(wfp, "[Raw Frames, ignoring flags]\n");
- else
- fprintf(wfp, "[Field Operation None, using flags]\n");
- // Get framerate.
- fgets(line, 2048, fp);
- sscanf(line, "Frame_Rate=%d", &frame_rate);
- // Skip past the rest of the D2V header info to the data lines.
- while (fgets(line, 2048, fp) != 0)
- {
- if (strncmp(line, "Location", 8) == 0) break;
- }
- while (fgets(line, 2048, fp) != 0)
- {
- if (line[0] != '\n') break;
- }
- // Process the data lines.
- do
- {
- // Skip to the TFF/RFF flags entries.
- p = line;
- sscanf(p, "%x", &gop_field);
- if (gop_field & 0x100)
- {
- if (gop_field & 0x400)
- fprintf(wfp, "[GOP: closed]\n");
- else
- fprintf(wfp, "[GOP: open]\n");
- }
- while (*p++ != ' ');
- while (*p++ != ' ');
- while (*p++ != ' ');
- while (*p++ != ' ');
- while (*p++ != ' ');
- sscanf(p, "%d", &vob);
- while (*p++ != ' ');
- sscanf(p, "%d", &cell);
- while (*p++ != ' ');
- // Process the flags entries.
- while ((*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f'))
- {
- sscanf(p, "%x", &val);
- if (val == 0xff)
- {
- fprintf(wfp, "[EOF]\n");
- break;
- }
- // Pick up the frame type.
- type = (val & 0x30) >> 4;
- sprintf(temp, "%d [%s]", ndx, type == 1 ? "I" : (type == 2 ? "P" : "B"));
- // Isolate the TFF/RFF bits.
- val &= 0x3;
- // Determine field dominance.
- if (fdom == -1)
- {
- fdom = (val >> 1) & 1;
- fprintf(wfp, "[Clip is %s]\n", fdom ? "TFF" : "BFF");
- }
-
- // Show encoded-to-display mapping.
- if (field_operation == 0)
- {
- if ((count % 2) && (val == 1 || val == 3))
- {
- sprintf(render, "%s: %d,%d,%d", temp, ndx + count/2, ndx + count/2 + 1, ndx + count/2 + 1);
- }
- else if ((count % 2) && !(val == 1 || val == 3))
- {
- sprintf(render, "%s: %d,%d", temp, ndx + count/2, ndx + count/2 + 1);
- }
- else if (!(count % 2) && (val == 1 || val == 3))
- {
- sprintf(render, "%s: %d,%d,%d", temp, ndx + count/2, ndx + count/2, ndx + count/2 + 1);
- }
- else if (!(count % 2) && !(val == 1 || val == 3))
- {
- sprintf(render, "%s: %d,%d", temp, ndx + count/2, ndx + count/2);
- }
- fill = 32 - strlen(render);
- for (i = 0; i < fill; i++) strcat(render, ".");
- sprintf(temp, "%x", val);
- fprintf(wfp, "%s%s", render, temp);
- }
- else
- {
- sprintf(render, "%s: %d,%d", temp, ndx, ndx);
- fill = 32 - strlen(render);
- for (i = 0; i < fill; i++) strcat(render, ".");
- sprintf(temp, "%x", val);
- fprintf(wfp, "%s%s", render, temp);
- }
-
- // Show vob cell id.
-// printf(" [vob/cell=%d/%d]", vob, cell);
-
- // Print warnings for 3:2 breaks and field order transitions.
- if ((prev_val >= 0) && ((val == 0 && prev_val == 3) || (val != 0 && val == prev_val + 1)))
- {
- fprintf(wfp, " *");
- }
-
- if (prev_val >= 0)
- {
- if ((val == 2 && prev_val == 0) || (val == 2 && prev_val == 0))
- fprintf(wfp, " [FIELD ORDER TRANSITION!]");
- else if ((val == 3 && prev_val == 0) || (val == 2 && prev_val == 0))
- fprintf(wfp, " [FIELD ORDER TRANSITION!]");
- else if ((val == 0 && prev_val == 1) || (val == 2 && prev_val == 0))
- fprintf(wfp, " [FIELD ORDER TRANSITION!]");
- else if ((val == 1 && prev_val == 1) || (val == 2 && prev_val == 0))
- fprintf(wfp, " [FIELD ORDER TRANSITION!]");
- else if ((val == 0 && prev_val == 2) || (val == 2 && prev_val == 0))
- fprintf(wfp, " [FIELD ORDER TRANSITION!]");
- else if ((val == 1 && prev_val == 2) || (val == 2 && prev_val == 0))
- fprintf(wfp, " [FIELD ORDER TRANSITION!]");
- else if ((val == 2 && prev_val == 3) || (val == 2 && prev_val == 0))
- fprintf(wfp, " [FIELD ORDER TRANSITION!]");
- else if ((val == 3 && prev_val == 3) || (val == 2 && prev_val == 0))
- fprintf(wfp, " [FIELD ORDER TRANSITION!]");
- }
-
- fprintf(wfp, "\n");
-
- // Count the encoded frames.
- ndx++;
- // Count the number of pulled-down fields.
- if (val == 1 || val == 3) count++;
- // Move to the next flags entry.
- while (*p != ' ' && *p != '\n') p++;
- p++;
- prev_val = val;
- }
- } while ((fgets(line, 2048, fp) != 0) &&
- ((line[0] >= '0' && line[0] <= '9') || (line[0] >= 'a' && line[0] <= 'f')));
- sec = ((float)(ndx + count / 2)) * 1000.0 / frame_rate;
- hour = (int) (sec / 3600);
- sec -= hour * 3600;
- min = (int) (sec / 60);
- sec -= min * 60;
- fprintf(wfp, "Running time = %d hours, %d minutes, %f seconds\n", hour, min, sec);
-
- fclose(fp);
- fclose(wfp);
- return 1;
-}
-
-int analyze_sync(HWND hWnd, char *Input, int audio_id)
-{
- FILE *fp, *wfp;
- char line[2048], *p;
- __int64 vpts, apts;
- int delay, ref;
- double rate, picture_period;
- int leadingBframes;
- char audio_id_str[10], tmp[20];
-
- sprintf(audio_id_str, " A%02x", audio_id);
- fp = fopen(Input, "r");
- if (fp == 0)
- {
- MessageBox(hWnd, "Cannot open the dump file!", NULL, MB_OK | MB_ICONERROR);
- return 0;
- }
- // Check that it is a timestamps dump file
- fgets(line, 1024, fp);
- if (strncmp(line, "DGIndex Timestamps Dump", 23) != 0)
- {
- MessageBox(hWnd, "The file is not a DGIndex timestamps dump file!", NULL, MB_OK | MB_ICONERROR);
- fclose(fp);
- return 0;
- }
-
- // Mutate the file name to the output text file to receive the parsed data.
- p = &szInput[strlen(Input)];
- while (*p != '.') p--;
- p[1] = 0;
- sprintf(tmp, "delayT%x.txt", audio_id);
- strcat(p, tmp);
- // Open the output file.
- wfp = fopen(szInput, "w");
- if (wfp == 0)
- {
- MessageBox(hWnd, "Cannot create the output file!", NULL, MB_OK | MB_ICONERROR);
- return 0;
- }
- fprintf(wfp, "Delay Analysis Output (Audio ID %x)\n\n", audio_id);
-
- fgets(line, 1024, fp);
- fgets(line, 1024, fp);
- p = line;
- while (*p++ != '=');
- sscanf(p, "%Lf", &rate);
- fgets(line, 1024, fp);
- p = line;
- while (*p++ != '=');
- sscanf(p, "%d", &leadingBframes);
-next_vpts:
- while (fgets(line, 1024, fp) != 0)
- {
- if (!strncmp(line, "V PTS", 5))
- {
- p = line;
- while (*p++ != 'S');
- vpts = _atoi64(p);
- while (fgets(line, 1024, fp) != 0)
- {
- if (!strncmp(line, "Decode picture", 14))
- {
- p = line + 35;
- sscanf(p, "%d", &ref);
- while (*p++ != '[');
- if (*p != 'I')
- goto next_vpts;
- fprintf(wfp, "%s", line);
- break;
- }
- }
- picture_period = 1.0 / rate;
- vpts -= (int) (leadingBframes * picture_period * 90000);
- while (fgets(line, 1024, fp) != 0)
- {
- if (!strncmp(line, audio_id_str, 4))
- {
- p = line;
- while (*p++ != 'S');
- apts = _atoi64(p);
- delay = (int) ((apts - vpts) / 90);
- fprintf(wfp, "delay = %d\n", delay);
- break;
- }
- }
- }
- }
- fclose(fp);
- fclose(wfp);
-
- return 1;
-}
-
-// Return 1 if a transition was detected in test_only mode and the user wants to correct it, otherwise 0.
-int fix_d2v(HWND hWnd, char *Input, int test_only)
-{
- FILE *fp, *wfp, *dfp;
- char line[2048], prev_line[2048], wfile[2048], logfile[2048], *p, *q;
- int val, mval, prev_val, mprev_val, fix;
- bool first, found;
- int D2Vformat = 0;
- unsigned int info;
-
- fp = fopen(Input, "r");
- if (fp == 0)
- {
- MessageBox(hWnd, "Cannot open the D2V file!", NULL, MB_OK | MB_ICONERROR);
- return 0;
- }
- // Pick up the D2V format number
- fgets(line, 1024, fp);
- if (strncmp(line, "DGIndexProjectFile", 18) != 0)
- {
- MessageBox(hWnd, "The file is not a DGIndex project file!", NULL, MB_OK | MB_ICONERROR);
- fclose(fp);
- return 0;
- }
- sscanf(line, "DGIndexProjectFile%d", &D2Vformat);
- if (D2Vformat != D2V_FILE_VERSION)
- {
- MessageBox(hWnd, "Obsolete D2V file.\nRecreate it with this version of DGIndex.", NULL, MB_OK | MB_ICONERROR);
- fclose(fp);
- return 0;
- }
-
- if (!test_only)
- {
- strcpy(wfile, Input);
- strcat(wfile,".fixed");
- wfp = fopen(wfile, "w");
- if (wfp == 0)
- {
- MessageBox(hWnd, "Cannot create the fixed D2V file!", NULL, MB_OK | MB_ICONERROR);
- fclose(fp);
- return 0;
- }
- fputs(line, wfp);
- // Mutate the file name to the output text file to receive processing status information.
- strcpy(logfile, Input);
- p = &logfile[strlen(logfile)];
- while (*p != '.') p--;
- p[1] = 0;
- strcat(p, "fix.txt");
- // Open the output file.
- dfp = fopen(logfile, "w");
- if (dfp == 0)
- {
- fclose(fp);
- fclose(wfp);
- MessageBox(hWnd, "Cannot create the info output file!", NULL, MB_OK | MB_ICONERROR);
- return 0;
- }
-
- fprintf(dfp, "D2V Fix Output\n\n");
- }
-
- while (fgets(line, 1024, fp) != 0)
- {
- if (!test_only) fputs(line, wfp);
- if (strncmp(line, "Location", 8) == 0) break;
- }
- fgets(line, 1024, fp);
- if (!test_only) fputs(line, wfp);
- fgets(line, 1024, fp);
- prev_line[0] = 0;
- prev_val = -1;
- mprev_val = -1;
- found = false;
- do
- {
- p = line;
- sscanf(p, "%x", &info);
- // If it's a progressive sequence then we can't have any transitions.
- if (info & (1 << 9))
- continue;
- while (*p++ != ' ');
- while (*p++ != ' ');
- while (*p++ != ' ');
- while (*p++ != ' ');
- while (*p++ != ' ');
- while (*p++ != ' ');
- while (*p++ != ' ');
- first = true;
- while ((*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f'))
- {
- fix = -1;
- sscanf(p, "%x", &val);
- if (val == 0xff) break;
- // Isolate the TFF/RFF bits.
- mval = val & 0x3;
- if (prev_val >= 0) mprev_val = prev_val & 0x3;
- // Detect field order transitions.
- if (mval == 2 && mprev_val == 0) fix = 1;
- else if (mval == 3 && mprev_val == 0) fix = 1;
- else if (mval == 0 && mprev_val == 1) fix = 0;
- else if (mval == 1 && mprev_val == 1) fix = 0;
- else if (mval == 0 && mprev_val == 2) fix = 3;
- else if (mval == 1 && mprev_val == 2) fix = 3;
- else if (mval == 2 && mprev_val == 3) fix = 2;
- else if (mval == 3 && mprev_val == 3) fix = 2;
- // Correct the field order transition.
- if (fix >= 0)
- {
- found = true;
- if (!test_only) fprintf(dfp, "Field order transition: %x -> %x\n", mprev_val, mval);
- if (!test_only) fprintf(dfp, prev_line);
- if (!test_only) fprintf(dfp, line);
- if (first == false)
- {
- q = p;
- while (*q-- != ' ');
- }
- else
- {
- q = prev_line;
- while (*q != '\n') q++;
- while (!((*q >= '0' && *q <= '9') || (*q >= 'a' && *q <= 'f'))) q--;
- }
- *q = (char) fix + '0';
- if (!test_only) fprintf(dfp, "corrected...\n");
- if (!test_only) fprintf(dfp, prev_line);
- if (!test_only) fprintf(dfp, line);
- if (!test_only) fprintf(dfp, "\n");
- }
- while (*p != ' ' && *p != '\n') p++;
- p++;
- prev_val = val;
- first = false;
- }
- if (!test_only) fputs(prev_line, wfp);
- strcpy(prev_line, line);
- } while ((fgets(line, 2048, fp) != 0) &&
- ((line[0] >= '0' && line[0] <= '9') || (line[0] >= 'a' && line[0] <= 'f')));
- if (!test_only) fputs(prev_line, wfp);
- if (!test_only) fputs(line, wfp);
- while (fgets(line, 2048, fp) != 0)
- if (!test_only) fputs(line, wfp);
- fclose(fp);
- if (!test_only) fclose(wfp);
- if (test_only)
- {
- if (!CorrectFieldOrderTrans)
- return 0;
- if (found == true)
- {
- if (!CLIActive)
- {
- if (MessageBox(hWnd, "A field order transition was detected.\n"
- "It is not possible to decide automatically if this should be corrected.\n"
- "Refer to the DGIndex Users Manual for an explanation.\n"
- "You can choose to correct it by hitting the Yes button below or\n"
- "you can correct it later using the Fix D2V tool.\n\n"
- "Correct the field order transition?",
- "Field Order Transition Detected", MB_YESNO | MB_ICONWARNING) == IDYES)
- return 1;
- else
- return 0;
- }
- else
- return 1;
- }
- return 0;
- }
- if (found == false)
- {
- fprintf(dfp, "No errors found.\n");
- fclose(dfp);
- _unlink(wfile);
- MessageBox(hWnd, "No errors found.", "Fix D2V", MB_OK | MB_ICONINFORMATION);
- return 0;
- }
- else
- {
- FILE *bad, *good, *fixed;
- char c;
-
- fclose(dfp);
- // Copy the D2V file to *.d2v.bad version.
- good = fopen(Input, "r");
- if (good == 0)
- return 0;
- sprintf(line, "%s.bad", Input);
- bad = fopen(line, "w");
- if (bad == 0)
- {
- fclose(good);
- return 0;
- }
- while ((c = fgetc(good)) != EOF) fputc(c, bad);
- fclose(good);
- fclose(bad);
- // Copy the *.d2v.fixed version to the D2V file.
- good = fopen(Input, "w");
- if (good == 0)
- return 0;
- sprintf(line, "%s.fixed", Input);
- fixed = fopen(line, "r");
- while ((c = fgetc(fixed)) != EOF) fputc(c, good);
- fclose(good);
- fclose(fixed);
- // Ditch the *.d2v.fixed version.
- _unlink(line);
- if (!CLIActive)
- {
- MessageBox(hWnd, "Field order corrected. The original version was\nsaved with the extension \".bad\".", "Correct Field Order", MB_OK | MB_ICONINFORMATION);
- ShellExecute(hDlg, "open", logfile, NULL, NULL, SW_SHOWNORMAL);
- }
- }
-
- return 0;
-}
diff --git a/src/dgindex/filter.h b/src/dgindex/filter.h
deleted file mode 100644
index 6c0aff8..0000000
--- a/src/dgindex/filter.h
+++ /dev/null
@@ -1,955 +0,0 @@
-/*
- * Mutated into DGIndex. Modifications Copyright (C) 2004, Donald Graft
- *
- * Copyright (C) Chia-chen Kuo - June 2002
- *
- * This file is part of DVD2AVI, a free MPEG-2 decoder
- *
- * DVD2AVI is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * DVD2AVI is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
-#include
-
-int half_height, pheight, iheight;
-static int DOUBLE_WIDTH, HALF_WIDTH, LUM_AREA, PROGRESSIVE_HEIGHT, INTERLACED_HEIGHT;
-static int HALF_WIDTH_D8, RGB_DOWN1, RGB_DOWN2;
-
-static int NINE_CLIP_WIDTH, QUAD_CLIP_WIDTH, DOUBLE_CLIP_WIDTH, HALF_CLIP_WIDTH;
-static int CLIP_AREA, HALF_CLIP_AREA, CLIP_STEP, CLIP_HALF_STEP;
-
-static const __int64 mmmask_0001 = 0x0001000100010001;
-static const __int64 mmmask_0002 = 0x0002000200020002;
-static const __int64 mmmask_0003 = 0x0003000300030003;
-static const __int64 mmmask_0004 = 0x0004000400040004;
-static const __int64 mmmask_0005 = 0x0005000500050005;
-static const __int64 mmmask_0007 = 0x0007000700070007;
-static const __int64 mmmask_0064 = 0x0040004000400040;
-static const __int64 mmmask_0128 = 0x0080008000800080;
-static const __int64 lastmask = 0xFF00000000000000;
-static const __int64 mmmask_0101 = 0x0101010101010101;
-
-static unsigned char LuminanceTable[256];
-
-static void InitializeFilter()
-{
- int i;
- double value;
-
- for (i=0; i<256; i++)
- {
- value = 255.0 * pow(i/255.0, pow(2.0, -LumGamma/128.0)) + LumOffset + 0.5;
-
- if (value < 0)
- LuminanceTable[i] = 0;
- else if (value > 255.0)
- LuminanceTable[i] = 255;
- else
- LuminanceTable[i] = (unsigned char)value;
- }
-}
-
-static void LuminanceFilter(unsigned char *src, unsigned char *dst)
-{
- int i;
-
- src += CLIP_AREA;
- dst += CLIP_AREA;
-
- for (i=0; i>1)-8
- mov edx, HALF_WIDTH
- xor esi, esi // esi = 0
- movq mm7, lastmask
-
-xloop:
- movq mm0, [eax+esi] // mm7 = hgfedcba
- movq mm1, [eax+esi+1]// mm1 = ihgfedcb
- pavgb mm1, mm0
- movq mm2, mm0
- punpcklbw mm0,mm1
- punpckhbw mm2,mm1
-
- movq [ebx+esi*2], mm0 // store mm0
- movq [ebx+esi*2+8], mm2 // store mm2
-
- add esi, 8
- cmp esi, ecx
- jl xloop // loop back if not to last 8 pixels
-
- movq mm0, [eax+esi] // mm7 = hgfedcba
- movq mm1, mm0 // mm1 = hgfedcba
- movq mm2, mm0 // mm2 = hgfedcba
- psrlq mm1, 8 // mm1 = 0hgfedcb
- pand mm2, mm7 // mm2 = h0000000
- por mm1, mm2 // mm1 = hhgfedcb
- pavgb mm1, mm0
- movq mm2, mm0
- punpcklbw mm0,mm1
- punpckhbw mm2,mm1
-
- movq [ebx+esi*2], mm0 // store mm0
- movq [ebx+esi*2+8], mm2 // store mm2
-
- add eax, edx
- add ebx, Coded_Picture_Width
- xor esi, esi
- dec edi
- jnz xloop
- emms
- }
-}
-
-static void conv422to444(unsigned char *src, unsigned char *dst)
-{
- if (cpu.ssemmx)
- {
- conv422to444_iSSE(src, dst);
- return;
- }
-
- src += HALF_CLIP_AREA;
- dst += CLIP_AREA;
-
- __asm
- {
- mov eax, [src] // eax = src
- mov ebx, [dst] // ebx = dst
- mov edi, Clip_Height // edi = height
- mov ecx, HALF_WIDTH_D8 // ecx = (width>>1)-8
- movq mm1, mmmask_0001 // mm1 = 1's
- pxor mm0, mm0 // mm0 = 0's
-
-convyuv444init:
- movq mm7, [eax] // mm7 = hgfedcba
- xor esi, esi // esi = 0
-
-convyuv444:
- movq mm2, mm7 // mm2 = hgfedcba
- movq mm7, [eax+esi+8] // mm7 = ponmlkji
- movq mm3, mm2 // mm3 = hgfedcba
- movq mm4, mm7 // mm4 = ponmlkji
-
- psrlq mm3, 8 // mm3 = 0hgfedcb
- psllq mm4, 56 // mm4 = i0000000
- por mm3, mm4 // mm3 = ihgfedcb
-
- movq mm4, mm2 // mm4 = hgfedcba
- movq mm5, mm3 // mm5 = ihgfedcb
-
- punpcklbw mm4, mm0 // 0d0c0b0a
- punpcklbw mm5, mm0 // 0e0d0c0b
-
- movq mm6, mm4 // mm6 = 0d0c0b0a
- paddusw mm4, mm1
- paddusw mm4, mm5
- psrlw mm4, 1 // average mm4/mm5 (d/e,c/d,b/c,a/b)
- psllq mm4, 8 // mm4 = z0z0z0z0
- por mm4, mm6 // mm4 = zdzczbza
-
- punpckhbw mm2, mm0 // 0h0g0f0e
- punpckhbw mm3, mm0 // 0i0h0g0f
-
- movq mm6, mm2 // mm6 = 0h0g0f0e
- paddusw mm2, mm1
- paddusw mm2, mm3
- psrlw mm2, 1 // average mm2/mm3 (h/i,g/h,f/g,e/f)
- psllq mm2, 8 // mm2 = z0z0z0z0
- por mm2, mm6 // mm2 = zhzgzfze
-
- movq [ebx+esi*2], mm4 // store zdzczbza
- movq [ebx+esi*2+8], mm2 // store zhzgzfze
-
- add esi, 8
- cmp esi, ecx
- jl convyuv444 // loop back if not to last 8 pixels
-
- movq mm2, mm7 // mm2 = ponmlkji
-
- punpcklbw mm2, mm0 // mm2 = 0l0k0j0i
- punpckhbw mm7, mm0 // mm7 = 0p0o0n0m
-
- movq mm3, mm2 // mm3 = 0l0k0j0i
- movq mm4, mm7 // mm4 = 0p0o0n0m
-
- psrlq mm2, 16 // mm2 = 000l0k0j
- psllq mm4, 48 // mm4 = 0m000000
- por mm2, mm4 // mm2 = 0m0l0k0j
-
- paddusw mm2, mm1
- paddusw mm2, mm3
- psrlw mm2, 1 // average mm2/mm3 (m/l,l/k,k/j,j/i)
- psllq mm2, 8 // mm2 = z0z0z0z0
- por mm2, mm3 // mm2 = zlzkzjzi
-
- movq mm6, mm7 // mm6 = 0p0o0n0m
- movq mm4, mm7 // mm4 = 0p0o0n0m
-
- psrlq mm6, 48 // mm6 = 0000000p
- psrlq mm4, 16 // mm4 = 000p0o0n
- psllq mm6, 48 // mm6 = 0p000000
- por mm4,mm6 // mm4 = 0p0p0o0n
-
- paddusw mm4, mm1
- paddusw mm4, mm7
- psrlw mm4, 1 // average mm4/mm7 (p/p,p/o,o/n,n/m)
- psllq mm4, 8 // mm4 = z0z0z0z0
- por mm4, mm7 // mm4 = zpzoznzm
-
- movq [ebx+esi*2], mm2 // store mm2
- movq [ebx+esi*2+8], mm4 // store mm4
-
- add eax, HALF_WIDTH
- add ebx, Coded_Picture_Width
- dec edi
- jnz convyuv444init
-
- emms
- }
-}
-
-static void conv420to422P_iSSE(const unsigned char *src, unsigned char *dst)
-{
- pheight = PROGRESSIVE_HEIGHT;
-
- __asm
- {
- mov eax, [src] // eax = src
- mov ebx, [dst] // ebx = dst
- mov ecx, ebx // ecx = dst
- mov edi, HALF_WIDTH
- add ecx, edi // ecx = dst + dst_pitch
- mov edx, eax // edx = src
- add edx, edi // edx = src + src_pitch
- xor esi, esi
- movq mm6, mmmask_0101
- movq mm7, mm6
-
-convyuv422topp:
- movq mm0, [eax+esi]
- movq mm1, [edx+esi]
- movq [ebx+esi], mm0
- psubusb mm1, mm7
- pavgb mm1, mm0
- pavgb mm1, mm0
- movq [ecx+esi], mm1
- add esi, 0x08
- cmp esi, edi
- jl convyuv422topp
- add eax, edi
- add ebx, Coded_Picture_Width
- add ecx, Coded_Picture_Width
- xor esi, esi
-
-convyuv422p:
- movq mm0, [eax+esi]
- mov edx, eax // edx = src
- movq mm1, mm0
- sub edx, edi
- movq mm2, [edx+esi]
- add edx, Coded_Picture_Width
- movq mm3, [edx+esi]
- psubusb mm2, mm6
- psubusb mm3, mm7
- pavgb mm2, mm0
- pavgb mm3, mm1
- pavgb mm2, mm0
- pavgb mm3, mm1
- movq [ebx+esi], mm2
- movq [ecx+esi], mm3
- add esi, 0x08
- cmp esi, edi
- jl convyuv422p
- add eax, edi
- add ebx, Coded_Picture_Width
- add ecx, Coded_Picture_Width
- xor esi, esi
- dec pheight
- jnz convyuv422p
- mov edx, eax
- sub edx, edi
-
-convyuv422bottomp:
- movq mm0, [eax+esi]
- movq mm1, [edx+esi]
- movq [ecx+esi], mm0
- psubusb mm1, mm7
- pavgb mm1, mm0
- pavgb mm1, mm0
- movq [ebx+esi], mm1
- add esi, 0x08
- cmp esi, edi
- jl convyuv422bottomp
- emms
- }
-}
-
-static void conv420to422(const unsigned char *src, unsigned char *dst, bool frame_type)
-{
- pheight = PROGRESSIVE_HEIGHT;
- iheight = INTERLACED_HEIGHT;
-
- if (frame_type)
- {
- if (cpu.ssemmx)
- {
- conv420to422P_iSSE(src, dst);
- return;
- }
-
- __asm
- {
- mov eax, [src] // eax = src
- mov ebx, [dst] // ebx = dst
- mov ecx, ebx // ecx = dst
- mov edi, HALF_WIDTH
- add ecx, edi // ecx = dst + dst_pitch
- xor esi, esi
- movq mm3, [mmmask_0003]
- pxor mm0, mm0
- movq mm4, [mmmask_0002]
-
- mov edx, eax // edx = src
- add edx, edi // edx = src + src_pitch
-
-convyuv422topp:
- movd mm1, [eax+esi]
- movd mm2, [edx+esi]
- movd [ebx+esi], mm1
- punpcklbw mm1, mm0
- pmullw mm1, mm3
- paddusw mm1, mm4
- punpcklbw mm2, mm0
- paddusw mm2, mm1
- psrlw mm2, 0x02
- packuswb mm2, mm0
-
- add esi, 0x04
- cmp esi, edi
- movd [ecx+esi-4], mm2
- jl convyuv422topp
-
- add eax, edi
- add ebx, Coded_Picture_Width
- add ecx, Coded_Picture_Width
- xor esi, esi
-
-convyuv422p:
- movd mm1, [eax+esi]
-
- punpcklbw mm1, mm0
- mov edx, eax // edx = src
-
- pmullw mm1, mm3
- sub edx, edi
-
- movd mm5, [edx+esi]
- add edx, Coded_Picture_Width
- movd mm2, [edx+esi]
-
- punpcklbw mm5, mm0
- punpcklbw mm2, mm0
- paddusw mm5, mm1
- paddusw mm2, mm1
- paddusw mm5, mm4
- paddusw mm2, mm4
- psrlw mm5, 0x02
- psrlw mm2, 0x02
- packuswb mm5, mm0
- packuswb mm2, mm0
-
- add esi, 0x04
- cmp esi, edi
- movd [ebx+esi-4], mm5
- movd [ecx+esi-4], mm2
-
- jl convyuv422p
-
- add eax, edi
- add ebx, Coded_Picture_Width
- add ecx, Coded_Picture_Width
- xor esi, esi
- dec pheight
- jnz convyuv422p
-
- mov edx, eax
- sub edx, edi
-convyuv422bottomp:
- movd mm1, [eax+esi]
- movd mm5, [edx+esi]
- punpcklbw mm5, mm0
- movd [ecx+esi], mm1
-
- punpcklbw mm1, mm0
- pmullw mm1, mm3
- paddusw mm5, mm1
- paddusw mm5, mm4
- psrlw mm5, 0x02
- packuswb mm5, mm0
-
- add esi, 0x04
- cmp esi, edi
- movd [ebx+esi-4], mm5
- jl convyuv422bottomp
-
- emms
- }
- }
- else
- {
- __asm
- {
- mov eax, [src] // eax = src
- mov ecx, [dst] // ecx = dst
- xor esi, esi
- pxor mm0, mm0
- movq mm3, [mmmask_0003]
- movq mm4, [mmmask_0004]
- movq mm5, [mmmask_0005]
- mov edi, HALF_WIDTH
-
-convyuv422topi:
- movd mm1, [eax+esi]
- mov ebx, eax
- add ebx, Coded_Picture_Width
- movd mm2, [ebx+esi]
- movd [ecx+esi], mm1
- sub ebx, edi
-
- punpcklbw mm1, mm0
- movq mm6, [ebx+esi]
- pmullw mm1, mm5
- add ebx, Coded_Picture_Width
- punpcklbw mm2, mm0
- movq mm7, [ebx+esi]
- pmullw mm2, mm3
- paddusw mm2, mm1
- paddusw mm2, mm4
- psrlw mm2, 0x03
- packuswb mm2, mm0
-
- mov edx, ecx
- add edx, Coded_Picture_Width
- movd [edx+esi], mm2
- sub edx, edi
-
- movd [edx+esi], mm6
- punpcklbw mm6, mm0
- pmullw mm6, [mmmask_0007]
- punpcklbw mm7, mm0
- paddusw mm7, mm6
- paddusw mm7, mm4
- psrlw mm7, 0x03
- packuswb mm7, mm0
-
- add edx, Coded_Picture_Width
- add esi, 0x04
- cmp esi, edi
- movd [edx+esi-4], mm7
-
- jl convyuv422topi
-
- add eax, Coded_Picture_Width
- add ecx, DOUBLE_WIDTH
- xor esi, esi
-
-convyuv422i:
- movd mm1, [eax+esi]
- punpcklbw mm1, mm0
- movq mm6, mm1
- mov ebx, eax
- sub ebx, Coded_Picture_Width
- movd mm3, [ebx+esi]
- pmullw mm1, [mmmask_0007]
- punpcklbw mm3, mm0
- paddusw mm3, mm1
- paddusw mm3, mm4
- psrlw mm3, 0x03
- packuswb mm3, mm0
-
- add ebx, edi
- movq mm1, [ebx+esi]
- add ebx, Coded_Picture_Width
- movd [ecx+esi], mm3
-
- movq mm3, [mmmask_0003]
- movd mm2, [ebx+esi]
-
- punpcklbw mm1, mm0
- pmullw mm1, mm3
- punpcklbw mm2, mm0
- movq mm7, mm2
- pmullw mm2, mm5
- paddusw mm2, mm1
- paddusw mm2, mm4
- psrlw mm2, 0x03
- packuswb mm2, mm0
-
- pmullw mm6, mm5
- mov edx, ecx
- add edx, edi
- movd [edx+esi], mm2
-
- add ebx, edi
- movd mm2, [ebx+esi]
- punpcklbw mm2, mm0
- pmullw mm2, mm3
- paddusw mm2, mm6
- paddusw mm2, mm4
- psrlw mm2, 0x03
- packuswb mm2, mm0
-
- pmullw mm7, [mmmask_0007]
- add edx, edi
- add ebx, edi
- movd [edx+esi], mm2
-
- movd mm2, [ebx+esi]
- punpcklbw mm2, mm0
- paddusw mm2, mm7
- paddusw mm2, mm4
- psrlw mm2, 0x03
- packuswb mm2, mm0
-
- add edx, edi
- add esi, 0x04
- cmp esi, edi
- movd [edx+esi-4], mm2
-
- jl convyuv422i
- add eax, Coded_Picture_Width
- add ecx, DOUBLE_WIDTH
- xor esi, esi
- dec iheight
- jnz convyuv422i
-
-convyuv422bottomi:
- movd mm1, [eax+esi]
- movq mm6, mm1
- punpcklbw mm1, mm0
- mov ebx, eax
- sub ebx, Coded_Picture_Width
- movd mm3, [ebx+esi]
- punpcklbw mm3, mm0
- pmullw mm1, [mmmask_0007]
- paddusw mm3, mm1
- paddusw mm3, mm4
- psrlw mm3, 0x03
- packuswb mm3, mm0
-
- add ebx, edi
- movq mm1, [ebx+esi]
- punpcklbw mm1, mm0
- movd [ecx+esi], mm3
-
- pmullw mm1, [mmmask_0003]
- add ebx, Coded_Picture_Width
- movd mm2, [ebx+esi]
- movq mm7, mm2
- punpcklbw mm2, mm0
- pmullw mm2, mm5
- paddusw mm2, mm1
- paddusw mm2, mm4
- psrlw mm2, 0x03
- packuswb mm2, mm0
-
- mov edx, ecx
- add edx, edi
- movd [edx+esi], mm2
- add edx, edi
- movd [edx+esi], mm6
-
- add edx, edi
- add esi, 0x04
- cmp esi, edi
- movd [edx+esi-4], mm7
-
- jl convyuv422bottomi
-
- emms
- }
- }
-}
-
-static void conv422toyuy2odd(unsigned char *py, unsigned char *pu, unsigned char *pv, unsigned char *dst)
-{
- py += CLIP_STEP;
- pu += CLIP_HALF_STEP;
- pv += CLIP_HALF_STEP;
- half_height = Clip_Height>>1;
-
- __asm
- {
- mov eax, [py]
- mov ebx, [pu]
- mov ecx, [pv]
- mov edx, [dst]
- xor esi, esi
- mov edi, [Clip_Width]
-
-yuy2conv:
- movd mm2, [ebx+esi]
- movd mm3, [ecx+esi]
- punpcklbw mm2, mm3
- movq mm1, [eax+esi*2]
- movq mm4, mm1
- punpcklbw mm1, mm2
- punpckhbw mm4, mm2
-
- add esi, 0x04
- cmp esi, edi
- movq [edx+esi*4-16], mm1
- movq [edx+esi*4-8], mm4
- jl yuy2conv
-
- add eax, [DOUBLE_WIDTH]
- add ebx, [Coded_Picture_Width]
- add ecx, [Coded_Picture_Width]
- add edx, [QUAD_CLIP_WIDTH]
- xor esi, esi
- dec half_height
- jnz yuy2conv
-
- emms
- }
-}
-
-static void conv422toyuy2even(unsigned char *py, unsigned char *pu, unsigned char *pv, unsigned char *dst)
-{
- py += Coded_Picture_Width + CLIP_STEP;
- pu += HALF_WIDTH + CLIP_HALF_STEP;
- pv += HALF_WIDTH + CLIP_HALF_STEP;
- dst += DOUBLE_CLIP_WIDTH;
- half_height = Clip_Height>>1;
-
- __asm
- {
- mov eax, [py]
- mov ebx, [pu]
- mov ecx, [pv]
- mov edx, [dst]
- xor esi, esi
- mov edi, [Clip_Width]
-
-yuy2conv:
- movd mm2, [ebx+esi]
- movd mm3, [ecx+esi]
- punpcklbw mm2, mm3
- movq mm1, [eax+esi*2]
- movq mm4, mm1
- punpcklbw mm1, mm2
- punpckhbw mm4, mm2
-
- add esi, 0x04
- cmp esi, edi
- movq [edx+esi*4-16], mm1
- movq [edx+esi*4-8], mm4
- jl yuy2conv
-
- add eax, [DOUBLE_WIDTH]
- add ebx, [Coded_Picture_Width]
- add ecx, [Coded_Picture_Width]
- add edx, [QUAD_CLIP_WIDTH]
- xor esi, esi
- dec half_height
- jnz yuy2conv
-
- emms
- }
-}
-
-static void conv444toRGB24odd(unsigned char *py, unsigned char *pu, unsigned char *pv, unsigned char *dst)
-{
- py += CLIP_STEP;
- pu += CLIP_STEP;
- pv += CLIP_STEP;
- dst += RGB_DOWN1;
- half_height = Clip_Height>>1;
-
- __asm
- {
- mov eax, [py]
- mov ebx, [pu]
- mov ecx, [pv]
- mov edx, [dst]
- mov edi, [Clip_Width]
- xor esi, esi
- pxor mm0, mm0
-
-convRGB24:
- movd mm1, [eax+esi]
- movd mm3, [ebx+esi]
- punpcklbw mm1, mm0
- punpcklbw mm3, mm0
- movd mm5, [ecx+esi]
- punpcklbw mm5, mm0
- movq mm7, [mmmask_0128]
- psubw mm3, mm7
- psubw mm5, mm7
-
- psubw mm1, [RGB_Offset]
- movq mm2, mm1
- movq mm7, [mmmask_0001]
- punpcklwd mm1, mm7
- punpckhwd mm2, mm7
- movq mm7, [RGB_Scale]
- pmaddwd mm1, mm7
- pmaddwd mm2, mm7
-
- movq mm4, mm3
- punpcklwd mm3, mm0
- punpckhwd mm4, mm0
- movq mm7, [RGB_CBU]
- pmaddwd mm3, mm7
- pmaddwd mm4, mm7
- paddd mm3, mm1
- paddd mm4, mm2
- psrad mm3, 13
- psrad mm4, 13
- packuswb mm3, mm0
- packuswb mm4, mm0
-
- movq mm6, mm5
- punpcklwd mm5, mm0
- punpckhwd mm6, mm0
- movq mm7, [RGB_CRV]
- pmaddwd mm5, mm7
- pmaddwd mm6, mm7
- paddd mm5, mm1
- paddd mm6, mm2
-
- psrad mm5, 13
- psrad mm6, 13
- packuswb mm5, mm0
- packuswb mm6, mm0
-
- punpcklbw mm3, mm5
- punpcklbw mm4, mm6
- movq mm5, mm3
- movq mm6, mm4
- psrlq mm5, 16
- psrlq mm6, 16
- por mm3, mm5
- por mm4, mm6
-
- movd mm5, [ebx+esi]
- movd mm6, [ecx+esi]
- punpcklbw mm5, mm0
- punpcklbw mm6, mm0
- movq mm7, [mmmask_0128]
- psubw mm5, mm7
- psubw mm6, mm7
-
- movq mm7, mm6
- punpcklwd mm6, mm5
- punpckhwd mm7, mm5
- movq mm5, [RGB_CGX]
- pmaddwd mm6, mm5
- pmaddwd mm7, mm5
- paddd mm6, mm1
- paddd mm7, mm2
-
- psrad mm6, 13
- psrad mm7, 13
- packuswb mm6, mm0
- packuswb mm7, mm0
-
- punpcklbw mm3, mm6
- punpcklbw mm4, mm7
-
- movq mm1, mm3
- movq mm5, mm4
- movq mm6, mm4
-
- psrlq mm1, 32
- psllq mm1, 24
- por mm1, mm3
-
- psrlq mm3, 40
- psllq mm6, 16
- por mm3, mm6
- movd [edx], mm1
-
- psrld mm4, 16
- psrlq mm5, 24
- por mm5, mm4
- movd [edx+4], mm3
-
- add edx, 0x0c
- add esi, 0x04
- cmp esi, edi
- movd [edx-4], mm5
-
- jl convRGB24
-
- add eax, [DOUBLE_WIDTH]
- add ebx, [DOUBLE_WIDTH]
- add ecx, [DOUBLE_WIDTH]
- sub edx, [NINE_CLIP_WIDTH]
- xor esi, esi
- dec half_height
- jnz convRGB24
-
- emms
- }
-}
-
-static void conv444toRGB24even(unsigned char *py, unsigned char *pu, unsigned char *pv, unsigned char *dst)
-{
- py += Coded_Picture_Width + CLIP_STEP;
- pu += Coded_Picture_Width + CLIP_STEP;
- pv += Coded_Picture_Width + CLIP_STEP;
- dst += RGB_DOWN2;
- half_height = Clip_Height>>1;
-
- __asm
- {
- mov eax, [py]
- mov ebx, [pu]
- mov ecx, [pv]
- mov edx, [dst]
- mov edi, [Clip_Width]
- xor esi, esi
- pxor mm0, mm0
-
-convRGB24:
- movd mm1, [eax+esi]
- movd mm3, [ebx+esi]
- punpcklbw mm1, mm0
- punpcklbw mm3, mm0
- movd mm5, [ecx+esi]
- punpcklbw mm5, mm0
- movq mm7, [mmmask_0128]
- psubw mm3, mm7
- psubw mm5, mm7
-
- psubw mm1, [RGB_Offset]
- movq mm2, mm1
- movq mm7, [mmmask_0001]
- punpcklwd mm1, mm7
- punpckhwd mm2, mm7
- movq mm7, [RGB_Scale]
- pmaddwd mm1, mm7
- pmaddwd mm2, mm7
-
- movq mm4, mm3
- punpcklwd mm3, mm0
- punpckhwd mm4, mm0
- movq mm7, [RGB_CBU]
- pmaddwd mm3, mm7
- pmaddwd mm4, mm7
- paddd mm3, mm1
- paddd mm4, mm2
- psrad mm3, 13
- psrad mm4, 13
- packuswb mm3, mm0
- packuswb mm4, mm0
-
- movq mm6, mm5
- punpcklwd mm5, mm0
- punpckhwd mm6, mm0
- movq mm7, [RGB_CRV]
- pmaddwd mm5, mm7
- pmaddwd mm6, mm7
- paddd mm5, mm1
- paddd mm6, mm2
- psrad mm5, 13
- psrad mm6, 13
- packuswb mm5, mm0
- packuswb mm6, mm0
-
- punpcklbw mm3, mm5
- punpcklbw mm4, mm6
- movq mm5, mm3
- movq mm6, mm4
- psrlq mm5, 16
- psrlq mm6, 16
- por mm3, mm5
- por mm4, mm6
-
- movd mm5, [ebx+esi]
- movd mm6, [ecx+esi]
- punpcklbw mm5, mm0
- punpcklbw mm6, mm0
- movq mm7, [mmmask_0128]
- psubw mm5, mm7
- psubw mm6, mm7
-
- movq mm7, mm6
- punpcklwd mm6, mm5
- punpckhwd mm7, mm5
- movq mm5, [RGB_CGX]
- pmaddwd mm6, mm5
- pmaddwd mm7, mm5
- paddd mm6, mm1
- paddd mm7, mm2
-
- psrad mm6, 13
- psrad mm7, 13
- packuswb mm6, mm0
- packuswb mm7, mm0
-
- punpcklbw mm3, mm6
- punpcklbw mm4, mm7
-
- movq mm1, mm3
- movq mm5, mm4
- movq mm6, mm4
-
- psrlq mm1, 32
- psllq mm1, 24
- por mm1, mm3
-
- psrlq mm3, 40
- psllq mm6, 16
- por mm3, mm6
- movd [edx], mm1
-
- psrld mm4, 16
- psrlq mm5, 24
- por mm5, mm4
- movd [edx+4], mm3
-
- add edx, 0x0c
- add esi, 0x04
- cmp esi, edi
- movd [edx-4], mm5
-
- jl convRGB24
-
- add eax, [DOUBLE_WIDTH]
- add ebx, [DOUBLE_WIDTH]
- add ecx, [DOUBLE_WIDTH]
- sub edx, [NINE_CLIP_WIDTH]
- xor esi, esi
- dec half_height
- jnz convRGB24
-
- emms
- }
-}
diff --git a/src/dgindex/getbit.cpp b/src/dgindex/getbit.cpp
deleted file mode 100644
index a6fb230..0000000
--- a/src/dgindex/getbit.cpp
+++ /dev/null
@@ -1,3099 +0,0 @@
-/*
- * Mutated into DGIndex. Modifications Copyright (C) 2004-2008, Donald Graft
- *
- * Copyright (C) Chia-chen Kuo - April 2001
- *
- * This file is part of DVD2AVI, a free MPEG-2 decoder
- *
- * DVD2AVI is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * DVD2AVI is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
-#define GETBIT_GLOBAL
-#include "global.h"
-#include "getbit.h"
-#include "AC3Dec\ac3.h"
-
-unsigned int start;
-
-int _donread(int fd, void *buffer, unsigned int count)
-{
- int bytes;
- bytes = _read(fd, buffer, count);
- return bytes;
-}
-
-#define MONO 3
-#define STEREO 0
-#define LAYER1 3
-#define LAYER2 2
-#define LAYER3 1
-#define LAYERRESERVED 0
-#define SAMPLE32K 2
-#define SAMPLE44K 0
-#define SAMPLERESERVED 3
-#define BITRATERESERVED 0xf
-
-static int check_adts_aac_header(int layer, int profile, int sample)
-{
- if (layer)
- return 1;
- if (profile == 3)
- return 1;
- if (sample > 12)
- return 1;
- return 0;
-}
-
-int check_audio_syncword(unsigned int audio_id, int layer, int bitrate, int sample, int mode, int emphasis)
-{
- // Try to validate this syncword by validating semantics of the audio header.
- // We're trying to filter out emulated syncwords.
- if (layer == LAYERRESERVED)
- return 1;
- if (bitrate == BITRATERESERVED)
- return 1;
- if (sample == SAMPLERESERVED)
- return 1;
- if (layer == LAYER2)
- {
- if ((bitrate == 1 || bitrate == 2 || bitrate == 3 || bitrate == 5) && mode != MONO)
- return 1;
- if ((bitrate == 11 || bitrate == 12 || bitrate == 13 || bitrate == 14) && mode == MONO)
- return 1;
- }
- // Emphasis is almost never used. It's less likely than hitting an emulated header. :-)
-// if (emphasis != 0)
-// return 1;
- // The header appears to be valid. Store the audio characteristics.
- audio[audio_id].layer = layer;
- audio[audio_id].rate = bitrate;
- audio[audio_id].sample = sample;
- audio[audio_id].mode = mode;
- return 0;
-}
-
-int PTSDifference(__int64 apts, __int64 vpts, int *result)
-{
- __int64 diff = 0;
-
- if (apts == vpts)
- {
- *result = 0;
-#ifdef NO_NEED_AUDIO_DELAY_VALUE
- return 1;
-#else
- return 0;
-#endif
- }
- diff = apts - vpts;
- WRAPAROUND_CORRECTION(diff);
- diff /= 90;
- *result = (int) diff;
- if (_abs64(diff) > 1000 && (D2V_Flag || AudioOnly_Flag) && !CLIActive)
- {
- MessageBox(hWnd,
- "The calculated audio delay is unusually large. This is sometimes\n"
- "caused by an initial black video lead in that does not have valid\n"
- "timestamps. You can try setting your project range to skip this\n"
- "portion of the video. Use the > button to skip GOPS and then hit\n"
- "the [ button to set the start of the project. This may give you a\n"
- "valid delay value.",
- "Audio Delay Warning",
- MB_OK | MB_ICONWARNING);
- // Reset data timeout.
- start = timeGetTime();
- }
- return 0;
-}
-
-
-FILE *OpenAudio(char *path, char *mode, unsigned int id)
-{
- // Pick up the first audio file path for
- // use in the AVS template.
- if (id < LowestAudioId)
- {
- strcpy(AudioFilePath, path);
- LowestAudioId = id;
- }
- return fopen(path, mode);
-}
-
-#define LOCATE \
-while (Rdptr >= (Rdbfr + BUFFER_SIZE)) \
-{ \
- Read = _donread(Infile[CurrentFile], Rdbfr, BUFFER_SIZE); \
- if (Read < BUFFER_SIZE) Next_File(); \
- Rdptr -= BUFFER_SIZE; \
-}
-
-#define DECODE_AC3 \
-{ \
- if (SystemStream_Flag == TRANSPORT_STREAM && TransportPacketSize == 204) \
- Packet_Length -= 16; \
- size = 0; \
- while (Packet_Length > 0) \
- { \
- if (Packet_Length+Rdptr > BUFFER_SIZE+Rdbfr) \
- { \
- size = ac3_decode_data(Rdptr, BUFFER_SIZE+Rdbfr-Rdptr, size); \
- Packet_Length -= BUFFER_SIZE+Rdbfr-Rdptr; \
- Read = _donread(Infile[CurrentFile], Rdbfr, BUFFER_SIZE); \
- if (Read < BUFFER_SIZE) Next_File(); \
- Rdptr = Rdbfr; \
- } \
- else \
- { \
- size = ac3_decode_data(Rdptr, Packet_Length, size); \
- Rdptr += Packet_Length; \
- Packet_Length = 0; \
- } \
- } \
-}
-
-#define DEMUX_AC3 \
-{ \
- if (SystemStream_Flag == TRANSPORT_STREAM && TransportPacketSize == 204) \
- Packet_Length -= 16; \
- while (Packet_Length > 0) \
- { \
- if (Packet_Length+Rdptr > BUFFER_SIZE+Rdbfr) \
- { \
- fwrite(Rdptr, BUFFER_SIZE+Rdbfr-Rdptr, 1, audio[AUDIO_ID].file); \
- Packet_Length -= BUFFER_SIZE+Rdbfr-Rdptr; \
- Read = _donread(Infile[CurrentFile], Rdbfr, BUFFER_SIZE); \
- if (Read < BUFFER_SIZE) Next_File(); \
- Rdptr = Rdbfr; \
- } \
- else \
- { \
- fwrite(Rdptr, Packet_Length, 1, audio[AUDIO_ID].file); \
- Rdptr += Packet_Length; \
- Packet_Length = 0; \
- } \
- } \
-}
-
-void DemuxLPCM(int *size, int *Packet_Length, unsigned char PCM_Buffer[], unsigned char format)
-{
- unsigned char tmp[12];
- int i;
-
- *size = 0;
- while (*Packet_Length > 0)
- {
- if (*Packet_Length + Rdptr > BUFFER_SIZE + Rdbfr)
- {
- memcpy(PCM_Buffer + *size, Rdptr, BUFFER_SIZE + Rdbfr - Rdptr);
- *size += (BUFFER_SIZE + Rdbfr - Rdptr);
- *Packet_Length -= (BUFFER_SIZE + Rdbfr - Rdptr);
- Read = _donread(Infile[CurrentFile], Rdbfr, BUFFER_SIZE);
- if (Read < BUFFER_SIZE)
- Next_File();
- Rdptr = Rdbfr;
- }
- else
- {
- memcpy(PCM_Buffer + *size, Rdptr, *Packet_Length);
- Rdptr += *Packet_Length;
- *size += *Packet_Length;
- *Packet_Length = 0;
- }
- }
- if ((format & 0xc0) == 0)
- {
- // 16-bit LPCM.
- for (i = 0; i < *size; i += 2)
- {
- tmp[0] = PCM_Buffer[i];
- PCM_Buffer[i] = PCM_Buffer[i+1];
- PCM_Buffer[i+1] = tmp[0];
- }
- }
- else
- {
- // 24-bit LPCM.
- if ((format & 0x07) + 1 == 1)
- {
- // Mono
- for (i = 0; i < *size; i += 6)
- {
- tmp[0]=PCM_Buffer[i+4];
- tmp[1]=PCM_Buffer[i+1];
- tmp[2]=PCM_Buffer[i+0];
- tmp[3]=PCM_Buffer[i+5];
- tmp[4]=PCM_Buffer[i+3];
- tmp[5]=PCM_Buffer[i+2];
- memcpy(&PCM_Buffer[i], tmp, 6);
- }
- }
- else
- {
- // Stereo
- for (i = 0; i < *size; i += 12)
- {
- tmp[0] = PCM_Buffer[i+8];
- tmp[1] = PCM_Buffer[i+1];
- tmp[2] = PCM_Buffer[i+0];
- tmp[3] = PCM_Buffer[i+9];
- tmp[4] = PCM_Buffer[i+3];
- tmp[5] = PCM_Buffer[i+2];
- tmp[6] = PCM_Buffer[i+10];
- tmp[7] = PCM_Buffer[i+5];
- tmp[8] = PCM_Buffer[i+4];
- tmp[9] = PCM_Buffer[i+11];
- tmp[10] = PCM_Buffer[i+7];
- tmp[11] = PCM_Buffer[i+6];
- memcpy(&PCM_Buffer[i], tmp, 12);
- }
- }
- }
-}
-
-#define DEMUX_MPA_AAC(fp) \
-do { \
- if (SystemStream_Flag == TRANSPORT_STREAM && TransportPacketSize == 204) \
- Packet_Length -= 16; \
- while (Packet_Length > 0) \
- { \
- if (Packet_Length+Rdptr > BUFFER_SIZE+Rdbfr) \
- { \
- fwrite(Rdptr, BUFFER_SIZE+Rdbfr-Rdptr, 1, (fp)); \
- Packet_Length -= BUFFER_SIZE+Rdbfr-Rdptr; \
- Read = _donread(Infile[CurrentFile], Rdbfr, BUFFER_SIZE); \
- if (Read < BUFFER_SIZE) Next_File(); \
- Rdptr = Rdbfr; \
- } \
- else \
- { \
- fwrite(Rdptr, Packet_Length, 1, (fp)); \
- Rdptr += Packet_Length; \
- Packet_Length = 0; \
- } \
- } \
-} while( 0 )
-
-#define DEMUX_DTS \
-{ \
- if (SystemStream_Flag == TRANSPORT_STREAM && TransportPacketSize == 204) \
- Packet_Length -= 16; \
- while (Packet_Length > 0) \
- { \
- if (Packet_Length+Rdptr > BUFFER_SIZE+Rdbfr) \
- { \
- fwrite(Rdptr, BUFFER_SIZE+Rdbfr-Rdptr, 1, audio[AUDIO_ID].file); \
- Packet_Length -= BUFFER_SIZE+Rdbfr-Rdptr; \
- Read = _donread(Infile[CurrentFile], Rdbfr, BUFFER_SIZE); \
- if (Read < BUFFER_SIZE) Next_File(); \
- Rdptr = Rdbfr; \
- } \
- else \
- { \
- fwrite(Rdptr, Packet_Length, 1, audio[AUDIO_ID].file); \
- Rdptr += Packet_Length; \
- Packet_Length = 0; \
- } \
- } \
-}
-
-static char *FTType[5] = {
- "48KHz", "44.1KHz", "44.1KHz", "44.1KHz", "44.1KHz"
-};
-
-static char *AC3ModeDash[8] = {
- "1+1", "1_0", "2_0", "3_0", "2_1", "3_1", "2_2", "3_2"
-};
-
-static char *AC3Mode[8] = {
- "1+1", "1/0", "2/0", "3/0", "2/1", "3/1", "2/2", "3/2"
-};
-
-static int AC3Rate[32] = {
- 32, 40, 48, 56, 64, 80, 96, 112, 128, 160,
- 192, 224, 256, 320, 384, 448, 512, 576, 640,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-};
-
-static char *MPALayer[4] = {
- "", "L3", "L2", "L1"
-};
-
-static char *MPAExtension[4] = {
- "mpa", "mp3", "mp2", "mp1"
-};
-
-static char *MPAMode[4] = {
- "2ch", "2ch", "2ch", "mono"
-};
-
-static char *MPASample[3] = {
- "44.1", "48", "32"
-};
-
-static char *MPARate[4][15] = {
- { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" }, // Layer reserved
- { "free", "32", "40", "48", "56", "64", "80", "96", "112", "128", "160", "192", "224", "256", "320" }, // Layer 3
- { "free", "32", "48", "56", "64", "80", "96", "112", "128", "160", "192", "224", "256", "320", "384" }, // Layer 2
- { "free", "32", "64", "96", "128", "160", "192", "224", "256", "288", "320", "352", "384", "416", "448" } // Layer 1
-};
-
-int check_audio_packet_continue = 0;
-unsigned int num_pmt_pids = 0;
-
-__int64 VideoPTS, AudioPTS, LastVideoPTS;
-static unsigned char PCM_Buffer[SECTOR_SIZE];
-static short *ptrPCM_Buffer = (short*)PCM_Buffer;
-
-unsigned char *buffer_invalid;
-
-void VideoDemux(void);
-
-void Initialize_Buffer()
-{
- Rdptr = Rdbfr + BUFFER_SIZE;
- Rdmax = Rdptr;
- buffer_invalid = (unsigned char *) 0xffffffff;
-
- if (SystemStream_Flag != ELEMENTARY_STREAM && !AudioOnly_Flag)
- {
- if (Rdptr >= Rdmax)
- Next_Packet();
- CurrentBfr = *Rdptr++ << 24;
-
- if (Rdptr >= Rdmax)
- Next_Packet();
- CurrentBfr += *Rdptr++ << 16;
-
- if (Rdptr >= Rdmax)
- Next_Packet();
- CurrentBfr += *Rdptr++ << 8;
-
- if (Rdptr >= Rdmax)
- Next_Packet();
- CurrentBfr += *Rdptr++;
-
- Fill_Next();
- }
- else
- {
- Fill_Buffer();
-
- CurrentBfr = (*Rdptr << 24) + (*(Rdptr+1) << 16) + (*(Rdptr+2) << 8) + *(Rdptr+3);
- Rdptr += 4;
-
- Fill_Next();
- }
-
- BitsLeft = 32;
-}
-
-// Skips ahead in transport stream by specified number of bytes.
-#define SKIP_TRANSPORT_PACKET_BYTES(bytes_to_skip) \
-do { \
- int temp = (bytes_to_skip); \
- while (temp > 0) \
- { \
- if (temp + Rdptr > BUFFER_SIZE + Rdbfr) \
- { \
- temp -= BUFFER_SIZE + Rdbfr - Rdptr; \
- Read = _donread(Infile[CurrentFile], Rdbfr, BUFFER_SIZE); \
- if (Read < BUFFER_SIZE) Next_File(); \
- Rdptr = Rdbfr; \
- } \
- else \
- { \
- Rdptr += temp; \
- temp = 0; \
- } \
- } \
- Packet_Length -= (bytes_to_skip); \
-} while (0)
-
-#define GET_PES_TIMESTAMP(ts, b1, b2, b3, b4, b5) \
-do { \
- ts = (__int64) (b1 & 0x0e) << 29 \
- | (b2 ) << 22 \
- | (b3 & 0xfe) << 14 \
- | (b4 ) << 7 \
- | (b5 ) >> 1; \
-} while (0)
-
-// Transport packet data structure.
-typedef struct
-{
- // 1 byte
- unsigned char sync_byte; // 8 bits
-
- // 2 bytes
- unsigned char transport_error_indicator; // 1 bit
- unsigned char payload_unit_start_indicator; // 1 bit
- unsigned char transport_priority; // 1 bit
- unsigned short pid; // 13 bits
-
- // 1 byte
- unsigned char transport_scrambling_control; // 2 bits
- unsigned char adaptation_field_control; // 2 bits
- unsigned char continuity_counter; // 4 bits
-
- // 1 byte
- unsigned char adaptation_field_length; // 8 bits
-
- // 1 byte
- unsigned char discontinuity_indicator; // 1 bit
- unsigned char random_access_indicator; // 1 bit
- unsigned char elementary_stream_priority_indicator; // 1 bit
- unsigned char PCR_flag; // 1 bit
- unsigned char OPCR_flag; // 1 bit
- unsigned char splicing_point_flag; // 1 bit
- unsigned char transport_private_data_flag; // 1 bit
- unsigned char adaptation_field_extension_flag; // 1 bit
-} transport_packet;
-
-transport_packet tp_zeroed = { 0 };
-
-FILE *mpafp = NULL;
-FILE *mpvfp = NULL;
-FILE *pcmfp = NULL;
-
-// ATSC transport stream parser.
-// We ignore the 'continuity counter' because with some DTV
-// broadcasters, this isnt a reliable indicator.
-void Next_Transport_Packet()
-{
- static int i, Packet_Length, Packet_Header_Length, size;
- static unsigned int code, flags, VOBCELL_Count, AUDIO_ID = 0;
- __int64 PES_PTS, PES_DTS;
- __int64 pts_stamp = 0, dts_stamp = 0;
- int PTSDiff;
- unsigned int bytes_left;
- transport_packet tp;
- unsigned int time;
- double picture_period;
- char ext[4], EXT[4];
-
- static unsigned int prev_code;
- bool pmt_check = false;
- unsigned int check_num_pmt = 0;
- unsigned int time_limit = 5000;
-#ifdef _DEBUG
- time_limit = 300000; /* Change 5 minutes. */
-#endif
-
- start = timeGetTime();
- for (;;)
- {
- PES_PTS = 0;
- bytes_left = 0;
- Packet_Length = TransportPacketSize; // total length of an MPEG-2 transport packet
- tp = tp_zeroed; // to avoid warnings
-
- // If the packet size is 192, then assume it is an M2TS (blueray) file, which has 4 extra bytes
- // in front of the sync byte.
- if (TransportPacketSize == 192)
- {
- // Suck up the extra bytes.
- Get_Byte();
- Get_Byte();
- Get_Byte();
- Get_Byte();
- Packet_Length -= 4;
- }
-retry_sync:
- // Don't loop forever. If we don't get data
- // in a reasonable time (5 secs) we exit.
- time = timeGetTime();
- if (time - start > time_limit)
- {
- MessageBox(hWnd, "Cannot find audio or video data. Ensure that your PIDs\nare set correctly in the Stream menu. Refer to the\nUsers Manual for details.",
- NULL, MB_OK | MB_ICONERROR);
- ThreadKill(MISC_KILL);
- }
- else if ((Start_Flag || process.locate == LOCATE_SCROLL) && !pmt_check && time - start > 500)
- {
- pat_parser.InitializePMTCheckItems();
- pmt_check = true;
- }
-
- // Search for a sync byte. Gives some protection against emulation.
- if (Stop_Flag)
- ThreadKill(MISC_KILL);
- if (Get_Byte() != 0x47)
- goto retry_sync;
- if (Rdptr - Rdbfr > TransportPacketSize)
- {
- if (Rdptr[-(TransportPacketSize+1)] != 0x47)
- goto retry_sync;
- }
- else if (Rdbfr + Read - Rdptr > TransportPacketSize - 1)
- {
- if (Rdptr[+(TransportPacketSize-1)] != 0x47)
- goto retry_sync;
- }
- else
- {
- // We can't check so just accept this sync byte.
- }
-
- // Record the location of the start of the packet. This will be used
- // for indexing when an I frame is detected.
- if (D2V_Flag)
- {
- PackHeaderPosition = _telli64(Infile[CurrentFile])
- - (__int64)BUFFER_SIZE + (__int64)Rdptr - (__int64)Rdbfr - 1;
- }
- // For M2TS (blueray) files, index the extra 4 bytes in front of the sync byte,
- // because DGDecode will expect to see them.
- if (TransportPacketSize == 192)
- PackHeaderPosition -= 4;
- --Packet_Length; // swallow the sync_byte
-
- code = Get_Short();
- Packet_Length = Packet_Length - 2; // swallow the two bytes we just got
- tp.pid = (unsigned short) (code & 0x1FFF);
- tp.transport_error_indicator = (unsigned char) ((code >> 15) & 0x01);
- tp.payload_unit_start_indicator = (unsigned char) ((code >> 14) & 0x01);
- tp.transport_priority = (unsigned char) ((code >> 13) & 0x01);
-
- if (tp.transport_error_indicator)
- {
- // Skip remaining bytes in current packet.
- SKIP_TRANSPORT_PACKET_BYTES(Packet_Length);
- // Try the next packet in the stream.
- continue;
- }
-
- code = Get_Byte();
- --Packet_Length; // decrement the 1 byte we just got;
- tp.transport_scrambling_control = (unsigned char) ((code >> 6) & 0x03);// 2 bslbf
- tp.adaptation_field_control = (unsigned char) ((code >> 4 ) & 0x03);// 2 bslbf
- tp.continuity_counter = (unsigned char) (code & 0x0F);// 4 uimsbf
-
- // we don't care about the continuity counter
-
- if (tp.adaptation_field_control == 0)
- {
- // no payload
- // skip remaining bytes in current packet
- SKIP_TRANSPORT_PACKET_BYTES(Packet_Length);
- continue;
- }
-
- // 3) check the Adaptation-header, only so we can determine
- // the exact #bytes to skip
- if ( tp.adaptation_field_control == 2 || tp.adaptation_field_control == 3)
- {
- // adaptation field is present
- tp.adaptation_field_length = (unsigned char) Get_Byte(); // 8-bits
- --Packet_Length; // decrement the 1 byte we just got;
-
- if ( tp.adaptation_field_length != 0 ) // end of field already?
- {
- code = Get_Byte();
- --Packet_Length; // decrement the 1 byte we just got;
- tp.discontinuity_indicator = (unsigned char) ((code >> 7) & 0x01); // 1 bslbf
- tp.random_access_indicator = (unsigned char) ((code >> 6) & 0x01); // 1 bslbf
- tp.elementary_stream_priority_indicator = (unsigned char) ((code >> 5) & 0x01); // 1 bslbf
- tp.PCR_flag = (unsigned char) ((code >> 4) & 0x01); // 1 bslbf
- tp.OPCR_flag = (unsigned char) ((code >> 3) & 0x01); // 1 bslbf
- tp.splicing_point_flag = (unsigned char) ((code >> 2) & 0x01); // 1 bslbf
- tp.transport_private_data_flag = (unsigned char) ((code >> 1) & 0x01); // 1 bslbf
- tp.adaptation_field_extension_flag = (unsigned char) ((code >> 0) & 0x01); // 1 bslbf
- bytes_left = tp.adaptation_field_length - 1;
- if (LogTimestamps_Flag && D2V_Flag && tp.PCR_flag && tp.pid == MPEG2_Transport_PCRPID && StartLogging_Flag)
- {
- __int64 PCR, PCRbase, PCRext, tmp;
- char pcr[64];
-
- tmp = (__int64) Get_Byte();
- PCRbase = tmp << 25;
- tmp = (__int64) Get_Byte();
- PCRbase |= tmp << 17;
- tmp = (__int64) Get_Byte();
- PCRbase |= tmp << 9;
- tmp = (__int64) Get_Byte();
- PCRbase |= tmp << 1;
- tmp = (__int64) Get_Byte();
- PCRbase |= tmp >> 7;
- PCRext = (tmp & 0x01) << 8;
- tmp = (__int64) Get_Byte();
- PCRext |= tmp;
- PCR = 300 * PCRbase + PCRext;
- _i64toa(PCR, pcr, 10);
- fprintf(Timestamps, "PCR %s ", pcr);
- _i64toa(PCR/27000, pcr, 10);
- bytes_left -= 6;
- Packet_Length -= 6;
- fprintf(Timestamps, "[%sms]\n", pcr);
- }
-
- // skip the remainder of the adaptation_field
- SKIP_TRANSPORT_PACKET_BYTES(bytes_left);
- } // if ( tp.adaptation_field_length != 0 )
- } // if ( tp.adaptation_field_control != 1 )
-
- // We've processed the MPEG-2 transport header.
- // Any data left in the current transport packet?
- if (Packet_Length == 0)
- continue;
-
- if (tp.pid && tp.pid == MPEG2_Transport_VideoPID)
- {
- LOCATE
-
- if (tp.payload_unit_start_indicator)
- {
- Get_Short();
- Get_Short();
- Get_Short(); // MPEG2-PES total Packet_Length
- Get_Byte(); // skip a byte
- flags = Get_Byte();
- Packet_Header_Length = Get_Byte();
- Packet_Length = Packet_Length - 9; // compensate the bytes we extracted
-
- // Get timestamp, and skip rest of PES-header.
- if ((flags & 0x80) && (Packet_Header_Length > 4))
- {
- GET_PES_TIMESTAMP(PES_PTS, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte());
- pts_stamp = PES_PTS;
- if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag)
- fprintf(Timestamps, "V PTS %lld [%lldms]\n", pts_stamp, pts_stamp/90);
- Packet_Length -= 5;
- // DTS is not used. The code is here for analysis and debugging.
- if ((flags & 0xc0) == 0xc0)
- {
- GET_PES_TIMESTAMP(PES_DTS, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte());
- dts_stamp = PES_DTS;
- if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag)
- fprintf(Timestamps, "V DTS %lld [%lldms]\n", dts_stamp, dts_stamp/90);
- Packet_Length -= 5;
- SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length - 10);
- }
- else
- SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length - 5);
- }
- else
- SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length);
- if (!Start_Flag)
- {
- // Start_Flag becomes true after the first I frame.
- // So VideoPTS will be left at the value corresponding to
- // the first I frame.
- VideoPTS = pts_stamp;
- }
- LastVideoPTS = pts_stamp;
- }
-
- Rdmax = Rdptr + Packet_Length;
- if (TransportPacketSize == 204)
- Rdmax -= 16;
-
- Bitrate_Monitor += (Rdmax - Rdptr);
- if (AudioOnly_Flag)
- SKIP_TRANSPORT_PACKET_BYTES(Packet_Length);
- return;
- }
-
- else if ((Method_Flag == AUDIO_DEMUXALL || Method_Flag == AUDIO_DEMUX) && Start_Flag &&
- tp.pid && (tp.pid == MPEG2_Transport_AudioPID) &&
- (MPEG2_Transport_AudioType == 3 || MPEG2_Transport_AudioType == 4 || MPEG2_Transport_AudioType == 0xffffffff))
- {
- // Both MPEG and AAC audio come here. The sync word will be checked to
- // distinguish between them.
- if (mpafp)
- {
- if (tp.payload_unit_start_indicator)
- {
- Get_Short(); // start code and stream id
- Get_Short();
- Get_Short(); // packet length
- Get_Byte(); // flags
- code = Get_Byte(); // more flags
- Packet_Header_Length = Get_Byte();
- Packet_Length -= 9;
- if (code & 0x80)
- {
-// unsigned int dts_stamp;
- code = Get_Byte();
- GET_PES_TIMESTAMP(PES_PTS, code, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte());
- AudioPTS = PES_PTS;
- if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag)
- fprintf(Timestamps, " A00 PTS %lld [%lldms]\n", AudioPTS, AudioPTS/90);
- Packet_Length -= 5;
-#if 0
- if ((code & 0xc0) == 0xc0)
- {
- GET_PES_TIMESTAMP(PES_DTS, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte());
- dts_stamp = PES_DTS;
- if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag)
- fprintf(Timestamps, "A DTS %lld [%lldms]\n", dts_stamp, dts_stamp/90);
- Packet_Length -= 5;
- SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length - 10);
- }
- else
-#endif
- SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length-5);
- }
- else
- SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length);
- }
- DEMUX_MPA_AAC(mpafp);
- }
- else if (!(tp.payload_unit_start_indicator) && check_audio_packet_continue)
- {
- check_audio_packet_continue = 0;
- code = prev_code;
- goto emulated3;
- }
- else if (tp.payload_unit_start_indicator)
- {
- check_audio_packet_continue = 0;
- Get_Short(); // start code
- Get_Short(); // rest of start code and stream id
- Get_Short(); // packet length
- Get_Byte(); // flags
- code = Get_Byte(); // more flags
- Packet_Header_Length = Get_Byte();
- Packet_Length -= 9;
- if (code & 0x80)
- {
-// unsigned int dts_stamp;
- code = Get_Byte();
- GET_PES_TIMESTAMP(PES_PTS, code, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte());
- AudioPTS = PES_PTS;
- if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag)
- fprintf(Timestamps, " A00 PTS %lld [%lldms]\n", AudioPTS, AudioPTS/90);
- Packet_Length = Packet_Length - 5;
-#if 0
- if ((code & 0xc0) == 0xc0)
- {
- GET_PES_TIMESTAMP(PES_DTS, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte());
- dts_stamp = PES_DTS;
- if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag)
- fprintf(Timestamps, "A DTS %lld [%lldms]\n", dts_stamp, dts_stamp/90);
- Packet_Length -= 5;
- SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length - 10);
- }
- else
-#endif
- SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length-5);
-
- // Now we're at the start of the audio.
- // Find the audio header.
- code = (Get_Byte() << 24) | (Get_Byte() << 16) | (Get_Byte() << 8) | Get_Byte();
- Packet_Length -= 4;
- while ((code & 0xfff80000) != 0xfff80000 && Packet_Length > 0)
- {
-emulated3:
- code = (code << 8) | Get_Byte();
- Packet_Length--;
- }
- if ((code & 0xfff80000) != 0xfff80000)
- {
- SKIP_TRANSPORT_PACKET_BYTES(Packet_Length);
- check_audio_packet_continue = 1;
- prev_code = code;
- continue;
- }
- if ((MPEG2_Transport_AudioType == 4) && ((code & 0xfffe0000) != 0xfff80000))
- {
- goto emulated3;
- }
- // Found the audio header. Now check the layer field.
- // For MPEG, layer is 1, 2, or 3. For AAC, it is 0.
- // We demux the same for both; only the filename we create is different.
- if (((code >> 17) & 3) == 0x00)
- {
- // AAC audio.
- if (check_adts_aac_header((code >> 17) & 3, (code >> 14) & 3, (code >> 10) & 0xf))
- {
- goto emulated3;
- }
- audio[0].type = FORMAT_AAC;
- }
- else
- {
- // MPEG audio.
- // Try to detect emulated sync words by enforcing semantics.
- if (check_audio_syncword(0, (code >> 17) & 3, (code >> 12) & 0xf, (code >> 10) & 3, (code >> 6) & 3, code & 3))
- {
- goto emulated3;
- }
- audio[0].type = FORMAT_MPA;
- }
- if (AudioOnly_Flag)
- {
- char *p;
- strcpy(szOutput, Infilename[0]);
- p = &szOutput[sizeof(szOutput)];
- while (*p != '.') p--;
- *p = 0;
- if (audio[0].type == FORMAT_AAC)
- sprintf(szBuffer, "%s PID %03x.aac", szOutput, MPEG2_Transport_AudioPID);
- else
- sprintf(szBuffer, "%s PID %03x %s %s %s %s.%s", szOutput, MPEG2_Transport_AudioPID,
- MPALayer[audio[0].layer], MPAMode[audio[0].mode], MPASample[audio[0].sample],
- MPARate[audio[0].layer][audio[0].rate],
- UseMPAExtensions ? MPAExtension[0] : MPAExtension[audio[0].layer]);
- }
- else
- {
- // Adjust the VideoPTS to account for frame reordering.
- if (!PTSAdjustDone)
- {
- PTSAdjustDone = 1;
- picture_period = 1.0 / frame_rate;
- VideoPTS -= (int) (LeadingBFrames * picture_period * 90000);
- }
-
- if (PTSDifference(AudioPTS, VideoPTS, &PTSDiff))
- {
- if (audio[0].type == FORMAT_AAC)
- sprintf(szBuffer, "%s PID %03x.aac", szOutput, MPEG2_Transport_AudioPID);
- else
- sprintf(szBuffer, "%s PID %03x %s %s %s %s.%s", szOutput, MPEG2_Transport_AudioPID,
- MPALayer[audio[0].layer], MPAMode[audio[0].mode], MPASample[audio[0].sample],
- MPARate[audio[0].layer][audio[0].rate],
- UseMPAExtensions ? MPAExtension[0] : MPAExtension[audio[0].layer]);
- }
- else
- {
- if (audio[0].type == FORMAT_AAC)
- sprintf(szBuffer, "%s PID %03x DELAY %dms.aac", szOutput, MPEG2_Transport_AudioPID, PTSDiff);
- else
- sprintf(szBuffer, "%s PID %03x %s %s %s %s DELAY %dms.%s", szOutput, MPEG2_Transport_AudioPID,
- MPALayer[audio[0].layer], MPAMode[audio[0].mode], MPASample[audio[0].sample],
- MPARate[audio[0].layer][audio[0].rate], PTSDiff,
- UseMPAExtensions ? MPAExtension[0] : MPAExtension[audio[0].layer]);
- }
- }
- if (D2V_Flag || AudioOnly_Flag)
- {
- mpafp = OpenAudio(szBuffer, "wb", 0);
- if (mpafp == NULL)
- {
- // Cannot open the output file, Disable further audio processing.
- MPEG2_Transport_AudioType = 0xff;
- SKIP_TRANSPORT_PACKET_BYTES(Packet_Length);
- continue;
- }
- fputc((code >> 24) & 0xff, mpafp);
- fputc((code >> 16) & 0xff, mpafp);
- fputc((code >> 8) & 0xff, mpafp);
- fputc((code ) & 0xff, mpafp);
- DEMUX_MPA_AAC(mpafp);
- }
- }
- }
- if (AudioOnly_Flag && Info_Flag && !(AudioPktCount++ % 128))
- UpdateInfo();
- }
-
- else if ((Method_Flag == AUDIO_DEMUXALL || Method_Flag == AUDIO_DEMUX) && Start_Flag &&
- tp.pid && (tp.pid == MPEG2_Transport_AudioPID) && (MPEG2_Transport_AudioType == 0x80))
- {
- if (pcmfp)
- {
- if (tp.payload_unit_start_indicator)
- {
- Get_Short(); // start code and stream id
- Get_Short();
- Get_Short(); // packet length
- Get_Byte(); // flags
- code = Get_Byte(); // more flags
- Packet_Header_Length = Get_Byte();
- Packet_Length -= 9;
- if (code & 0x80)
- {
- code = Get_Byte();
- GET_PES_TIMESTAMP(PES_PTS, code, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte());
- AudioPTS = PES_PTS;
- if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag)
- fprintf(Timestamps, " A00 PTS %lld [%lldms]\n", AudioPTS, AudioPTS/90);
- Packet_Length -= 5;
- SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length-5);
- }
- else
- SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length);
- // Now we're at the start of the audio.
- code = Get_Byte();
- code = Get_Byte();
- audio[0].format_m2ts = Get_Short();
- Packet_Length -= 4;
- }
- DEMUX_MPA_AAC(pcmfp);
- }
- else if (tp.payload_unit_start_indicator)
- {
- audio[0].type = FORMAT_LPCM_M2TS;
- strcpy(ext, "pcm");
- strcpy(EXT, "pcm");
- _strupr(EXT);
- Get_Short(); // start code
- Get_Short(); // rest of start code and stream id
- Get_Short(); // packet length
- Get_Byte(); // flags
- code = Get_Byte(); // more flags
- Packet_Header_Length = Get_Byte();
- Packet_Length -= 9;
- if (code & 0x80)
- {
- code = Get_Byte();
- GET_PES_TIMESTAMP(PES_PTS, code, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte());
- AudioPTS = PES_PTS;
- if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag)
- fprintf(Timestamps, " A00 PTS %lld [%lldms]\n", AudioPTS, AudioPTS/90);
- Packet_Length = Packet_Length - 5;
- SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length-5);
-
- // Now we're at the start of the audio.
- code = Get_Byte();
- code = Get_Byte();
- audio[0].format_m2ts = Get_Short();
- Packet_Length -= 4;
-
- if (AudioOnly_Flag)
- {
- char *p;
- strcpy(szOutput, Infilename[0]);
- p = &szOutput[sizeof(szOutput)];
- while (*p != '.') p--;
- *p = 0;
- sprintf(szBuffer, "%s %s PID %03x.%s", szOutput, EXT, MPEG2_Transport_AudioPID, ext);
- }
- else
- {
- // Adjust the VideoPTS to account for frame reordering.
- if (!PTSAdjustDone)
- {
- PTSAdjustDone = 1;
- picture_period = 1.0 / frame_rate;
- VideoPTS -= (int) (LeadingBFrames * picture_period * 90000);
- }
-
- if (PTSDifference(AudioPTS, VideoPTS, &PTSDiff))
- sprintf(szBuffer, "%s %s PID %03x.%s",
- szOutput, EXT, MPEG2_Transport_AudioPID, ext);
- else
- sprintf(szBuffer, "%s %s PID %03x DELAY %dms.%s",
- szOutput, EXT, MPEG2_Transport_AudioPID, PTSDiff, ext);
- }
- if (D2V_Flag || AudioOnly_Flag)
- {
- pcmfp = OpenAudio(szBuffer, "wb", 0);
- if (pcmfp == NULL)
- {
- // Cannot open the output file, Disable further audio processing.
- MPEG2_Transport_AudioType = 0xff;
- SKIP_TRANSPORT_PACKET_BYTES(Packet_Length);
- continue;
- }
- DEMUX_MPA_AAC(pcmfp);
- }
- }
- }
- if (AudioOnly_Flag && Info_Flag && !(AudioPktCount++ % 128))
- UpdateInfo();
- }
-
- else if (tp.pid && tp.pid == MPEG2_Transport_AudioPID && (MPEG2_Transport_AudioType == 0x81))
- {
- // We are demuxing AC3 audio.
- // search for an MPEG-PES packet header
- if (tp.random_access_indicator || tp.payload_unit_start_indicator )
- {
- LOCATE
-
- code = Get_Short();
- code = (code & 0xffff)<<16 | Get_Short();
- Packet_Length = Packet_Length - 4; // remove these two bytes
-
- // Check for MPEG2-PES packet header. This may contains a PTS.
- if ((TransportPacketSize != 192 && code != PRIVATE_STREAM_1) ||
- (TransportPacketSize == 192 && (code != BLURAY_STREAM_1 && code != PRIVATE_STREAM_1)))
- {
- // No, move the buffer-pointer back.
- Rdptr -= 4;
- Packet_Length = Packet_Length + 4;
- }
- else
- {
- // YES, pull out PTS
- //Packet_Length = Get_Short();
- Get_Short(); // MPEG2-PES total Packet_Length
- Get_Byte(); // skip a byte
-
- code = Get_Byte();
- Packet_Header_Length = Get_Byte();
- Packet_Length = Packet_Length - 5; // compensate the bytes we extracted
-
- // get PTS, and skip rest of PES-header
- if (code >= 0x80 && Packet_Header_Length > 4 )
- {
-// unsigned int dts_stamp;
- code = Get_Byte();
- GET_PES_TIMESTAMP(PES_PTS, code, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte());
- AudioPTS = PES_PTS;
- if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag)
- fprintf(Timestamps, " A00 PTS %lld [%lldms]\n", AudioPTS, AudioPTS/90);
- Packet_Length = Packet_Length - 5;
-#if 0
- if ((code & 0xc0) == 0xc0)
- {
- GET_PES_TIMESTAMP(PES_DTS, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte());
- dts_stamp = PES_DTS;
- if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag)
- fprintf(Timestamps, "A DTS %lld [%lldms]\n", dts_stamp, dts_stamp/90);
- Packet_Length -= 5;
- SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length - 10);
- }
- else
-#endif
- SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length - 5);
- }
- else
- SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length);
- }
- }
-
- // Done processing the MPEG-2 PES header, now for the *real* audio-data
-
- LOCATE
- // if this is the *first* observation, we will seek to the
- // first valid AC3-frame, then decode its header.
- // We tried checking for tp.payload_unit_start_indicator, but this
- // indicator isn't reliable on a lot of DTV-stations!
- // Instead, we'll manually search for an AC3-sync word.
- if (!audio[0].rip && Start_Flag && !audio[0].type &&
- (tp.random_access_indicator || tp.payload_unit_start_indicator)
- && Packet_Length > 5 )
- {
- code = Get_Byte();
- code = (code & 0xff)<<8 | Get_Byte();
- Packet_Length = Packet_Length - 2; // remove these two bytes
-
- // search for an AC3-sync word. We wouldn't have to do this if
- // DTV-stations made proper use of tp.payload_unit_start_indicator;
-#if 0
- if (tp.payload_unit_start_indicator)
- {
- MessageBox(hWnd, "This is a harmless condition but I want to know if it\n"
- "ever occurs. Please email me at neuron2@comcast.net to inform\n"
- "me that you saw this message box. Thank you.",
- "Please tell me about this!", MB_OK | MB_ICONINFORMATION);
- }
-#endif
- while (code != 0xb77 && Packet_Length > 0)
- {
-
-oops2:
- code = (code & 0xff)<<8 | Get_Byte();
- --Packet_Length;
- }
-
- if ( code != 0xb77 ) // did we find the sync-header?
- {
- // no, we searched the *ENTIRE* transport-packet and came up empty!
- SKIP_TRANSPORT_PACKET_BYTES(Packet_Length);
- continue;
- }
-
- // First time that we detected this particular channel? yes
- audio[0].type = FORMAT_AC3;
-
- //Packet_Length = Packet_Length - 5; // remove five bytes
- Get_Short();
- audio[0].rate = (Get_Byte()>>1) & 0x1f;
- if (audio[0].rate > 0x12)
- goto oops2;
- Get_Byte();
- audio[0].mode = (Get_Byte()>>5) & 0x07;
- //Packet_Length = Packet_Length + 5; // restore these five bytes
- Rdptr -= 5; // restore these five bytes
-
- // ok, now move "backward" by two more bytes, so we're back at the
- // start of the AC3-sync header
-
- Packet_Length += 2;
- Rdptr -= 2;
-
- if (D2V_Flag || Decision_Flag || AudioOnly_Flag)
- {
- // For transport streams, the audio is always track 1.
- if (Decision_Flag && audio[0].selected_for_demux == true)
- {
- InitialAC3();
-
- DECODE_AC3
-
- audio[0].rip = 1;
- }
- else if (Method_Flag==AUDIO_DECODE && audio[0].selected_for_demux == true)
- {
- InitialAC3();
-
- sprintf(szBuffer, "%s PID %03x %sch %dKbps %s.wav", szOutput, MPEG2_Transport_AudioPID,
- AC3ModeDash[audio[0].mode], AC3Rate[audio[0].rate], FTType[SRC_Flag]);
-
- strcpy(audio[0].filename, szBuffer);
- audio[0].file = OpenAudio(szBuffer, "wb", 0);
- if (audio[0].file == NULL)
- {
- // Cannot open the output file, Disable further audio processing.
- MPEG2_Transport_AudioType = 0xff;
- SKIP_TRANSPORT_PACKET_BYTES(Packet_Length);
- continue;
- }
-
- StartWAV(audio[0].file, 0x01); // 48K, 16bit, 2ch
-
- // Adjust the VideoPTS to account for frame reordering.
- if (!PTSAdjustDone)
- {
- PTSAdjustDone = 1;
- picture_period = 1.0 / frame_rate;
- VideoPTS -= (int) (LeadingBFrames * picture_period * 90000);
- }
-
- if (PTSDifference(AudioPTS, VideoPTS, &PTSDiff))
- audio[0].delay = 0;
- else
- audio[0].delay = PTSDiff * 192;
-
- if (SRC_Flag)
- {
- DownWAV(audio[0].file);
- InitialSRC();
- }
-
- if (audio[0].delay > 0)
- {
- if (SRC_Flag)
- audio[0].delay = ((int)(0.91875*audio[0].delay)>>2)<<2;
-
- for (i=0; i