Package bdsup2sub.core
Class Core
java.lang.Object
java.lang.Thread
bdsup2sub.core.Core
- All Implemented Interfaces:
Runnable
This class contains the core functionality of BDSup2Sub.
It's meant to be used from the command line as well as from the GUI.
It's meant to be used from the command line as well as from the GUI.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enum
Enumeration of caption types (used for moving captions)private static enum
Enumeration of functionalities executed in the started threadNested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Configuration
private static Palette
Current DVD palette (for create mode) - initialized as defaultprivate static Palette
Current palette based on the one imported from SUB/IDX or SUP/IFOprivate static final int[]
Default alpha mapprivate static Palette
Palette imported from SUB/IDX or SUP/IFOprivate static String
Full filename of current source SUP (needed for thread)private static InputMode
Input mode used for last importprivate static final Logger
private static final int
private static Progress
Progress dialog for loading/exportingprivate static int
Last relative value for progress barprivate static int
Maximum absolute value for progress barprivate static boolean
Semaphore to disable actions while changing component propertiesprivate static Core.RunType
Functionality executed in the started threadprivate static final Object
Semaphore for synchronizationprivate static CoreThreadState
Thread stateprivate static SubDvd
Used for handling VobSubprivate static SubPicture[]
Array of subpictures used for editing and exportprivate static SubtitleStream
Used for common handling of either SUPsprivate static SubPictureDVD
Used for creating VobSub streamsprivate static SupBD
Used for handling BD SUPsprivate static SupDvd
Used for handling SUP/IFOprivate static SupHD
Used for handling HD-DVD SUPsprivate static SupXml
Used for handling Xmlsprivate static Exception
Used to store exception thrown in the threadprivate static Bitmap
Converted target bitmap of current subpicture - just for displayprivate static Bitmap
Converted unpatched target bitmap of current subpicture - just for displayprivate static Palette
Palette of target captionprivate static boolean
Use BT.601 color model instead of BT.709Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
cancel()
Force Core to cancel current operation.static void
close()
Reset the core, close all filesstatic void
convertSup
(int index, int displayNum, int displayMax) Convert source subpicture image to target subpicture image.private static void
convertSup
(int index, int displayNum, int displayMax, boolean skipScaling) Convert source subpicture image to target subpicture image.private static int
Count the number of forced subpictures to be exported.static void
createSubThreaded
(String fname, JFrame parent) Write a VobSub or BD-SUP in a thread and display the progress dialog.private static void
determineFramePal
(int index) Create the frame individual 4-color palette for VobSub mode.static void
exit()
Shut down the Core (write properties, close files etc.).static Palette
Get current DVD palette.static Palette
Get modified imported palette if input is DVD format.static Palette
Get imported palette if input is DVD format.static int[]
getFrameAlpha
(int index) Return frame alpha values of given subtitle.static int[]
getFramePal
(int index) Return frame palette of given subtitle.static InputMode
Get input mode.static int
Get number of forced subtitles.static int
Get number of subtitles.static int[]
getOriginalFrameAlpha
(int index) Return original frame alpha values of given subtitle.static int[]
getOriginalFramePal
(int index) Return original frame palette of given subtitle.static BufferedImage
Get source image as BufferedImage.static BufferedImage
getSrcImage
(int idx) Get source image as BufferedImage.static String
getSrcInfoStr
(int index) Create info string for source subtitle.static CoreThreadState
Get Core state.static SubPicture
getSubPictureSrc
(int index) Get source subpicture.Return indexes of subpictures to be exported.static SubPicture
getSubPictureTrg
(int index) Get target subpicture.static boolean
getTrgExcluded
(int index) Get exclude (from export) state of target.static int
getTrgHeight
(int index) Get screen height of target.static BufferedImage
Get target image as BufferedImage.static BufferedImage
Get target image as BufferedImage.static int
getTrgImgHeight
(int index) Get subtitle height of target.static int
getTrgImgWidth
(int index) Get subtitle width of target.static String
getTrgInfoStr
(int index) Create info string for target subtitle.static int
getTrgOfsX
(int index) Get subtitle x offset of target.static int
getTrgOfsY
(int index) Get subtitle y offset of target.static int
getTrgWidth
(int index) Get screen width of target.static boolean
Get cancel state.static boolean
isReady()
Get Core ready state.static void
moveAllThreaded
(JFrame parent) Move all subpictures into or outside given bounds in a thread and display the progress dialog.static void
Move all subpictures into or outside given bounds.static void
moveToBounds
(SubPicture pic, int idx, double barFactor, int offsetX, int offsetY, CaptionMoveModeX mmx, CaptionMoveModeY mmy, int cropOffsetY) Move subpicture into or outside given bounds.private static void
readDVDSubstream
(String fname, boolean isVobSub) Read VobSub or SUP/IFO.static void
readStreamThreaded
(String fname, JFrame parent, StreamID sid) Read a subtitle stream in a thread and display the progress dialog.static void
Read BD-SUP or HD-DVD-SUP.static void
readSupIfo
(String fname) Read SUP/IFO.static void
readVobSub
(String fname) Read VobSub.static void
Read Sony BDN XML file.static void
reScanSubtitles
(Resolution resOld, double fpsTrgOld, int delayOld, boolean convertFpsOld, double fsXOld, double fsYOld) Same as scanSubtitles, but consider existing frame copies.
Times and X/Y offsets of existing frames are converted to new settings.void
run()
Thread used for threaded import/export.static void
Create a copy of the loaded subpicture information frames.
Apply scaling and speedup/delay to the copied frames.
Sync frames to target fps.static void
Set current DVD palette.static void
Set modified imported palette.static void
setProgress
(long p) Set progress in progress bar.static void
setProgressMax
(int max) Set internal maximum for progress bar.static void
setReady
(boolean r) Set Core ready state.private static boolean
updateTrgPic
(int index) Update width, height and offsets of target SubPicture.
This is needed if cropping captions during decode (i.e.static boolean
Get: use of BT.601 color model instead of BT.709.private static void
validateTimes
(int idx, SubPicture subPic, SubPicture subPicNext, SubPicture subPicPrev) Check start and end time, fix overlaps etc.private static void
writePGCEditPal
(String fname, Palette p) Create PGCEdit palette file from given Palette.static void
Create BD-SUP or VobSub or Xml.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Field Details
-
configuration
-
logger
-
currentDVDPalette
Current DVD palette (for create mode) - initialized as default -
MIN_IMAGE_DIMENSION
private static final int MIN_IMAGE_DIMENSION- See Also:
-
defaultSourceDVDPalette
Palette imported from SUB/IDX or SUP/IFO -
currentSourceDVDPalette
Current palette based on the one imported from SUB/IDX or SUP/IFO -
DEFAULT_ALPHA
private static final int[] DEFAULT_ALPHADefault alpha map -
trgBitmapUnpatched
Converted unpatched target bitmap of current subpicture - just for display -
trgBitmap
Converted target bitmap of current subpicture - just for display -
trgPal
Palette of target caption -
subVobTrg
Used for creating VobSub streams -
supBD
Used for handling BD SUPs -
supHD
Used for handling HD-DVD SUPs -
supXml
Used for handling Xmls -
subDVD
Used for handling VobSub -
supDVD
Used for handling SUP/IFO -
subtitleStream
Used for common handling of either SUPs -
subPictures
Array of subpictures used for editing and export -
inMode
Input mode used for last import -
useBT601
private static boolean useBT601Use BT.601 color model instead of BT.709 -
fileName
Full filename of current source SUP (needed for thread) -
progress
Progress dialog for loading/exporting -
progressMax
private static int progressMaxMaximum absolute value for progress bar -
progressLast
private static int progressLastLast relative value for progress bar -
runType
Functionality executed in the started thread -
state
Thread state -
threadException
Used to store exception thrown in the thread -
ready
private static volatile boolean readySemaphore to disable actions while changing component properties -
semaphore
Semaphore for synchronization
-
-
Constructor Details
-
Core
public Core()
-
-
Method Details
-
run
public void run()Thread used for threaded import/export. -
close
public static void close()Reset the core, close all files -
exit
public static void exit()Shut down the Core (write properties, close files etc.). -
readStreamThreaded
Read a subtitle stream in a thread and display the progress dialog.- Parameters:
fname
- File name of subtitle stream to readparent
- Parent frame (needed for progress dialog)sid
- stream identifier- Throws:
Exception
-
createSubThreaded
Write a VobSub or BD-SUP in a thread and display the progress dialog.- Parameters:
fname
- File name of subtitle stream to createparent
- Parent frame (needed for progress dialog)- Throws:
Exception
-
determineFramePal
private static void determineFramePal(int index) Create the frame individual 4-color palette for VobSub mode. -
readSup
Read BD-SUP or HD-DVD-SUP.- Parameters:
fname
- File name- Throws:
CoreException
-
readXml
Read Sony BDN XML file.- Parameters:
fname
- File name- Throws:
CoreException
-
readVobSub
Read VobSub.- Parameters:
fname
- File name- Throws:
CoreException
-
readSupIfo
Read SUP/IFO.- Parameters:
fname
- File name- Throws:
CoreException
-
readDVDSubstream
Read VobSub or SUP/IFO.- Parameters:
fname
- File nameisVobSub
- True if SUB/IDX, false if SUP/IFO- Throws:
CoreException
-
validateTimes
private static void validateTimes(int idx, SubPicture subPic, SubPicture subPicNext, SubPicture subPicPrev) Check start and end time, fix overlaps etc.- Parameters:
idx
- Index of subpicture (just for display)subPic
- Subpicture to check/fixsubPicNext
- Next subpicturesubPicPrev
- Previous subpicture
-
updateTrgPic
private static boolean updateTrgPic(int index) Update width, height and offsets of target SubPicture.
This is needed if cropping captions during decode (i.e. the source image size changes).- Parameters:
index
- Index of caption- Returns:
- true: image size has changed, false: image size didn't change.
-
scanSubtitles
public static void scanSubtitles()Create a copy of the loaded subpicture information frames.
Apply scaling and speedup/delay to the copied frames.
Sync frames to target fps. -
reScanSubtitles
public static void reScanSubtitles(Resolution resOld, double fpsTrgOld, int delayOld, boolean convertFpsOld, double fsXOld, double fsYOld) Same as scanSubtitles, but consider existing frame copies.
Times and X/Y offsets of existing frames are converted to new settings.- Parameters:
resOld
- Resolution of existing framesfpsTrgOld
- Target fps of existing framesdelayOld
- Delay of existing framesconvertFpsOld
- ConverFPS setting for existing framesfsXOld
- Old free scaling factor in X directionfsYOld
- Old free scaling factor in Y direction
-
convertSup
Convert source subpicture image to target subpicture image.- Parameters:
index
- Index of subtitle to convertdisplayNum
- Subtitle number to display (needed for forced subs)displayMax
- Maximum subtitle number to display (needed for forced subs)- Throws:
CoreException
-
convertSup
private static void convertSup(int index, int displayNum, int displayMax, boolean skipScaling) throws CoreException Convert source subpicture image to target subpicture image.- Parameters:
index
- Index of subtitle to convertdisplayNum
- Subtitle number to display (needed for forced subs)displayMax
- Maximum subtitle number to display (needed for forced subs)skipScaling
- true: skip bitmap scaling and palette transformation (used for moving captions)- Throws:
CoreException
-
writeSub
Create BD-SUP or VobSub or Xml.- Parameters:
fname
- File name of SUP/SUB/XML to create- Throws:
CoreException
-
moveAllThreaded
Move all subpictures into or outside given bounds in a thread and display the progress dialog.- Parameters:
parent
- Parent frame (needed for progress dialog)- Throws:
Exception
-
moveAllToBounds
Move all subpictures into or outside given bounds.- Throws:
CoreException
-
moveToBounds
public static void moveToBounds(SubPicture pic, int idx, double barFactor, int offsetX, int offsetY, CaptionMoveModeX mmx, CaptionMoveModeY mmy, int cropOffsetY) Move subpicture into or outside given bounds.- Parameters:
pic
- SubPicture object containing coordinates and sizeidx
- Index (only used for display)barFactor
- Factor to calculate cinemascope bar height from screen heightoffsetX
- X offset to consider when movingoffsetY
- Y offset to consider when movingmmx
- Move mode in X directionmmy
- Move mode in Y directioncropOffsetY
- Number of lines to crop from bottom and top
-
writePGCEditPal
Create PGCEdit palette file from given Palette.- Parameters:
fname
- File namep
- Palette- Throws:
CoreException
-
countForcedIncluded
private static int countForcedIncluded()Count the number of forced subpictures to be exported.- Returns:
- Number of forced subpictures to be exported
-
getSubPicturesToBeExported
Return indexes of subpictures to be exported.- Returns:
- indexes of subpictures to be exported
-
isReady
public static boolean isReady()Get Core ready state.- Returns:
- True if the Core is ready
-
setReady
public static void setReady(boolean r) Set Core ready state.- Parameters:
r
- true if the Core is ready
-
cancel
public static void cancel()Force Core to cancel current operation. -
isCanceled
public static boolean isCanceled()Get cancel state.- Returns:
- True if the current operation was canceled
-
getStatus
Get Core state.- Returns:
- Current Core state
-
setProgress
public static void setProgress(long p) Set progress in progress bar.- Parameters:
p
- Subtitle index processed
-
getInputMode
Get input mode.- Returns:
- Current input mode
-
getSrcImage
Get source image as BufferedImage.- Returns:
- Source image as BufferedImage
-
getSrcImage
Get source image as BufferedImage.- Parameters:
idx
- Index of subtitle- Returns:
- Source image as BufferedImage
- Throws:
CoreException
-
getTrgImage
Get target image as BufferedImage.- Returns:
- Target image as BufferedImage
-
getTrgImagePatched
Get target image as BufferedImage.- Parameters:
pic
- SubPicture to use for applying erase patches- Returns:
- Target image as BufferedImage
-
getTrgWidth
public static int getTrgWidth(int index) Get screen width of target.- Parameters:
index
- Subtitle index- Returns:
- Screen width of target
-
getTrgHeight
public static int getTrgHeight(int index) Get screen height of target.- Parameters:
index
- Subtitle index- Returns:
- Screen height of target
-
getTrgImgWidth
public static int getTrgImgWidth(int index) Get subtitle width of target.- Parameters:
index
- Subtitle index- Returns:
- Subtitle width of target
-
getTrgImgHeight
public static int getTrgImgHeight(int index) Get subtitle height of target.- Parameters:
index
- Subtitle index- Returns:
- Subtitle height of target
-
getTrgExcluded
public static boolean getTrgExcluded(int index) Get exclude (from export) state of target.- Parameters:
index
- Subtitle index- Returns:
- Screen width of target
-
getTrgOfsX
public static int getTrgOfsX(int index) Get subtitle x offset of target.- Parameters:
index
- Subtitle index- Returns:
- Subtitle x offset of target
-
getTrgOfsY
public static int getTrgOfsY(int index) Get subtitle y offset of target.- Parameters:
index
- Subtitle index- Returns:
- Subtitle y offset of target
-
getNumFrames
public static int getNumFrames()Get number of subtitles.- Returns:
- Number of subtitles
-
getNumForcedFrames
public static int getNumForcedFrames()Get number of forced subtitles.- Returns:
- Number of forced subtitles
-
getTrgInfoStr
Create info string for target subtitle.- Parameters:
index
- Index of subtitle- Returns:
- Info string for target subtitle
-
getSrcInfoStr
Create info string for source subtitle.- Parameters:
index
- Index of subtitle- Returns:
- Info string for source subtitle
-
getCurrentDVDPalette
Get current DVD palette.- Returns:
- DVD palette
-
setCurrentDVDPalette
Set current DVD palette.- Parameters:
pal
- DVD palette
-
getSubPictureTrg
Get target subpicture.- Parameters:
index
- Index of subpicture- Returns:
- Target SubPicture
-
getSubPictureSrc
Get source subpicture.- Parameters:
index
- Index of subpicture- Returns:
- Source SubPicture
-
usesBT601
public static boolean usesBT601()Get: use of BT.601 color model instead of BT.709.- Returns:
- True if BT.601 is used
-
setProgressMax
public static void setProgressMax(int max) Set internal maximum for progress bar.- Parameters:
max
- Internal maximum for progress bar (e.g. number of subtitles)
-
getDefSrcDVDPalette
Get imported palette if input is DVD format.- Returns:
- Imported palette if input is DVD format, else null
-
getCurSrcDVDPalette
Get modified imported palette if input is DVD format.- Returns:
- Imported palette if input is DVD format, else null
-
setCurSrcDVDPalette
Set modified imported palette.- Parameters:
pal
- Modified imported palette
-
getFramePal
public static int[] getFramePal(int index) Return frame palette of given subtitle.- Parameters:
index
- Index of subtitle- Returns:
- Frame palette of given subtitle as array of int (4 entries)
-
getFrameAlpha
public static int[] getFrameAlpha(int index) Return frame alpha values of given subtitle.- Parameters:
index
- Index of subtitle- Returns:
- Frame alpha values of given subtitle as array of int (4 entries)
-
getOriginalFramePal
public static int[] getOriginalFramePal(int index) Return original frame palette of given subtitle.- Parameters:
index
- Index of subtitle- Returns:
- Frame palette of given subtitle as array of int (4 entries)
-
getOriginalFrameAlpha
public static int[] getOriginalFrameAlpha(int index) Return original frame alpha values of given subtitle.- Parameters:
index
- Index of subtitle- Returns:
- Frame alpha values of given subtitle as array of int (4 entries)
-