Add Graphics plugin
8
com.wudsn.ide.gfx/.classpath
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/js.jar" sourcepath="lib/js-src.zip"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
28
com.wudsn.ide.gfx/.project
Normal file
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>com.wudsn.ide.gfx</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
7
com.wudsn.ide.gfx/.settings/org.eclipse.jdt.core.prefs
Normal file
@ -0,0 +1,7 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
20
com.wudsn.ide.gfx/META-INF/MANIFEST.MF
Normal file
@ -0,0 +1,20 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: WUDSN IDE Graphics Plug-in
|
||||
Bundle-SymbolicName: com.wudsn.ide.gfx;singleton:=true
|
||||
Bundle-Version: 1.7.0.qualifier
|
||||
Bundle-Activator: com.wudsn.ide.gfx.GraphicsPlugin
|
||||
Bundle-Vendor: Peter Dell
|
||||
Require-Bundle: com.wudsn.ide.base,
|
||||
org.eclipse.core.runtime,
|
||||
org.eclipse.core.resources,
|
||||
org.eclipse.ui,
|
||||
org.eclipse.ui.editors,
|
||||
org.eclipse.ui.ide,
|
||||
org.eclipse.ui.console
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Bundle-Localization: plugin
|
||||
Export-Package: com.wudsn.ide.gfx.editor
|
||||
Bundle-ClassPath: lib/js.jar,
|
||||
.
|
1
com.wudsn.ide.gfx/Scrapbook.jpage
Normal file
@ -0,0 +1 @@
|
||||
The method getAtariRGBColor(int) is undefined for the type PaletteTypeUtility
com.wudsn.ide.base.common.HexUtility.getLongValueHexString( com.wudsn.ide.gfx.model.PaletteTypeUtility.getAtariRGBColor(0xff));
|
2
com.wudsn.ide.gfx/bin/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/com
|
||||
/palettes
|
15
com.wudsn.ide.gfx/build.properties
Normal file
@ -0,0 +1,15 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
plugin.xml,\
|
||||
plugin.properties,\
|
||||
src/,\
|
||||
schema/,\
|
||||
icons/,\
|
||||
build.properties,\
|
||||
.project,\
|
||||
.classpath,\
|
||||
lib/js.jar,\
|
||||
plugin_de_DE.properties
|
||||
|
BIN
com.wudsn.ide.gfx/icons/Thumbs.db
Normal file
BIN
com.wudsn.ide.gfx/icons/file-type-charset.gif
Normal file
After Width: | Height: | Size: 905 B |
BIN
com.wudsn.ide.gfx/icons/file-type-picture.gif
Normal file
After Width: | Height: | Size: 910 B |
BIN
com.wudsn.ide.gfx/icons/graphics-editor-16x16.gif
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
com.wudsn.ide.gfx/icons/occ_write.gif
Normal file
After Width: | Height: | Size: 218 B |
BIN
com.wudsn.ide.gfx/icons/refresh.gif
Normal file
After Width: | Height: | Size: 327 B |
BIN
com.wudsn.ide.gfx/icons/save_edit.gif
Normal file
After Width: | Height: | Size: 639 B |
BIN
com.wudsn.ide.gfx/icons/saveall_edit.gif
Normal file
After Width: | Height: | Size: 604 B |
BIN
com.wudsn.ide.gfx/icons/search_ref_obj.gif
Normal file
After Width: | Height: | Size: 356 B |
BIN
com.wudsn.ide.gfx/icons/searchm_obj.gif
Normal file
After Width: | Height: | Size: 200 B |
BIN
com.wudsn.ide.gfx/icons/smartmode_co.gif
Normal file
After Width: | Height: | Size: 553 B |
BIN
com.wudsn.ide.gfx/icons/zoom-disabled.gif
Normal file
After Width: | Height: | Size: 326 B |
BIN
com.wudsn.ide.gfx/icons/zoom.gif
Normal file
After Width: | Height: | Size: 546 B |
BIN
com.wudsn.ide.gfx/lib/js-src.zip
Normal file
BIN
com.wudsn.ide.gfx/lib/js.jar
Normal file
60
com.wudsn.ide.gfx/plugin.properties
Normal file
@ -0,0 +1,60 @@
|
||||
#Properties file for com.wudsn.ide.gfx
|
||||
com.wudsn.ide.gfx.converter.GraphicsFile.name=Graphics File
|
||||
com.wudsn.ide.gfx.converter.apple2.AppleIIGraphicsFile.name=Apple II Graphics File
|
||||
com.wudsn.ide.gfx.converter.atari8.Atari8GraphicsFile.name=Atari 8-bit Graphics File
|
||||
com.wudsn.ide.gfx.converter.c64.C64GraphicsFile.name=C64 Graphics File
|
||||
|
||||
com.wudsn.ide.gfx.editor.GraphicsEditor.name=Graphics Editor
|
||||
com.wudsn.ide.gfx.editor.GraphicsEditorOpenCommand.name=Open With Graphics Editor
|
||||
com.wudsn.ide.gfx.editor.GraphicsCategory.name=Graphics
|
||||
com.wudsn.ide.gfx.editor.ImageView.name=Image
|
||||
com.wudsn.ide.gfx.editor.ImageViewShrinkToFit.name=Shrink
|
||||
com.wudsn.ide.gfx.editor.ImageViewZoomToFit.name=Zoom
|
||||
com.wudsn.ide.gfx.editor.ImagePaletteView.name=Image Palette
|
||||
|
||||
com.wudsn.ide.gfx.model.ConverterMode.RAW=Raw
|
||||
com.wudsn.ide.gfx.model.ConverterMode.CNV=Conversion
|
||||
|
||||
com.wudsn.ide.gfx.model.ConverterDirection.FILES_TO_IMAGE=Files to Image
|
||||
com.wudsn.ide.gfx.model.ConverterDirection.IMAGE_TO_FILES=Image to Files
|
||||
|
||||
com.wudsn.ide.gfx.model.Palette.TRUE_COLOR=True Color
|
||||
com.wudsn.ide.gfx.model.Palette.HIRES_1=Hires (1)
|
||||
com.wudsn.ide.gfx.model.Palette.HIRES_2=Hires (2)
|
||||
com.wudsn.ide.gfx.model.Palette.HIRES_MANUAL=Hires (manual)
|
||||
com.wudsn.ide.gfx.model.Palette.MULTI_1=Multi (1)
|
||||
com.wudsn.ide.gfx.model.Palette.MULTI_2=Multi (2)
|
||||
com.wudsn.ide.gfx.model.Palette.MULTI_3=Multi (3)
|
||||
com.wudsn.ide.gfx.model.Palette.MULTI_4=Multi (4)
|
||||
com.wudsn.ide.gfx.model.Palette.MULTI_5=Multi (5)
|
||||
com.wudsn.ide.gfx.model.Palette.MULTI_6=Multi (6)
|
||||
com.wudsn.ide.gfx.model.Palette.MULTI_MANUAL=Multi (manual)
|
||||
com.wudsn.ide.gfx.model.Palette.GTIA_GREY_1=GITA grey (1)
|
||||
com.wudsn.ide.gfx.model.Palette.GTIA_GREY_2=GITA grey (2)
|
||||
com.wudsn.ide.gfx.model.Palette.GTIA_GREY_MANUAL=GTIA grey (manual)
|
||||
|
||||
com.wudsn.ide.gfx.model.PaletteType.FIXED=Fixed
|
||||
com.wudsn.ide.gfx.model.PaletteType.TRUE_COLOR=True Color
|
||||
com.wudsn.ide.gfx.model.PaletteType.ATARI_DEFAULT=ATARI (default)
|
||||
com.wudsn.ide.gfx.model.PaletteType.ATARI_REAL=ATARI (real)
|
||||
com.wudsn.ide.gfx.model.PaletteType.ATARI_XFORMER=ATARI (XFormer)
|
||||
com.wudsn.ide.gfx.model.PaletteType.C64_NORMAL=C64 (normal)
|
||||
com.wudsn.ide.gfx.model.PaletteType.C64_PAL=C64 (PAL)
|
||||
|
||||
com.wudsn.ide.gfx.converter.XYFactorDefaults.FACTOR_1_1=1 x 1
|
||||
com.wudsn.ide.gfx.converter.XYFactorDefaults.FACTOR_2_1=2 x 1
|
||||
com.wudsn.ide.gfx.converter.XYFactorDefaults.FACTOR_2_2=2 x 2
|
||||
com.wudsn.ide.gfx.converter.XYFactorDefaults.FACTOR_4_2=4 x 2
|
||||
com.wudsn.ide.gfx.converter.XYFactorDefaults.FACTOR_4_4=4 x 4
|
||||
|
||||
com.wudsn.ide.gfx.model.PixelType.HIRES=Hires
|
||||
com.wudsn.ide.gfx.model.PixelType.MULTI=Multicolor
|
||||
com.wudsn.ide.gfx.model.PixelType.GTIA_GREY=GTIA (grey)
|
||||
|
||||
com.wudsn.ide.gfx.converter.generic.CharSetConverter.CHAR_SET_FILE=Char Set File
|
||||
com.wudsn.ide.gfx.converter.generic.CharMapConverter.CHAR_SET_FILE=Char Set File
|
||||
com.wudsn.ide.gfx.converter.generic.CharMapConverter.CHAR_MAP_FILE=Char Map File
|
||||
com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE=Bit Map File
|
||||
com.wudsn.ide.gfx.converter.generic.TiledBitMapConverter.VIDEO_RAM_FILE=Video RAM File
|
||||
com.wudsn.ide.gfx.converter.generic.TiledBitMapConverter.COLOR_RAM_FILE=Color RAM File
|
||||
com.wudsn.ide.gfx.converter.c64.SpriteHiresConverter.SPRITE_FILE=Sprite File
|
567
com.wudsn.ide.gfx/plugin.xml
Normal file
@ -0,0 +1,567 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.4"?>
|
||||
<plugin>
|
||||
<extension-point id="converters" name="Converters" schema="schema/com.wudsn.ide.gfx.converters.exsd"/>
|
||||
<extension
|
||||
point="org.eclipse.ui.commands">
|
||||
<command
|
||||
id="com.wudsn.ide.gfx.editor.GraphicsEditorOpenCommand"
|
||||
name="%com.wudsn.ide.gfx.editor.GraphicsEditorOpenCommand.name">
|
||||
</command>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.handlers">
|
||||
<handler
|
||||
class="com.wudsn.ide.gfx.editor.GraphicsEditorOpenCommandHandler"
|
||||
commandId="com.wudsn.ide.gfx.editor.GraphicsEditorOpenCommand">
|
||||
</handler>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.menus">
|
||||
<menuContribution
|
||||
locationURI="popup:org.eclipse.ui.popup.any?after=com.wudsn.ide.base.editor.hex.HexEditorOpenCommand">
|
||||
<command
|
||||
commandId="com.wudsn.ide.gfx.editor.GraphicsEditorOpenCommand"
|
||||
id="com.wudsn.ide.gfx.editor.GraphicsEditorOpenCommand"
|
||||
style="push">
|
||||
<visibleWhen
|
||||
checkEnabled="false">
|
||||
<or>
|
||||
<with
|
||||
variable="activeMenuSelection">
|
||||
<iterate
|
||||
ifEmpty="false"
|
||||
operator="or">
|
||||
<instanceof
|
||||
value="org.eclipse.core.resources.IFile">
|
||||
</instanceof>
|
||||
</iterate>
|
||||
</with>
|
||||
<with
|
||||
variable="activeMenuEditorInput">
|
||||
<iterate
|
||||
ifEmpty="false"
|
||||
operator="or">
|
||||
<instanceof
|
||||
value="org.eclipse.ui.IFileEditorInput">
|
||||
</instanceof>
|
||||
</iterate>
|
||||
</with>
|
||||
</or>
|
||||
</visibleWhen>
|
||||
</command>
|
||||
</menuContribution>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.core.contenttype.contentTypes">
|
||||
<content-type
|
||||
file-extensions="bmp, ico, gif, jpg, png, cnv"
|
||||
id="com.wudsn.ide.gfx.converter.GraphicsFile"
|
||||
name="%com.wudsn.ide.gfx.converter.GraphicsFile.name"
|
||||
priority="normal">
|
||||
</content-type>
|
||||
<content-type
|
||||
base-type="com.wudsn.ide.gfx.converter.GraphicsFile"
|
||||
file-extensions="ap3, apc, chr, cci, cin, cpr, fnt, ghg, gr8, gr9, hip, hr, hr2, mcp, ilc, inp, int, mic, pic, plm, rip, sxs, tip"
|
||||
id="com.wudsn.ide.gfx.converter.atari8.Atari8GraphicsFile"
|
||||
name="%com.wudsn.ide.gfx.converter.atari8.Atari8GraphicsFile.name"
|
||||
priority="normal">
|
||||
</content-type>
|
||||
<content-type
|
||||
base-type="com.wudsn.ide.gfx.converter.GraphicsFile"
|
||||
file-extensions="64c, chr, fnt, spr"
|
||||
id="com.wudsn.ide.gfx.converter.c64.C64GraphicsFile"
|
||||
name="%com.wudsn.ide.gfx.converter.c64.C64GraphicsFile.name"
|
||||
priority="normal">
|
||||
</content-type>
|
||||
<content-type
|
||||
base-type="com.wudsn.ide.gfx.converter.GraphicsFile"
|
||||
file-extensions="hgr"
|
||||
id="com.wudsn.ide.gfx.converter.apple2.AppleIIGraphicsFile"
|
||||
name="%com.wudsn.ide.gfx.converter.apple2.AppleIIGraphicsFile.name"
|
||||
priority="normal">
|
||||
</content-type>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.editors">
|
||||
<editor
|
||||
class="com.wudsn.ide.gfx.editor.GraphicsEditor"
|
||||
contributorClass="org.eclipse.ui.part.EditorActionBarContributor"
|
||||
default="true"
|
||||
extensions="bmp, ico, gif, jpg, png, cnv"
|
||||
icon="icons/graphics-editor-16x16.gif"
|
||||
id="com.wudsn.ide.gfx.editor.GraphicsEditor"
|
||||
name="%com.wudsn.ide.gfx.editor.GraphicsEditor.name">
|
||||
<contentTypeBinding
|
||||
contentTypeId="com.wudsn.ide.gfx.converter.GraphicsFile">
|
||||
</contentTypeBinding>
|
||||
</editor>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.views">
|
||||
<category
|
||||
id="com.wudsn.ide.gfx.editor.GraphicsCategory"
|
||||
name="%com.wudsn.ide.gfx.editor.GraphicsCategory.name">
|
||||
</category>
|
||||
<view
|
||||
allowMultiple="false"
|
||||
category="com.wudsn.ide.gfx.editor.GraphicsCategory"
|
||||
class="com.wudsn.ide.gfx.editor.ImageView"
|
||||
icon="icons/graphics-editor-16x16.gif"
|
||||
id="com.wudsn.ide.gfx.editor.ImageView"
|
||||
name="%com.wudsn.ide.gfx.editor.ImageView.name"
|
||||
restorable="true">
|
||||
</view>
|
||||
<view
|
||||
allowMultiple="false"
|
||||
category="com.wudsn.ide.gfx.editor.GraphicsCategory"
|
||||
class="com.wudsn.ide.gfx.editor.ImagePaletteView"
|
||||
icon="icons/graphics-editor-16x16.gif"
|
||||
id="com.wudsn.ide.gfx.editor.ImagePaletteView"
|
||||
name="%com.wudsn.ide.gfx.editor.ImagePaletteView.name"
|
||||
restorable="true">
|
||||
</view>
|
||||
</extension>
|
||||
<extension
|
||||
point="com.wudsn.ide.gfx.converters">
|
||||
<converterGroup
|
||||
name="Generic">
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.generic.CharSet1x1HiresConverter"
|
||||
name="Char Set 1x1 - Hires"
|
||||
sourceFileExtensions="64c, chr, fnt"
|
||||
targetImageDisplayAspect="1x1"
|
||||
targetImagePaletteSize="2">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.CharSetConverter.CHAR_SET_FILE">
|
||||
</sourceFile>
|
||||
<targetFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.CharSetConverter.CHAR_SET_FILE">
|
||||
</targetFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.generic.CharSet1x1MultiColorConverter"
|
||||
name="Char Set 1x1 - Multi Color"
|
||||
targetImagePaletteSize="4"
|
||||
targetImageDisplayAspect="2x1">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.CharSetConverter.CHAR_SET_FILE">
|
||||
</sourceFile>
|
||||
<targetFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.CharSetConverter.CHAR_SET_FILE">
|
||||
</targetFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.generic.CharSet2x1HiresConverter"
|
||||
name="Char Set 2x1 - Hires"
|
||||
sourceFileExtensions="64c, chr, fnt"
|
||||
targetImageDisplayAspect="1x1"
|
||||
targetImagePaletteSize="2">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.CharSetConverter.CHAR_SET_FILE">
|
||||
</sourceFile>
|
||||
<targetFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.CharSetConverter.CHAR_SET_FILE">
|
||||
</targetFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.generic.CharSet2x2HiresConverter"
|
||||
name="Char Set 2x2 - Hires"
|
||||
sourceFileExtensions="sxs"
|
||||
targetImageDisplayAspect="1x1"
|
||||
targetImagePaletteSize="2">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.CharSetConverter.CHAR_SET_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.generic.CharSet2x2MultiColorConverter"
|
||||
name="Char Set 2x2 - MultiColor"
|
||||
targetImagePaletteSize="4"
|
||||
targetImageDisplayAspect="2x1">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.CharSetConverter.CHAR_SET_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.generic.CharMapHiresConverter"
|
||||
name="Char Map - Hires"
|
||||
targetImageDisplayAspect="1x1"
|
||||
targetImagePaletteSize="2">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.CharSetConverter.CHAR_SET_FILE">
|
||||
</sourceFile>
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.CharMapConverter.CHAR_MAP_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.generic.CharMapMultiColorConverter"
|
||||
name="Char Map - Multi Color"
|
||||
targetImageDisplayAspect="2x1"
|
||||
targetImagePaletteSize="4">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.CharSetConverter.CHAR_SET_FILE">
|
||||
</sourceFile>
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.CharMapConverter.CHAR_MAP_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.generic.TiledBitMapHiresConverter"
|
||||
name="Tiled Bitmap - Hires"
|
||||
targetImageDisplayAspect="1x1"
|
||||
targetImagePaletteSize="2">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.TiledBitMapConverter.VIDEO_RAM_FILE">
|
||||
</sourceFile>
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.TiledBitMapConverter.COLOR_RAM_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.generic.TiledBitMapMultiColorConverter"
|
||||
name="Tiled Bitmap - Multi Color"
|
||||
targetImageDisplayAspect="2x1"
|
||||
targetImagePaletteSize="4">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.TiledBitMapConverter.VIDEO_RAM_FILE">
|
||||
</sourceFile>
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.TiledBitMapConverter.COLOR_RAM_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.generic.TiledBitMap2x2MultiColorConverter"
|
||||
name="Tiled Bitmap 2x2 - Multi Color"
|
||||
targetImageDisplayAspect="2x1"
|
||||
targetImagePaletteSize="16">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.TiledBitMapConverter.VIDEO_RAM_FILE">
|
||||
</sourceFile>
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.TiledBitMapConverter.COLOR_RAM_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
</converterGroup>
|
||||
<converterGroup
|
||||
name="Apple II">
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.apple2.HiresGraphicsConverter"
|
||||
name="Apple II - HGR"
|
||||
sourceFileExtensions="hgr"
|
||||
targetImageDisplayAspect="1x1"
|
||||
targetImagePaletteSize="6">
|
||||
<targetFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</targetFile>
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
</converterGroup>
|
||||
<converterGroup
|
||||
name="Atari 2600">
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.atari2600.AsymetricalPlayfieldConverter"
|
||||
name="Atari 2600 - Asymetrical Playfield"
|
||||
sourceFileExtensions="bin"
|
||||
targetImageDisplayAspect="4x1"
|
||||
targetImagePaletteSize="2">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
<targetFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</targetFile>
|
||||
</converter>
|
||||
</converterGroup>
|
||||
<converterGroup
|
||||
name="Atari 8-bit">
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.atari8bit.LinearBitMapAP3Converter"
|
||||
name="Atari 8-bit - AP3"
|
||||
sourceFileExtensions="ap3"
|
||||
targetImageDisplayAspect="4x1"
|
||||
targetImagePaletteSize="0">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.atari8bit.LinearBitMapAPACConverter"
|
||||
name="Atari 8-bit - APAC"
|
||||
sourceFileExtensions="apc"
|
||||
targetImageDisplayAspect="4x2"
|
||||
targetImagePaletteSize="0">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
<targetFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</targetFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.atari8bit.LinearBitMapAPCConverter"
|
||||
name="Atari 8-bit - APC"
|
||||
sourceFileExtensions="apc, plm"
|
||||
targetImageDisplayAspect="4x2"
|
||||
targetImagePaletteSize="0">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.atari8bit.LinearBitMapCINConverter"
|
||||
name="Atari 8-bit - CCI/CIN"
|
||||
sourceFileExtensions="cci, cin"
|
||||
targetImageDisplayAspect="2x1"
|
||||
targetImagePaletteSize="0">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.atari8bit.LinearBitMapCPRConverter"
|
||||
name="Atari 8-bit - CPR"
|
||||
sourceFileExtensions="cpr"
|
||||
targetImageDisplayAspect="1x1"
|
||||
targetImagePaletteSize="4">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.atari8bit.LinearBitMapGHGConverter"
|
||||
name="Atari 8-bit - GHG"
|
||||
sourceFileExtensions="ghg"
|
||||
targetImageDisplayAspect="1x1"
|
||||
targetImagePaletteSize="2">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.atari8bit.LinearBitMapGraphics8Converter"
|
||||
name="Atari 8-bit - Graphics 8"
|
||||
sourceFileExtensions="gr8"
|
||||
targetImageDisplayAspect="1x1"
|
||||
targetImagePaletteSize="2">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
<targetFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</targetFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.atari8bit.LinearBitMapGraphics9Converter"
|
||||
name="Atari 8-bit - Graphics 9"
|
||||
sourceFileExtensions="gr9"
|
||||
targetImageDisplayAspect="4x1"
|
||||
targetImagePaletteSize="16">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
<targetFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</targetFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.atari8bit.LinearBitMapGraphics10Converter"
|
||||
name="Atari 8-bit - Graphics 10"
|
||||
targetImageDisplayAspect="4x1"
|
||||
targetImagePaletteSize="16">
|
||||
<targetFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</targetFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.atari8bit.CharMapGraphics12Converter"
|
||||
name="Atari 8-bit - Graphics 12"
|
||||
targetImageDisplayAspect="2x1"
|
||||
targetImagePaletteSize="5">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.CharSetConverter.CHAR_SET_FILE">
|
||||
</sourceFile>
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.CharMapConverter.CHAR_MAP_FILE">
|
||||
</sourceFile>
|
||||
<targetFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.CharMapConverter.CHAR_SET_FILE">
|
||||
</targetFile>
|
||||
<targetFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.CharMapConverter.CHAR_MAP_FILE">
|
||||
</targetFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.atari8bit.LinearBitMapGraphics15Converter"
|
||||
name="Atari 8-bit - Graphics 15"
|
||||
targetImageDisplayAspect="2x1"
|
||||
targetImagePaletteSize="4">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
<targetFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</targetFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.atari8bit.LinearBitMapHIPConverter"
|
||||
name="Atari 8-bit - HIP"
|
||||
sourceFileExtensions="hip"
|
||||
targetImageDisplayAspect="2x1"
|
||||
targetImagePaletteSize="0">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.atari8bit.LinearBitMapHRConverter"
|
||||
name="Atari 8-bit - HR"
|
||||
sourceFileExtensions="hr"
|
||||
targetImageDisplayAspect="1x1"
|
||||
targetImagePaletteSize="4">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.atari8bit.LinearBitMapHR2Converter"
|
||||
name="Atari 8-bit - HR2"
|
||||
sourceFileExtensions="hr2"
|
||||
targetImageDisplayAspect="1x1"
|
||||
targetImagePaletteSize="4">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.atari8bit.LinearBitMapILCConverter"
|
||||
name="Atari 8-bit - ILC"
|
||||
sourceFileExtensions="ilc"
|
||||
targetImageDisplayAspect="4x1"
|
||||
targetImagePaletteSize="0">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.atari8bit.LinearBitMapINPConverter"
|
||||
name="Atari 8-bit - INP"
|
||||
sourceFileExtensions="inp"
|
||||
targetImageDisplayAspect="2x1"
|
||||
targetImagePaletteSize="8">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.atari8bit.LinearBitMapRIPConverter"
|
||||
name="Atari 8-bit - RIP"
|
||||
sourceFileExtensions="rip"
|
||||
targetImageDisplayAspect="2x1"
|
||||
targetImagePaletteSize="0">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.atari8bit.LinearBitMapTIPConverter"
|
||||
name="Atari 8-bit - TIP"
|
||||
sourceFileExtensions="tip"
|
||||
targetImageDisplayAspect="1x1"
|
||||
targetImagePaletteSize="0">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.atari8bit.LinearBitMapINTConverter"
|
||||
name="Atari 8-bit - INT"
|
||||
sourceFileExtensions="int"
|
||||
targetImageDisplayAspect="2x1"
|
||||
targetImagePaletteSize="8">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.atari8bit.LinearBitMapKoalaConverter"
|
||||
name="Atari 8-bit - Koala"
|
||||
sourceFileExtensions="pic"
|
||||
targetImageDisplayAspect="2x1"
|
||||
targetImagePaletteSize="4">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.atari8bit.LinearBitMapMCPConverter"
|
||||
name="Atari 8-bit - MCP"
|
||||
sourceFileExtensions="mcp"
|
||||
targetImageDisplayAspect="2x1"
|
||||
targetImagePaletteSize="8">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.atari8bit.LinearBitMapMicroPainterConverter"
|
||||
name="Atari 8-bit - Micropainter"
|
||||
sourceFileExtensions="mic"
|
||||
targetImageDisplayAspect="2x1"
|
||||
targetImagePaletteSize="4">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
</converterGroup>
|
||||
<converterGroup
|
||||
name="C64">
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.c64.SpriteHiresConverter"
|
||||
name="C64 - Sprites - Hires"
|
||||
sourceFileExtensions="spr"
|
||||
targetImageDisplayAspect="1x1"
|
||||
targetImagePaletteSize="2">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.c64.SpriteHiresConverter.SPRITE_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.c64.SpriteMultiColorConverter"
|
||||
name="C64 - Sprites - Multi Color"
|
||||
targetImagePaletteSize="4"
|
||||
targetImageDisplayAspect="2x1">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.c64.SpriteHiresConverter.SPRITE_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
</converterGroup>
|
||||
<converterGroup
|
||||
name="Atari ST">
|
||||
<converter
|
||||
id="com.wudsn.ide.gfx.converter.atarist.InterleavedBitMap4Planes"
|
||||
name="Atari ST - Interleaved Bitmap (4 Planes)"
|
||||
sourceFileExtensions="sts"
|
||||
targetImageDisplayAspect="1x1"
|
||||
targetImagePaletteSize="16">
|
||||
<sourceFile
|
||||
label="%com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE">
|
||||
</sourceFile>
|
||||
</converter>
|
||||
</converterGroup>
|
||||
|
||||
</extension>
|
||||
|
||||
</plugin>
|
60
com.wudsn.ide.gfx/plugin_de_DE.properties
Normal file
@ -0,0 +1,60 @@
|
||||
#Properties file for com.wudsn.ide.gfx
|
||||
com.wudsn.ide.gfx.converter.GraphicsFile.name=Grafik-Datei
|
||||
com.wudsn.ide.gfx.converter.apple2.AppleIIGraphicsFile.name=Apple II Grafik-Datei
|
||||
com.wudsn.ide.gfx.converter.atari8.Atari8GraphicsFile.name=Atari 8-bit Grafik-Datei
|
||||
com.wudsn.ide.gfx.converter.c64.C64GraphicsFile.name=C64 Grafik-Datei
|
||||
|
||||
com.wudsn.ide.gfx.editor.GraphicsEditor.name=Grafik Editor
|
||||
com.wudsn.ide.gfx.editor.GraphicsEditorOpenCommand.name=Öffnen mit Grafik Editor
|
||||
com.wudsn.ide.gfx.editor.GraphicsCategory.name=Grafik
|
||||
com.wudsn.ide.gfx.editor.ImageView.name=Bild
|
||||
com.wudsn.ide.gfx.editor.ImageViewShrinkToFit.name=Verkleinern
|
||||
com.wudsn.ide.gfx.editor.ImageViewZoomToFit.name=Vergrößern
|
||||
com.wudsn.ide.gfx.editor.ImagePaletteView.name=Bildpalette
|
||||
|
||||
com.wudsn.ide.gfx.model.ConverterMode.RAW=Rohdaten
|
||||
com.wudsn.ide.gfx.model.ConverterMode.CNV=Konverterieung
|
||||
|
||||
com.wudsn.ide.gfx.model.ConverterDirection.FILES_TO_IMAGE=Dateien zu Bild
|
||||
com.wudsn.ide.gfx.model.ConverterDirection.IMAGE_TO_FILES=Bild zu Dateien
|
||||
|
||||
com.wudsn.ide.gfx.model.Palette.TRUE_COLOR=True Color
|
||||
com.wudsn.ide.gfx.model.Palette.HIRES_1=Hires (1)
|
||||
com.wudsn.ide.gfx.model.Palette.HIRES_2=Hires (2)
|
||||
com.wudsn.ide.gfx.model.Palette.HIRES_MANUAL=Hires (manuell)
|
||||
com.wudsn.ide.gfx.model.Palette.MULTI_1=Multi (1)
|
||||
com.wudsn.ide.gfx.model.Palette.MULTI_2=Multi (2)
|
||||
com.wudsn.ide.gfx.model.Palette.MULTI_3=Multi (3)
|
||||
com.wudsn.ide.gfx.model.Palette.MULTI_4=Multi (4)
|
||||
com.wudsn.ide.gfx.model.Palette.MULTI_5=Multi (5)
|
||||
com.wudsn.ide.gfx.model.Palette.MULTI_6=Multi (6)
|
||||
com.wudsn.ide.gfx.model.Palette.MULTI_MANUAL=Multi (manuell)
|
||||
com.wudsn.ide.gfx.model.Palette.GTIA_GREY_1=GITA grau (1)
|
||||
com.wudsn.ide.gfx.model.Palette.GTIA_GREY_2=GITA grau (2)
|
||||
com.wudsn.ide.gfx.model.Palette.GTIA_GREY_MANUAL=GTIA grau (manuell)
|
||||
|
||||
com.wudsn.ide.gfx.model.PaletteType.FIXED=Fest
|
||||
com.wudsn.ide.gfx.model.PaletteType.TRUE_COLOR=True Color
|
||||
com.wudsn.ide.gfx.model.PaletteType.ATARI_DEFAULT=ATARI (standard)
|
||||
com.wudsn.ide.gfx.model.PaletteType.ATARI_REAL=ATARI (real)
|
||||
com.wudsn.ide.gfx.model.PaletteType.ATARI_XFORMER=ATARI (XFormer)
|
||||
com.wudsn.ide.gfx.model.PaletteType.C64_NORMAL=C64 (normal)
|
||||
com.wudsn.ide.gfx.model.PaletteType.C64_PAL=C64 (PAL)
|
||||
|
||||
com.wudsn.ide.gfx.converter.XYFactorDefaults.FACTOR_1_1=1 x 1
|
||||
com.wudsn.ide.gfx.converter.XYFactorDefaults.FACTOR_2_1=2 x 1
|
||||
com.wudsn.ide.gfx.converter.XYFactorDefaults.FACTOR_2_2=2 x 2
|
||||
com.wudsn.ide.gfx.converter.XYFactorDefaults.FACTOR_4_2=4 x 2
|
||||
com.wudsn.ide.gfx.converter.XYFactorDefaults.FACTOR_4_4=4 x 4
|
||||
|
||||
com.wudsn.ide.gfx.model.PixelType.HIRES=Hires
|
||||
com.wudsn.ide.gfx.model.PixelType.MULTI=Multicolor
|
||||
com.wudsn.ide.gfx.model.PixelType.GTIA_GREY=GTIA (grau)
|
||||
|
||||
com.wudsn.ide.gfx.converter.generic.CharSetConverter.CHAR_SET_FILE=Zeichensatz-Datei
|
||||
com.wudsn.ide.gfx.converter.generic.CharMapConverter.CHAR_SET_FILE=Zeichensatz-Datei
|
||||
com.wudsn.ide.gfx.converter.generic.CharMapConverter.CHAR_MAP_FILE=Char Map-Datei
|
||||
com.wudsn.ide.gfx.converter.generic.BitMapConverter.BIT_MAP_FILE=Bit Map-Datei
|
||||
com.wudsn.ide.gfx.converter.generic.TiledBitMapConverter.VIDEO_RAM_FILE=Video RAM-Datei
|
||||
com.wudsn.ide.gfx.converter.generic.TiledBitMapConverter.COLOR_RAM_FILE=Color RAM-Datei
|
||||
com.wudsn.ide.gfx.converter.c64.SpriteHiresConverter.SPRITE_FILE=Sprite-Datei
|
183
com.wudsn.ide.gfx/schema/com.wudsn.ide.gfx.converters.exsd
Normal file
@ -0,0 +1,183 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Schema file written by PDE -->
|
||||
<schema targetNamespace="com.wudsn.ide.gfx" xmlns="http://www.w3.org/2001/XMLSchema">
|
||||
<annotation>
|
||||
<appinfo>
|
||||
<meta.schema plugin="com.wudsn.ide.gfx" id="converters" name="Converters"/>
|
||||
</appinfo>
|
||||
<documentation>
|
||||
[Enter description of this extension point.]
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
<element name="extension">
|
||||
<annotation>
|
||||
<appinfo>
|
||||
<meta.element />
|
||||
</appinfo>
|
||||
</annotation>
|
||||
<complexType>
|
||||
<sequence>
|
||||
<element ref="converterGroup" minOccurs="1" maxOccurs="unbounded"/>
|
||||
</sequence>
|
||||
<attribute name="point" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="id" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="name" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
<appinfo>
|
||||
<meta.attribute translatable="true"/>
|
||||
</appinfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="converterGroup">
|
||||
<complexType>
|
||||
<sequence minOccurs="0" maxOccurs="unbounded">
|
||||
<element ref="converter"/>
|
||||
</sequence>
|
||||
<attribute name="name" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="converter">
|
||||
<complexType>
|
||||
<choice>
|
||||
<sequence>
|
||||
<element ref="sourceFile" minOccurs="1" maxOccurs="10"/>
|
||||
</sequence>
|
||||
<sequence>
|
||||
<element ref="targetFile" minOccurs="1" maxOccurs="10"/>
|
||||
</sequence>
|
||||
</choice>
|
||||
<attribute name="id" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
The id of the converter. Must be requal to its class name.
|
||||
</documentation>
|
||||
<appinfo>
|
||||
<meta.attribute kind="java" basedOn="com.wudsn.ide.gfx.converter.Converter:"/>
|
||||
</appinfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="name" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
The displayed name of the converter.
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="sourceFileExtensions" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
Possibly empty sequence of file extensions which are recognized by the converter. Entries must be lower case without leading dot. Multiple entries are separated with comma.
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="targetImagePaletteSize" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
Size of the target image palette. Must be 0 for a direct palette or a power of 2 for an indexed palette.
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="targetImageDisplayAspect" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="sourceFile">
|
||||
<complexType>
|
||||
<attribute name="label" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
<appinfo>
|
||||
<meta.attribute translatable="true"/>
|
||||
</appinfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="targetFile">
|
||||
<complexType>
|
||||
<attribute name="label" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
<appinfo>
|
||||
<meta.attribute translatable="true"/>
|
||||
</appinfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<annotation>
|
||||
<appinfo>
|
||||
<meta.section type="since"/>
|
||||
</appinfo>
|
||||
<documentation>
|
||||
[Enter the first release in which this extension point appears.]
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
<annotation>
|
||||
<appinfo>
|
||||
<meta.section type="examples"/>
|
||||
</appinfo>
|
||||
<documentation>
|
||||
[Enter extension point usage example here.]
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
<annotation>
|
||||
<appinfo>
|
||||
<meta.section type="apiinfo"/>
|
||||
</appinfo>
|
||||
<documentation>
|
||||
[Enter API information here.]
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
<annotation>
|
||||
<appinfo>
|
||||
<meta.section type="implementation"/>
|
||||
</appinfo>
|
||||
<documentation>
|
||||
[Enter information about supplied implementation of this extension point.]
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
|
||||
</schema>
|
124
com.wudsn.ide.gfx/src/com/wudsn/ide/gfx/GraphicsPlugin.java
Normal file
@ -0,0 +1,124 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.wudsn.ide.gfx;
|
||||
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
import com.wudsn.ide.base.common.AbstractIDEPlugin;
|
||||
import com.wudsn.ide.gfx.converter.ConverterConsole;
|
||||
import com.wudsn.ide.gfx.converter.ConverterRegistry;
|
||||
import com.wudsn.ide.gfx.converter.ConverterScript;
|
||||
import com.wudsn.ide.gfx.converter.ImageConverterData;
|
||||
|
||||
/**
|
||||
* The activator class controls the plug-in life cycle. This plugin uses classes
|
||||
* from the Mozilla Rhino in the classes {@link ConverterScript} and
|
||||
* {@link ImageConverterData}. See <a href=
|
||||
* "https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Download_Rhino"
|
||||
* >https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/
|
||||
* Download_Rhino"</a>.
|
||||
*/
|
||||
public final class GraphicsPlugin extends AbstractIDEPlugin {
|
||||
|
||||
/**
|
||||
* The plugin id.
|
||||
*/
|
||||
public static final String ID = "com.wudsn.ide.gfx";
|
||||
|
||||
/**
|
||||
* Creates a new instance. Must be public for dynamic instantiation.
|
||||
*/
|
||||
private static GraphicsPlugin plugin;
|
||||
|
||||
/**
|
||||
* The converter registry.
|
||||
*/
|
||||
private ConverterRegistry converterRegistry;
|
||||
|
||||
/**
|
||||
* The converter console.
|
||||
*/
|
||||
private ConverterConsole converterConsole;
|
||||
|
||||
/**
|
||||
* The constructor
|
||||
*/
|
||||
public GraphicsPlugin() {
|
||||
converterRegistry = new ConverterRegistry();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPluginId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void start(BundleContext context) throws Exception {
|
||||
super.start(context);
|
||||
plugin = this;
|
||||
converterRegistry.init();
|
||||
converterConsole = new ConverterConsole();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
plugin = null;
|
||||
super.stop(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the shared plugin instance
|
||||
*
|
||||
* @return The plug-in, not <code>null</code>.
|
||||
*/
|
||||
public static GraphicsPlugin getInstance() {
|
||||
if (plugin == null) {
|
||||
throw new IllegalStateException("Plugin not initialized or already stopped");
|
||||
}
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the converter registry for this plugin.
|
||||
*
|
||||
* @return The converter registry, not <code>null</code>.
|
||||
*/
|
||||
public ConverterRegistry getConverterRegistry() {
|
||||
if (converterRegistry == null) {
|
||||
throw new IllegalStateException("Field 'converterRegistry' must not be null.");
|
||||
}
|
||||
return converterRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the converter console for this plugin.
|
||||
*
|
||||
* @return The converter console, not <code>null</code>.
|
||||
*/
|
||||
public ConverterConsole getConverterConsole() {
|
||||
return converterConsole;
|
||||
}
|
||||
}
|
110
com.wudsn.ide.gfx/src/com/wudsn/ide/gfx/Texts.java
Normal file
@ -0,0 +1,110 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.wudsn.ide.gfx;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
import com.wudsn.ide.gfx.editor.GraphicsEditor;
|
||||
|
||||
/**
|
||||
* Class which holds the localized text constants.
|
||||
*
|
||||
* @author Peter Dell
|
||||
*/
|
||||
public final class Texts extends NLS {
|
||||
|
||||
public static String FILE_SECTION_FIELD_SIZE_LABEL;
|
||||
public static String FILE_SECTION_FIELD_SIZE_NO_DATA;
|
||||
public static String FILE_SECTION_FIELD_OFFSET_LABEL;
|
||||
|
||||
public static String FIND_DEFAULT_FILE_CONVERTER_BUTTON_TOOLTIP;
|
||||
public static String CREATE_CONVERSION_BUTTON_TOOLTIP;
|
||||
|
||||
public static String FILES_CONVERTER_DATA_VIEW_TAB;
|
||||
public static String IMAGE_CONVERTER_DATA_VIEW_TAB;
|
||||
|
||||
public static String CONVERTER_PARAMETERS_CONVERTER_ID_LABEL;
|
||||
public static String REFRESH_BUTTON_TOOLTIP;
|
||||
public static String SAVE_IMAGE_BUTTON_TOOLTIP;
|
||||
public static String SAVE_FILES_BUTTON_TOOLTIP;
|
||||
|
||||
public static String CONVERTER_PARAMETERS_BIT_MAP_FILE_PATH_LABEL;
|
||||
public static String CONVERTER_PARAMETERS_BIT_MAP_FILE_SECTION_LABEL;
|
||||
public static String CONVERTER_PARAMETERS_CHAR_SET_FILE_PATH_LABEL;
|
||||
public static String CONVERTER_PARAMETERS_CHAR_SET_FILE_SECTION_LABEL;
|
||||
public static String CONVERTER_PARAMETERS_CHAR_MAP_FILE_PATH_LABEL;
|
||||
public static String CONVERTER_PARAMETERS_CHAR_MAP_FILE_SECTION_LABEL;
|
||||
public static String CONVERTER_PARAMETERS_COLOR_MAP_FILE_PATH_LABEL;
|
||||
public static String CONVERTER_PARAMETERS_COLOR_MAP_FILE_SECTION_LABEL;
|
||||
public static String CONVERTER_PARAMETERS_IMAGE_FILE_PATH_LABEL;
|
||||
|
||||
// Files to image texts
|
||||
public static String CONVERTER_PARAMETERS_COLUMNS_LABEL;
|
||||
public static String CONVERTER_PARAMETERS_ROWS_LABEL;
|
||||
|
||||
public static String CONVERTER_PARAMETERS_SPACING_COLOR_LABEL;
|
||||
public static String CONVERTER_PARAMETERS_SPACING_WIDTH_LABEL;
|
||||
|
||||
// Image to Files texts
|
||||
public static String CONVERTER_PARAMETERS_USE_DEFAULT_SCRIPT_LABEL;
|
||||
public static String CONVERTER_PARAMETERS_SCRIPT_LABEL;
|
||||
|
||||
public static String CONVERTER_DATA_IMAGE_DATA_WIDTH_LABEL;
|
||||
public static String CONVERTER_DATA_IMAGE_DATA_HEIGHT_LABEL;
|
||||
|
||||
public static String CONVERTER_PARAMETERS_IMAGE_ASPECT_LABEL;
|
||||
|
||||
public static String CREATE_CONVERSION_DIALOG_TITLE;
|
||||
public static String CREATE_CONVERSION_DIALOG_MESSAGE;
|
||||
public static String SAVE_AS_DIALOG_TITLE;
|
||||
public static String SAVE_AS_DIALOG_MESSAGE;
|
||||
|
||||
public static String CONVERTER_CONSOLE_TITLE;
|
||||
|
||||
public static String IMAGE_VIEW_ASPECT_LABEL;
|
||||
|
||||
public static String IMAGE_PALETTE_VIEW_EDIT_COLOR_ACTION_LABEL;
|
||||
public static String IMAGE_PALETTE_VIEW_EDIT_COLOR_ACTION_TOOLTIP;
|
||||
public static String IMAGE_PALETTE_VIEW_UNUSED_COLORS_ACTION_LABEL;
|
||||
public static String IMAGE_PALETTE_VIEW_UNUSED_COLORS_ACTION_TOOLTIP;
|
||||
public static String IMAGE_PALETTE_VIEW_INFO_NO_IMAGE;
|
||||
public static String IMAGE_PALETTE_VIEW_INFO_INDEXED_PALETTE_IMAGE;
|
||||
public static String IMAGE_PALETTE_VIEW_INFO_DIRECT_PALETTE_IMAGE;
|
||||
|
||||
public static String IMAGE_PALETTE_VIEW_COLUMN_INDEX_TEXT;
|
||||
public static String IMAGE_PALETTE_VIEW_COLUMN_COLOR_HEX_TEXT;
|
||||
public static String IMAGE_PALETTE_VIEW_COLUMN_COLOR_BINARY_TEXT;
|
||||
public static String IMAGE_PALETTE_VIEW_COLUMN_RGB_COLOR_TEXT;
|
||||
public static String IMAGE_PALETTE_VIEW_COLUMN_COLOR_COUNT_TEXT;
|
||||
public static String IMAGE_PALETTE_VIEW_COLUMN_COLOR_COUNT_PERCENT_TEXT;
|
||||
|
||||
/**
|
||||
* Messages for {@link GraphicsEditor}.
|
||||
*/
|
||||
public static String MESSAGE_S100 = "Source files loaded and converted in {0} ms";
|
||||
public static String MESSAGE_E400;
|
||||
|
||||
/**
|
||||
* Initializes the constants.
|
||||
*/
|
||||
static {
|
||||
NLS.initializeMessages(Texts.class.getName(), Texts.class);
|
||||
}
|
||||
}
|
73
com.wudsn.ide.gfx/src/com/wudsn/ide/gfx/Texts.properties
Normal file
@ -0,0 +1,73 @@
|
||||
FILE_SECTION_FIELD_SIZE_LABEL=Size
|
||||
FILE_SECTION_FIELD_SIZE_NO_DATA=No data
|
||||
FILE_SECTION_FIELD_OFFSET_LABEL=Offset
|
||||
|
||||
FIND_DEFAULT_FILE_CONVERTER_BUTTON_TOOLTIP=Find Converter
|
||||
CREATE_CONVERSION_BUTTON_TOOLTIP=Create Conversion...
|
||||
|
||||
# Tabs.
|
||||
FILES_CONVERTER_DATA_VIEW_TAB=Files to Image
|
||||
IMAGE_CONVERTER_DATA_VIEW_TAB=Image to Files
|
||||
|
||||
# Tab content
|
||||
CONVERTER_PARAMETERS_CONVERTER_ID_LABEL=Converter
|
||||
REFRESH_BUTTON_TOOLTIP=Refresh
|
||||
SAVE_IMAGE_BUTTON_TOOLTIP=Save Image
|
||||
SAVE_FILES_BUTTON_TOOLTIP=Save Files
|
||||
|
||||
CONVERTER_PARAMETERS_BIT_MAP_FILE_PATH_LABEL=Bit Map
|
||||
CONVERTER_PARAMETERS_BIT_MAP_FILE_SECTION_LABEL=Bit Map
|
||||
CONVERTER_PARAMETERS_CHAR_SET_FILE_PATH_LABEL=Char Set
|
||||
CONVERTER_PARAMETERS_CHAR_SET_FILE_SECTION_LABEL=Char Set
|
||||
CONVERTER_PARAMETERS_CHAR_MAP_FILE_PATH_LABEL=Char Map
|
||||
CONVERTER_PARAMETERS_CHAR_MAP_FILE_SECTION_LABEL=Char Map
|
||||
CONVERTER_PARAMETERS_COLOR_MAP_FILE_PATH_LABEL=Color Map
|
||||
CONVERTER_PARAMETERS_COLOR_MAP_FILE_SECTION_LABEL=Color Map
|
||||
CONVERTER_PARAMETERS_IMAGE_FILE_PATH_LABEL=Image
|
||||
|
||||
CONVERTER_PARAMETERS_COLUMNS_LABEL=Columns
|
||||
CONVERTER_PARAMETERS_ROWS_LABEL=Rows
|
||||
|
||||
CONVERTER_PARAMETERS_SPACING_COLOR_LABEL=Spacing Color
|
||||
CONVERTER_PARAMETERS_SPACING_WIDTH_LABEL=Spacing Width
|
||||
|
||||
CONVERTER_PARAMETERS_USE_DEFAULT_SCRIPT_LABEL=Use Default Script
|
||||
CONVERTER_PARAMETERS_SCRIPT_LABEL=Script
|
||||
|
||||
CONVERTER_DATA_IMAGE_DATA_WIDTH_LABEL=Width
|
||||
CONVERTER_DATA_IMAGE_DATA_HEIGHT_LABEL=Height
|
||||
CONVERTER_PARAMETERS_IMAGE_ASPECT_LABEL=Aspect
|
||||
|
||||
# Dialogs.
|
||||
|
||||
CREATE_CONVERSION_DIALOG_TITLE=Create Conversion
|
||||
CREATE_CONVERSION_DIALOG_MESSAGE=Creates a conversion file with the current settings, closes the current editor and opens the file a a new editor
|
||||
|
||||
SAVE_AS_DIALOG_TITLE=Save As
|
||||
SAVE_AS_DIALOG_MESSAGE=Save the current conversion file to another location
|
||||
|
||||
# Converter Console
|
||||
CONVERTER_CONSOLE_TITLE=Converter Console
|
||||
|
||||
# Image View.
|
||||
IMAGE_VIEW_ASPECT_LABEL=Aspect
|
||||
|
||||
# Image Palette View.
|
||||
IMAGE_PALETTE_VIEW_EDIT_COLOR_ACTION_LABEL=Edit
|
||||
IMAGE_PALETTE_VIEW_EDIT_COLOR_ACTION_TOOLTIP=Edit the color of the currently selected table entry or select presets
|
||||
IMAGE_PALETTE_VIEW_UNUSED_COLORS_ACTION_LABEL=Unused
|
||||
IMAGE_PALETTE_VIEW_UNUSED_COLORS_ACTION_TOOLTIP=Toggle the display of the used colors in the indexed palette
|
||||
IMAGE_PALETTE_VIEW_INFO_NO_IMAGE=No image
|
||||
IMAGE_PALETTE_VIEW_INFO_INDEXED_PALETTE_IMAGE={0} bit indexed palette. {1} out of {2} colors used.
|
||||
IMAGE_PALETTE_VIEW_INFO_DIRECT_PALETTE_IMAGE={0} bit direct palette. {1} colors used.
|
||||
|
||||
IMAGE_PALETTE_VIEW_COLUMN_INDEX_TEXT=Index
|
||||
IMAGE_PALETTE_VIEW_COLUMN_COLOR_HEX_TEXT=Hex
|
||||
IMAGE_PALETTE_VIEW_COLUMN_COLOR_BINARY_TEXT=Binary
|
||||
IMAGE_PALETTE_VIEW_COLUMN_RGB_COLOR_TEXT=Color
|
||||
IMAGE_PALETTE_VIEW_COLUMN_COLOR_COUNT_TEXT=Count
|
||||
IMAGE_PALETTE_VIEW_COLUMN_COLOR_COUNT_PERCENT_TEXT=Percent
|
||||
|
||||
# Messages
|
||||
MESSAGE_E400=Unused
|
||||
MESSAGE_S100=Source files loaded and converted in {0} ms
|
@ -0,0 +1,72 @@
|
||||
FILE_SECTION_FIELD_SIZE_LABEL=Größe
|
||||
FILE_SECTION_FIELD_SIZE_NO_DATA=Keine Daten
|
||||
FILE_SECTION_FIELD_OFFSET_LABEL=Offset
|
||||
|
||||
FIND_DEFAULT_FILE_CONVERTER_BUTTON_TOOLTIP=Finde Konverter
|
||||
CREATE_CONVERSION_BUTTON_TOOLTIP=Konvertierung anlegen...
|
||||
|
||||
# Tabs.
|
||||
FILES_CONVERTER_DATA_VIEW_TAB=Datei nach Bild
|
||||
IMAGE_CONVERTER_DATA_VIEW_TAB=Bild nach Datei
|
||||
|
||||
# Tab content
|
||||
CONVERTER_PARAMETERS_CONVERTER_ID_LABEL=Konverter
|
||||
REFRESH_BUTTON_TOOLTIP=Aktualisieren
|
||||
SAVE_IMAGE_BUTTON_TOOLTIP=Bild speichern
|
||||
SAVE_FILES_BUTTON_TOOLTIP=Dateien speichern
|
||||
|
||||
CONVERTER_PARAMETERS_BIT_MAP_FILE_PATH_LABEL=Bit Map
|
||||
CONVERTER_PARAMETERS_BIT_MAP_FILE_SECTION_LABEL=Bit Map
|
||||
CONVERTER_PARAMETERS_CHAR_SET_FILE_PATH_LABEL=Zeichensatz
|
||||
CONVERTER_PARAMETERS_CHAR_SET_FILE_SECTION_LABEL=Zeichensatz
|
||||
CONVERTER_PARAMETERS_CHAR_MAP_FILE_PATH_LABEL=Char Map
|
||||
CONVERTER_PARAMETERS_CHAR_MAP_FILE_SECTION_LABEL=Char Map
|
||||
CONVERTER_PARAMETERS_COLOR_MAP_FILE_PATH_LABEL=Color Map
|
||||
CONVERTER_PARAMETERS_COLOR_MAP_FILE_SECTION_LABEL=Color Map
|
||||
CONVERTER_PARAMETERS_IMAGE_FILE_PATH_LABEL=Bild
|
||||
|
||||
CONVERTER_PARAMETERS_COLUMNS_LABEL=Spalten
|
||||
CONVERTER_PARAMETERS_ROWS_LABEL=Zeilen
|
||||
|
||||
CONVERTER_PARAMETERS_SPACING_COLOR_LABEL=Freiraumfarbe
|
||||
CONVERTER_PARAMETERS_SPACING_WIDTH_LABEL=Freiraumbreite
|
||||
|
||||
CONVERTER_PARAMETERS_USE_DEFAULT_SCRIPT_LABEL=Standard Skript verwenden
|
||||
CONVERTER_PARAMETERS_SCRIPT_LABEL=Skript
|
||||
|
||||
CONVERTER_DATA_IMAGE_DATA_WIDTH_LABEL=Breite
|
||||
CONVERTER_DATA_IMAGE_DATA_HEIGHT_LABEL=Höhe
|
||||
CONVERTER_PARAMETERS_IMAGE_ASPECT_LABEL=Seitenverhältnis
|
||||
|
||||
# Dialogs.
|
||||
|
||||
CREATE_CONVERSION_DIALOG_TITLE=Konvertierung anlegen
|
||||
CREATE_CONVERSION_DIALOG_MESSAGE=Legt eine Konvertierungs-Datei mit den aktuellen Einstellungen an, schließt den aktuellen Editor und öffnet die neue Datei in einem neuen Editor
|
||||
|
||||
SAVE_AS_DIALOG_TITLE=Speichern unter
|
||||
SAVE_AS_DIALOG_MESSAGE=Speicher die aktuelle Konvertierungs-Datei an einen anderen Ort
|
||||
|
||||
# Converter Console
|
||||
CONVERTER_CONSOLE_TITLE=Konverter Konsole
|
||||
|
||||
# Image View.
|
||||
IMAGE_VIEW_ASPECT_LABEL=Seitenverhältnis
|
||||
|
||||
# Image Palette View.
|
||||
IMAGE_PALETTE_VIEW_EDIT_COLOR_ACTION_LABEL=Bearbeiten
|
||||
IMAGE_PALETTE_VIEW_EDIT_COLOR_ACTION_TOOLTIP=Bearbeitet die Farbe des aktuelle ausgewählten Tabelleneintrages oder wählt eine der Voreinstellungen aus
|
||||
IMAGE_PALETTE_VIEW_UNUSED_COLORS_ACTION_LABEL=Nicht verwendet
|
||||
IMAGE_PALETTE_VIEW_UNUSED_COLORS_ACTION_TOOLTIP=Schaltet die Anzeige der nicht verwendeten Farben in der Index-Palette um
|
||||
IMAGE_PALETTE_VIEW_INFO_NO_IMAGE=Kein Bild
|
||||
IMAGE_PALETTE_VIEW_INFO_INDEXED_PALETTE_IMAGE={0} Bit Index-Palette. {1} von {2} Farben verwendet.
|
||||
IMAGE_PALETTE_VIEW_INFO_DIRECT_PALETTE_IMAGE={0} Bit Direkt-Palette. {1} Farben verwendent.
|
||||
|
||||
IMAGE_PALETTE_VIEW_COLUMN_INDEX_TEXT=Index
|
||||
IMAGE_PALETTE_VIEW_COLUMN_COLOR_HEX_TEXT=Hex
|
||||
IMAGE_PALETTE_VIEW_COLUMN_COLOR_BINARY_TEXT=Binär
|
||||
IMAGE_PALETTE_VIEW_COLUMN_RGB_COLOR_TEXT=Farbe
|
||||
IMAGE_PALETTE_VIEW_COLUMN_COLOR_COUNT_TEXT=Anzahl
|
||||
IMAGE_PALETTE_VIEW_COLUMN_COLOR_COUNT_PERCENT_TEXT=Prozent
|
||||
|
||||
# Messages
|
||||
MESSAGE_E400=Nicht verwendet
|
182
com.wudsn.ide.gfx/src/com/wudsn/ide/gfx/converter/Converter.java
Normal file
@ -0,0 +1,182 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.wudsn.ide.gfx.converter;
|
||||
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
|
||||
import com.wudsn.ide.gfx.model.Palette;
|
||||
|
||||
public abstract class Converter {
|
||||
|
||||
private ConverterDefinition definition;
|
||||
|
||||
/**
|
||||
* Constants for 1 bit pixels. Constants are defined as int to ensure no
|
||||
* sign extension takes place when anding with byte values.
|
||||
*/
|
||||
protected static final int[] mask_1bit = new int[] { 0x80, 0x40, 0x20,
|
||||
0x10, 0x08, 0x04, 0x02, 0x01 };
|
||||
protected static final int[] shift_1bit = new int[] { 7, 6, 5, 4, 3, 2, 1,
|
||||
0 };
|
||||
|
||||
/**
|
||||
* Constants for 2 bit pixels.Constants are defined as int to ensure no sign
|
||||
* extension takes place when anding with byte values.
|
||||
*/
|
||||
protected static final int[] mask_2bit = new int[] { 0xc0, 0x30, 0x0c, 0x03 };
|
||||
protected static final int[] shift_2bit = new int[] { 6, 4, 2, 0 };
|
||||
|
||||
/**
|
||||
* Constants for 4 bit pixels.Constants are defined as int to ensure no sign
|
||||
* extension takes place when anding with byte values.
|
||||
*/
|
||||
protected static final int[] mask_4bit = new int[] { 0xf0, 0x0f };
|
||||
protected static final int[] shift_4bit = new int[] { 4, 0 };
|
||||
|
||||
/**
|
||||
* Creation is protected.
|
||||
*/
|
||||
protected Converter() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the definition of the Converter. Called by {@link ConverterRegistry}
|
||||
* only.
|
||||
*
|
||||
* @param definition
|
||||
* The definition if the Converter, not <code>null</code>.
|
||||
*/
|
||||
final void setDefinition(ConverterDefinition definition) {
|
||||
if (definition == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'type' must not be null.");
|
||||
}
|
||||
this.definition = definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the definition of the Converter.
|
||||
*
|
||||
* @return The definition of the Converter, not <code>null</code>.
|
||||
*/
|
||||
public final ConverterDefinition getDefinition() {
|
||||
if (definition == null) {
|
||||
throw new IllegalStateException(
|
||||
"Field 'definition' must not be null.");
|
||||
}
|
||||
return definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the given byte array can be converted to an image by this
|
||||
* converter.
|
||||
*
|
||||
* @param bytes
|
||||
* The byte array, not empty and not <code>null</code>.
|
||||
*
|
||||
* @return <code>true</code> if the given byte array can be converted to an
|
||||
* image by this converter, <code>false</code> otherwise.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public boolean canConvertToImage(byte[] bytes) {
|
||||
if (bytes == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'bytes' must not be null.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the byte array content to image size and palette. Implementation
|
||||
* shall call
|
||||
* {@link #setImageSizeAndPalette(FilesConverterData, int, int, Palette, RGB[])}
|
||||
* to set the corresponding values.
|
||||
*
|
||||
* @param data
|
||||
* The file converter data container to be filled, not
|
||||
* <code>null</code>.
|
||||
* @param bytes
|
||||
* The byte array, not empty and not <code>null</code>.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public void convertToImageSizeAndPalette(FilesConverterData data,
|
||||
byte[] bytes) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current converter, applies its defaults and then sets the image
|
||||
* size and palette.
|
||||
*
|
||||
* @param data
|
||||
* The file converter data container to be filled, not
|
||||
* <code>null</code>.
|
||||
* @param columns
|
||||
* The number of columns.
|
||||
* @param rows
|
||||
* The number of rows.
|
||||
* @param palette
|
||||
* The palette, not <code>null</code>.
|
||||
* @param paletteColors
|
||||
* The palette colors or not <code>null</code> if palette is
|
||||
* {@link Palette#TRUE_COLOR}.
|
||||
*/
|
||||
protected final void setImageSizeAndPalette(FilesConverterData data,
|
||||
int columns, int rows, Palette palette, RGB[] paletteColors) {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'data' must not be null.");
|
||||
}
|
||||
if (palette == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'palette' must not be null.");
|
||||
}
|
||||
if (paletteColors == null) {
|
||||
if (!palette.equals(Palette.TRUE_COLOR)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'paletteColors' must not be null if palette is not TRUE_COLOR.");
|
||||
}
|
||||
paletteColors = new RGB[0];
|
||||
}
|
||||
FilesConverterParameters parameters;
|
||||
parameters = data.getParameters();
|
||||
parameters.setConverterId(this.getClass().getName());
|
||||
parameters.setDisplayAspect(getDefinition()
|
||||
.getTargetImageDisplayAspect());
|
||||
parameters.setColumns(columns);
|
||||
parameters.setRows(rows);
|
||||
parameters.setPalette(palette);
|
||||
parameters.setPaletteRGBs(paletteColors);
|
||||
}
|
||||
|
||||
public abstract void convertToImageDataSize(FilesConverterData data);
|
||||
|
||||
/**
|
||||
* Converts the files to an image.
|
||||
*
|
||||
* @param data
|
||||
* The data, not <code>null</code>.
|
||||
* @return <code>true</code> if an image was created and can be saved (i.e.
|
||||
* pixels set), <code>false</code> if not.
|
||||
*/
|
||||
public abstract boolean convertToImageData(FilesConverterData data);
|
||||
}
|
@ -0,0 +1,131 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.wudsn.ide.gfx.converter;
|
||||
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.swt.graphics.ImageData;
|
||||
|
||||
/**
|
||||
* Base class for {@link FilesConverterData} and {@link ImageConverterData}.
|
||||
*
|
||||
* @author Peter Dell
|
||||
*
|
||||
*/
|
||||
public abstract class ConverterCommonData {
|
||||
|
||||
protected final ConverterData converterData;
|
||||
|
||||
private int imageDataWidth;
|
||||
private int imageDataHeight;
|
||||
protected ImageData imageData;
|
||||
private ImageColorHistogram imageColorHistogram;
|
||||
|
||||
ConverterCommonData(ConverterData converterData) {
|
||||
if (converterData == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'converterData' must not be null.");
|
||||
}
|
||||
|
||||
this.converterData = converterData;
|
||||
imageData = null;
|
||||
imageColorHistogram = new ImageColorHistogram();
|
||||
}
|
||||
|
||||
public final IPath getFilePathPrefix() {
|
||||
IPath result;
|
||||
if (converterData.isValid()) {
|
||||
result = converterData.getFile().getFullPath()
|
||||
.removeLastSegments(1);
|
||||
} else {
|
||||
result = new Path("");
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public abstract boolean isCreateConversionEnabled();
|
||||
|
||||
public abstract boolean isValid();
|
||||
|
||||
public abstract boolean isRefreshEnabled();
|
||||
|
||||
protected void clear() {
|
||||
imageData = null;
|
||||
imageColorHistogram.clear();
|
||||
}
|
||||
|
||||
public final void setImageDataWidth(int width) {
|
||||
this.imageDataWidth = width;
|
||||
}
|
||||
|
||||
public final int getImageDataWidth() {
|
||||
return imageDataWidth;
|
||||
}
|
||||
|
||||
public final void setImageDataHeight(int height) {
|
||||
this.imageDataHeight = height;
|
||||
}
|
||||
|
||||
public final int getImageDataHeight() {
|
||||
return imageDataHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the image data.
|
||||
*
|
||||
* @param imageData
|
||||
* The image data, may be <code>null</code>.
|
||||
*/
|
||||
final void setImageData(ImageData imageData) {
|
||||
this.imageData = imageData;
|
||||
imageColorHistogram = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the image data.
|
||||
*
|
||||
* @return The image data or <code>null</code>.
|
||||
*/
|
||||
public final ImageData getImageData() {
|
||||
return imageData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the image color histogram.
|
||||
*
|
||||
* @param imageColorHistogram
|
||||
* The image color histogram, may be <code>null</code>.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
final void setImageColorHistogram(ImageColorHistogram imageColorHistogram) {
|
||||
this.imageColorHistogram = imageColorHistogram;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the image color histogram.
|
||||
*
|
||||
* @return The image color histogram, not <code>null</code>.
|
||||
*/
|
||||
public final ImageColorHistogram getImageColorHistogram() {
|
||||
return imageColorHistogram;
|
||||
}
|
||||
}
|
@ -0,0 +1,234 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.wudsn.ide.gfx.converter;
|
||||
|
||||
import com.wudsn.ide.gfx.model.Aspect;
|
||||
import com.wudsn.ide.gfx.model.GraphicsPropertiesSerializer;
|
||||
|
||||
public abstract class ConverterCommonParameters {
|
||||
|
||||
/**
|
||||
* Names of the attributes.
|
||||
*
|
||||
* @author Peter Dell
|
||||
*
|
||||
*/
|
||||
public static final class Attributes {
|
||||
|
||||
/**
|
||||
* Creation is private.
|
||||
*/
|
||||
private Attributes() {
|
||||
}
|
||||
|
||||
public static final String CONVERTER_ID = "converterId";
|
||||
|
||||
public static final String IMAGE_ASPECT = "imageAspect";
|
||||
|
||||
// Display attributes.
|
||||
public static final String DISPLAY_ASPECT = "displayAspect";
|
||||
public static final String DISPLAY_SHRINK_TO_FIT = "displayShrinkToFit";
|
||||
public static final String DISPLAY_ZOOM_TO_FIT = "displayZoomToFit";
|
||||
}
|
||||
|
||||
/**
|
||||
* Defaults of the attributes.
|
||||
*
|
||||
* @author Peter Dell
|
||||
*
|
||||
*/
|
||||
private static final class Defaults {
|
||||
|
||||
/**
|
||||
* Creation is protected.
|
||||
*/
|
||||
private Defaults() {
|
||||
}
|
||||
|
||||
public static final String CONVERTER_ID = "";
|
||||
|
||||
public static final Aspect IMAGE_ASPECT = new Aspect(1, 1);
|
||||
public static final Aspect DISPLAY_ASPECT = new Aspect(1, 1);
|
||||
public static final boolean DISPLAY_SHRINK_TO_FIT = false;
|
||||
public static final boolean DISPLAY_ZOOM_TO_FIT = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Message ids of the attributes.
|
||||
*
|
||||
* @author Peter Dell
|
||||
*
|
||||
*/
|
||||
public static final class MessageIds {
|
||||
|
||||
/**
|
||||
* Creation is private.
|
||||
*/
|
||||
private MessageIds() {
|
||||
}
|
||||
|
||||
public static final int CONVERTER_ID = 1000;
|
||||
public static final int IMAGE_ASPECT = 1001;
|
||||
public static final int DISPLAY_ASPECT = 1002;
|
||||
}
|
||||
|
||||
protected String converterId;
|
||||
|
||||
private Aspect imageAspect;
|
||||
private Aspect displayAspect;
|
||||
private boolean displayShrinkToFit;
|
||||
private boolean displayZoomToFit;
|
||||
|
||||
ConverterCommonParameters() {
|
||||
}
|
||||
|
||||
protected void setDefaults() {
|
||||
converterId = Defaults.CONVERTER_ID;
|
||||
imageAspect = Defaults.IMAGE_ASPECT;
|
||||
displayAspect = Defaults.DISPLAY_ASPECT;
|
||||
displayShrinkToFit = Defaults.DISPLAY_SHRINK_TO_FIT;
|
||||
displayZoomToFit = Defaults.DISPLAY_ZOOM_TO_FIT;
|
||||
}
|
||||
|
||||
public abstract void setConverterId(String value);
|
||||
|
||||
|
||||
public final String getConverterId() {
|
||||
return converterId;
|
||||
}
|
||||
|
||||
public final void setImageAspect(Aspect value) {
|
||||
if (value == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'value' must not be null.");
|
||||
}
|
||||
this.imageAspect = value;
|
||||
}
|
||||
|
||||
public final Aspect getImageAspect() {
|
||||
return imageAspect;
|
||||
}
|
||||
|
||||
public final void setDisplayAspect(Aspect value) {
|
||||
if (value == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'value' must not be null.");
|
||||
}
|
||||
this.displayAspect = value;
|
||||
}
|
||||
|
||||
public final Aspect getDisplayAspect() {
|
||||
return displayAspect;
|
||||
}
|
||||
|
||||
public final void setDisplayShrinkToFit(boolean displayShrinkToFit) {
|
||||
this.displayShrinkToFit = displayShrinkToFit;
|
||||
}
|
||||
|
||||
public final boolean isDisplayShrinkToFit() {
|
||||
return displayShrinkToFit;
|
||||
}
|
||||
|
||||
public final void setDisplayZoomToFit(boolean displayZoomToFit) {
|
||||
this.displayZoomToFit = displayZoomToFit;
|
||||
}
|
||||
|
||||
public final boolean isDisplayZoomToFit() {
|
||||
return displayZoomToFit;
|
||||
}
|
||||
|
||||
protected void copyTo(ConverterCommonParameters target) {
|
||||
if (target == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'target' must not be null.");
|
||||
}
|
||||
|
||||
target.setConverterId(converterId);
|
||||
target.setImageAspect(imageAspect);
|
||||
target.setDisplayAspect(displayAspect);
|
||||
target.setDisplayShrinkToFit(displayShrinkToFit);
|
||||
target.setDisplayZoomToFit(displayZoomToFit);
|
||||
}
|
||||
|
||||
protected boolean equals(ConverterCommonParameters target) {
|
||||
if (target == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'target' must not be null.");
|
||||
}
|
||||
boolean result;
|
||||
|
||||
result = target.getImageAspect().equals(imageAspect);
|
||||
result = result && target.getDisplayAspect().equals(displayAspect);
|
||||
result = result && target.isDisplayShrinkToFit() == displayShrinkToFit;
|
||||
result = result && target.isDisplayZoomToFit() == displayZoomToFit;
|
||||
return result;
|
||||
}
|
||||
|
||||
protected void serialize(GraphicsPropertiesSerializer serializer, String key) {
|
||||
if (serializer == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'serializer' must not be null.");
|
||||
}
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'key' must not be null.");
|
||||
}
|
||||
GraphicsPropertiesSerializer ownSerializer;
|
||||
|
||||
ownSerializer = new GraphicsPropertiesSerializer();
|
||||
ownSerializer.writeString(Attributes.CONVERTER_ID, converterId);
|
||||
ownSerializer.writeAspect(Attributes.IMAGE_ASPECT, imageAspect);
|
||||
ownSerializer.writeAspect(Attributes.DISPLAY_ASPECT, displayAspect);
|
||||
ownSerializer.writeBoolean(Attributes.DISPLAY_SHRINK_TO_FIT,
|
||||
displayShrinkToFit);
|
||||
ownSerializer.writeBoolean(Attributes.DISPLAY_ZOOM_TO_FIT,
|
||||
displayZoomToFit);
|
||||
|
||||
serializer.writeProperties(key, ownSerializer);
|
||||
}
|
||||
|
||||
protected void deserialize(GraphicsPropertiesSerializer serializer,
|
||||
String key) {
|
||||
if (serializer == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'serializer' must not be null.");
|
||||
}
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
GraphicsPropertiesSerializer ownSerializer;
|
||||
ownSerializer = new GraphicsPropertiesSerializer();
|
||||
serializer.readProperties(key, ownSerializer);
|
||||
|
||||
setConverterId(ownSerializer.readString(Attributes.CONVERTER_ID,
|
||||
Defaults.CONVERTER_ID));
|
||||
|
||||
imageAspect = ownSerializer.readXYFactor(Attributes.DISPLAY_ASPECT,
|
||||
Defaults.IMAGE_ASPECT);
|
||||
displayAspect = ownSerializer.readXYFactor(Attributes.DISPLAY_ASPECT,
|
||||
Defaults.DISPLAY_ASPECT);
|
||||
displayShrinkToFit = ownSerializer.readBoolean(
|
||||
Attributes.DISPLAY_SHRINK_TO_FIT,
|
||||
Defaults.DISPLAY_SHRINK_TO_FIT);
|
||||
displayZoomToFit = ownSerializer.readBoolean(
|
||||
Attributes.DISPLAY_ZOOM_TO_FIT, Defaults.DISPLAY_ZOOM_TO_FIT);
|
||||
}
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.wudsn.ide.gfx.converter;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.eclipse.ui.console.ConsolePlugin;
|
||||
import org.eclipse.ui.console.IConsole;
|
||||
import org.eclipse.ui.console.IConsoleManager;
|
||||
import org.eclipse.ui.console.IConsoleView;
|
||||
import org.eclipse.ui.console.MessageConsole;
|
||||
import org.eclipse.ui.console.MessageConsoleStream;
|
||||
|
||||
import com.wudsn.ide.gfx.Texts;
|
||||
|
||||
/**
|
||||
* The console to show the user the output from the converter.
|
||||
*
|
||||
* @author Peter Dell
|
||||
*/
|
||||
public final class ConverterConsole {
|
||||
|
||||
private IConsoleManager consoleManager;
|
||||
public MessageConsole console;
|
||||
|
||||
private MessageConsoleStream messageStream;
|
||||
private PrintStream printStream;
|
||||
|
||||
/**
|
||||
* Create a new console-window.
|
||||
*
|
||||
*/
|
||||
public ConverterConsole() {
|
||||
consoleManager = ConsolePlugin.getDefault().getConsoleManager();
|
||||
console = new MessageConsole(Texts.CONVERTER_CONSOLE_TITLE, null);
|
||||
consoleManager.addConsoles(new IConsole[] { console });
|
||||
|
||||
messageStream = console.newMessageStream();
|
||||
messageStream.setActivateOnWrite(false);
|
||||
messageStream.print("");
|
||||
printStream = new PrintStream(messageStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Brings this console view instance to front in the console view editor
|
||||
* part.
|
||||
*
|
||||
* @param consoleView
|
||||
* The console view editor part, not <code>null</code>.
|
||||
*/
|
||||
|
||||
public void display(IConsoleView consoleView) {
|
||||
if (consoleView == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'consoleView' must not be null.");
|
||||
}
|
||||
consoleView.display(console);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a line to console.
|
||||
*
|
||||
* @param message
|
||||
* The message to print, not <code>null</code>.
|
||||
*/
|
||||
public void println(String message) {
|
||||
if (message == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'message' must not be null.");
|
||||
}
|
||||
messageStream.println(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a print messageStream to write to this console.
|
||||
*
|
||||
* @return The print messageStream, not <code>null</code>.
|
||||
*/
|
||||
public PrintStream getPrintStream() {
|
||||
return printStream;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,161 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.wudsn.ide.gfx.converter;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
import com.wudsn.ide.base.common.IPathUtility;
|
||||
import com.wudsn.ide.gfx.model.ConverterDirection;
|
||||
import com.wudsn.ide.gfx.model.ConverterMode;
|
||||
|
||||
public final class ConverterData {
|
||||
|
||||
private static final class Defaults {
|
||||
|
||||
/**
|
||||
* Creation is private.
|
||||
*/
|
||||
private Defaults() {
|
||||
}
|
||||
|
||||
public static final ConverterMode CONVERTER_MODE = ConverterMode.NONE;
|
||||
}
|
||||
|
||||
private IFile file;
|
||||
private IPath filePathPrefix;
|
||||
|
||||
private ConverterMode converterMode;
|
||||
private ConverterParameters parameters;
|
||||
private ConverterParameters parametersBackup;
|
||||
|
||||
private FilesConverterData filesConverterData;
|
||||
private ImageConverterData imageConverterData;
|
||||
|
||||
ConverterData() {
|
||||
parameters = new ConverterParameters();
|
||||
parametersBackup = new ConverterParameters();
|
||||
filesConverterData = new FilesConverterData(this);
|
||||
imageConverterData = new ImageConverterData(this);
|
||||
clear();
|
||||
}
|
||||
|
||||
public void setFile(IFile file) {
|
||||
this.file = file;
|
||||
if (file != null) {
|
||||
filePathPrefix = file.getFullPath().removeLastSegments(1);
|
||||
} else {
|
||||
filePathPrefix = IPathUtility.createEmptyPath();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public IFile getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public IPath getFilePathPrefix() {
|
||||
return filePathPrefix;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return file != null;
|
||||
}
|
||||
|
||||
public void setConverterMode(ConverterMode value) {
|
||||
if (value == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'value' must not be null.");
|
||||
}
|
||||
this.converterMode = value;
|
||||
}
|
||||
|
||||
public ConverterMode getConverterMode() {
|
||||
return converterMode;
|
||||
}
|
||||
|
||||
public boolean isValidFile() {
|
||||
return isValid()
|
||||
&& (converterMode == ConverterMode.RAW_FILE || converterMode == ConverterMode.CNV);
|
||||
}
|
||||
|
||||
public boolean isValidImage() {
|
||||
return isValid()
|
||||
&& (converterMode == ConverterMode.RAW_IMAGE || converterMode == ConverterMode.CNV);
|
||||
}
|
||||
|
||||
public boolean isValidConversion() {
|
||||
return isValid() && converterMode == ConverterMode.CNV;
|
||||
}
|
||||
|
||||
public ConverterDirection getConverterDirection() {
|
||||
|
||||
return parameters.getConverterDirection();
|
||||
}
|
||||
|
||||
public ConverterParameters getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public ConverterCommonData getConverterCommonData() {
|
||||
switch (parameters.getConverterDirection()) {
|
||||
case FILES_TO_IMAGE:
|
||||
return filesConverterData;
|
||||
case IMAGE_TO_FILES:
|
||||
return imageConverterData;
|
||||
default:
|
||||
throw new IllegalStateException("Unknown converter direction "
|
||||
+ parameters.getConverterDirection() + ".");
|
||||
}
|
||||
}
|
||||
|
||||
public FilesConverterData getFilesConverterData() {
|
||||
return filesConverterData;
|
||||
}
|
||||
|
||||
public ImageConverterData getImageConverterData() {
|
||||
return imageConverterData;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
file = null;
|
||||
clearContent();
|
||||
}
|
||||
|
||||
public void clearContent() {
|
||||
converterMode = Defaults.CONVERTER_MODE;
|
||||
parameters.setDefaults();
|
||||
filesConverterData.clear();
|
||||
imageConverterData.clear();
|
||||
|
||||
}
|
||||
|
||||
final void copyParametersToBackup() {
|
||||
parametersBackup.setDefaults();
|
||||
parameters.copyTo(parametersBackup);
|
||||
}
|
||||
|
||||
public boolean isChanged() {
|
||||
boolean result;
|
||||
result = !parameters.equals(parametersBackup);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,787 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.wudsn.ide.gfx.converter;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.SWTException;
|
||||
import org.eclipse.swt.graphics.ImageData;
|
||||
import org.eclipse.swt.graphics.ImageLoader;
|
||||
import org.eclipse.swt.graphics.PaletteData;
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
|
||||
import com.wudsn.ide.base.BasePlugin;
|
||||
import com.wudsn.ide.base.common.FileUtility;
|
||||
import com.wudsn.ide.base.common.HexUtility;
|
||||
import com.wudsn.ide.base.common.IPathUtility;
|
||||
import com.wudsn.ide.base.common.StringUtility;
|
||||
import com.wudsn.ide.base.gui.MessageManager;
|
||||
import com.wudsn.ide.gfx.GraphicsPlugin;
|
||||
import com.wudsn.ide.gfx.converter.FilesConverterParameters.SourceFile;
|
||||
import com.wudsn.ide.gfx.converter.ImageConverterParameters.TargetFile;
|
||||
import com.wudsn.ide.gfx.converter.atari8bit.LinearBitMapGraphics8Converter;
|
||||
import com.wudsn.ide.gfx.model.ConverterDirection;
|
||||
import com.wudsn.ide.gfx.model.ConverterMode;
|
||||
|
||||
public final class ConverterDataLogic {
|
||||
private MessageManager messageManager;
|
||||
private FilesConverterDataLogic filesConverterDataLogic;
|
||||
|
||||
/**
|
||||
* Helper class to detect the support image file formats by their extension.
|
||||
*
|
||||
* @author Peter Dell
|
||||
*/
|
||||
private static final class ImageExtensions {
|
||||
public static final String CNV = "cnv";
|
||||
public static final String BMP = "bmp";
|
||||
public static final String ICO = "ico";
|
||||
public static final String GIF = "gif";
|
||||
public static final String JPG = "jpg";
|
||||
public static final String PNG = "png";
|
||||
|
||||
public static final int UNKNOWN_FORMAT = -1;
|
||||
|
||||
public static int getImageFormat(IPath filePath) {
|
||||
int result;
|
||||
|
||||
String fileExtension = filePath.getFileExtension();
|
||||
if (fileExtension == null) {
|
||||
result = UNKNOWN_FORMAT;
|
||||
} else if (fileExtension.equalsIgnoreCase(BMP)) {
|
||||
result = SWT.IMAGE_BMP;
|
||||
} else if (fileExtension.equalsIgnoreCase(ICO)) {
|
||||
result = SWT.IMAGE_ICO;
|
||||
} else if (fileExtension.equalsIgnoreCase(GIF)) {
|
||||
result = SWT.IMAGE_GIF;
|
||||
} else if (fileExtension.equalsIgnoreCase(JPG)) {
|
||||
result = SWT.IMAGE_JPEG;
|
||||
} else if (fileExtension.equalsIgnoreCase(PNG)) {
|
||||
result = SWT.IMAGE_PNG;
|
||||
} else {
|
||||
result = UNKNOWN_FORMAT;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public ConverterDataLogic(MessageManager messageManager) {
|
||||
if (messageManager == null) {
|
||||
throw new IllegalArgumentException("Parameter 'messageManager' must not be null.");
|
||||
}
|
||||
this.messageManager = messageManager;
|
||||
filesConverterDataLogic = new FilesConverterDataLogic();
|
||||
}
|
||||
|
||||
public ConverterData createData() {
|
||||
return new ConverterData();
|
||||
}
|
||||
|
||||
public void load(ConverterData data) {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Parameter 'data' must not be null.");
|
||||
}
|
||||
|
||||
data.clearContent();
|
||||
|
||||
IFile file = data.getFile();
|
||||
String fileName = file.getFullPath().lastSegment();
|
||||
String extension = file.getFileExtension();
|
||||
if (extension == null) {
|
||||
extension = "";
|
||||
} else {
|
||||
extension = extension.toLowerCase();
|
||||
}
|
||||
|
||||
if (extension.equals(ImageExtensions.CNV)) {
|
||||
data.setConverterMode(ConverterMode.CNV);
|
||||
try {
|
||||
|
||||
data.getParameters().read(file);
|
||||
|
||||
} catch (CoreException ex) {
|
||||
messageManager.sendMessage(0, ex);
|
||||
}
|
||||
loadSources(data, true);
|
||||
} else {
|
||||
int imageFormat = ImageExtensions.getImageFormat(file.getFullPath());
|
||||
if (imageFormat != ImageExtensions.UNKNOWN_FORMAT) {
|
||||
data.setConverterMode(ConverterMode.RAW_IMAGE);
|
||||
data.getParameters().setConverterDirection(ConverterDirection.IMAGE_TO_FILES);
|
||||
data.getImageConverterData().getParameters().setImageFilePath(fileName);
|
||||
data.getImageConverterData().getParameters()
|
||||
.setConverterId(LinearBitMapGraphics8Converter.class.getName());
|
||||
loadSources(data, true);
|
||||
|
||||
} else {
|
||||
data.setConverterMode(ConverterMode.RAW_FILE);
|
||||
data.getParameters().setConverterDirection(ConverterDirection.FILES_TO_IMAGE);
|
||||
data.getFilesConverterData().getParameters().setDefaultSourceFilePath(fileName);
|
||||
data.getFilesConverterData().getParameters().setImageFilePath(fileName + "." + ImageExtensions.PNG);
|
||||
findDefaultFileConverter(data);
|
||||
loadSources(data, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void findDefaultFileConverter(ConverterData data) {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Parameter 'data' must not be null.");
|
||||
}
|
||||
FilesConverterData filesConverterData;
|
||||
filesConverterData = data.getFilesConverterData();
|
||||
FilesConverterParameters fileConverterParameters = filesConverterData.getParameters();
|
||||
|
||||
IPath filePathPrefix = filesConverterData.getFilePathPrefix();
|
||||
|
||||
SourceFile sourceFile = fileConverterParameters.getSourceFile(0);
|
||||
IPath filePath = Path.fromPortableString(sourceFile.getPath());
|
||||
filePath = IPathUtility.makeAbsolute(filePath, filePathPrefix, false);
|
||||
byte[] bytes = loadSourceFile(sourceFile.getPathMessageId(), filePath);
|
||||
|
||||
// TODO: If bytes is null or length is 0, an error message should be displayed instead.
|
||||
if (bytes != null) {
|
||||
String fileExtension = filePath.getFileExtension();
|
||||
if (fileExtension != null) {
|
||||
fileExtension = fileExtension.toLowerCase();
|
||||
} else {
|
||||
fileExtension = "";
|
||||
}
|
||||
filesConverterDataLogic.findDefaultFileConverter(filesConverterData, bytes, fileExtension);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public boolean loadSources(ConverterData data, boolean copyToBackup) {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Parameter 'data' must not be null.");
|
||||
}
|
||||
boolean success;
|
||||
|
||||
success = true;
|
||||
switch (data.getConverterDirection()) {
|
||||
case FILES_TO_IMAGE:
|
||||
|
||||
FilesConverterData filesConverterData;
|
||||
filesConverterData = data.getFilesConverterData();
|
||||
FilesConverterParameters fileConverterParameters = filesConverterData.getParameters();
|
||||
|
||||
IPath filePathPrefix = filesConverterData.getFilePathPrefix();
|
||||
for (int i = 0; i < fileConverterParameters.getSourceFilesSize(); i++) {
|
||||
SourceFile sourceFile = fileConverterParameters.getSourceFile(i);
|
||||
IPath filePath = Path.fromPortableString(sourceFile.getPath());
|
||||
filePath = IPathUtility.makeAbsolute(filePath, filePathPrefix, false);
|
||||
byte[] bytes = loadSourceFile(sourceFile.getPathMessageId(), filePath);
|
||||
filesConverterData.setSourceFileBytes(sourceFile.getId(), bytes);
|
||||
if (bytes == null) {
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case IMAGE_TO_FILES:
|
||||
ImageConverterData imageConverterData;
|
||||
imageConverterData = data.getImageConverterData();
|
||||
|
||||
filePathPrefix = imageConverterData.getFilePathPrefix();
|
||||
IPath filePath = Path.fromPortableString(imageConverterData.getParameters().getImageFilePath());
|
||||
filePath = IPathUtility.makeAbsolute(filePath, filePathPrefix, false);
|
||||
ImageData imageData = loadSourceImage(ImageConverterParameters.MessageIds.IMAGE_FILE_PATH, filePath);
|
||||
imageConverterData.setImageData(imageData);
|
||||
if (imageData != null) {
|
||||
// Remember last loaded state.
|
||||
success = true;
|
||||
|
||||
} else {
|
||||
success = false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unknown converter direction '" + data.getConverterDirection() + "'.");
|
||||
|
||||
}
|
||||
|
||||
// Remember last loaded state.
|
||||
if (success && copyToBackup) {
|
||||
data.copyParametersToBackup();
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the converter based default values after the converter has been
|
||||
* selected.
|
||||
*
|
||||
* @param data
|
||||
* The converter data, not <code>null</code>.
|
||||
*/
|
||||
public void applyDefaults(ConverterData data) {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Parameter 'data' must not be null.");
|
||||
}
|
||||
|
||||
switch (data.getConverterDirection()) {
|
||||
case FILES_TO_IMAGE:
|
||||
filesConverterDataLogic.applyDefaults(data.getFilesConverterData());
|
||||
|
||||
break;
|
||||
case IMAGE_TO_FILES:
|
||||
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unknown converter direction '" + data.getConverterDirection() + "'.");
|
||||
}
|
||||
}
|
||||
|
||||
public ConverterData createConversion(ConverterData data) {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Parameter 'data' must not be null.");
|
||||
}
|
||||
if (!data.isValid()) {
|
||||
throw new IllegalStateException("Converter data is not valid.");
|
||||
}
|
||||
if (data.getConverterMode() != ConverterMode.RAW_FILE && data.getConverterMode() != ConverterMode.RAW_IMAGE) {
|
||||
throw new IllegalStateException("Converter data is not in mode RAW_FILE or RAW_IMAGE.");
|
||||
}
|
||||
|
||||
// Compute new file name.
|
||||
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
|
||||
IPath saveAsPath = data.getFile().getFullPath().addFileExtension(ImageExtensions.CNV);
|
||||
IFile saveAsFile = workspaceRoot.getFile(saveAsPath);
|
||||
|
||||
// Compute new content.
|
||||
ConverterData newConverterData = new ConverterData();
|
||||
newConverterData.setConverterMode(ConverterMode.CNV);
|
||||
newConverterData.setFile(saveAsFile);
|
||||
data.getParameters().copyTo(newConverterData.getParameters());
|
||||
|
||||
return newConverterData;
|
||||
}
|
||||
|
||||
public IFile saveConversion(ConverterData data, IProgressMonitor monitor) {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Parameter 'data' must not be null.");
|
||||
}
|
||||
|
||||
IFile saveFile;
|
||||
String saveFilePath;
|
||||
saveFile = data.getFile();
|
||||
saveFilePath = saveFile.getFullPath().toString();
|
||||
|
||||
try {
|
||||
InputStream inputStream;
|
||||
inputStream = data.getParameters().getContents(saveFilePath);
|
||||
if (saveFile.exists()) {
|
||||
saveFile.setContents(inputStream, false, false, monitor);
|
||||
} else {
|
||||
saveFile.create(inputStream, true, monitor);
|
||||
}
|
||||
// Remember last saved state.
|
||||
data.copyParametersToBackup();
|
||||
|
||||
} catch (CoreException ex) {
|
||||
messageManager.sendMessage(0, ex);
|
||||
saveFile = null;
|
||||
}
|
||||
return saveFile;
|
||||
}
|
||||
|
||||
public void saveTargets(ConverterData data) {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Parameter 'data' must not be null.");
|
||||
}
|
||||
IPath filePathPrefix;
|
||||
IPath filePath;
|
||||
if (convert(data)) {
|
||||
switch (data.getConverterDirection()) {
|
||||
case FILES_TO_IMAGE:
|
||||
|
||||
FilesConverterData filesConverterData;
|
||||
filesConverterData = data.getFilesConverterData();
|
||||
|
||||
filePathPrefix = filesConverterData.getFilePathPrefix();
|
||||
filePath = Path.fromPortableString(filesConverterData.getParameters().getImageFilePath());
|
||||
filePath = IPathUtility.makeAbsolute(filePath, filePathPrefix, false);
|
||||
saveTargetImage(FilesConverterParameters.MessageIds.IMAGE_FILE_PATH, filePath,
|
||||
filesConverterData.getImageData());
|
||||
break;
|
||||
case IMAGE_TO_FILES:
|
||||
ImageConverterData imageConverterData;
|
||||
ImageConverterParameters imageConverterParameters;
|
||||
imageConverterData = data.getImageConverterData();
|
||||
imageConverterParameters = imageConverterData.getParameters();
|
||||
|
||||
filePathPrefix = imageConverterData.getFilePathPrefix();
|
||||
int size = imageConverterData.getConverter().getDefinition().getTargetFileDefinitions().size();
|
||||
int minSize = Math.min(size, imageConverterParameters.getTargetFilesSize());
|
||||
boolean saved = true;
|
||||
for (int i = 0; i < minSize; i++) {
|
||||
TargetFile targetFile = imageConverterParameters.getTargetFile(i);
|
||||
filePath = Path.fromPortableString(targetFile.getPath());
|
||||
filePath = IPathUtility.makeAbsolute(filePath, filePathPrefix, false);
|
||||
saved &= saveTargetFile(targetFile.getPathMessageId(), filePath,
|
||||
imageConverterData.getTargetFileBytes(targetFile.getId()));
|
||||
}
|
||||
if (!saved) {
|
||||
for (int i = 0; i < minSize; i++) {
|
||||
TargetFile targetFile = imageConverterParameters.getTargetFile(i);
|
||||
messageManager.sendMessage(targetFile.getPathMessageId(), IStatus.ERROR,
|
||||
"No target file with file path and content present");
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unknown converter direction '" + data.getConverterDirection() + "'.");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a target file, if path and content are present. Empty content is
|
||||
* allowed, <code>null</code> content is interpreted as missing file.
|
||||
*
|
||||
* @param messageId
|
||||
* The message id.
|
||||
* @param filePath
|
||||
* The target file path, may be empty, not <code>null</code>.
|
||||
* @param bytes
|
||||
* The target file content, may be empty or <code>null</code>.
|
||||
*
|
||||
* @return <code>true</code> if the file was save, <code>false</code>
|
||||
* otherwise.
|
||||
*/
|
||||
private boolean saveTargetFile(int messageId, IPath filePath, byte[] bytes) {
|
||||
if (filePath == null) {
|
||||
throw new IllegalArgumentException("Parameter 'filePath' must not be null.");
|
||||
}
|
||||
boolean result;
|
||||
|
||||
if (filePath.isEmpty()) {
|
||||
messageManager.sendMessage(messageId, IStatus.WARNING, "No target file path specified");
|
||||
return false;
|
||||
}
|
||||
if (bytes == null) {
|
||||
messageManager.sendMessage(messageId, IStatus.INFO, "File {0} not saved as there is no data for this file",
|
||||
filePath.toPortableString());
|
||||
return false;
|
||||
}
|
||||
|
||||
IWorkspaceRoot workspaceRoot;
|
||||
IFile saveFile;
|
||||
IProgressMonitor monitor;
|
||||
|
||||
result = false;
|
||||
workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
|
||||
saveFile = workspaceRoot.getFile(filePath);
|
||||
monitor = null;
|
||||
|
||||
try {
|
||||
InputStream inputStream;
|
||||
inputStream = new ByteArrayInputStream(bytes);
|
||||
if (saveFile.exists()) {
|
||||
saveFile.setContents(inputStream, false, false, monitor);
|
||||
} else {
|
||||
saveFile.create(inputStream, true, monitor);
|
||||
}
|
||||
|
||||
} catch (CoreException ex) {
|
||||
messageManager.sendMessage(0, ex);
|
||||
saveFile = null;
|
||||
}
|
||||
|
||||
if (saveFile != null) {
|
||||
messageManager.sendMessage(messageId, IStatus.INFO, "File {0} saved with ${1} bytes",
|
||||
filePath.toPortableString(), HexUtility.getLongValueHexString(bytes.length));
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void saveTargetImage(int messageId, IPath filePath, ImageData imageData) {
|
||||
if (filePath == null) {
|
||||
throw new IllegalArgumentException("Parameter 'filePath' must not be null.");
|
||||
}
|
||||
if (filePath.isEmpty()) {
|
||||
messageManager.sendMessage(messageId, IStatus.ERROR, "No image path specified");
|
||||
return;
|
||||
}
|
||||
if (imageData == null) {
|
||||
messageManager.sendMessage(messageId, IStatus.ERROR,
|
||||
"Image {0} not saved as there is no data for this image", filePath.toPortableString());
|
||||
return;
|
||||
}
|
||||
|
||||
ImageLoader imageLoader = new ImageLoader();
|
||||
imageLoader.data = new ImageData[] { imageData };
|
||||
int format = ImageExtensions.getImageFormat(filePath);
|
||||
if (format == ImageExtensions.UNKNOWN_FORMAT) {
|
||||
messageManager.sendMessage(messageId, IStatus.ERROR,
|
||||
"Image {0} not saved as there is the extension cannot be mapped to a supported image format",
|
||||
filePath.toPortableString());
|
||||
return;
|
||||
}
|
||||
|
||||
boolean success = false;
|
||||
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(filePath);
|
||||
try {
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
imageLoader.save(bos, format);
|
||||
bos.close();
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
|
||||
if (!file.exists()) {
|
||||
file.create(bis, IResource.FORCE, null);
|
||||
} else {
|
||||
file.setContents(bis, IResource.FORCE, null);
|
||||
}
|
||||
success = true;
|
||||
} catch (Exception ex) {
|
||||
messageManager.sendMessage(messageId, IStatus.ERROR, "Image {0} not saved. {1}",
|
||||
filePath.toPortableString(), ex.getMessage());
|
||||
}
|
||||
// file.refreshLocal(IResource.DEPTH_ZERO, null);
|
||||
|
||||
if (success) {
|
||||
messageManager.sendMessage(messageId, IStatus.INFO, "Image {0} saved", filePath.toPortableString());
|
||||
}
|
||||
}
|
||||
|
||||
private ImageData loadSourceImage(int messageId, IPath filePath) {
|
||||
if (filePath == null) {
|
||||
throw new IllegalArgumentException("Parameter 'fileSection' must not be null.");
|
||||
}
|
||||
ImageData imageData = null;
|
||||
if (!filePath.isEmpty()) {
|
||||
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(filePath);
|
||||
|
||||
InputStream is;
|
||||
try {
|
||||
is = file.getContents(true);
|
||||
} catch (CoreException ex) {
|
||||
messageManager.sendMessage(messageId, ex);
|
||||
is = null;
|
||||
}
|
||||
|
||||
if (is != null) {
|
||||
try {
|
||||
try {
|
||||
imageData = new ImageData(is);
|
||||
|
||||
} catch (SWTException ex) {
|
||||
messageManager.sendMessage(messageId, IStatus.ERROR,
|
||||
"Cannot open image file. " + ex.getMessage());
|
||||
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException ex) {
|
||||
BasePlugin.getInstance().logError("Cannot close input stream for {0}",
|
||||
new Object[] { filePath }, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return imageData;
|
||||
}
|
||||
|
||||
private byte[] loadSourceFile(int messageId, IPath filePath) {
|
||||
if (filePath == null) {
|
||||
throw new IllegalArgumentException("Parameter 'filePath' must not be null.");
|
||||
}
|
||||
byte[] result;
|
||||
|
||||
if (!filePath.isEmpty()) {
|
||||
try {
|
||||
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(filePath);
|
||||
|
||||
result = FileUtility.readBytes(file, FileUtility.MAX_SIZE_1MB, true);
|
||||
} catch (CoreException ex) {
|
||||
messageManager.sendMessage(messageId, ex);
|
||||
result = null;
|
||||
} catch (IllegalArgumentException ex) {
|
||||
messageManager.sendMessage(messageId, IStatus.ERROR, ex.getMessage());
|
||||
result = null;
|
||||
}
|
||||
|
||||
} else {
|
||||
result = null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean convert(ConverterData data) {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Parameter 'data' must not be null.");
|
||||
}
|
||||
ConverterDirection converterDirection;
|
||||
converterDirection = data.getConverterDirection();
|
||||
boolean result;
|
||||
switch (converterDirection) {
|
||||
|
||||
case FILES_TO_IMAGE:
|
||||
result = convertFilesToImage(data);
|
||||
break;
|
||||
|
||||
case IMAGE_TO_FILES:
|
||||
result = convertImageToFiles(data);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new RuntimeException("Unknown converter direction '" + converterDirection + "'.");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean convertImageToFiles(ConverterData data) {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Parameter 'data' must not be null.");
|
||||
}
|
||||
if (!data.isValidImage()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ImageConverterData imageConverterData;
|
||||
imageConverterData = data.getImageConverterData();
|
||||
|
||||
ImageConverterParameters imageConverterParameters;
|
||||
imageConverterParameters = imageConverterData.getParameters();
|
||||
|
||||
// Setup image data fields.
|
||||
if (imageConverterData.getImageData() == null) {
|
||||
|
||||
// Create empty image data.
|
||||
PaletteData palette = new PaletteData(255, 255, 255);
|
||||
data.getImageConverterData().setImageData(new ImageData(320, 256, 8, palette));
|
||||
imageConverterData.setImageColorHistogram(null);
|
||||
|
||||
} else {
|
||||
ImageColorHistogram imageColorHistogram = new ImageColorHistogram();
|
||||
imageColorHistogram.analyze(imageConverterData.getImageData());
|
||||
imageConverterData.setImageColorHistogram(imageColorHistogram);
|
||||
|
||||
}
|
||||
|
||||
imageConverterData.setImageDataWidth(imageConverterData.getImageData().width);
|
||||
imageConverterData.setImageDataHeight(imageConverterData.getImageData().height);
|
||||
imageConverterData.clearTargetFileBytes();
|
||||
|
||||
Converter converter;
|
||||
|
||||
if (StringUtility.isEmpty(imageConverterParameters.getConverterId())) {
|
||||
messageManager.sendMessage(ConverterCommonParameters.MessageIds.CONVERTER_ID, IStatus.ERROR,
|
||||
"No converter selected");
|
||||
return false;
|
||||
}
|
||||
converter = imageConverterData.getConverter();
|
||||
if (converter == null) {
|
||||
messageManager.sendMessage(ConverterCommonParameters.MessageIds.CONVERTER_ID, IStatus.ERROR,
|
||||
"Converter '{0}' is not registered", String.valueOf(imageConverterParameters.getConverterId()));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (messageManager.containsError()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Default the script if none is specified.
|
||||
if (StringUtility.isEmpty(imageConverterParameters.getScript())) {
|
||||
try {
|
||||
imageConverterParameters.setScript(ConverterScript.getScript(converter.getClass()));
|
||||
} catch (CoreException ex) {
|
||||
messageManager.sendMessage(ImageConverterParameters.MessageIds.SCRIPT, ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Apply default to conversion parameters.
|
||||
if (imageConverterParameters.isUseDefaultScript()
|
||||
|| StringUtility.isEmpty(imageConverterParameters.getScript())) {
|
||||
String script = ConverterScript.getScript(converter.getClass());
|
||||
imageConverterParameters.setScript(script);
|
||||
}
|
||||
|
||||
ConverterScript.convertToFileData(converter, imageConverterData);
|
||||
} catch (CoreException ex) {
|
||||
messageManager.sendMessage(ConverterCommonParameters.MessageIds.CONVERTER_ID, ex);
|
||||
return false;
|
||||
} catch (RuntimeException ex) {
|
||||
String message = ex.getMessage();
|
||||
if (message == null) {
|
||||
message = ex.getClass().getName();
|
||||
}
|
||||
messageManager.sendMessage(ImageConverterParameters.MessageIds.SCRIPT, IStatus.ERROR, message);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean convertFilesToImage(ConverterData data) {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Parameter 'data' must not be null.");
|
||||
}
|
||||
if (!data.isValidFile()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
FilesConverterData filesConverterData;
|
||||
filesConverterData = data.getFilesConverterData();
|
||||
|
||||
filesConverterData.setImageDataValid(false);
|
||||
filesConverterData.setImageDataWidth(0);
|
||||
filesConverterData.setImageDataHeight(0);
|
||||
filesConverterData.setImageData(null);
|
||||
|
||||
FilesConverterParameters filesConverterParameters;
|
||||
filesConverterParameters = filesConverterData.getParameters();
|
||||
|
||||
if (filesConverterParameters.getSpacingWidth() < 0) {
|
||||
messageManager.sendMessage(FilesConverterParameters.MessageIds.SPACING_WIDTH, IStatus.ERROR,
|
||||
"Spacing width must not be negative. Current value is {0}",
|
||||
String.valueOf(filesConverterParameters.getSpacingWidth()));
|
||||
}
|
||||
|
||||
if (filesConverterParameters.getColumns() <= 0) {
|
||||
messageManager.sendMessage(FilesConverterParameters.MessageIds.COLUMNS, IStatus.ERROR,
|
||||
"Columns count must be positive. Current value is {0}",
|
||||
String.valueOf(filesConverterParameters.getColumns()));
|
||||
}
|
||||
if (filesConverterParameters.getRows() <= 0) {
|
||||
messageManager.sendMessage(FilesConverterParameters.MessageIds.ROWS, IStatus.ERROR,
|
||||
"Rows count must be positive. Current value is {0}",
|
||||
String.valueOf(filesConverterParameters.getRows()));
|
||||
}
|
||||
|
||||
Converter converter;
|
||||
|
||||
if (StringUtility.isEmpty(filesConverterParameters.getConverterId())) {
|
||||
messageManager.sendMessage(ConverterCommonParameters.MessageIds.CONVERTER_ID, IStatus.ERROR,
|
||||
"No converter selected");
|
||||
return false;
|
||||
}
|
||||
converter = filesConverterData.getConverter();
|
||||
if (converter == null) {
|
||||
messageManager.sendMessage(ConverterCommonParameters.MessageIds.CONVERTER_ID, IStatus.ERROR,
|
||||
"Converter '{0}' is not registered", String.valueOf(filesConverterParameters.getConverterId()));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (messageManager.containsError()) {
|
||||
return false;
|
||||
}
|
||||
converter.convertToImageDataSize(filesConverterData);
|
||||
if (filesConverterData.getImageDataWidth() <= 0) {
|
||||
messageManager.sendMessage(FilesConverterParameters.MessageIds.COLUMNS, IStatus.ERROR,
|
||||
"Resulting image data with '{0}' is not positive",
|
||||
String.valueOf(filesConverterData.getImageDataWidth()));
|
||||
}
|
||||
if (filesConverterData.getImageDataHeight() <= 0) {
|
||||
messageManager.sendMessage(FilesConverterParameters.MessageIds.ROWS, IStatus.ERROR,
|
||||
"Resulting image data height '{0}' is not positive",
|
||||
String.valueOf(filesConverterData.getImageDataWidth()));
|
||||
}
|
||||
|
||||
int MAX_PIXELS = 1000 * 1000;
|
||||
int pixels = filesConverterData.getImageDataWidth() * filesConverterData.getImageDataHeight();
|
||||
if (pixels > MAX_PIXELS) {
|
||||
messageManager.sendMessage(FilesConverterParameters.MessageIds.ROWS, IStatus.ERROR,
|
||||
"Resulting image would have {0} pixels and exceed the memory limit of {1} pixels",
|
||||
String.valueOf(pixels), String.valueOf(MAX_PIXELS));
|
||||
}
|
||||
|
||||
if (messageManager.containsError()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create index or direct palette and image data.
|
||||
PaletteData paletteData;
|
||||
ImageData imageData;
|
||||
int paletteSize;
|
||||
paletteSize = filesConverterData.getConverter().getDefinition().getTargetImagePaletteSize();
|
||||
if (paletteSize > 0) {
|
||||
// Create 8 bit index palette.
|
||||
RGB[] paletteColors = new RGB[paletteSize];
|
||||
RGB[] currentPaletteColors = filesConverterParameters.getPaletteRGBs();
|
||||
for (int i = 0; i < paletteColors.length; i++) {
|
||||
if (i < currentPaletteColors.length) {
|
||||
paletteColors[i] = currentPaletteColors[i];
|
||||
} else {
|
||||
paletteColors[i] = new RGB(0, 0, 0);
|
||||
}
|
||||
}
|
||||
filesConverterParameters.setPaletteRGBs(paletteColors);
|
||||
|
||||
RGB[] actualPaletteColors = new RGB[paletteColors.length + 1];
|
||||
System.arraycopy(paletteColors, 0, actualPaletteColors, 0, paletteColors.length);
|
||||
// The color at index actualPaletteColors.length is used as spacing
|
||||
// color in order to keep the original palette index order
|
||||
int spacingColorIndex = paletteColors.length;
|
||||
actualPaletteColors[spacingColorIndex] = filesConverterParameters.getSpacingColor();
|
||||
paletteData = new PaletteData(actualPaletteColors);
|
||||
imageData = new ImageData(filesConverterData.getImageDataWidth(), filesConverterData.getImageDataHeight(),
|
||||
8, paletteData);
|
||||
for (int y = 0; y < filesConverterData.getImageDataHeight(); y++) {
|
||||
for (int x = 0; x < filesConverterData.getImageDataWidth(); x++) {
|
||||
imageData.setPixel(x, y, spacingColorIndex);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Create 24 bit direct palette.
|
||||
paletteData = new PaletteData(0xFF0000, 0xFF00, 0xFF);
|
||||
imageData = new ImageData(filesConverterData.getImageDataWidth(), filesConverterData.getImageDataHeight(),
|
||||
24, paletteData);
|
||||
}
|
||||
filesConverterData.setImageData(imageData);
|
||||
boolean conversionResult;
|
||||
try {
|
||||
conversionResult = converter.convertToImageData(filesConverterData);
|
||||
} catch (RuntimeException ex) {
|
||||
GraphicsPlugin.getInstance().logError("Runtime exception during convertFilesToImage()", null, ex);
|
||||
conversionResult = false;
|
||||
}
|
||||
filesConverterData.setImageDataValid(conversionResult);
|
||||
|
||||
ImageColorHistogram imageColorHistogram = new ImageColorHistogram();
|
||||
imageColorHistogram.analyze(imageData);
|
||||
filesConverterData.setImageColorHistogram(imageColorHistogram);
|
||||
return conversionResult;
|
||||
}
|
||||
}
|
@ -0,0 +1,285 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.wudsn.ide.gfx.converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import com.wudsn.ide.gfx.model.Aspect;
|
||||
|
||||
/**
|
||||
* Definition of a converter. The definition contains all static meta
|
||||
* information about the converter. It is normally defined via an extension.
|
||||
*
|
||||
*
|
||||
* For launching application under MacOS see
|
||||
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=82155 and
|
||||
* http://www.coderanch.com/t/111494/Mac-OS/launching-Safari-from-Java-App.
|
||||
*
|
||||
* @author Peter Dell
|
||||
*/
|
||||
public final class ConverterDefinition implements
|
||||
Comparable<ConverterDefinition> {
|
||||
|
||||
// Id
|
||||
private String id;
|
||||
private String name;
|
||||
private List<String> sourceFileExtensions;
|
||||
private int targetImagePaletteSize;
|
||||
private Aspect targetImageDisplayAspect;
|
||||
|
||||
private List<ConverterSourceFileDefinition> sourceFileDefinitions;
|
||||
private List<ConverterTargetFileDefinition> targetFileDefinitions;
|
||||
|
||||
/**
|
||||
* Creates an instance. Called by {@link ConverterRegistry} only.
|
||||
*/
|
||||
ConverterDefinition() {
|
||||
sourceFileExtensions = new ArrayList<String>(1);
|
||||
sourceFileDefinitions = new ArrayList<ConverterSourceFileDefinition>();
|
||||
targetFileDefinitions = new ArrayList<ConverterTargetFileDefinition>();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the id of the converter. Called by {@link ConverterRegistry} only.
|
||||
*
|
||||
* @param id
|
||||
* The id of the converter, not empty and not <code>null</code>.
|
||||
*/
|
||||
final void setId(String id) {
|
||||
if (id == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'id' must not be null.");
|
||||
}
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id of the converter.
|
||||
*
|
||||
* @return The id of the converter, not empty and not <code>null</code>.
|
||||
*/
|
||||
public final String getId() {
|
||||
if (id == null) {
|
||||
throw new IllegalStateException("Field 'id' must not be null.");
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the converter. Called by {@link ConverterRegistry} only.
|
||||
*
|
||||
* @param name
|
||||
* The name of the converter, not empty and not <code>null</code>
|
||||
* .
|
||||
*/
|
||||
final void setName(String name) {
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'name' must not be null.");
|
||||
}
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the converter.
|
||||
*
|
||||
* @return The name of the converter, not empty and not <code>null</code>.
|
||||
*/
|
||||
public final String getName() {
|
||||
if (name == null) {
|
||||
throw new IllegalStateException("Field 'name' must not be null.");
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the supported source file extensions the converter. Called by
|
||||
* {@link ConverterRegistry} only.
|
||||
*
|
||||
* @param sourceFileExtensions
|
||||
* The comma separated list of source file extensions in lower
|
||||
* case characters, may be empty or <code>null</code>.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
final void setSourceFileExtensions(String sourceFileExtensions) {
|
||||
if (sourceFileExtensions == null) {
|
||||
sourceFileExtensions = "";
|
||||
}
|
||||
StringTokenizer st = new StringTokenizer(sourceFileExtensions, ",");
|
||||
while (st.hasMoreTokens()) {
|
||||
this.sourceFileExtensions.add(st.nextToken().trim());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a given file extension is supported.
|
||||
*
|
||||
* @param fileExtension
|
||||
* The file extension in lower case letters, may be empty, not
|
||||
* <code>null</code>.
|
||||
* @return <code>true</code> if the file extension is supported,
|
||||
* <code>false</code> otherwise.
|
||||
*
|
||||
* @since V1.6.0
|
||||
*/
|
||||
public final boolean isSourceFileExtensionSupported(String fileExtension) {
|
||||
if (fileExtension == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'fileExtension' must not be null.");
|
||||
}
|
||||
|
||||
return sourceFileExtensions.contains(fileExtension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the palette size of the converter. Called by
|
||||
* {@link ConverterRegistry} only.
|
||||
*
|
||||
* @param targetImagePaletteSize
|
||||
* The palette size of the converter, a positive number if a
|
||||
* palette is used, 0 for a direct palette.
|
||||
*/
|
||||
final void setTargetImagePaletteSize(int targetImagePaletteSize) {
|
||||
if (targetImagePaletteSize < 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'targetImagePaletteSize' must not be negative. Specified value is "
|
||||
+ targetImagePaletteSize + ".");
|
||||
}
|
||||
this.targetImagePaletteSize = targetImagePaletteSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the palette size of the target image.
|
||||
*
|
||||
* @return The palette size of the target image, a positive number if a
|
||||
* palette is used, 0 for direct palette.
|
||||
*/
|
||||
public final int getTargetImagePaletteSize() {
|
||||
if (targetImagePaletteSize < 0) {
|
||||
throw new IllegalStateException(
|
||||
"Field 'targetImagePaletteSize' must not be negative. Specified value is "
|
||||
+ targetImagePaletteSize + ".");
|
||||
}
|
||||
return targetImagePaletteSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the zoom factor of the target image.
|
||||
*
|
||||
* @param targetImageDisplayAspect
|
||||
* The target image zoom factor, not <code>null</code>.
|
||||
*/
|
||||
final void setTargetImageDisplayAspect(Aspect targetImageDisplayAspect) {
|
||||
if (targetImageDisplayAspect == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'targetImageDisplayAspect' must not be null.");
|
||||
}
|
||||
if (!targetImageDisplayAspect.isValid()) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'targetImageDisplayAspect' must not be invalid.");
|
||||
}
|
||||
this.targetImageDisplayAspect = targetImageDisplayAspect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the zoom factor of the target image.
|
||||
*
|
||||
* @return The zoom factor of the target image.
|
||||
*/
|
||||
public final Aspect getTargetImageDisplayAspect() {
|
||||
if (targetImageDisplayAspect == null) {
|
||||
throw new IllegalStateException(
|
||||
"Field 'targetImageDisplayAspect' must not be empty.");
|
||||
}
|
||||
return targetImageDisplayAspect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a source file definition. Called by {@link ConverterRegistry} only.
|
||||
*
|
||||
* @param sourceFileDefinition
|
||||
* The source file definition, not <code>null</code>.
|
||||
*/
|
||||
final void addSourceFileDefinition(
|
||||
ConverterSourceFileDefinition sourceFileDefinition) {
|
||||
if (sourceFileDefinition == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'sourceFileDefinition' must not be null.");
|
||||
}
|
||||
sourceFileDefinitions.add(sourceFileDefinition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the unmodifiable list of source file definitions.
|
||||
*
|
||||
* @return The unmodifiable list of source file definitions, may be empty,
|
||||
* not <code>null</code>.
|
||||
*/
|
||||
public final List<ConverterSourceFileDefinition> getSourceFileDefinitions() {
|
||||
return Collections.unmodifiableList(sourceFileDefinitions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a target file definition. Called by {@link ConverterRegistry} only.
|
||||
*
|
||||
* @param targetFileDefinition
|
||||
* The target file definition, not <code>null</code>.
|
||||
*/
|
||||
final void addTargetFileDefinition(
|
||||
ConverterTargetFileDefinition targetFileDefinition) {
|
||||
if (targetFileDefinition == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'targetFileDefinition' must not be null.");
|
||||
}
|
||||
targetFileDefinitions.add(targetFileDefinition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the unmodifiable list of target file definitions.
|
||||
*
|
||||
* @return The unmodifiable list of target file definitions, may be empty,
|
||||
* not <code>null</code>.
|
||||
*/
|
||||
public final List<ConverterTargetFileDefinition> getTargetFileDefinitions() {
|
||||
|
||||
return Collections.unmodifiableList(targetFileDefinitions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int compareTo(ConverterDefinition o) {
|
||||
if (o == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'o' must not be null.");
|
||||
}
|
||||
if (name == null || o.name == null) {
|
||||
if (name == null) {
|
||||
throw new IllegalStateException(
|
||||
"Field 'name' must not be null for this or for argument.");
|
||||
}
|
||||
}
|
||||
return name.compareTo(o.name);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,270 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.wudsn.ide.gfx.converter;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
|
||||
import com.wudsn.ide.base.Texts;
|
||||
import com.wudsn.ide.base.common.FileUtility;
|
||||
import com.wudsn.ide.base.common.SequencedProperties;
|
||||
import com.wudsn.ide.base.common.TextUtility;
|
||||
import com.wudsn.ide.gfx.GraphicsPlugin;
|
||||
import com.wudsn.ide.gfx.model.ConverterDirection;
|
||||
import com.wudsn.ide.gfx.model.GraphicsPropertiesSerializer;
|
||||
|
||||
public final class ConverterParameters {
|
||||
|
||||
private static final class Attributes {
|
||||
|
||||
/**
|
||||
* Creation is private.
|
||||
*/
|
||||
private Attributes() {
|
||||
}
|
||||
|
||||
public static final String CONVERTER_DIRECTION = "converterDirection";
|
||||
public static final String FILES_CONVERTER_PARAMETERS = "filesConverterParameters";
|
||||
public static final String IMAGE_CONVERTER_PARAMETERS = "imageConverterParameters";
|
||||
|
||||
}
|
||||
|
||||
private static final class Defaults {
|
||||
|
||||
/**
|
||||
* Creation is private.
|
||||
*/
|
||||
private Defaults() {
|
||||
}
|
||||
|
||||
public static final ConverterDirection CONVERTER_DIRECTION = ConverterDirection.FILES_TO_IMAGE;
|
||||
}
|
||||
|
||||
private ConverterDirection converterDirection;
|
||||
private FilesConverterParameters filesConverterParameters;
|
||||
private ImageConverterParameters imageConverterParameters;
|
||||
|
||||
public ConverterParameters() {
|
||||
|
||||
filesConverterParameters = new FilesConverterParameters();
|
||||
imageConverterParameters = new ImageConverterParameters();
|
||||
setDefaults();
|
||||
}
|
||||
|
||||
public void setDefaults() {
|
||||
|
||||
converterDirection = Defaults.CONVERTER_DIRECTION;
|
||||
filesConverterParameters.setDefaults();
|
||||
imageConverterParameters.setDefaults();
|
||||
}
|
||||
|
||||
public void setConverterDirection(ConverterDirection value) {
|
||||
if (value == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'value' must not be null.");
|
||||
}
|
||||
this.converterDirection = value;
|
||||
}
|
||||
|
||||
public ConverterDirection getConverterDirection() {
|
||||
return converterDirection;
|
||||
}
|
||||
|
||||
public ConverterCommonParameters getConverterCommonParameters() {
|
||||
switch (getConverterDirection()) {
|
||||
case FILES_TO_IMAGE:
|
||||
return filesConverterParameters;
|
||||
case IMAGE_TO_FILES:
|
||||
return imageConverterParameters;
|
||||
default:
|
||||
throw new IllegalStateException("Unknown converter direction "
|
||||
+ getConverterDirection() + ".");
|
||||
}
|
||||
}
|
||||
|
||||
public FilesConverterParameters getFilesConverterParameters() {
|
||||
return filesConverterParameters;
|
||||
}
|
||||
|
||||
public ImageConverterParameters getImageConverterParameters() {
|
||||
return imageConverterParameters;
|
||||
}
|
||||
|
||||
public void copyTo(ConverterParameters target) {
|
||||
if (target == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'target' must not be null.");
|
||||
}
|
||||
target.setConverterDirection(converterDirection);
|
||||
filesConverterParameters.copyTo(target.getFilesConverterParameters());
|
||||
imageConverterParameters.copyTo(target.getImageConverterParameters());
|
||||
}
|
||||
|
||||
public boolean equals(ConverterParameters target) {
|
||||
if (target == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'target' must not be null.");
|
||||
}
|
||||
boolean result;
|
||||
result = target.getConverterDirection().equals(converterDirection);
|
||||
result = result
|
||||
&& target.getFilesConverterParameters().equals(
|
||||
filesConverterParameters);
|
||||
result = result
|
||||
&& target.getImageConverterParameters().equals(
|
||||
imageConverterParameters);
|
||||
return result;
|
||||
}
|
||||
|
||||
public InputStream getContents(String filePath) throws CoreException {
|
||||
if (filePath == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'filePath' must not be null.");
|
||||
}
|
||||
|
||||
GraphicsPropertiesSerializer serializer;
|
||||
Properties properties;
|
||||
|
||||
serializer = new GraphicsPropertiesSerializer();
|
||||
serialize(serializer);
|
||||
properties = serializer.getProperties();
|
||||
ByteArrayOutputStream propertiesStream = new ByteArrayOutputStream();
|
||||
|
||||
try {
|
||||
// ByteArrayOutputStream propertiesStream = new
|
||||
// ByteArrayOutputStream();
|
||||
properties
|
||||
.store(propertiesStream, "WUDSN IDE Converter Parameters");
|
||||
propertiesStream.close();
|
||||
|
||||
// Iterator<ImageWriter> iterator = ImageIO
|
||||
// .getImageWritersBySuffix("png");
|
||||
//
|
||||
// if (!iterator.hasNext()) {
|
||||
// throw new RuntimeException("No image writer for suffix 'png'");
|
||||
// }
|
||||
//
|
||||
// ImageWriter imagewriter = iterator.next();
|
||||
// imagewriter.setOutput(ImageIO
|
||||
// .createImageOutputStream(resourceStream));
|
||||
//
|
||||
// // Create & populate metadata
|
||||
// PNGMetadata metadata = new PNGMetadata();
|
||||
// metadata.tEXt_keyword.add("WUDSN");
|
||||
// metadata.tEXt_text.add(new
|
||||
// String(propertiesStream.toByteArray()));//
|
||||
//
|
||||
// // Render the PNG to memory
|
||||
// BufferedImage bufferedImage = new BufferedImage(imageData.width,
|
||||
// imageData.height, BufferedImage.TYPE_INT_RGB);
|
||||
// for (int y = 0; y < imageData.height; y++) {
|
||||
// for (int x = 0; x < imageData.width; x++) {
|
||||
// int pixel;
|
||||
// RGB rgb;
|
||||
//
|
||||
// pixel = imageData.getPixel(x, y);
|
||||
// rgb = imageData.palette.getRGB(pixel);
|
||||
// bufferedImage.setRGB(x, y, rgb.red << 16 | rgb.green << 8
|
||||
// | rgb.blue);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Build the image container, set the metadata and write the
|
||||
// // container.
|
||||
// IIOImage iioImage = new IIOImage(bufferedImage, null, null);
|
||||
// iioImage.setMetadata(metadata); // Attach the metadata
|
||||
// imagewriter.write(null, iioImage, null);
|
||||
|
||||
} catch (IOException ex) {
|
||||
// ERROR: Cannot write content of file '{0}'.
|
||||
throw new CoreException(new Status(IStatus.ERROR, GraphicsPlugin.ID,
|
||||
TextUtility.format(Texts.MESSAGE_E212, filePath), ex));
|
||||
|
||||
}
|
||||
|
||||
return new ByteArrayInputStream(propertiesStream.toByteArray());
|
||||
}
|
||||
|
||||
private void serialize(GraphicsPropertiesSerializer serializer) {
|
||||
if (serializer == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'serializer' must not be null.");
|
||||
}
|
||||
serializer
|
||||
.writeEnum(Attributes.CONVERTER_DIRECTION, converterDirection);
|
||||
filesConverterParameters.serialize(serializer,
|
||||
Attributes.FILES_CONVERTER_PARAMETERS);
|
||||
imageConverterParameters.serialize(serializer,
|
||||
Attributes.IMAGE_CONVERTER_PARAMETERS);
|
||||
}
|
||||
|
||||
public void read(IFile file) throws CoreException {
|
||||
if (file == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'file' must not be null.");
|
||||
}
|
||||
|
||||
byte[] content;
|
||||
content = FileUtility.readBytes(file, FileUtility.MAX_SIZE_UNLIMITED,
|
||||
false);
|
||||
SequencedProperties properties = new SequencedProperties();
|
||||
|
||||
try {
|
||||
properties.load(new ByteArrayInputStream(content));
|
||||
} catch (IOException ex) {
|
||||
// ERROR: Cannot read content of file '{0}'.
|
||||
throw new CoreException(new Status(IStatus.ERROR, GraphicsPlugin.ID,
|
||||
TextUtility.format(Texts.MESSAGE_E206, file.getFullPath()
|
||||
.toOSString()), ex));
|
||||
|
||||
}
|
||||
GraphicsPropertiesSerializer serializer;
|
||||
|
||||
serializer = new GraphicsPropertiesSerializer();
|
||||
serializer.getProperties().putAll(properties);
|
||||
deserialize(serializer);
|
||||
|
||||
GraphicsPlugin.getInstance().log("ConverterParameters.read({0}):{1}",
|
||||
new Object[] { file, serializer.getProperties() });
|
||||
|
||||
}
|
||||
|
||||
private void deserialize(GraphicsPropertiesSerializer serializer) {
|
||||
if (serializer == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'serializer' must not be null.");
|
||||
}
|
||||
converterDirection = serializer.readEnum(
|
||||
Attributes.CONVERTER_DIRECTION, Defaults.CONVERTER_DIRECTION,
|
||||
ConverterDirection.class);
|
||||
filesConverterParameters.deserialize(serializer,
|
||||
Attributes.FILES_CONVERTER_PARAMETERS);
|
||||
imageConverterParameters.deserialize(serializer,
|
||||
Attributes.IMAGE_CONVERTER_PARAMETERS);
|
||||
}
|
||||
}
|
@ -0,0 +1,305 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.wudsn.ide.gfx.converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
import org.eclipse.core.runtime.IExtension;
|
||||
import org.eclipse.core.runtime.IExtensionPoint;
|
||||
import org.eclipse.core.runtime.IExtensionRegistry;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
|
||||
import com.wudsn.ide.gfx.model.AspectUtility;
|
||||
import com.wudsn.ide.gfx.model.ConverterDirection;
|
||||
|
||||
/**
|
||||
* Registry for converters, based on the extension points
|
||||
* {@value ConverterRegistry#CONVERTERS}.
|
||||
*
|
||||
* @author Peter Dell
|
||||
*
|
||||
*/
|
||||
public final class ConverterRegistry {
|
||||
|
||||
/**
|
||||
* The id of the extension point which provides the converters.
|
||||
*/
|
||||
private static final String CONVERTERS = "com.wudsn.ide.gfx.converters";
|
||||
|
||||
/**
|
||||
* Maximum number of source files.
|
||||
*/
|
||||
public static final int MAX_SOURCE_FILES = 10;
|
||||
|
||||
/**
|
||||
* Maximum number of target files.
|
||||
*/
|
||||
public static final int MAX_TARGET_FILES = 10;
|
||||
|
||||
/**
|
||||
* The registered converter definitions.
|
||||
*/
|
||||
private List<ConverterDefinition> filesToImageConverterDefinitionList;
|
||||
private List<ConverterDefinition> imageToFilesConverterDefinitionList;
|
||||
|
||||
/**
|
||||
* The cached map of converter instances.
|
||||
*/
|
||||
private Map<String, Converter> converterMap;
|
||||
|
||||
/**
|
||||
* Creation is public.
|
||||
*/
|
||||
public ConverterRegistry() {
|
||||
filesToImageConverterDefinitionList = Collections.emptyList();
|
||||
imageToFilesConverterDefinitionList = Collections.emptyList();
|
||||
converterMap = Collections.emptyMap();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the list of available converters.
|
||||
*/
|
||||
public void init() {
|
||||
|
||||
filesToImageConverterDefinitionList = new ArrayList<ConverterDefinition>();
|
||||
imageToFilesConverterDefinitionList = new ArrayList<ConverterDefinition>();
|
||||
converterMap = new TreeMap<String, Converter>();
|
||||
|
||||
IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
|
||||
IExtensionPoint extensionPoint = extensionRegistry
|
||||
.getExtensionPoint(CONVERTERS);
|
||||
if (extensionPoint == null) {
|
||||
throw new IllegalStateException("Extension point '" + CONVERTERS
|
||||
+ "' is not defined.");
|
||||
}
|
||||
|
||||
IExtension[] extensions = extensionPoint.getExtensions();
|
||||
|
||||
for (IExtension extension : extensions) {
|
||||
IConfigurationElement[] converterGroupElements = extension
|
||||
.getConfigurationElements();
|
||||
for (IConfigurationElement converterGroupElement : converterGroupElements) {
|
||||
IConfigurationElement[] converterElements = converterGroupElement
|
||||
.getChildren("converter");
|
||||
for (IConfigurationElement converterElement : converterElements) {
|
||||
|
||||
ConverterDefinition converterDefinition;
|
||||
converterDefinition = new ConverterDefinition();
|
||||
converterDefinition.setId(converterElement
|
||||
.getAttribute("id"));
|
||||
converterDefinition.setName(converterElement
|
||||
.getAttribute("name"));
|
||||
converterDefinition
|
||||
.setSourceFileExtensions(converterElement
|
||||
.getAttribute("sourceFileExtensions"));
|
||||
converterDefinition.setTargetImagePaletteSize(Integer
|
||||
.parseInt(converterElement
|
||||
.getAttribute("targetImagePaletteSize")));
|
||||
converterDefinition
|
||||
.setTargetImageDisplayAspect(AspectUtility.fromString(converterElement
|
||||
.getAttribute("targetImageDisplayAspect")));
|
||||
IConfigurationElement[] sourceFileElements = converterElement
|
||||
.getChildren("sourceFile");
|
||||
int i = 0;
|
||||
for (IConfigurationElement sourceFileElement : sourceFileElements) {
|
||||
ConverterSourceFileDefinition sourceFileDefinition;
|
||||
sourceFileDefinition = new ConverterSourceFileDefinition();
|
||||
sourceFileDefinition.setSourceFileId(i);
|
||||
sourceFileDefinition.setLabel(sourceFileElement
|
||||
.getAttribute("label"));
|
||||
converterDefinition
|
||||
.addSourceFileDefinition(sourceFileDefinition);
|
||||
i++;
|
||||
}
|
||||
|
||||
IConfigurationElement[] targetFileElements = converterElement
|
||||
.getChildren("targetFile");
|
||||
i = 0;
|
||||
for (IConfigurationElement targetFileElement : targetFileElements) {
|
||||
ConverterTargetFileDefinition targetFileDefinition;
|
||||
targetFileDefinition = new ConverterTargetFileDefinition();
|
||||
targetFileDefinition.setSourceFileId(i);
|
||||
targetFileDefinition.setLabel(targetFileElement
|
||||
.getAttribute("label"));
|
||||
converterDefinition
|
||||
.addTargetFileDefinition(targetFileDefinition);
|
||||
i++;
|
||||
}
|
||||
|
||||
// If there is a source file, it is a files to image
|
||||
// converter.
|
||||
if (!converterDefinition.getSourceFileDefinitions()
|
||||
.isEmpty()) {
|
||||
filesToImageConverterDefinitionList
|
||||
.add(converterDefinition);
|
||||
|
||||
}
|
||||
// If there is a target file, it is a files to image
|
||||
// converter.
|
||||
if (!converterDefinition.getTargetFileDefinitions()
|
||||
.isEmpty()) {
|
||||
imageToFilesConverterDefinitionList
|
||||
.add(converterDefinition);
|
||||
|
||||
}
|
||||
addConverter(converterElement, converterDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create a sorted, unmodifiable copy.
|
||||
filesToImageConverterDefinitionList = new ArrayList<ConverterDefinition>(
|
||||
filesToImageConverterDefinitionList);
|
||||
Collections.sort(filesToImageConverterDefinitionList);
|
||||
filesToImageConverterDefinitionList = Collections
|
||||
.unmodifiableList(filesToImageConverterDefinitionList);
|
||||
|
||||
// Create a sorted, unmodifiable copy.
|
||||
imageToFilesConverterDefinitionList = new ArrayList<ConverterDefinition>(
|
||||
imageToFilesConverterDefinitionList);
|
||||
Collections.sort(imageToFilesConverterDefinitionList);
|
||||
imageToFilesConverterDefinitionList = Collections
|
||||
.unmodifiableList(imageToFilesConverterDefinitionList);
|
||||
|
||||
// Create an unmodifiable copy.
|
||||
converterMap = Collections.unmodifiableMap(converterMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new converter.
|
||||
*
|
||||
* @param configurationElement
|
||||
* The configuration element used as class instance factory, not
|
||||
* <code>null</code>.
|
||||
*
|
||||
* @param converterDefinition
|
||||
* The converter definition, not <code>null</code>.
|
||||
*/
|
||||
private void addConverter(IConfigurationElement configurationElement,
|
||||
ConverterDefinition converterDefinition) {
|
||||
if (configurationElement == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'configurationElement' must not be null.");
|
||||
}
|
||||
if (converterDefinition == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'converterDefinition' must not be null.");
|
||||
}
|
||||
|
||||
String id = converterDefinition.getId();
|
||||
Converter converter;
|
||||
try {
|
||||
converter = (Converter) configurationElement
|
||||
.createExecutableExtension("id");
|
||||
} catch (CoreException ex) {
|
||||
throw new RuntimeException("Cannot instantiate converter '" + id
|
||||
+ "'.", ex);
|
||||
}
|
||||
converter.setDefinition(converterDefinition);
|
||||
converter = converterMap.put(id, converter);
|
||||
if (converter != null) {
|
||||
throw new RuntimeException("Converter id '" + id
|
||||
+ "' is already registered to class '"
|
||||
+ converter.getClass().getName() + "'.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the unmodifiable list of converter definitions, sorted by their id.
|
||||
*
|
||||
* @param converterDirection
|
||||
* The converter direction, not <code>null</code>.
|
||||
*
|
||||
* @return The unmodifiable list of converter definitions, sorted by their
|
||||
* id, not empty and not <code>null</code>.
|
||||
*/
|
||||
public List<ConverterDefinition> getDefinitions(
|
||||
ConverterDirection converterDirection) {
|
||||
if (converterDirection == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'converterDirection' must not be null.");
|
||||
}
|
||||
switch (converterDirection) {
|
||||
case FILES_TO_IMAGE:
|
||||
return filesToImageConverterDefinitionList;
|
||||
case IMAGE_TO_FILES:
|
||||
return imageToFilesConverterDefinitionList;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown converter directtion "
|
||||
+ converterDirection + ".");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the converter definition for an id.
|
||||
*
|
||||
* @param converterId
|
||||
* The converter id, may be empty, not <code>null</code>.
|
||||
* @param converterDirection
|
||||
* The direction of the converter, not <code>null</code>.
|
||||
*
|
||||
* @return The converter definition or <code>null</code>.
|
||||
*/
|
||||
public ConverterDefinition getDefinition(String converterId,
|
||||
ConverterDirection converterDirection) {
|
||||
if (converterId == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'converterId' must not be null.");
|
||||
}
|
||||
List<ConverterDefinition> converterDefinitionList = getDefinitions(converterDirection);
|
||||
for (ConverterDefinition converterDefinition : converterDefinitionList) {
|
||||
if (converterDefinition.getId().equals(converterId)) {
|
||||
return converterDefinition;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the converter for a given id. Instances of {@link Converter} are
|
||||
* stateless singletons within the plugin.
|
||||
*
|
||||
* @param converterId
|
||||
* The converter id, not <code>null</code>.
|
||||
*
|
||||
* @return The converter or <code>null</code>.
|
||||
*/
|
||||
public Converter getConverter(String converterId) {
|
||||
if (converterId == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'converterId' must not be null.");
|
||||
}
|
||||
Converter result;
|
||||
synchronized (converterMap) {
|
||||
|
||||
result = converterMap.get(converterId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,162 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.wudsn.ide.gfx.converter;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.ContextFactory;
|
||||
import org.mozilla.javascript.Function;
|
||||
import org.mozilla.javascript.RhinoException;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
import com.wudsn.ide.base.common.FileUtility;
|
||||
import com.wudsn.ide.gfx.GraphicsPlugin;
|
||||
|
||||
/**
|
||||
* Converter script utility class.
|
||||
*
|
||||
* @author Peter Dell
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public final class ConverterScript {
|
||||
|
||||
public static void convertToFileData(Converter converter, ImageConverterData data) throws CoreException {
|
||||
|
||||
// Collect the arguments into a single string.
|
||||
String script = data.getParameters().getScript();
|
||||
ConverterScriptData converterScriptData = data.getConverterScriptData();
|
||||
ContextFactory contextFactory = ContextFactory.getGlobal();
|
||||
Context context = null;
|
||||
Scriptable scope = null;
|
||||
|
||||
try {
|
||||
if (!script.equals(converterScriptData.getCompiledScript())) {
|
||||
|
||||
if (converterScriptData.getCompiledContext() != null && Context.getCurrentContext() != null) {
|
||||
Context.exit();
|
||||
}
|
||||
// Creates and enters a new Context. The Context stores
|
||||
// information
|
||||
// about the execution environment of a script.
|
||||
context = contextFactory.enterContext();
|
||||
scope = context.initStandardObjects();
|
||||
context.setOptimizationLevel(9);
|
||||
context.evaluateString(scope, script, "Line ", 1, null);
|
||||
// Initialize the standard objects (Object, Function, etc.)
|
||||
// This must be done before scripts can be executed. Returns
|
||||
// a scope object that we use in later calls.
|
||||
converterScriptData.setCompiledScript(script);
|
||||
converterScriptData.setCompiledContext(context);
|
||||
converterScriptData.setCompiledScope(scope);
|
||||
} else {
|
||||
// Restore the previous context.
|
||||
context = converterScriptData.getCompiledContext();
|
||||
contextFactory.enterContext(context);
|
||||
scope = converterScriptData.getCompiledScope();
|
||||
}
|
||||
|
||||
// Set global variables.
|
||||
ConverterConsole converterConsole = GraphicsPlugin.getInstance().getConverterConsole();
|
||||
scope.put("Console", scope, Context.toObject(converterConsole, scope));
|
||||
|
||||
// Call function
|
||||
converterScriptData.setErrorLineNumber(-1);
|
||||
String functionName = "convertToFileData";
|
||||
Object functionObject = scope.get(functionName, scope);
|
||||
if (functionObject == null) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, GraphicsPlugin.ID, "'" + functionName
|
||||
+ "' is undefined."));
|
||||
}
|
||||
if (!(functionObject instanceof Function)) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, GraphicsPlugin.ID, "'" + functionName
|
||||
+ "' is not a function."));
|
||||
}
|
||||
|
||||
Object functionArgs[] = { Context.toObject(data, scope) };
|
||||
Function function = (Function) functionObject;
|
||||
function.call(context, scope, scope, functionArgs);
|
||||
|
||||
} catch (RhinoException ex) {
|
||||
converterScriptData.setErrorLineNumber(ex.lineNumber());
|
||||
String message = getMessageString(ex.details());
|
||||
String lineSource = getMessageString(ex.lineSource());
|
||||
throw new CoreException(new Status(IStatus.ERROR, GraphicsPlugin.ID, "Error in script line "
|
||||
+ ex.lineNumber() + ": " + message + " " + lineSource, ex));
|
||||
|
||||
} finally {
|
||||
|
||||
// Exit from the context. Remove the context association to the
|
||||
// current thread.
|
||||
if (Context.getCurrentContext() != null) {
|
||||
Context.exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a string to message format (not <code>null</code>, no tabs).
|
||||
*
|
||||
* @param string
|
||||
* The string, or <code>null</code>.
|
||||
* @return The message string, may be empty, not <code>null</code>.
|
||||
*/
|
||||
private static String getMessageString(String string) {
|
||||
String result;
|
||||
if (string != null) {
|
||||
result = string.replace('\t', ' ');
|
||||
} else {
|
||||
result = "";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the script associated with a compiler class.
|
||||
*
|
||||
* @param converterClass
|
||||
* The of the converter, not <code>null</code>.
|
||||
* @return The script for the converter, may be empty, not <code>null</code>
|
||||
* .
|
||||
* @throws CoreException
|
||||
* In case there is an error while reading an existing script.
|
||||
*/
|
||||
public static String getScript(Class<? extends Converter> converterClass) throws CoreException {
|
||||
if (converterClass == null) {
|
||||
throw new IllegalArgumentException("Parameter 'converterClass' must not be null.");
|
||||
}
|
||||
String result;
|
||||
|
||||
String converterScriptFileName = "/" + converterClass.getName().replace('.', '/') + ".js";
|
||||
InputStream inputStream = converterClass.getResourceAsStream(converterScriptFileName);
|
||||
|
||||
if (inputStream != null) {
|
||||
result = FileUtility.readString(converterScriptFileName, inputStream, FileUtility.MAX_SIZE_UNLIMITED);
|
||||
} else {
|
||||
result = "";
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.wudsn.ide.gfx.converter;
|
||||
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* Container for a compiled converter scripts and its context.
|
||||
*
|
||||
* @author Peter Dell
|
||||
* @since 1.6.6
|
||||
*/
|
||||
public final class ConverterScriptData {
|
||||
private String compiledScript;
|
||||
private Context compiledContext;
|
||||
private Scriptable compiledScope;
|
||||
private int errorLineNumber;
|
||||
|
||||
/**
|
||||
* Gets the compiled script for which the compiled context and scope are
|
||||
* cached.
|
||||
*
|
||||
* @return The compiled script, maybe be empty, not <code>null</code>.
|
||||
*/
|
||||
public String getCompiledScript() {
|
||||
return compiledScript;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the compiled script for which the compiled context and scope are
|
||||
* cached.
|
||||
*
|
||||
* @param compiledScript
|
||||
* The compiled script, may be empty, not <code>null</code>.
|
||||
*/
|
||||
public void setCompiledScript(String compiledScript) {
|
||||
if (compiledScript == null) {
|
||||
throw new IllegalArgumentException("Parameter 'compiledScript' must not be null.");
|
||||
}
|
||||
this.compiledScript = compiledScript;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the compiled context which was created for the compiled script.
|
||||
*
|
||||
* @return The compiled context or <code>null</code>.
|
||||
*/
|
||||
public Context getCompiledContext() {
|
||||
return compiledContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the compiled context which was created for the compiled script.
|
||||
*
|
||||
* @param compiledContext
|
||||
* The compiled context or <code>null</code>.
|
||||
*/
|
||||
public void setCompiledContext(Context compiledContext) {
|
||||
this.compiledContext = compiledContext;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the compiled scope which was created for the compiled script.
|
||||
*
|
||||
* @return The compiled context or <code>null</code>.
|
||||
*/
|
||||
public Scriptable getCompiledScope() {
|
||||
return compiledScope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the compiled scope which was created for the compiled script.
|
||||
*
|
||||
* @param compiledScope
|
||||
* The compiled scope or <code>null</code>.
|
||||
*/
|
||||
public void setCompiledScope(Scriptable compiledScope) {
|
||||
this.compiledScope = compiledScope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the line number of the first error that occurred in the script.
|
||||
*
|
||||
* @param errorLineNumber
|
||||
* The line number of the first error that occurred in the
|
||||
* script, a positive integer or <code>-1</code> if there is
|
||||
* no error.
|
||||
*/
|
||||
public void setErrorLineNumber(int errorLineNumber) {
|
||||
this.errorLineNumber = errorLineNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the line number of the first error that occurred in the script.
|
||||
*
|
||||
* @return The line number of the first error that occurred in the script,a
|
||||
* positive integer or <code>-1</code> if there is no error.
|
||||
*/
|
||||
public int geErrorLineNumber() {
|
||||
return errorLineNumber;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.wudsn.ide.gfx.converter;
|
||||
|
||||
public final class ConverterSourceFileDefinition {
|
||||
private int sourceFileId;
|
||||
private String label;
|
||||
|
||||
ConverterSourceFileDefinition() {
|
||||
|
||||
}
|
||||
|
||||
public int getSourceFileId() {
|
||||
return sourceFileId;
|
||||
}
|
||||
|
||||
final void setSourceFileId(int sourceFileId) {
|
||||
this.sourceFileId = sourceFileId;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
final void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.wudsn.ide.gfx.converter;
|
||||
|
||||
public final class ConverterTargetFileDefinition {
|
||||
private int sourceFileId;
|
||||
private String label;
|
||||
|
||||
ConverterTargetFileDefinition() {
|
||||
|
||||
}
|
||||
|
||||
public int getSourceFileId() {
|
||||
return sourceFileId;
|
||||
}
|
||||
|
||||
final void setSourceFileId(int sourceFileId) {
|
||||
this.sourceFileId = sourceFileId;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
final void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,212 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.wudsn.ide.gfx.converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.wudsn.ide.base.common.HexUtility;
|
||||
import com.wudsn.ide.base.common.NumberUtility;
|
||||
import com.wudsn.ide.gfx.GraphicsPlugin;
|
||||
import com.wudsn.ide.gfx.model.ConverterDirection;
|
||||
import com.wudsn.ide.gfx.model.ConverterMode;
|
||||
|
||||
public final class FilesConverterData extends ConverterCommonData {
|
||||
|
||||
private FilesConverterParameters parameters;
|
||||
|
||||
private List<byte[]> sourceFilesBytes;
|
||||
|
||||
private boolean imageDataValid;
|
||||
|
||||
FilesConverterData(ConverterData converterData) {
|
||||
super(converterData);
|
||||
|
||||
this.parameters = converterData.getParameters()
|
||||
.getFilesConverterParameters();
|
||||
sourceFilesBytes = new ArrayList<byte[]>(0);
|
||||
}
|
||||
|
||||
public FilesConverterParameters getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the converter for a converter id specified in the parameters.
|
||||
* Instances of {@link Converter} are stateless singletons within the
|
||||
* plugin.
|
||||
*
|
||||
* @return The converter or <code>null</code>.
|
||||
*/
|
||||
public Converter getConverter() {
|
||||
ConverterRegistry converterRegistry;
|
||||
Converter converter;
|
||||
converterRegistry = GraphicsPlugin.getInstance().getConverterRegistry();
|
||||
converter = converterRegistry.getConverter(parameters.getConverterId());
|
||||
return converter;
|
||||
}
|
||||
|
||||
public int getTargetImagePaletteSize() {
|
||||
ConverterRegistry converterRegistry;
|
||||
ConverterDefinition converterDefinition;
|
||||
int result;
|
||||
|
||||
converterRegistry = GraphicsPlugin.getInstance().getConverterRegistry();
|
||||
converterDefinition = converterRegistry.getDefinition(
|
||||
parameters.getConverterId(), ConverterDirection.FILES_TO_IMAGE);
|
||||
if (converterDefinition != null) {
|
||||
result = converterDefinition.getTargetImagePaletteSize();
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCreateConversionEnabled() {
|
||||
return converterData.isValid()
|
||||
&& converterData.getConverterMode() == ConverterMode.RAW_FILE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return converterData.isValidFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRefreshEnabled() {
|
||||
return converterData.isValidFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
super.clear();
|
||||
sourceFilesBytes.clear();
|
||||
}
|
||||
|
||||
public void setSourceFileBytes(int sourceFileId, byte[] bytes) {
|
||||
if (sourceFileId < 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'sourceFileId' must not be negative. Specified value is "
|
||||
+ sourceFileId + ".");
|
||||
}
|
||||
while (sourceFilesBytes.size() <= sourceFileId) {
|
||||
sourceFilesBytes.add(null);
|
||||
}
|
||||
sourceFilesBytes.set(sourceFileId, bytes);
|
||||
}
|
||||
|
||||
public byte[] getSourceFileBytes(int sourceFileId) {
|
||||
if (sourceFileId < 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'sourceFileId' must not be negative. Specified value is "
|
||||
+ sourceFileId + ".");
|
||||
}
|
||||
byte[] bytes;
|
||||
if (sourceFileId < sourceFilesBytes.size()) {
|
||||
bytes = sourceFilesBytes.get(sourceFileId);
|
||||
} else {
|
||||
bytes = null;
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public void setImageDataValid(boolean imageDataValid) {
|
||||
this.imageDataValid = imageDataValid;
|
||||
}
|
||||
|
||||
public boolean isImageDataValid() {
|
||||
return imageDataValid;
|
||||
}
|
||||
|
||||
public boolean isSaveImageEnabled() {
|
||||
return converterData.isValidFile()&& isImageDataValid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a byte from the source file, taking it offset from the parameter
|
||||
* into account plus the relative offset of the conversion routine.
|
||||
*
|
||||
* @param sourceFileId
|
||||
* The id of the source file, a non-negative integer.
|
||||
* @param offset
|
||||
* The relative object of the conversion routine, a non-negative
|
||||
* integer.
|
||||
* @return The byte as integer or <code>-1</code> to indicate that the
|
||||
* offset is outside of the file.
|
||||
*/
|
||||
public int getSourceFileByte(int sourceFileId, int offset) {
|
||||
if (sourceFileId >= sourceFilesBytes.size()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
byte[] sourceFileBytes = sourceFilesBytes.get(sourceFileId);
|
||||
if (sourceFileBytes == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
offset = offset + parameters.getSourceFile(sourceFileId).getOffset();
|
||||
if (offset < 0 || offset >= sourceFileBytes.length) {
|
||||
return -1;
|
||||
}
|
||||
int value = sourceFileBytes[offset] & 0xff;
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setPalettePixel(int x, int y, int color) {
|
||||
try {
|
||||
imageData.setPixel(x, y, color);
|
||||
} catch (RuntimeException ex) {
|
||||
GraphicsPlugin
|
||||
.getInstance()
|
||||
.logError(
|
||||
"Error setting palette pixel at ({0}, {1}) to color {2}. Image size is {3},{4}",
|
||||
new String[] {
|
||||
NumberUtility.getLongValueDecimalString(x),
|
||||
NumberUtility.getLongValueDecimalString(y),
|
||||
HexUtility.getLongValueHexString(color),
|
||||
NumberUtility
|
||||
.getLongValueDecimalString(imageData.width),
|
||||
NumberUtility
|
||||
.getLongValueDecimalString(imageData.height) },
|
||||
ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void setDirectPixel(int x, int y, int color) {
|
||||
try {
|
||||
imageData.setPixel(x, y, color);
|
||||
} catch (RuntimeException ex) {
|
||||
GraphicsPlugin
|
||||
.getInstance()
|
||||
.logError(
|
||||
"Error setting direct pixel at ({0}, {1}) to color {2}. Image size is {3},{4}",
|
||||
new String[] {
|
||||
NumberUtility.getLongValueDecimalString(x),
|
||||
NumberUtility.getLongValueDecimalString(y),
|
||||
HexUtility.getLongValueHexString(color),
|
||||
NumberUtility
|
||||
.getLongValueDecimalString(imageData.width),
|
||||
NumberUtility
|
||||
.getLongValueDecimalString(imageData.height) },
|
||||
ex);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,293 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.wudsn.ide.gfx.converter;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
|
||||
import com.wudsn.ide.gfx.GraphicsPlugin;
|
||||
import com.wudsn.ide.gfx.converter.atari8bit.LinearBitMapGraphics8Converter;
|
||||
import com.wudsn.ide.gfx.model.ConverterDirection;
|
||||
|
||||
/**
|
||||
* This class is based on the excellent open source
|
||||
* "First Atari Image Library (FAIL)". Thanks to the creators to FAIL: Piotr
|
||||
* Fusik, Adrian Matoga and Pawel Szewczyk for their support. You can find FAIL
|
||||
* on sourceforge "http://fail.sourceforge.net".
|
||||
*
|
||||
* @author Peter Dell
|
||||
*
|
||||
*/
|
||||
|
||||
public final class FilesConverterDataLogic {
|
||||
|
||||
/**
|
||||
* Helper class to detect the support binary file formats by their
|
||||
* extension. The extension have to be defined with lower case characters.
|
||||
*
|
||||
* @author Peter Dell
|
||||
*/
|
||||
public static final class FileExtensions {
|
||||
|
||||
// C64 font with 2 bytes load address
|
||||
public static final String _64c = "64c";
|
||||
|
||||
// 80x192, 256 colors, interlaced
|
||||
// @since FAIL 1.0.0
|
||||
public static final String AP3 = "ap3";
|
||||
|
||||
// Any Point, Any Color; 80x96, 256 colors, interlaced
|
||||
// @since FAIL 1.0.0
|
||||
public static final String APC = "apc";
|
||||
|
||||
// 8x8 charset, mono or multicolor
|
||||
// @since FAIL 1.0.0
|
||||
public static final String CHR = "chr";
|
||||
|
||||
// Champions' Interlace; 160x192, compressed
|
||||
// @since FAIL 1.0.0
|
||||
public static final String CCI = "cci";
|
||||
|
||||
// Champions' Interlace; 160x192
|
||||
// @since FAIL 1.0.0
|
||||
public static final String CIN = "cin";
|
||||
|
||||
// Trzmiel; 320x192, mono, compressed
|
||||
// @since FAIL 1.0.0
|
||||
public static final String CPR = "cpr";
|
||||
|
||||
// Standard 8x8 font, mono
|
||||
// @since FAIL 1.0.0
|
||||
public static final String FNT = "fnt";
|
||||
|
||||
// Gephard Hires Graphics; up to 320x200, mono
|
||||
// @since FAIL 1.0.1
|
||||
public static final String GHG = "ghg";
|
||||
|
||||
// Standard 320x192, mono
|
||||
// @since FAIL 1.0.0
|
||||
public static final String GR8 = "gr8";
|
||||
|
||||
// Standard 80x192, grayscale
|
||||
// @since FAIL 1.0.0
|
||||
public static final String GR9 = "gr9";
|
||||
|
||||
// Hard Interlace Picture; 160x200, grayscale
|
||||
// @since FAIL 1.0.0
|
||||
public static final String HIP = "hip";
|
||||
|
||||
// Hires 256x239, 3 colors, interlaced
|
||||
// @since FAIL 1.0.0
|
||||
public static final String HR = "hr";
|
||||
|
||||
// Hires 320x200, 5 colors, interlaced
|
||||
// @since FAIL 1.0.1
|
||||
public static final String HR2 = "hr2";
|
||||
|
||||
// APAC 80x192, 256 colors interlaced
|
||||
// @since FAIL 1.0.0
|
||||
public static final String ILC = "ilc";
|
||||
|
||||
// Interlace Picture 160x200, 7 colors, interlaced
|
||||
// @since FAIL 1.0.0
|
||||
public static final String INP = "inp";
|
||||
|
||||
// INT95a, up to 160x239, 16 colors, interlaced
|
||||
// @since FAIL 1.0.0
|
||||
public static final String INT = "int";
|
||||
|
||||
// McPainter; 160x200, 16 colors, interlaced
|
||||
// @since FAIL 1.0.1
|
||||
public static final String MCP = "mcp";
|
||||
|
||||
// Micropainter 160x192, 4 colors
|
||||
// @since FAIL 1.0.0
|
||||
public static final String MIC = "mic";
|
||||
|
||||
// Koala MicroIllustrator; 160x192, 4 colors, compressed
|
||||
// @since FAIL 1.0.0
|
||||
public static final String PIC = "pic";
|
||||
|
||||
// Plama 256; 80x96, 256 colors
|
||||
// @since FAIL 1.0.0
|
||||
public static final String PLM = "plm";
|
||||
|
||||
// Rocky Interlace Picture; up to 160x239
|
||||
// @since FAIL 1.0.0
|
||||
public static final String RIP = "rip";
|
||||
|
||||
// C64 sprites
|
||||
// Can be mono or multi color.
|
||||
public static final String SPR = "spr";
|
||||
|
||||
// 16x16 font, mono
|
||||
// @since FAIL 1.0.0
|
||||
public static final String SXS = "sxs";
|
||||
|
||||
// Taquart Interlace Picture; up to 160x119
|
||||
// @since FAIL 1.0.0
|
||||
public static final String TIP = "tip";
|
||||
|
||||
|
||||
|
||||
// TODO Fail 1.1.0
|
||||
// Fixed decoding of ILC, AP3, RIP, PIC, CPR, HIP and CIN.
|
||||
// Added support for MCH, IGE, 256, AP2, JGP, DGP, ESC, PZM, IST and RAW.
|
||||
// MCH IGE 256 AP2 JGP DGP ESC PZM IST RAW
|
||||
// 256:: 80x96, 256 colors.
|
||||
// AP2:: 80x96, 256 colors.
|
||||
//
|
||||
// DGP:: "DigiPaint", 80x192, 256 colors, interlaced.
|
||||
// ESC:: "EscalPaint", 80x192, 256 colors, interlaced.
|
||||
// IGE:: "Interlace Graphics Editor", 128x96, 16 colors, interlaced.
|
||||
//
|
||||
// IST:: "Interlace Studio", 160x200, interlaced.
|
||||
// JGP:: "Jet Graphics Planner", 8x16 tiles, 4 colors.
|
||||
// MCH:: Up to 192x240, 128 colors.
|
||||
// PZM:: "EscalPaint", 80x192, 256 colors, interlaced.
|
||||
// RAW:: "XL-Paint MAX", 160x192, 16 colors, interlaced.
|
||||
|
||||
// fail.h: #define FAIL_WIDTH_MAX 320 => 384, used in RIP
|
||||
//
|
||||
// /* Limits. */
|
||||
// #define FAIL_IMAGE_MAX 30000
|
||||
// #define FAIL_WIDTH_MAX 384
|
||||
// #define FAIL_HEIGHT_MAX 240
|
||||
// #define FAIL_PALETTE_MAX 768
|
||||
// #define FAIL_PIXELS_MAX (FAIL_WIDTH_MAX * FAIL_HEIGHT_MAX * 3)
|
||||
}
|
||||
|
||||
FilesConverterDataLogic() {
|
||||
|
||||
}
|
||||
|
||||
public void applyDefaults(FilesConverterData data) {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'data' must not be null.");
|
||||
}
|
||||
FilesConverterParameters parameters;
|
||||
Converter converter;
|
||||
|
||||
parameters = data.getParameters();
|
||||
converter = data.getConverter();
|
||||
|
||||
// Take defaults from the definition.
|
||||
if (converter != null) {
|
||||
int targetImagePaletteSize = converter.getDefinition()
|
||||
.getTargetImagePaletteSize();
|
||||
RGB[] rgbs;
|
||||
if (targetImagePaletteSize > 0) {
|
||||
rgbs = new RGB[targetImagePaletteSize];
|
||||
for (int i = 0; i < targetImagePaletteSize; i++) {
|
||||
int brightness = (255 * i) / (targetImagePaletteSize - 1);
|
||||
RGB rgb = new RGB(brightness, brightness, brightness);
|
||||
rgbs[i] = rgb;
|
||||
}
|
||||
} else {
|
||||
rgbs = new RGB[0];
|
||||
}
|
||||
parameters.setPaletteRGBs(rgbs);
|
||||
parameters.setDisplayAspect(converter.getDefinition()
|
||||
.getTargetImageDisplayAspect());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the most suitable converter, apply its defaults and preset image
|
||||
* dimensions and colors based on the input file. In case of compressed
|
||||
* images, the source file in the data container is replaced by the unpacked
|
||||
* content. This leads to unwanted effect during reload which can only be
|
||||
* removed by the introduction of separate converters for these cases.
|
||||
*
|
||||
* @param data
|
||||
* The file converter data, not <code>null</code>.
|
||||
* @param bytes
|
||||
* The file content of the input file, not <code>null</code>.
|
||||
* @param fileExtension
|
||||
* The file extension of the input file, may be empty, not
|
||||
* <code>null</code>.
|
||||
*/
|
||||
public void findDefaultFileConverter(FilesConverterData data, byte[] bytes,
|
||||
String fileExtension) {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'data' must not be null.");
|
||||
}
|
||||
if (bytes == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'bytes' must not be null.");
|
||||
}
|
||||
if (fileExtension == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'fileExtension' must not be null.");
|
||||
}
|
||||
int columns;
|
||||
int rows;
|
||||
FilesConverterParameters parameters = data.getParameters();
|
||||
|
||||
ConverterRegistry converterRegistry = GraphicsPlugin.getInstance()
|
||||
.getConverterRegistry();
|
||||
List<ConverterDefinition> converterDefinitions = converterRegistry
|
||||
.getDefinitions(ConverterDirection.FILES_TO_IMAGE);
|
||||
|
||||
// Try to match file extensions and content.
|
||||
boolean converted = false;
|
||||
Iterator<ConverterDefinition> i = converterDefinitions.iterator();
|
||||
while (i.hasNext() && !converted) {
|
||||
ConverterDefinition converterDefinition = i.next();
|
||||
if (converterDefinition
|
||||
.isSourceFileExtensionSupported(fileExtension)) {
|
||||
Converter converter = converterRegistry
|
||||
.getConverter(converterDefinition.getId());
|
||||
if (converter.canConvertToImage(bytes)) {
|
||||
converter.convertToImageSizeAndPalette(data, bytes);
|
||||
converted = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ignore file extension and try to match content only.
|
||||
if (!converted) {
|
||||
i = converterDefinitions.iterator();
|
||||
while (i.hasNext() && !converted) {
|
||||
ConverterDefinition converterDefinition = i.next();
|
||||
Converter converter = converterRegistry
|
||||
.getConverter(converterDefinition.getId());
|
||||
if (converter.canConvertToImage(bytes)) {
|
||||
converter.convertToImageSizeAndPalette(data, bytes);
|
||||
converted = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If nothing matched, display as hires bitmap.
|
||||
if (!converted) {
|
||||
data.getParameters().setConverterId(
|
||||
LinearBitMapGraphics8Converter.class.getName());
|
||||
applyDefaults(data);
|
||||
columns = 40;
|
||||
rows = (bytes.length + columns - 1) / columns;
|
||||
parameters.setColumns(columns);
|
||||
parameters.setRows(rows);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,550 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.wudsn.ide.gfx.converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
|
||||
import com.wudsn.ide.gfx.GraphicsPlugin;
|
||||
import com.wudsn.ide.gfx.model.ConverterDirection;
|
||||
import com.wudsn.ide.gfx.model.GraphicsPropertiesSerializer;
|
||||
import com.wudsn.ide.gfx.model.Palette;
|
||||
import com.wudsn.ide.gfx.model.PaletteType;
|
||||
|
||||
public final class FilesConverterParameters extends ConverterCommonParameters {
|
||||
|
||||
/**
|
||||
* Names of the attributes.
|
||||
*
|
||||
* @author Peter Dell
|
||||
*
|
||||
*/
|
||||
public static final class Attributes {
|
||||
|
||||
/**
|
||||
* Creation is private.
|
||||
*/
|
||||
private Attributes() {
|
||||
}
|
||||
|
||||
public static final String SOURCE_FILES = "sourceFiles";
|
||||
public static final String SOURCE_FILE_PATH = "path";
|
||||
public static final String SOURCE_FILE_OFFSET = "offset";
|
||||
public static final String IMAGE_FILE_PATH = "imageFilePath";
|
||||
|
||||
public static final String COLUMNS = "columns";
|
||||
public static final String ROWS = "rows";
|
||||
|
||||
public static final String SPACING_COLOR = "spacingColor";
|
||||
public static final String SPACING_WIDTH = "spacingWidth";
|
||||
|
||||
public static final String PIXEL_TYPE = "pixelType";
|
||||
public static final String PALETTE = "palette";
|
||||
public static final String PALETTE_TYPE = "paletteType";
|
||||
public static final String PALETTE_COLORS = "paletteRGBs";
|
||||
}
|
||||
|
||||
/**
|
||||
* Defaults of the attributes.
|
||||
*
|
||||
* @author Peter Dell
|
||||
*
|
||||
*/
|
||||
private static final class Defaults {
|
||||
|
||||
/**
|
||||
* Creation is private.
|
||||
*/
|
||||
private Defaults() {
|
||||
}
|
||||
|
||||
public static final String SOURCE_FILE_PATH = "";
|
||||
public static final int SOURCE_FILE_OFFSET = 0;
|
||||
public static final String IMAGE_FILE_PATH = "";
|
||||
|
||||
public static final int COLUMNS = 40;
|
||||
public static final int ROWS = 24;
|
||||
|
||||
public static final RGB SPACING_COLOR = new RGB(0, 0, 128);
|
||||
public static final int SPACING_WIDTH = 0;
|
||||
|
||||
public static final PaletteType PALETTE_TYPE = PaletteType.ATARI_DEFAULT;
|
||||
public static final Palette PALETTE = Palette.HIRES_1;
|
||||
public static final RGB[] PALETTE_COLORS = new RGB[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Message ids of the attributes.
|
||||
*
|
||||
* @author Peter Dell
|
||||
*
|
||||
*/
|
||||
public static final class MessageIds {
|
||||
|
||||
/**
|
||||
* Creation is private.
|
||||
*/
|
||||
private MessageIds() {
|
||||
}
|
||||
|
||||
public static final int SOURCE_FILE_PATH = 1010;
|
||||
public static final int SOURCE_FILE_OFFSET = 1020;
|
||||
public static final int IMAGE_FILE_PATH = 1030;
|
||||
|
||||
public static final int SPACING_COLOR = 1100;
|
||||
public static final int SPACING_WIDTH = 1101;
|
||||
public static final int COLUMNS = 1102;
|
||||
public static final int ROWS = 1103;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A source file.
|
||||
*
|
||||
* @author Peter Dell
|
||||
*
|
||||
*/
|
||||
public static final class SourceFile {
|
||||
private int id;
|
||||
private String path;
|
||||
private int offset;
|
||||
|
||||
public SourceFile(int id) {
|
||||
this.id = id;
|
||||
path = Defaults.SOURCE_FILE_PATH;
|
||||
offset = Defaults.SOURCE_FILE_OFFSET;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getPathMessageId() {
|
||||
return MessageIds.SOURCE_FILE_PATH + id;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
if (path == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'path' must not be null.");
|
||||
}
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public int getOffsetMessageId() {
|
||||
return MessageIds.SOURCE_FILE_OFFSET + id;
|
||||
}
|
||||
|
||||
public int getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
public void setOffset(int offset) {
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'obj' must not be null.");
|
||||
}
|
||||
SourceFile other = (SourceFile) obj;
|
||||
return other.id == this.id && other.path.equals(this.path)
|
||||
&& other.offset == this.offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id + 7 * path.hashCode() + 17 * offset;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int sourceFilesSize;
|
||||
private List<SourceFile> sourceFiles;
|
||||
private String imageFilePath;
|
||||
|
||||
private int columns;
|
||||
private int rows;
|
||||
|
||||
private RGB spacingColor;
|
||||
private int spacingWidth;
|
||||
|
||||
private PaletteType paletteType;
|
||||
private Palette palette;
|
||||
private RGB[] paletteRGBs;
|
||||
|
||||
FilesConverterParameters() {
|
||||
|
||||
int size = ConverterRegistry.MAX_SOURCE_FILES;
|
||||
this.sourceFiles = new ArrayList<SourceFile>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
this.sourceFiles.add(new SourceFile(i));
|
||||
}
|
||||
setDefaults();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaults() {
|
||||
super.setDefaults();
|
||||
|
||||
for (SourceFile sourceFile : sourceFiles) {
|
||||
sourceFile.setPath(Defaults.SOURCE_FILE_PATH);
|
||||
sourceFile.setOffset(Defaults.SOURCE_FILE_OFFSET);
|
||||
}
|
||||
imageFilePath = Defaults.IMAGE_FILE_PATH;
|
||||
|
||||
columns = Defaults.COLUMNS;
|
||||
rows = Defaults.ROWS;
|
||||
spacingColor = Defaults.SPACING_COLOR;
|
||||
spacingWidth = Defaults.SPACING_WIDTH;
|
||||
|
||||
paletteType = Defaults.PALETTE_TYPE;
|
||||
palette = Defaults.PALETTE;
|
||||
paletteRGBs = Defaults.PALETTE_COLORS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConverterId(String value) {
|
||||
if (value == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'value' must not be null.");
|
||||
}
|
||||
this.converterId = value;
|
||||
|
||||
ConverterDefinition converterDefinition;
|
||||
converterDefinition = GraphicsPlugin.getInstance()
|
||||
.getConverterRegistry()
|
||||
.getDefinition(converterId, ConverterDirection.FILES_TO_IMAGE);
|
||||
if (converterDefinition != null) {
|
||||
sourceFilesSize = converterDefinition.getSourceFileDefinitions().size();
|
||||
} else {
|
||||
sourceFilesSize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void setDefaultSourceFilePath(String sourceFilePath) {
|
||||
if (sourceFilePath == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'sourceFilePath' must not be null.");
|
||||
}
|
||||
for (int i = 0; i < sourceFiles.size(); i++) {
|
||||
SourceFile sourceFile = sourceFiles.get(i);
|
||||
sourceFile.setPath(sourceFilePath);
|
||||
sourceFile.setOffset(0);
|
||||
}
|
||||
}
|
||||
|
||||
public int getSourceFilesSize() {
|
||||
return sourceFilesSize;
|
||||
}
|
||||
|
||||
public SourceFile getSourceFile(int sourceFileId) {
|
||||
return sourceFiles.get(sourceFileId);
|
||||
}
|
||||
|
||||
public void setImageFilePath(String value) {
|
||||
if (value == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'value' must not be null.");
|
||||
}
|
||||
this.imageFilePath = value;
|
||||
}
|
||||
|
||||
public String getImageFilePath() {
|
||||
return imageFilePath;
|
||||
}
|
||||
|
||||
public void setColumns(int value) {
|
||||
this.columns = value;
|
||||
}
|
||||
|
||||
public int getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public void setRows(int value) {
|
||||
this.rows = value;
|
||||
}
|
||||
|
||||
public int getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the spacing color.
|
||||
*
|
||||
* @param value
|
||||
* The spacing color or <code>null</code> to set the default
|
||||
* value.
|
||||
*/
|
||||
public void setSpacingColor(RGB value) {
|
||||
if (value == null) {
|
||||
value = Defaults.SPACING_COLOR;
|
||||
}
|
||||
this.spacingColor = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the spacing color.
|
||||
*
|
||||
* @return The spacing color, not <code>null</code>.
|
||||
*/
|
||||
public RGB getSpacingColor() {
|
||||
if (spacingColor == null) {
|
||||
throw new IllegalStateException("Spacing color must not be null");
|
||||
}
|
||||
return spacingColor;
|
||||
}
|
||||
|
||||
public void setSpacingWidth(int value) {
|
||||
this.spacingWidth = value;
|
||||
}
|
||||
|
||||
public int getSpacingWidth() {
|
||||
return spacingWidth;
|
||||
}
|
||||
|
||||
public void setPaletteType(PaletteType value) {
|
||||
if (value == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'value' must not be null.");
|
||||
}
|
||||
this.paletteType = value;
|
||||
}
|
||||
|
||||
public PaletteType getPaletteType() {
|
||||
return paletteType;
|
||||
}
|
||||
|
||||
public void setPalette(Palette value) {
|
||||
if (value == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'value' must not be null.");
|
||||
}
|
||||
this.palette = value;
|
||||
}
|
||||
|
||||
public void setPaletteManual() {
|
||||
switch (palette) {
|
||||
case TRUE_COLOR:
|
||||
palette = Palette.TRUE_COLOR;
|
||||
break;
|
||||
case HIRES_1:
|
||||
case HIRES_2:
|
||||
case HIRES_MANUAL:
|
||||
palette = Palette.HIRES_MANUAL;
|
||||
break;
|
||||
case MULTI_1:
|
||||
case MULTI_2:
|
||||
case MULTI_3:
|
||||
case MULTI_4:
|
||||
case MULTI_5:
|
||||
case MULTI_6:
|
||||
case MULTI_MANUAL:
|
||||
palette = Palette.MULTI_MANUAL;
|
||||
break;
|
||||
case GTIA_GREY_1:
|
||||
case GTIA_GREY_2:
|
||||
case GTIA_GREY_MANUAL:
|
||||
palette = Palette.GTIA_GREY_MANUAL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public Palette getPalette() {
|
||||
return palette;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the array of palette RGBs. Note that the values is kept as a reference.
|
||||
*
|
||||
* @param value The array of palette RGBs, may be empty, not <code>null</code>.
|
||||
*/
|
||||
public void setPaletteRGBs(RGB[] value) {
|
||||
if (value == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'value' must not be null.");
|
||||
}
|
||||
this.paletteRGBs = value;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the array of palette RGBs. Note that the returned values is a reference.
|
||||
*
|
||||
* @return The array of palette RGBs, may be empty, not <code>null</code>.
|
||||
*/
|
||||
public RGB[] getPaletteRGBs() {
|
||||
return paletteRGBs;
|
||||
}
|
||||
|
||||
protected final void copyTo(FilesConverterParameters target) {
|
||||
if (target == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'target' must not be null.");
|
||||
}
|
||||
super.copyTo(target);
|
||||
|
||||
target.sourceFiles.clear();
|
||||
for (SourceFile sourceFile : sourceFiles) {
|
||||
SourceFile targetSourceFile;
|
||||
targetSourceFile = new SourceFile(sourceFile.getId());
|
||||
targetSourceFile.setPath(sourceFile.getPath());
|
||||
targetSourceFile.setOffset(sourceFile.getOffset());
|
||||
target.sourceFiles.add(targetSourceFile);
|
||||
}
|
||||
target.setImageFilePath(imageFilePath);
|
||||
|
||||
target.setRows(rows);
|
||||
target.setColumns(columns);
|
||||
target.setSpacingColor(spacingColor);
|
||||
target.setSpacingWidth(spacingWidth);
|
||||
|
||||
target.setPaletteType(paletteType);
|
||||
target.setPalette(palette);
|
||||
target.setPaletteRGBs(paletteRGBs);
|
||||
}
|
||||
|
||||
protected final boolean equals(FilesConverterParameters target) {
|
||||
if (target == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'target' must not be null.");
|
||||
}
|
||||
boolean result;
|
||||
result = super.equals(target);
|
||||
result = result && target.sourceFiles.equals(sourceFiles);
|
||||
result = result && target.getImageFilePath().equals(imageFilePath);
|
||||
result = result && target.getRows() == rows;
|
||||
result = result && target.getColumns() == columns;
|
||||
result = result && target.getSpacingColor().equals(spacingColor);
|
||||
result = result && target.getSpacingWidth() == spacingWidth;
|
||||
|
||||
result = result && target.getPaletteType().equals(paletteType);
|
||||
result = result && target.getPalette().equals(palette);
|
||||
result = result && Arrays.equals(target.getPaletteRGBs(), paletteRGBs);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void serialize(GraphicsPropertiesSerializer serializer,
|
||||
String key) {
|
||||
if (serializer == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'serializer' must not be null.");
|
||||
}
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'key' must not be null.");
|
||||
}
|
||||
|
||||
super.serialize(serializer, key);
|
||||
|
||||
GraphicsPropertiesSerializer ownSerializer;
|
||||
ownSerializer = new GraphicsPropertiesSerializer();
|
||||
|
||||
ownSerializer.writeInteger(Attributes.SOURCE_FILES, sourceFilesSize);
|
||||
for (int i = 0; i < sourceFilesSize; i++) {
|
||||
SourceFile sourceFile = sourceFiles.get(i);
|
||||
GraphicsPropertiesSerializer innerSeralizer;
|
||||
innerSeralizer = new GraphicsPropertiesSerializer();
|
||||
innerSeralizer.writeString(Attributes.SOURCE_FILE_PATH,
|
||||
sourceFile.getPath());
|
||||
innerSeralizer.writeInteger(Attributes.SOURCE_FILE_OFFSET,
|
||||
sourceFile.getOffset());
|
||||
ownSerializer.writeProperties(Attributes.SOURCE_FILES + "." + i,
|
||||
innerSeralizer);
|
||||
}
|
||||
|
||||
ownSerializer.writeString(Attributes.IMAGE_FILE_PATH, imageFilePath);
|
||||
|
||||
ownSerializer.writeInteger(Attributes.COLUMNS, columns);
|
||||
ownSerializer.writeInteger(Attributes.ROWS, rows);
|
||||
|
||||
ownSerializer.writeRGB(Attributes.SPACING_COLOR, spacingColor);
|
||||
ownSerializer.writeInteger(Attributes.SPACING_WIDTH, spacingWidth);
|
||||
|
||||
ownSerializer.writeEnum(Attributes.PALETTE, palette);
|
||||
ownSerializer.writeEnum(Attributes.PALETTE_TYPE, paletteType);
|
||||
ownSerializer.writeRGBArray(Attributes.PALETTE_COLORS, paletteRGBs);
|
||||
|
||||
serializer.writeProperties(key, ownSerializer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void deserialize(GraphicsPropertiesSerializer serializer,
|
||||
String key) {
|
||||
if (serializer == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'serializer' must not be null.");
|
||||
}
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
super.deserialize(serializer, key);
|
||||
|
||||
GraphicsPropertiesSerializer ownSerializer;
|
||||
ownSerializer = new GraphicsPropertiesSerializer();
|
||||
serializer.readProperties(key, ownSerializer);
|
||||
|
||||
sourceFiles.clear();
|
||||
for (int i = 0; i < ConverterRegistry.MAX_SOURCE_FILES; i++) {
|
||||
SourceFile sourceFile = new SourceFile(i);
|
||||
GraphicsPropertiesSerializer innerSerializer;
|
||||
innerSerializer = new GraphicsPropertiesSerializer();
|
||||
ownSerializer.readProperties(Attributes.SOURCE_FILES + "." + i,
|
||||
innerSerializer);
|
||||
sourceFile.setPath(innerSerializer.readString(
|
||||
Attributes.SOURCE_FILE_PATH, Defaults.SOURCE_FILE_PATH));
|
||||
sourceFile
|
||||
.setOffset(innerSerializer.readInteger(
|
||||
Attributes.SOURCE_FILE_OFFSET,
|
||||
Defaults.SOURCE_FILE_OFFSET));
|
||||
sourceFiles.add(sourceFile);
|
||||
}
|
||||
|
||||
imageFilePath = ownSerializer.readString(Attributes.IMAGE_FILE_PATH,
|
||||
Defaults.IMAGE_FILE_PATH);
|
||||
|
||||
columns = ownSerializer.readInteger(Attributes.COLUMNS,
|
||||
Defaults.COLUMNS);
|
||||
rows = ownSerializer.readInteger(Attributes.ROWS, Defaults.ROWS);
|
||||
|
||||
spacingColor = ownSerializer.readRGB(Attributes.SPACING_COLOR,
|
||||
Defaults.SPACING_COLOR);
|
||||
spacingWidth = ownSerializer.readInteger(Attributes.SPACING_WIDTH,
|
||||
Defaults.SPACING_WIDTH);
|
||||
|
||||
palette = ownSerializer.readEnum(Attributes.PALETTE, Defaults.PALETTE,
|
||||
Palette.class);
|
||||
paletteType = ownSerializer.readEnum(Attributes.PALETTE_TYPE,
|
||||
Defaults.PALETTE_TYPE, PaletteType.class);
|
||||
paletteRGBs = ownSerializer.readRGBArray(Attributes.PALETTE_COLORS,
|
||||
Defaults.PALETTE_COLORS);
|
||||
}
|
||||
}
|
@ -0,0 +1,240 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.wudsn.ide.gfx.converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.eclipse.swt.graphics.ImageData;
|
||||
import org.eclipse.swt.graphics.PaletteData;
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
|
||||
import com.wudsn.ide.base.common.NumberFactory;
|
||||
|
||||
/**
|
||||
* Image color histogram container. Counts the number of occurrences of a pixel
|
||||
* color value in an image data. Pixel color values may be greater than 256 in
|
||||
* case of direct palettes.
|
||||
*
|
||||
* @author Peter Dell
|
||||
*/
|
||||
public final class ImageColorHistogram {
|
||||
|
||||
private PaletteData paletteData;
|
||||
private int pixelCount;
|
||||
private List<Integer> pixelColors;
|
||||
private List<Integer> usedPixelColors;
|
||||
private TreeMap<Integer, Integer> pixelColorCounts;
|
||||
|
||||
/**
|
||||
* Created by {@link ImageConverterData}.
|
||||
*/
|
||||
ImageColorHistogram() {
|
||||
pixelColors = Collections.emptyList();
|
||||
usedPixelColors = Collections.emptyList();
|
||||
pixelColorCounts = new TreeMap<Integer, Integer>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the histogram.
|
||||
*/
|
||||
final void clear() {
|
||||
paletteData = null;
|
||||
pixelCount = 0;
|
||||
pixelColors = Collections.emptyList();
|
||||
usedPixelColors = Collections.emptyList();
|
||||
pixelColorCounts.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the number of occurrences of a pixel value in the image data.
|
||||
*
|
||||
* @param imageData
|
||||
* The image data or <code>null</code>.
|
||||
*/
|
||||
final void analyze(ImageData imageData) {
|
||||
|
||||
clear();
|
||||
if (imageData != null) {
|
||||
pixelCount = imageData.height * imageData.width;
|
||||
paletteData = imageData.palette;
|
||||
|
||||
if (paletteData.isDirect) {
|
||||
pixelColors = Collections.emptyList();
|
||||
} else {
|
||||
RGB[] rgbs = paletteData.getRGBs();
|
||||
int size = rgbs.length;
|
||||
pixelColors = new ArrayList<Integer>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
pixelColors.add(NumberFactory.getInteger(i));
|
||||
}
|
||||
pixelColors = Collections.unmodifiableList(pixelColors);
|
||||
}
|
||||
for (int y = 0; y < imageData.height; y++) {
|
||||
for (int x = 0; x < imageData.width; x++) {
|
||||
Integer pixelColor = NumberFactory.getInteger(imageData
|
||||
.getPixel(x, y));
|
||||
Integer pixelColorCount = pixelColorCounts.get(pixelColor);
|
||||
if (pixelColorCount == null) {
|
||||
pixelColorCount = NumberFactory.getInteger(1);
|
||||
} else {
|
||||
pixelColorCount = NumberFactory
|
||||
.getInteger(pixelColorCount.intValue() + 1);
|
||||
}
|
||||
pixelColorCounts.put(pixelColor, pixelColorCount);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pixelColors = Collections.emptyList();
|
||||
}
|
||||
usedPixelColors = Collections.unmodifiableList(new ArrayList<Integer>(
|
||||
pixelColorCounts.keySet()));
|
||||
}
|
||||
|
||||
public boolean isDirectPalette() {
|
||||
if (paletteData == null) {
|
||||
return true;
|
||||
}
|
||||
return paletteData.isDirect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of bits used for representing pixels.
|
||||
*
|
||||
* @return The number of bits used for representing pixels or <code>0</code>
|
||||
* if there is no image.
|
||||
*/
|
||||
public int getPaletteBits() {
|
||||
if (paletteData == null) {
|
||||
return 0;
|
||||
}
|
||||
if (paletteData.isDirect) {
|
||||
return Integer.bitCount(paletteData.redMask)
|
||||
+ Integer.bitCount(paletteData.greenMask)
|
||||
+ Integer.bitCount(paletteData.blueMask);
|
||||
}
|
||||
int length = paletteData.getRGBs().length;
|
||||
int result = 0;
|
||||
while (length != 0) {
|
||||
result++;
|
||||
length = length >>> 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the total number of pixels in the image data. It corresponds to the
|
||||
* sum of count returned by {@link #getPixelColorCount(Integer)}.
|
||||
*
|
||||
* @return The total pixel color count.
|
||||
*/
|
||||
public int getPixelCount() {
|
||||
return pixelCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of all pixel colors in the palette if the palette is an
|
||||
* indexed palette. If the palette is not indexed, the result is an empty
|
||||
* list.
|
||||
*
|
||||
* @return The unmodifiable list of pixel colors, sorted by their pixel
|
||||
* value, may be empty, not <code>null</code>.
|
||||
*/
|
||||
public List<Integer> getPalettePixelColors() {
|
||||
return pixelColors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of used pixel colors in the image data, sorted by their
|
||||
* pixel value. This method work the same way for direct and indexed
|
||||
* palettes.
|
||||
*
|
||||
* @return The unmodifiable list of pixel colors, sorted by their pixel
|
||||
* value, may be empty, not <code>null</code>.
|
||||
*/
|
||||
public List<Integer> getUsedPixelColors() {
|
||||
return usedPixelColors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of occurrences of a pixel color value in the image data.
|
||||
*
|
||||
* @param pixelColor
|
||||
* The pixel color, not <code>null</code>.
|
||||
* @return The count or <code>0</code> in case the pixel color is not
|
||||
* contained in the image.
|
||||
*/
|
||||
public int getPixelColorCount(Integer pixelColor) {
|
||||
if (pixelColor == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'pixelColor' must not be null.");
|
||||
}
|
||||
Integer count = pixelColorCounts.get(pixelColor);
|
||||
if (count == null) {
|
||||
return 0;
|
||||
}
|
||||
return count.intValue();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the RGB value for a pixel color. This method work the same way for
|
||||
* direct and indexed palettes.
|
||||
*
|
||||
* @param pixelColor
|
||||
* The pixel color, not <code>null</code>.
|
||||
* @return The RGB value for the pixel color, not <code>null</code>.
|
||||
*/
|
||||
public RGB getRGB(Integer pixelColor) {
|
||||
if (pixelColor == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'pixelColor' must not be null.");
|
||||
}
|
||||
|
||||
RGB rgb;
|
||||
if (paletteData != null) {
|
||||
// Indexed palette images may contain pixel values without
|
||||
// corresponding
|
||||
int intValue = pixelColor.intValue();
|
||||
if (paletteData.isDirect) {
|
||||
rgb = paletteData.getRGB(intValue);
|
||||
} else {
|
||||
// In indexed palette images, the palette may be shorter than
|
||||
// the actually used color.
|
||||
RGB[] rgbs = paletteData.getRGBs();
|
||||
if (intValue < rgbs.length) {
|
||||
rgb = rgbs[intValue];
|
||||
if (rgb == null) {
|
||||
throw new IllegalStateException(
|
||||
"Palette data has no RGB value at index "
|
||||
+ intValue + ".");
|
||||
}
|
||||
} else {
|
||||
rgb = new RGB(0, 0, 0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
rgb = new RGB(0, 0, 0);
|
||||
}
|
||||
return rgb;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,247 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.wudsn.ide.gfx.converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.swt.graphics.ImageData;
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
import org.mozilla.javascript.NativeArray;
|
||||
|
||||
import com.wudsn.ide.gfx.GraphicsPlugin;
|
||||
import com.wudsn.ide.gfx.model.ConverterMode;
|
||||
|
||||
public final class ImageConverterData extends ConverterCommonData {
|
||||
|
||||
private ImageConverterParameters parameters;
|
||||
|
||||
// Purely transient cache attributes.
|
||||
private transient ConverterScriptData converterScriptData;
|
||||
private transient ImageData targetImageData;
|
||||
private transient List<byte[]> targetFilesBytes;
|
||||
|
||||
ImageConverterData(ConverterData converterData) {
|
||||
super(converterData);
|
||||
this.parameters = converterData.getParameters().getImageConverterParameters();
|
||||
converterScriptData = new ConverterScriptData();
|
||||
targetFilesBytes = new ArrayList<byte[]>(0);
|
||||
|
||||
}
|
||||
|
||||
public ImageConverterParameters getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public Converter getConverter() {
|
||||
ConverterRegistry converterRegistry;
|
||||
Converter converter;
|
||||
converterRegistry = GraphicsPlugin.getInstance().getConverterRegistry();
|
||||
converter = converterRegistry.getConverter(parameters.getConverterId());
|
||||
return converter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCreateConversionEnabled() {
|
||||
return converterData.isValid() && converterData.getConverterMode() == ConverterMode.RAW_IMAGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return converterData.isValidImage();
|
||||
}
|
||||
|
||||
public boolean isValidConversion() {
|
||||
return converterData.isValidConversion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRefreshEnabled() {
|
||||
return converterData.isValidImage();
|
||||
}
|
||||
|
||||
public boolean isSaveFilesEnabled() {
|
||||
if (converterData.isValidConversion()) {
|
||||
for (byte[] bytes : targetFilesBytes) {
|
||||
if (bytes != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the image data.
|
||||
*/
|
||||
@Override
|
||||
public void clear() {
|
||||
super.clear();
|
||||
clearTargetFileBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the pixel color value for a given position. There must be an
|
||||
* instance of image data set.
|
||||
*
|
||||
* @param x
|
||||
* The x position, a non-negative integer.
|
||||
* @param y
|
||||
* The y position, a non-negative integer.
|
||||
*
|
||||
* @return The pixel color value.
|
||||
*
|
||||
* @throws NullPointerException
|
||||
* if there is no image data at all.
|
||||
*/
|
||||
public int getPixel(int x, int y) {
|
||||
try {
|
||||
return imageData.getPixel(x, y);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
throw new RuntimeException("Pixel (" + x + "," + y + ") is outside of the image.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the pixel RGB value for a given position. There must be an instance
|
||||
* of image data set.
|
||||
*
|
||||
* @param x
|
||||
* The x position, a non-negative integer.
|
||||
* @param y
|
||||
* The y position, a non-negative integer.
|
||||
*
|
||||
* @return The pixel color value.
|
||||
*
|
||||
* @throws NullPointerException
|
||||
* if there is no image data at all.
|
||||
*/
|
||||
public int getPixelRGB(int x, int y) {
|
||||
int result = getPixel(x, y);
|
||||
if (!imageData.palette.isDirect) {
|
||||
RGB rgb = imageData.palette.getRGB(result);
|
||||
result = rgb.red << 16 | rgb.green << 8 | rgb.blue;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the target image data, i.e. the image data after converting it to
|
||||
* files and back.
|
||||
*
|
||||
* @param targetImageData
|
||||
* The target image data or <code>null</code>.
|
||||
*/
|
||||
public void setTargetImageData(ImageData targetImageData) {
|
||||
this.targetImageData = targetImageData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the target image data, i.e. the image data after converting is to
|
||||
* files and back.
|
||||
*
|
||||
* @return The target image data or <code>null</code>.
|
||||
*/
|
||||
public ImageData getTargetImageData() {
|
||||
return targetImageData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the container for the converter script.
|
||||
*
|
||||
* @return The container for the converter script, not <code>null</code>.
|
||||
*/
|
||||
public ConverterScriptData getConverterScriptData() {
|
||||
return converterScriptData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all target files bytes.
|
||||
*/
|
||||
public void clearTargetFileBytes() {
|
||||
targetFilesBytes.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bytes for a target file from java script.
|
||||
*
|
||||
* @param targetFileId
|
||||
* The target field id, a non-negative integer.
|
||||
* @param scriptBytes
|
||||
* The bytes, may be empty or <code>null</code>.
|
||||
*/
|
||||
public void setTargetFileObject(int targetFileId, NativeArray scriptBytes) {
|
||||
byte[] bytes = null;
|
||||
if (scriptBytes != null) {
|
||||
int length = (int) scriptBytes.getLength();
|
||||
bytes = new byte[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
Object o = scriptBytes.get(i, null);
|
||||
if (o instanceof Double) {
|
||||
bytes[i] = ((Double) o).byteValue();
|
||||
} else if (o instanceof Integer) {
|
||||
bytes[i] = ((Integer) o).byteValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
setTargetFileBytes(targetFileId, bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bytes for a target file.
|
||||
*
|
||||
* @param targetFileId
|
||||
* The target field id, a non-negative integer.
|
||||
* @param bytes
|
||||
* The bytes, may be empty or <code>null</code>.
|
||||
*/
|
||||
public void setTargetFileBytes(int targetFileId, byte[] bytes) {
|
||||
if (targetFileId < 0) {
|
||||
throw new IllegalArgumentException("Parameter 'targetFileId' must not be negative. Specified value is "
|
||||
+ targetFileId + ".");
|
||||
}
|
||||
while (targetFilesBytes.size() <= targetFileId) {
|
||||
targetFilesBytes.add(null);
|
||||
}
|
||||
targetFilesBytes.set(targetFileId, bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the bytes for a target file.
|
||||
*
|
||||
* @param targetFileId
|
||||
* The target field id, a non-negative integer.
|
||||
* @return The bytes, may be empty or <code>null</code>.
|
||||
*/
|
||||
public byte[] getTargetFileBytes(int targetFileId) {
|
||||
if (targetFileId < 0) {
|
||||
throw new IllegalArgumentException("Parameter 'targetFileId' must not be negative. Specified value is "
|
||||
+ targetFileId + ".");
|
||||
}
|
||||
byte[] bytes;
|
||||
if (targetFileId < targetFilesBytes.size()) {
|
||||
bytes = targetFilesBytes.get(targetFileId);
|
||||
} else {
|
||||
bytes = null;
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,372 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.wudsn.ide.gfx.converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.wudsn.ide.gfx.GraphicsPlugin;
|
||||
import com.wudsn.ide.gfx.model.ConverterDirection;
|
||||
import com.wudsn.ide.gfx.model.GraphicsPropertiesSerializer;
|
||||
|
||||
public final class ImageConverterParameters extends ConverterCommonParameters {
|
||||
|
||||
public static final class Attributes {
|
||||
|
||||
/**
|
||||
* Creation is private.
|
||||
*/
|
||||
private Attributes() {
|
||||
}
|
||||
|
||||
public static final String IMAGE_FILE_PATH = "imageFilePath";
|
||||
|
||||
public static final String TARGET_FILES = "targetFiles";
|
||||
public static final String TARGET_FILE_PATH = "path";
|
||||
|
||||
public static final String USE_DEFAULT_SCRIPT = "useDefaultScript";
|
||||
public static final String SCRIPT = "script";
|
||||
|
||||
}
|
||||
|
||||
private static final class Defaults {
|
||||
|
||||
/**
|
||||
* Creation is private.
|
||||
*/
|
||||
private Defaults() {
|
||||
}
|
||||
|
||||
public static final String IMAGE_FILE_PATH = "";
|
||||
public static final String TARGET_FILE_PATH = "";
|
||||
|
||||
public static final boolean USE_DEFAULT_SCRIPT = true;
|
||||
public static final String SCRIPT = "";
|
||||
}
|
||||
|
||||
public static final class MessageIds {
|
||||
|
||||
/**
|
||||
* Creation is private.
|
||||
*/
|
||||
private MessageIds() {
|
||||
}
|
||||
|
||||
public static final int IMAGE_FILE_PATH = 2010;
|
||||
public static final int TARGET_FILE_PATH = 2020;
|
||||
public static final int TARGET_FILE_OFFSET = 2030;
|
||||
public static final int USE_DEFAULT_SCRIPT = 2040;
|
||||
public static final int SCRIPT = 2041;
|
||||
}
|
||||
|
||||
public static final class TargetFile {
|
||||
private int id;
|
||||
private String path;
|
||||
private int offset;
|
||||
|
||||
public TargetFile(int id) {
|
||||
this.id = id;
|
||||
path = Defaults.TARGET_FILE_PATH;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getPathMessageId() {
|
||||
return MessageIds.TARGET_FILE_PATH + id;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
if (path == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'path' must not be null.");
|
||||
}
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public int getOffsetMessageId() {
|
||||
return MessageIds.TARGET_FILE_OFFSET + id;
|
||||
}
|
||||
|
||||
public int getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
public void setOffset(int offset) {
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'obj' must not be null.");
|
||||
}
|
||||
TargetFile other = (TargetFile) obj;
|
||||
return other.id == this.id && other.path.equals(this.path)
|
||||
&& other.offset == this.offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id + 7 * path.hashCode() + 17 * offset;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String imageFilePath;
|
||||
private int targetFilesSize;
|
||||
private List<TargetFile> targetFiles;
|
||||
private boolean useDefaultScript;
|
||||
private String script;
|
||||
|
||||
ImageConverterParameters() {
|
||||
|
||||
int size = ConverterRegistry.MAX_SOURCE_FILES;
|
||||
this.targetFiles = new ArrayList<TargetFile>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
this.targetFiles.add(new TargetFile(i));
|
||||
}
|
||||
setDefaults();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaults() {
|
||||
super.setDefaults();
|
||||
imageFilePath = Defaults.IMAGE_FILE_PATH;
|
||||
for (TargetFile targetFile : targetFiles) {
|
||||
targetFile.setPath(Defaults.TARGET_FILE_PATH);
|
||||
}
|
||||
useDefaultScript = Defaults.USE_DEFAULT_SCRIPT;
|
||||
script = Defaults.SCRIPT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConverterId(String value) {
|
||||
if (value == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'value' must not be null.");
|
||||
}
|
||||
|
||||
if (!value.equals(this.converterId))
|
||||
this.converterId = value;
|
||||
|
||||
ConverterDefinition converterDefinition;
|
||||
converterDefinition = GraphicsPlugin.getInstance()
|
||||
.getConverterRegistry()
|
||||
.getDefinition(converterId, ConverterDirection.IMAGE_TO_FILES);
|
||||
if (converterDefinition != null) {
|
||||
targetFilesSize = targetFiles.size();
|
||||
} else {
|
||||
targetFilesSize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void setDefaultTargetFilePath(String targetFilePath) {
|
||||
if (targetFilePath == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'targetFilePath' must not be null.");
|
||||
}
|
||||
for (int i = 0; i < targetFiles.size(); i++) {
|
||||
TargetFile targetFile = targetFiles.get(i);
|
||||
targetFile.setPath(targetFilePath);
|
||||
targetFile.setOffset(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void setImageFilePath(String value) {
|
||||
if (value == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'value' must not be null.");
|
||||
}
|
||||
this.imageFilePath = value;
|
||||
}
|
||||
|
||||
public String getImageFilePath() {
|
||||
return imageFilePath;
|
||||
}
|
||||
|
||||
public int getTargetFilesSize() {
|
||||
return targetFilesSize;
|
||||
}
|
||||
|
||||
public TargetFile getTargetFile(int targetFileId) {
|
||||
return targetFiles.get(targetFileId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the indicator to use the default script
|
||||
*
|
||||
* @param value
|
||||
* <code>true</code> to use the default script,
|
||||
* <code>false</code> to use the saved script.
|
||||
*/
|
||||
public void setUseDefaultScript(boolean value) {
|
||||
this.useDefaultScript = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the indicator to use the default script
|
||||
*
|
||||
* @return <code>true</code> to use the default script, <code>false</code>
|
||||
* to use the saved script.
|
||||
*/
|
||||
public boolean isUseDefaultScript() {
|
||||
return useDefaultScript;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the script for the conversion logic.
|
||||
*
|
||||
* @param value
|
||||
* The script, may be empty, not <code>null</code>.
|
||||
*/
|
||||
public void setScript(String value) {
|
||||
if (value == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'value' must not be null.");
|
||||
}
|
||||
this.script = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the script for the conversion logic.
|
||||
*
|
||||
* @return The script, may be empty, not <code>null</code>.
|
||||
*/
|
||||
public String getScript() {
|
||||
if (script == null) {
|
||||
throw new IllegalStateException("Field 'script' must not be null.");
|
||||
}
|
||||
return script;
|
||||
}
|
||||
|
||||
protected final void copyTo(ImageConverterParameters target) {
|
||||
if (target == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'target' must not be null.");
|
||||
}
|
||||
super.copyTo(target);
|
||||
|
||||
target.setImageFilePath(imageFilePath);
|
||||
target.targetFiles.clear();
|
||||
for (TargetFile targetFile : targetFiles) {
|
||||
TargetFile targetTargetFile;
|
||||
targetTargetFile = new TargetFile(targetFile.getId());
|
||||
targetTargetFile.setPath(targetFile.getPath());
|
||||
targetTargetFile.setOffset(targetFile.getOffset());
|
||||
target.targetFiles.add(targetTargetFile);
|
||||
}
|
||||
|
||||
target.setUseDefaultScript(useDefaultScript);
|
||||
target.setScript(script);
|
||||
}
|
||||
|
||||
protected final boolean equals(ImageConverterParameters target) {
|
||||
if (target == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'target' must not be null.");
|
||||
}
|
||||
boolean result;
|
||||
result = super.equals(target);
|
||||
result = result && target.getImageFilePath().equals(imageFilePath);
|
||||
result = result && target.targetFiles.equals(targetFiles);
|
||||
result = result && target.isUseDefaultScript() == useDefaultScript;
|
||||
result = result && target.getScript().equals(script);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void serialize(GraphicsPropertiesSerializer serializer,
|
||||
String key) {
|
||||
if (serializer == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'serializer' must not be null.");
|
||||
}
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'key' must not be null.");
|
||||
}
|
||||
|
||||
super.serialize(serializer, key);
|
||||
GraphicsPropertiesSerializer ownSerializer;
|
||||
|
||||
ownSerializer = new GraphicsPropertiesSerializer();
|
||||
ownSerializer.writeString(Attributes.IMAGE_FILE_PATH, imageFilePath);
|
||||
ownSerializer.writeInteger(Attributes.TARGET_FILES, targetFilesSize);
|
||||
for (int i = 0; i < targetFilesSize; i++) {
|
||||
TargetFile targetFile = targetFiles.get(i);
|
||||
GraphicsPropertiesSerializer innerSeralizer;
|
||||
innerSeralizer = new GraphicsPropertiesSerializer();
|
||||
innerSeralizer.writeString(Attributes.TARGET_FILE_PATH,
|
||||
targetFile.getPath());
|
||||
ownSerializer.writeProperties(Attributes.TARGET_FILES + "." + i,
|
||||
innerSeralizer);
|
||||
}
|
||||
|
||||
ownSerializer.writeBoolean(Attributes.USE_DEFAULT_SCRIPT, useDefaultScript);
|
||||
ownSerializer.writeString(Attributes.SCRIPT, script);
|
||||
|
||||
serializer.writeProperties(key, ownSerializer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void deserialize(GraphicsPropertiesSerializer serializer,
|
||||
String key) {
|
||||
if (serializer == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'serializer' must not be null.");
|
||||
}
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
super.deserialize(serializer, key);
|
||||
GraphicsPropertiesSerializer ownSerializer;
|
||||
ownSerializer = new GraphicsPropertiesSerializer();
|
||||
serializer.readProperties(key, ownSerializer);
|
||||
|
||||
imageFilePath = ownSerializer.readString(Attributes.IMAGE_FILE_PATH,
|
||||
Defaults.IMAGE_FILE_PATH);
|
||||
imageFilePath = ownSerializer.readString(Attributes.IMAGE_FILE_PATH,
|
||||
Defaults.IMAGE_FILE_PATH);
|
||||
targetFiles.clear();
|
||||
for (int i = 0; i < ConverterRegistry.MAX_TARGET_FILES; i++) {
|
||||
TargetFile targetFile = new TargetFile(i);
|
||||
GraphicsPropertiesSerializer innerSerializer;
|
||||
innerSerializer = new GraphicsPropertiesSerializer();
|
||||
ownSerializer.readProperties(Attributes.TARGET_FILES + "." + i,
|
||||
innerSerializer);
|
||||
targetFile.setPath(innerSerializer.readString(
|
||||
Attributes.TARGET_FILE_PATH, Defaults.TARGET_FILE_PATH));
|
||||
targetFiles.add(targetFile);
|
||||
}
|
||||
|
||||
useDefaultScript = ownSerializer.readBoolean(
|
||||
Attributes.USE_DEFAULT_SCRIPT, Defaults.USE_DEFAULT_SCRIPT);
|
||||
script = ownSerializer.readString(Attributes.SCRIPT, Defaults.SCRIPT);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.wudsn.ide.gfx.converter;
|
||||
|
||||
/**
|
||||
* Square block of character which shall be inverse
|
||||
*
|
||||
* @author Peter Dell
|
||||
*/
|
||||
public final class InverseBlock {
|
||||
|
||||
private int column1;
|
||||
private int column2;
|
||||
private int row1;
|
||||
private int row2;
|
||||
private Integer inverseColor;
|
||||
private boolean inverseIfConflict;
|
||||
|
||||
InverseBlock(int column1, int column2, int row1, int row2,
|
||||
Integer inverseColor, boolean inverseIfConflict) {
|
||||
this.column1 = column1;
|
||||
this.column2 = column2;
|
||||
this.row1 = row1;
|
||||
this.row2 = row2;
|
||||
this.inverseColor = inverseColor;
|
||||
this.inverseIfConflict = inverseIfConflict;
|
||||
|
||||
}
|
||||
|
||||
public int getColumn1() {
|
||||
return column1;
|
||||
}
|
||||
|
||||
public int getColumn2() {
|
||||
return column2;
|
||||
}
|
||||
|
||||
public int getRow1() {
|
||||
return row1;
|
||||
}
|
||||
|
||||
public int getRow2() {
|
||||
return row2;
|
||||
}
|
||||
|
||||
public Integer getInverseColor() {
|
||||
return inverseColor;
|
||||
}
|
||||
|
||||
public boolean isInverseIfConflict() {
|
||||
return inverseIfConflict;
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.wudsn.ide.gfx.converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* List of square blocks of character which shall be inverse
|
||||
*
|
||||
* @author Peter Dell
|
||||
*/
|
||||
public final class InverseBlockList {
|
||||
|
||||
private List<InverseBlock> inverseBlocks;
|
||||
|
||||
/**
|
||||
* Creates an empty inverse block list.
|
||||
*/
|
||||
public InverseBlockList() {
|
||||
inverseBlocks = new ArrayList<InverseBlock>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new inverse block to the list.
|
||||
*
|
||||
* @param column1
|
||||
* Start column, a non-negative integer
|
||||
* @param column2
|
||||
* End column, a non-negative integer
|
||||
* @param row1
|
||||
* Start row, a non-negative integer
|
||||
* @param row2
|
||||
* End row, a non-negative integer
|
||||
* @param inverseColor
|
||||
* The pixel color value which shall be used as inverse color
|
||||
* @param inverseIfConflict
|
||||
* <code>true</code> if the inverse color shall also be used in
|
||||
* case of conflict
|
||||
*/
|
||||
public void add(int column1, int column2, int row1, int row2,
|
||||
Integer inverseColor, boolean inverseIfConflict) {
|
||||
inverseBlocks.add(new InverseBlock(column1, column2, row1, row2,
|
||||
inverseColor, inverseIfConflict));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the inverse block at The sequence in which the blocks were added
|
||||
* determines, the sequence in which the method checks for matches.
|
||||
*
|
||||
* @param column
|
||||
* The column, a non-negative integer.
|
||||
* @param row
|
||||
* The column, a non-negative integer.
|
||||
* @return The first matching inverse block, or <code>null</code> if no
|
||||
* inverse block matches.
|
||||
*/
|
||||
public InverseBlock getInverseBlock(int column, int row) {
|
||||
|
||||
for (InverseBlock inverseBlock : inverseBlocks) {
|
||||
if (inverseBlock.getColumn1() <= column
|
||||
&& column <= inverseBlock.getColumn2()
|
||||
&& inverseBlock.getRow1() <= row
|
||||
&& row <= inverseBlock.getRow2()) {
|
||||
return inverseBlock;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,177 @@
|
||||
package com.wudsn.ide.gfx.converter;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
|
||||
import com.wudsn.ide.base.common.NumberFactory;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter
|
||||
* Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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
|
||||
* WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Palette mapper for mapping palette indices to RGB and back. The palette data
|
||||
* is stored in files in the folder for the sub-package "/palettes", relative to
|
||||
* the location if the palette mapper implementation class. The file content is
|
||||
* loaded from the class path using the class loader.
|
||||
*
|
||||
*
|
||||
* @since 1.6.4
|
||||
*/
|
||||
public abstract class PaletteMapper {
|
||||
private int palette_size;
|
||||
private int[] palette_r;
|
||||
private int[] palette_g;
|
||||
private int[] palette_b;
|
||||
private Map<Integer, Integer> map;
|
||||
|
||||
protected PaletteMapper(int palette_size) {
|
||||
if (palette_size < 1) {
|
||||
throw new IllegalArgumentException("Parameter 'palette_size' must be positive. Specified value is "
|
||||
+ palette_size + ".");
|
||||
}
|
||||
this.palette_size = palette_size;
|
||||
map = new HashMap<Integer, Integer>();
|
||||
palette_r = new int[palette_size];
|
||||
palette_g = new int[palette_size];
|
||||
palette_b = new int[palette_size];
|
||||
}
|
||||
|
||||
public final void loadPalette(String fileName) {
|
||||
if (fileName == null) {
|
||||
throw new IllegalArgumentException("Parameter 'fileName' must not be null.");
|
||||
}
|
||||
InputStream inputStream;
|
||||
Class<? extends PaletteMapper> clazz = getClass();
|
||||
inputStream = clazz.getClassLoader().getResourceAsStream(
|
||||
clazz.getPackage().getName().replace('.', '/') + "/palettes/" + fileName);
|
||||
if (inputStream == null) {
|
||||
try {
|
||||
|
||||
inputStream = new FileInputStream(fileName);
|
||||
} catch (FileNotFoundException ex) {
|
||||
throw new RuntimeException("File '" + fileName + "' not found or not readable", ex);
|
||||
}
|
||||
}
|
||||
|
||||
byte[] buffer = new byte[palette_size * 3];
|
||||
int count;
|
||||
do {
|
||||
try {
|
||||
count = inputStream.read(buffer);
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException("Cannot read palette '" + fileName + "'", ex);
|
||||
}
|
||||
if (count > 0) {
|
||||
int j = 0;
|
||||
for (int i = 0; i < count; i = i + 3, j++) {
|
||||
palette_r[j] = buffer[i] & 0xff;
|
||||
palette_g[j] = buffer[i + 1] & 0xff;
|
||||
palette_b[j] = buffer[i + 2] & 0xff;
|
||||
}
|
||||
}
|
||||
} while (count > -1);
|
||||
|
||||
map.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the index of an RGB value in the palette.
|
||||
*
|
||||
* @param rgb
|
||||
* The 24-bit RGB value
|
||||
* @return The palette index, or <code>-1</code> is there is not
|
||||
* corresponding palette index.
|
||||
*/
|
||||
public final int getPaletteIndex(int rgb) {
|
||||
return getPaletteIndex(rgb >>> 16 & 0xff, rgb >>> 8 & 0xff, rgb & 0xff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the index of an RGB value in the palette.
|
||||
*
|
||||
* @param r
|
||||
* The 8-bit red value
|
||||
* @param g
|
||||
* The 8-bit green value
|
||||
* @param b
|
||||
* The 8-bit blue value
|
||||
|
||||
* @return The palette index, or <code>-1</code> is there is not
|
||||
* corresponding palette index.
|
||||
*/
|
||||
public final int getPaletteIndex(int r, int g, int b) {
|
||||
int color = r << 16 | g << 8 | b;
|
||||
Integer colorKey = NumberFactory.getInteger(color);
|
||||
|
||||
Integer colorValue = map.get(colorKey);
|
||||
|
||||
if (colorValue == null) {
|
||||
|
||||
int diff = 0x7fffffff;
|
||||
int n = 0;
|
||||
for (int m = 0; m < 256; m++) {
|
||||
int e = (palette_r[m] - r);
|
||||
int d = e * e;
|
||||
e = (palette_g[m] - g);
|
||||
d += e * e;
|
||||
e = (palette_b[m] - b);
|
||||
d += e * e;
|
||||
if (d < diff) {
|
||||
diff = d;
|
||||
n = m;
|
||||
}
|
||||
}
|
||||
colorValue = new Integer(n);
|
||||
map.put(colorKey, colorValue);
|
||||
}
|
||||
return colorValue.intValue();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an Atari color with a given color code as RGB value.
|
||||
*
|
||||
* @param paletteIndex
|
||||
* The palette index, a non-negative integer.
|
||||
* @return The RGB value, not <code>null</code>.
|
||||
*/
|
||||
public final RGB getRGB(int paletteIndex) {
|
||||
RGB result;
|
||||
result = new RGB(palette_r[paletteIndex], palette_g[paletteIndex], palette_b[paletteIndex]);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an Atari color with a given color code as RGB int value.
|
||||
*
|
||||
* @param paletteIndex
|
||||
* The palette index, a non-negative integer.
|
||||
* @return The RGB color, not <code>null</code>.
|
||||
*/
|
||||
public final int getRGBColor(int paletteIndex) {
|
||||
int result = palette_r[paletteIndex] << 16 | palette_g[paletteIndex] << 8 | palette_b[paletteIndex];
|
||||
return result;
|
||||
}
|
||||
}
|
261
com.wudsn.ide.gfx/src/com/wudsn/ide/gfx/converter/Tile.java
Normal file
@ -0,0 +1,261 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.wudsn.ide.gfx.converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.wudsn.ide.base.common.NumberFactory;
|
||||
|
||||
public final class Tile {
|
||||
private TileSet tileSet;
|
||||
private int column;
|
||||
private int row;
|
||||
|
||||
private int xOffset;
|
||||
private int yOffset;
|
||||
|
||||
private Map<Integer, Integer> pixelColorCounts;
|
||||
private List<Map<Integer, Integer>> linePixelColorCounts;
|
||||
|
||||
private boolean inverseConflict;
|
||||
|
||||
public Tile(TileSet tileSet, int column, int row) {
|
||||
if (tileSet == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'tileSet' must not be null.");
|
||||
}
|
||||
if (column < 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'column' must not be negative. Specified value is "
|
||||
+ column + ".");
|
||||
}
|
||||
if (row < 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'row' must not be negative. Specified value is "
|
||||
+ row + ".");
|
||||
}
|
||||
this.tileSet = tileSet;
|
||||
this.column = column;
|
||||
this.row = row;
|
||||
|
||||
xOffset = column * tileSet.getPixelsPerColumn();
|
||||
yOffset = row * tileSet.getPixelsPerRow();
|
||||
|
||||
pixelColorCounts = new TreeMap<Integer, Integer>();
|
||||
linePixelColorCounts = new ArrayList<Map<Integer, Integer>>(tileSet
|
||||
.getPixelsPerRow());
|
||||
|
||||
for (int y = 0; y < tileSet.getPixelsPerRow(); y++) {
|
||||
linePixelColorCounts.add(new TreeMap<Integer, Integer>());
|
||||
for (int x = 0; x < tileSet.getPixelsPerColumn(); x++) {
|
||||
Integer pixelColor = getPixelColor(x, y);
|
||||
increment(pixelColorCounts, pixelColor);
|
||||
increment(linePixelColorCounts.get(y), pixelColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void increment(Map<Integer, Integer> pixelColorCounts,
|
||||
Integer pixelColorKey) {
|
||||
if (pixelColorCounts == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'pixelColorCounts' must not be null.");
|
||||
}
|
||||
if (pixelColorKey == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'pixelColorKey' must not be null.");
|
||||
}
|
||||
Integer pixelColorCount = pixelColorCounts.get(pixelColorKey);
|
||||
if (pixelColorCount == null) {
|
||||
pixelColorCount = NumberFactory.getInteger(1);
|
||||
} else {
|
||||
pixelColorCount = NumberFactory.getInteger(pixelColorCount
|
||||
.intValue() + 1);
|
||||
}
|
||||
pixelColorCounts.put(pixelColorKey, pixelColorCount);
|
||||
}
|
||||
|
||||
public int getColumn() {
|
||||
return column;
|
||||
}
|
||||
|
||||
public int getRow() {
|
||||
return row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the pixel color of a pixel in the tile.
|
||||
*
|
||||
* @param x
|
||||
* The relative x position in the tile, a non-negative integer.
|
||||
* @param y
|
||||
* The relative x position in the tile, a non-negative integer.
|
||||
* @return The pixel color, not <code>null</code>.
|
||||
*/
|
||||
public Integer getPixelColor(int x, int y) {
|
||||
try {
|
||||
return NumberFactory.getInteger(tileSet.getImageData().getPixel(
|
||||
xOffset + x, yOffset + y));
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// throw new IllegalArgumentException("Cannot access pixel at "
|
||||
// + xOffset + "+" + x + ", " + yOffset + "+" + y + ".", ex);
|
||||
return NumberFactory.getInteger(0);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasPixelColor(Integer pixelColor) {
|
||||
if (pixelColor == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'pixelColor' must not be null.");
|
||||
}
|
||||
return getPixelColorCount(pixelColor) > 0;
|
||||
}
|
||||
|
||||
public int getPixelColorCount(Integer pixelColor) {
|
||||
if (pixelColor == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'pixelColor' must not be null.");
|
||||
}
|
||||
Integer pixelColorCount = pixelColorCounts.get(pixelColor);
|
||||
if (pixelColorCount == null) {
|
||||
return 0;
|
||||
}
|
||||
return pixelColorCount.intValue();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the map of distinct colors used and their count in the tile.
|
||||
*
|
||||
* @param ignoredPixelColors
|
||||
* The array of colors to be ignored during counting or
|
||||
* <code>null</code>.
|
||||
* @return The map of distinct colors used and their count, not
|
||||
* <code>null</code>.
|
||||
*/
|
||||
public Map<Integer, Integer> getDistinctPixelColorCounts(
|
||||
List<Integer> ignoredPixelColors) {
|
||||
|
||||
if (ignoredPixelColors == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'ignoredPixelColors' must not be null.");
|
||||
}
|
||||
Map<Integer, Integer> pixelColorCounts;
|
||||
pixelColorCounts = new TreeMap<Integer, Integer>();
|
||||
for (int y = 0; y < tileSet.getPixelsPerRow(); y++) {
|
||||
for (int x = 0; x < tileSet.getPixelsPerColumn(); x++) {
|
||||
Integer pixelColor = getPixelColor(x, y);
|
||||
boolean ignore = false;
|
||||
if (ignoredPixelColors != null
|
||||
&& ignoredPixelColors.contains(pixelColor)) {
|
||||
ignore = true;
|
||||
}
|
||||
if (!ignore) {
|
||||
increment(pixelColorCounts, pixelColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
return pixelColorCounts;
|
||||
}
|
||||
|
||||
public static Integer getMajorColor(Map<Integer, Integer> pixelColorCounts,
|
||||
List<Integer> ignoredPixelColors) {
|
||||
if (pixelColorCounts == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'pixelColorCounts' must not be null.");
|
||||
}
|
||||
if (pixelColorCounts.isEmpty()) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'pixelColorCounts' must not be empty.");
|
||||
}
|
||||
Integer majorColor;
|
||||
int majorColorCount;
|
||||
majorColor = null;
|
||||
majorColorCount = -1;
|
||||
for (Map.Entry<Integer, Integer> entry : pixelColorCounts.entrySet()) {
|
||||
if (ignoredPixelColors == null
|
||||
|| !ignoredPixelColors.contains(entry.getKey())) {
|
||||
if (entry.getValue().intValue() > majorColorCount) {
|
||||
majorColor = entry.getKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
return majorColor;
|
||||
}
|
||||
|
||||
public int getLinePixelColorCount(int y, int pixelColor) {
|
||||
Map<Integer, Integer> pixelColorCounts = linePixelColorCounts.get(y);
|
||||
Integer pixelColorCount = pixelColorCounts.get(NumberFactory
|
||||
.getInteger(pixelColor));
|
||||
if (pixelColorCount == null) {
|
||||
return 0;
|
||||
}
|
||||
return pixelColorCount.intValue();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the map of distinct colors used and their count in a specific line
|
||||
* of the tile.
|
||||
*
|
||||
* @param y
|
||||
* The line of the tile, a non-negative integer.
|
||||
* @param ignoredPixelColors
|
||||
* The list of colors to be ignored during counting or
|
||||
* <code>null</code>.
|
||||
* @return The map of distinct colors used and their count, not
|
||||
* <code>null</code>.
|
||||
*/
|
||||
public Map<Integer, Integer> getDistinctLinePixelColorCounts(int y,
|
||||
List<Integer> ignoredPixelColors) {
|
||||
if (y < 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'y' must not be negative, specified value is "
|
||||
+ y + ".");
|
||||
}
|
||||
Map<Integer, Integer> pixelColorCounts;
|
||||
pixelColorCounts = new TreeMap<Integer, Integer>();
|
||||
for (int x = 0; x < tileSet.getPixelsPerColumn(); x++) {
|
||||
Integer pixelColor = getPixelColor(x, y);
|
||||
boolean ignore = false;
|
||||
if (ignoredPixelColors != null
|
||||
&& ignoredPixelColors.contains(pixelColor)) {
|
||||
ignore = true;
|
||||
|
||||
}
|
||||
if (!ignore) {
|
||||
increment(pixelColorCounts, pixelColor);
|
||||
}
|
||||
}
|
||||
return pixelColorCounts;
|
||||
}
|
||||
|
||||
public boolean isInverseConflict() {
|
||||
return inverseConflict;
|
||||
}
|
||||
|
||||
public void setInverseConflict(boolean inverseConflict) {
|
||||
this.inverseConflict = inverseConflict;
|
||||
|
||||
}
|
||||
}
|
240
com.wudsn.ide.gfx/src/com/wudsn/ide/gfx/converter/TileSet.java
Normal file
@ -0,0 +1,240 @@
|
||||
/**
|
||||
* Copyright (C) 2009 - 2014 <a href="http://www.wudsn.com" target="_top">Peter Dell</a>
|
||||
*
|
||||
* This file is part of WUDSN IDE.
|
||||
*
|
||||
* WUDSN IDE 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.
|
||||
*
|
||||
* WUDSN IDE 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 WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.wudsn.ide.gfx.converter;
|
||||
|
||||
import org.eclipse.swt.graphics.ImageData;
|
||||
|
||||
/**
|
||||
* An image data divided into a rectangle of tiles.
|
||||
*
|
||||
* @author Peter Dell
|
||||
*
|
||||
*/
|
||||
public final class TileSet {
|
||||
|
||||
private ImageData imageData;
|
||||
private int pixelsPerColumn;
|
||||
private int pixelsPerRow;
|
||||
|
||||
private int columns;
|
||||
private int rows;
|
||||
private int paletteSize;
|
||||
|
||||
private Tile[][] tiles;
|
||||
|
||||
/**
|
||||
* Creates a new tile set.
|
||||
*
|
||||
* @param imageData
|
||||
* The source image data, not <code>null</code>.
|
||||
* @param pixelsPerColumn
|
||||
* The number of pixels per column, a positive integer.
|
||||
* @param pixelsPerRow
|
||||
* The number of pixels per row, a positive integer.
|
||||
*/
|
||||
public TileSet(ImageData imageData, int pixelsPerColumn, int pixelsPerRow) {
|
||||
if (imageData == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'imageData' must not be null.");
|
||||
}
|
||||
if (pixelsPerColumn < 1) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'pixelsPerColumn' must be poitive. Specified value is "
|
||||
+ pixelsPerColumn + ".");
|
||||
}
|
||||
if (pixelsPerRow < 1) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'pixelsPerRow' must be poitive. Specified value is "
|
||||
+ pixelsPerRow + ".");
|
||||
}
|
||||
|
||||
this.imageData = imageData;
|
||||
this.pixelsPerColumn = pixelsPerColumn;
|
||||
this.pixelsPerRow = pixelsPerRow;
|
||||
|
||||
// Round-up columns and rows
|
||||
columns = (imageData.width + pixelsPerColumn - 1) / pixelsPerColumn;
|
||||
rows = (imageData.height + pixelsPerRow - 1) / pixelsPerRow;
|
||||
|
||||
// Create the tiles
|
||||
tiles = new Tile[rows][];
|
||||
for (int r = 0; r < rows; r++) {
|
||||
tiles[r] = new Tile[columns];
|
||||
for (int c = 0; c < columns; c++) {
|
||||
Tile tile = new Tile(this, c, r);
|
||||
tiles[r][c] = tile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the source image data.
|
||||
*
|
||||
* @return The source image data, not <code>null</code>.
|
||||
*/
|
||||
public ImageData getImageData() {
|
||||
return imageData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of columns.
|
||||
*
|
||||
* @return The number of columns, a positive integer.
|
||||
*/
|
||||
public int getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of rows.
|
||||
*
|
||||
* @return The number of rows, a positive integer.
|
||||
*/
|
||||
public int getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of pixels per column.
|
||||
*
|
||||
* @return The number of pixels per column, a positive integer.
|
||||
*/
|
||||
public int getPixelsPerColumn() {
|
||||
return pixelsPerColumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of pixels per row.
|
||||
*
|
||||
* @return The number of of pixels per row, a positive integer.
|
||||
*/
|
||||
public int getPixelsPerRow() {
|
||||
return pixelsPerRow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the size of the palette.
|
||||
*
|
||||
* @return The size of the palette, a positive integer.
|
||||
*/
|
||||
public int getPaletteSize() {
|
||||
return paletteSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the tile a a given location.
|
||||
*
|
||||
* @param column
|
||||
* The column, a non-negative integer
|
||||
* @param row
|
||||
* The row, a non-negative integer
|
||||
* @return The tile, not <code>null</code>.
|
||||
*/
|
||||
public Tile getTile(int column, int row) {
|
||||
if (column < 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'column' must not be negative. Specified value is "
|
||||
+ column + ".");
|
||||
}
|
||||
if (row < 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'row' must not be negative. Specified value is "
|
||||
+ row + ".");
|
||||
}
|
||||
return tiles[row][column];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an image data instance large enough to hold the tiled source
|
||||
* image.
|
||||
*
|
||||
* @return The tile image data, not <code>null</code>.
|
||||
*/
|
||||
public ImageData createTiledImageData() {
|
||||
int width = columns * (pixelsPerColumn + 1) + 1;
|
||||
int height = rows * (pixelsPerRow + 1) + 1;
|
||||
ImageData tiledImageData = new ImageData(width, height,
|
||||
imageData.depth, imageData.palette);
|
||||
return tiledImageData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws bounding rectangles around the tiles of the target image data.
|
||||
*
|
||||
* @param targetImageData
|
||||
* The target image data, not <code>null</code>.
|
||||
* @param gridColor
|
||||
* The pixel color for coloring the tile grid.
|
||||
* @param inverseConflictColor
|
||||
* The pixel color for coloring conflict tiles in the tile grid.
|
||||
*/
|
||||
public void drawTileBoundaries(ImageData targetImageData,
|
||||
Integer gridColor, Integer inverseConflictColor) {
|
||||
if (targetImageData == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'targetImageData' must not be null.");
|
||||
}
|
||||
if (gridColor == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'gridColor' must not be null.");
|
||||
}
|
||||
if (inverseConflictColor == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter 'inverseConflictColor' must not be null.");
|
||||
}
|
||||
for (int r = 0; r < rows + 1; r++) {
|
||||
int ty = r * (pixelsPerRow + 1);
|
||||
for (int x = 0; x < targetImageData.width; x++) {
|
||||
targetImageData.setPixel(x, ty, gridColor.intValue());
|
||||
}
|
||||
}
|
||||
for (int c = 0; c < columns + 1; c++) {
|
||||
int tx = c * (pixelsPerColumn + 1);
|
||||
for (int y = 0; y < targetImageData.height; y++) {
|
||||
targetImageData.setPixel(tx, y, gridColor.intValue());
|
||||
}
|
||||
}
|
||||
|
||||
for (int r = 0; r < rows; r++) {
|
||||
int ty = r * (pixelsPerRow + 1);
|
||||