Class Core

java.lang.Object
java.lang.Thread
bdsup2sub.core.Core
All Implemented Interfaces:
Runnable

public class Core extends Thread
This class contains the core functionality of BDSup2Sub.
It's meant to be used from the command line as well as from the GUI.
  • Field Details

    • configuration

      private static final Configuration configuration
    • logger

      private static final Logger logger
    • currentDVDPalette

      private static Palette currentDVDPalette
      Current DVD palette (for create mode) - initialized as default
    • MIN_IMAGE_DIMENSION

      private static final int MIN_IMAGE_DIMENSION
      See Also:
    • defaultSourceDVDPalette

      private static Palette defaultSourceDVDPalette
      Palette imported from SUB/IDX or SUP/IFO
    • currentSourceDVDPalette

      private static Palette currentSourceDVDPalette
      Current palette based on the one imported from SUB/IDX or SUP/IFO
    • DEFAULT_ALPHA

      private static final int[] DEFAULT_ALPHA
      Default alpha map
    • trgBitmapUnpatched

      private static Bitmap trgBitmapUnpatched
      Converted unpatched target bitmap of current subpicture - just for display
    • trgBitmap

      private static Bitmap trgBitmap
      Converted target bitmap of current subpicture - just for display
    • trgPal

      private static Palette trgPal
      Palette of target caption
    • subVobTrg

      private static SubPictureDVD subVobTrg
      Used for creating VobSub streams
    • supBD

      private static SupBD supBD
      Used for handling BD SUPs
    • supHD

      private static SupHD supHD
      Used for handling HD-DVD SUPs
    • supXml

      private static SupXml supXml
      Used for handling Xmls
    • subDVD

      private static SubDvd subDVD
      Used for handling VobSub
    • supDVD

      private static SupDvd supDVD
      Used for handling SUP/IFO
    • subtitleStream

      private static SubtitleStream subtitleStream
      Used for common handling of either SUPs
    • subPictures

      private static SubPicture[] subPictures
      Array of subpictures used for editing and export
    • inMode

      private static InputMode inMode
      Input mode used for last import
    • useBT601

      private static boolean useBT601
      Use BT.601 color model instead of BT.709
    • fileName

      private static String fileName
      Full filename of current source SUP (needed for thread)
    • progress

      private static Progress progress
      Progress dialog for loading/exporting
    • progressMax

      private static int progressMax
      Maximum absolute value for progress bar
    • progressLast

      private static int progressLast
      Last relative value for progress bar
    • runType

      private static Core.RunType runType
      Functionality executed in the started thread
    • state

      private static CoreThreadState state
      Thread state
    • threadException

      private static Exception threadException
      Used to store exception thrown in the thread
    • ready

      private static volatile boolean ready
      Semaphore to disable actions while changing component properties
    • semaphore

      private static final Object semaphore
      Semaphore for synchronization
  • Constructor Details

    • Core

      public Core()
  • Method Details

    • run

      public void run()
      Thread used for threaded import/export.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • 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

      public static void readStreamThreaded(String fname, JFrame parent, StreamID sid) throws Exception
      Read a subtitle stream in a thread and display the progress dialog.
      Parameters:
      fname - File name of subtitle stream to read
      parent - Parent frame (needed for progress dialog)
      sid - stream identifier
      Throws:
      Exception
    • createSubThreaded

      public static void createSubThreaded(String fname, JFrame parent) throws Exception
      Write a VobSub or BD-SUP in a thread and display the progress dialog.
      Parameters:
      fname - File name of subtitle stream to create
      parent - 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

      public static void readSup(String fname) throws CoreException
      Read BD-SUP or HD-DVD-SUP.
      Parameters:
      fname - File name
      Throws:
      CoreException
    • readXml

      public static void readXml(String fname) throws CoreException
      Read Sony BDN XML file.
      Parameters:
      fname - File name
      Throws:
      CoreException
    • readVobSub

      public static void readVobSub(String fname) throws CoreException
      Read VobSub.
      Parameters:
      fname - File name
      Throws:
      CoreException
    • readSupIfo

      public static void readSupIfo(String fname) throws CoreException
      Read SUP/IFO.
      Parameters:
      fname - File name
      Throws:
      CoreException
    • readDVDSubstream

      private static void readDVDSubstream(String fname, boolean isVobSub) throws CoreException
      Read VobSub or SUP/IFO.
      Parameters:
      fname - File name
      isVobSub - 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/fix
      subPicNext - Next subpicture
      subPicPrev - 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 frames
      fpsTrgOld - Target fps of existing frames
      delayOld - Delay of existing frames
      convertFpsOld - ConverFPS setting for existing frames
      fsXOld - Old free scaling factor in X direction
      fsYOld - Old free scaling factor in Y direction
    • convertSup

      public static void convertSup(int index, int displayNum, int displayMax) throws CoreException
      Convert source subpicture image to target subpicture image.
      Parameters:
      index - Index of subtitle to convert
      displayNum - 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 convert
      displayNum - 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

      public static void writeSub(String fname) throws CoreException
      Create BD-SUP or VobSub or Xml.
      Parameters:
      fname - File name of SUP/SUB/XML to create
      Throws:
      CoreException
    • moveAllThreaded

      public static void moveAllThreaded(JFrame parent) throws Exception
      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

      public static void moveAllToBounds() throws CoreException
      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 size
      idx - Index (only used for display)
      barFactor - Factor to calculate cinemascope bar height from screen height
      offsetX - X offset to consider when moving
      offsetY - Y offset to consider when moving
      mmx - Move mode in X direction
      mmy - Move mode in Y direction
      cropOffsetY - Number of lines to crop from bottom and top
    • writePGCEditPal

      private static void writePGCEditPal(String fname, Palette p) throws CoreException
      Create PGCEdit palette file from given Palette.
      Parameters:
      fname - File name
      p - 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

      private static List<Integer> 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

      public static CoreThreadState 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

      public static InputMode getInputMode()
      Get input mode.
      Returns:
      Current input mode
    • getSrcImage

      public static BufferedImage getSrcImage()
      Get source image as BufferedImage.
      Returns:
      Source image as BufferedImage
    • getSrcImage

      public static BufferedImage getSrcImage(int idx) throws CoreException
      Get source image as BufferedImage.
      Parameters:
      idx - Index of subtitle
      Returns:
      Source image as BufferedImage
      Throws:
      CoreException
    • getTrgImage

      public static BufferedImage getTrgImage()
      Get target image as BufferedImage.
      Returns:
      Target image as BufferedImage
    • getTrgImagePatched

      public static BufferedImage getTrgImagePatched(SubPicture pic)
      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

      public static String getTrgInfoStr(int index)
      Create info string for target subtitle.
      Parameters:
      index - Index of subtitle
      Returns:
      Info string for target subtitle
    • getSrcInfoStr

      public static String getSrcInfoStr(int index)
      Create info string for source subtitle.
      Parameters:
      index - Index of subtitle
      Returns:
      Info string for source subtitle
    • getCurrentDVDPalette

      public static Palette getCurrentDVDPalette()
      Get current DVD palette.
      Returns:
      DVD palette
    • setCurrentDVDPalette

      public static void setCurrentDVDPalette(Palette pal)
      Set current DVD palette.
      Parameters:
      pal - DVD palette
    • getSubPictureTrg

      public static SubPicture getSubPictureTrg(int index)
      Get target subpicture.
      Parameters:
      index - Index of subpicture
      Returns:
      Target SubPicture
    • getSubPictureSrc

      public static SubPicture getSubPictureSrc(int index)
      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

      public static Palette getDefSrcDVDPalette()
      Get imported palette if input is DVD format.
      Returns:
      Imported palette if input is DVD format, else null
    • getCurSrcDVDPalette

      public static Palette getCurSrcDVDPalette()
      Get modified imported palette if input is DVD format.
      Returns:
      Imported palette if input is DVD format, else null
    • setCurSrcDVDPalette

      public static void setCurSrcDVDPalette(Palette pal)
      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)