Christian Heimke commited on 2011-07-15 09:15:54
Showing 34 changed files, with 372 additions and 47 deletions.
| ... | ... |
@@ -1,5 +1,5 @@ |
| 1 | 1 |
/* BlinkenLightsInteractiveMovieProgram |
| 2 |
- * version 0.2 date 2004-11-10 |
|
| 2 |
+ * version 0.3 date 2004-11-12 |
|
| 3 | 3 |
* Copyright (C) 2004: Stefan Schuermans <1stein@schuermans.info> |
| 4 | 4 |
* Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
| 5 | 5 |
* a blinkenarea.org project |
| ... | ... |
@@ -29,6 +29,7 @@ public class Blimp extends JApplet |
| 29 | 29 |
|
| 30 | 30 |
//configuration variables |
| 31 | 31 |
boolean isFullApp = false; //if running as full application |
| 32 |
+ String initialFile = null; |
|
| 32 | 33 |
|
| 33 | 34 |
//GUI elements |
| 34 | 35 |
JFrame frame; //main window (if running as full application) |
| ... | ... |
@@ -37,7 +38,7 @@ public class Blimp extends JApplet |
| 37 | 38 |
JMenu menuFile, menuInfo, menuEdit, menuPlay, menuHelp; //menus |
| 38 | 39 |
JMenuItem menuFileNew, menuFileLoad, menuFileSave, menuFileSaveAs, menuFileQuit; |
| 39 | 40 |
JMenuItem menuInfoShow, menuInfoAdd, menuInfoDelete; |
| 40 |
- JMenuItem menuEditResize, menuEditInsertFrame, menuEditDuplicateFrame, menuEditDeleteFrame; |
|
| 41 |
+ JMenuItem menuEditResize, menuEditScale, menuEditInsertFrame, menuEditDuplicateFrame, menuEditDeleteFrame; |
|
| 41 | 42 |
JMenuItem menuPlayStart, menuPlayStop; |
| 42 | 43 |
JCheckBoxMenuItem menuPlayBegin, menuPlayLoop; |
| 43 | 44 |
JMenuItem menuHelpAbout; |
| ... | ... |
@@ -81,13 +82,14 @@ public class Blimp extends JApplet |
| 81 | 82 |
//constructor for applet |
| 82 | 83 |
public Blimp( ) |
| 83 | 84 |
{
|
| 84 |
- this.isFullApp = false; |
|
| 85 |
+ isFullApp = false; |
|
| 85 | 86 |
} |
| 86 | 87 |
|
| 87 |
- //constructor for full application (isFullApp == true) or applet (isFullAll == false) |
|
| 88 |
- public Blimp( boolean isFullApp ) |
|
| 88 |
+ //constructor for full application - perhaps load an initial file (filename != null) |
|
| 89 |
+ public Blimp( String filename ) |
|
| 89 | 90 |
{
|
| 90 |
- this.isFullApp = isFullApp; |
|
| 91 |
+ isFullApp = true; |
|
| 92 |
+ initialFile = filename; |
|
| 91 | 93 |
} |
| 92 | 94 |
|
| 93 | 95 |
//load an image |
| ... | ... |
@@ -140,13 +142,38 @@ public class Blimp extends JApplet |
| 140 | 142 |
labelStatus.setText( "new movie..." ); |
| 141 | 143 |
curFile = null; |
| 142 | 144 |
curMovie = new BlinkenMovie( 0, 0, 0, 0 ); |
| 143 |
- curMovie.insertInfo( 0, "creator", "Blimp (version 0.2 date 2004-11-10)" ); |
|
| 145 |
+ curMovie.insertInfo( 0, "creator", "Blimp (version 0.3 date 2004-11-12)" ); |
|
| 144 | 146 |
curMovieChanged = false; |
| 145 | 147 |
|
| 146 | 148 |
//update controls |
| 147 | 149 |
updateFrames( 0 ); |
| 148 | 150 |
} |
| 149 | 151 |
|
| 152 |
+ //load file (filename is taken from curFile) |
|
| 153 |
+ private void fileLoad( ) |
|
| 154 |
+ {
|
|
| 155 |
+ if( curMovie.load( curFile.getPath( ) ) ) |
|
| 156 |
+ {
|
|
| 157 |
+ //success |
|
| 158 |
+ if( frame != null ) |
|
| 159 |
+ frame.setTitle( "Blimp - " + curFile.getPath( ) ); |
|
| 160 |
+ labelStatus.setText( "movie \"" + curFile.getPath( ) + "\" was loaded successfully..." ); |
|
| 161 |
+ curMovieChanged = false; |
|
| 162 |
+ } |
|
| 163 |
+ else |
|
| 164 |
+ {
|
|
| 165 |
+ //some error |
|
| 166 |
+ if( frame != null ) |
|
| 167 |
+ frame.setTitle( "Blimp" ); |
|
| 168 |
+ labelStatus.setText( "movie \"" + curFile.getPath( ) + "\" could not be loaded..." ); |
|
| 169 |
+ curFile = null; |
|
| 170 |
+ curMovieChanged = false; |
|
| 171 |
+ } |
|
| 172 |
+ |
|
| 173 |
+ //update controls |
|
| 174 |
+ updateFrames( 0 ); |
|
| 175 |
+ } |
|
| 176 |
+ |
|
| 150 | 177 |
//"File Load" was chosen from menu |
| 151 | 178 |
private void actionFileLoad( ) |
| 152 | 179 |
{
|
| ... | ... |
@@ -168,29 +195,10 @@ public class Blimp extends JApplet |
| 168 | 195 |
curDir = fileChooser.getCurrentDirectory( ); |
| 169 | 196 |
curFile = fileChooser.getSelectedFile( ); |
| 170 | 197 |
//load file |
| 171 |
- if( curMovie.load( curFile.getPath( ) ) ) |
|
| 172 |
- {
|
|
| 173 |
- //success |
|
| 174 |
- if( frame != null ) |
|
| 175 |
- frame.setTitle( "Blimp - " + curFile.getPath( ) ); |
|
| 176 |
- labelStatus.setText( "movie \"" + curFile.getPath( ) + "\" was loaded successfully..." ); |
|
| 177 |
- curMovieChanged = false; |
|
| 178 |
- } |
|
| 179 |
- else |
|
| 180 |
- {
|
|
| 181 |
- //some error |
|
| 182 |
- if( frame != null ) |
|
| 183 |
- frame.setTitle( "Blimp" ); |
|
| 184 |
- labelStatus.setText( "movie \"" + curFile.getPath( ) + "\" could not be loaded..." ); |
|
| 185 |
- curFile = null; |
|
| 186 |
- curMovieChanged = false; |
|
| 198 |
+ fileLoad( ); |
|
| 187 | 199 |
} |
| 188 | 200 |
} |
| 189 | 201 |
|
| 190 |
- //update controls |
|
| 191 |
- updateFrames( 0 ); |
|
| 192 |
- } |
|
| 193 |
- |
|
| 194 | 202 |
//"File Save" was chosen from menu |
| 195 | 203 |
private void actionFileSave( ) |
| 196 | 204 |
{
|
| ... | ... |
@@ -398,6 +406,60 @@ public class Blimp extends JApplet |
| 398 | 406 |
labelStatus.setText( "movie resized successfully to " + size.toString( ) + "..." ); |
| 399 | 407 |
} |
| 400 | 408 |
|
| 409 |
+ //"Edit Scale Movie..." was chosen from menu |
|
| 410 |
+ private void actionEditScale( ) |
|
| 411 |
+ {
|
|
| 412 |
+ Pattern dimPattern; |
|
| 413 |
+ String curDim, curSize; |
|
| 414 |
+ Object dim; |
|
| 415 |
+ Matcher dimMatcher; |
|
| 416 |
+ |
|
| 417 |
+ //initialize dimension pattern |
|
| 418 |
+ dimPattern = Pattern.compile( "^([0-9]+)x([0-9]+)$" ); |
|
| 419 |
+ |
|
| 420 |
+ //get string with current movie size |
|
| 421 |
+ curDim = curMovie.getWidth( ) + "x" + |
|
| 422 |
+ curMovie.getHeight( ); |
|
| 423 |
+ curSize = curMovie.getWidth( ) + "x" + |
|
| 424 |
+ curMovie.getHeight( ) + "-" + |
|
| 425 |
+ curMovie.getChannels( ) + "/" + |
|
| 426 |
+ (curMovie.getMaxval( ) + 1); |
|
| 427 |
+ |
|
| 428 |
+ //ask until cancel or answer is valid |
|
| 429 |
+ dim = curDim; |
|
| 430 |
+ do |
|
| 431 |
+ {
|
|
| 432 |
+ //ask for new size |
|
| 433 |
+ dim = JOptionPane.showInputDialog( dialogParent, |
|
| 434 |
+ "Current movie dimension is: " + curDim + " (" + curSize + ")\n\n" +
|
|
| 435 |
+ "The format is: <width>x<height>\n" + |
|
| 436 |
+ " 18x8 (Blinkenlights, Blinkenlights Reloaded)\n" + |
|
| 437 |
+ " 26x20 (Blinkenlights Arcade)\n" + |
|
| 438 |
+ " 104x32 (TROIA big walls)\n" + |
|
| 439 |
+ " 80x32 (TROIA small walls)\n" + |
|
| 440 |
+ " 104x80 (TROIA floor + ceiling)\n\n" + |
|
| 441 |
+ "Please enter the new movie dimension:", |
|
| 442 |
+ "Blimp - Scale Movie...", |
|
| 443 |
+ JOptionPane.QUESTION_MESSAGE, |
|
| 444 |
+ null, null, dim ); |
|
| 445 |
+ //dialog was cancelled |
|
| 446 |
+ if( dim == null ) |
|
| 447 |
+ return; |
|
| 448 |
+ } |
|
| 449 |
+ while( ! (dimMatcher = dimPattern.matcher( dim.toString( ) )).find( ) ); //repeat question if answer not valid |
|
| 450 |
+ |
|
| 451 |
+ //scale movie |
|
| 452 |
+ curMovie.scale( Integer.parseInt( dimMatcher.group( 2 ) ), |
|
| 453 |
+ Integer.parseInt( dimMatcher.group( 1 ) ) ); |
|
| 454 |
+ curMovieChanged = true; |
|
| 455 |
+ |
|
| 456 |
+ //update controls |
|
| 457 |
+ updateFrames( scrollFrames.getValue( ) ); |
|
| 458 |
+ |
|
| 459 |
+ //update status |
|
| 460 |
+ labelStatus.setText( "movie scaled successfully to " + dim.toString( ) + "..." ); |
|
| 461 |
+ } |
|
| 462 |
+ |
|
| 401 | 463 |
//"Edit Insert Frame" was chosen from menu |
| 402 | 464 |
private void actionEditInsertFrame( ) |
| 403 | 465 |
{
|
| ... | ... |
@@ -549,7 +611,7 @@ public class Blimp extends JApplet |
| 549 | 611 |
{
|
| 550 | 612 |
JOptionPane.showMessageDialog( dialogParent, |
| 551 | 613 |
"BlinkenLightsInteractiveMovieProgram\n" + |
| 552 |
- "version 0.2 date 2004-11-10\n" + |
|
| 614 |
+ "version 0.3 date 2004-11-12\n" + |
|
| 553 | 615 |
"Copyright (C) 2004: Stefan Schuermans <1stein@schuermans.info>\n" + |
| 554 | 616 |
"Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html\n" + |
| 555 | 617 |
"a blinkenarea.org project\n" + |
| ... | ... |
@@ -997,6 +1059,8 @@ public class Blimp extends JApplet |
| 997 | 1059 |
actionInfoDelete( ); |
| 998 | 1060 |
else if( e.getSource( ) == menuEditResize ) |
| 999 | 1061 |
actionEditResize( ); |
| 1062 |
+ else if( e.getSource( ) == menuEditScale ) |
|
| 1063 |
+ actionEditScale( ); |
|
| 1000 | 1064 |
else if( e.getSource( ) == menuEditInsertFrame ) |
| 1001 | 1065 |
actionEditInsertFrame( ); |
| 1002 | 1066 |
else if( e.getSource( ) == menuEditDuplicateFrame ) |
| ... | ... |
@@ -1181,7 +1245,7 @@ public class Blimp extends JApplet |
| 1181 | 1245 |
//initialize current movie, frame |
| 1182 | 1246 |
curDir = new File( "." ); |
| 1183 | 1247 |
curMovie = new BlinkenMovie( 0, 0, 0, 0 ); |
| 1184 |
- curMovie.insertInfo( 0, "creator", "Blimp (version 0.2 date 2004-11-10)" ); |
|
| 1248 |
+ curMovie.insertInfo( 0, "creator", "Blimp (version 0.3 date 2004-11-12)" ); |
|
| 1185 | 1249 |
curFrame = null; |
| 1186 | 1250 |
|
| 1187 | 1251 |
//runnning as full application |
| ... | ... |
@@ -1256,6 +1320,9 @@ public class Blimp extends JApplet |
| 1256 | 1320 |
menuEditResize = new JMenuItem( "Resize Movie..." ); |
| 1257 | 1321 |
menuEditResize.addActionListener( this ); |
| 1258 | 1322 |
menuEdit.add( menuEditResize ); |
| 1323 |
+ menuEditScale = new JMenuItem( "Scale Movie..." ); |
|
| 1324 |
+ menuEditScale.addActionListener( this ); |
|
| 1325 |
+ menuEdit.add( menuEditScale ); |
|
| 1259 | 1326 |
menuEdit.addSeparator( ); |
| 1260 | 1327 |
menuEditInsertFrame = new JMenuItem( "Insert Frame" ); |
| 1261 | 1328 |
menuEditInsertFrame.addActionListener( this ); |
| ... | ... |
@@ -1595,6 +1662,17 @@ public class Blimp extends JApplet |
| 1595 | 1662 |
resize( 1, 1 ); |
| 1596 | 1663 |
resize( size ); |
| 1597 | 1664 |
} |
| 1665 |
+ |
|
| 1666 |
+ //load initial file |
|
| 1667 |
+ if( initialFile != null ) |
|
| 1668 |
+ {
|
|
| 1669 |
+ //set current file and current directory |
|
| 1670 |
+ curFile = (new File( initialFile )).getAbsoluteFile( ); |
|
| 1671 |
+ curDir = curFile.getParentFile( ); |
|
| 1672 |
+ |
|
| 1673 |
+ //load file |
|
| 1674 |
+ fileLoad( ); |
|
| 1675 |
+ } |
|
| 1598 | 1676 |
} |
| 1599 | 1677 |
|
| 1600 | 1678 |
//entry point for applet |
| ... | ... |
@@ -1606,7 +1684,146 @@ public class Blimp extends JApplet |
| 1606 | 1684 |
//entry point for full application |
| 1607 | 1685 |
public static void main( String[] args ) |
| 1608 | 1686 |
{
|
| 1609 |
- javax.swing.SwingUtilities.invokeLater( new Blimp( true ) ); |
|
| 1687 |
+ int i; |
|
| 1688 |
+ BlinkenMovie movie; |
|
| 1689 |
+ Pattern sizePattern, dimPattern; |
|
| 1690 |
+ Matcher sizeMatcher, dimMatcher; |
|
| 1691 |
+ String txtOld, txtNew; |
|
| 1692 |
+ |
|
| 1693 |
+ //running interactively - without arguments |
|
| 1694 |
+ if( args.length <= 0 ) |
|
| 1695 |
+ {
|
|
| 1696 |
+ javax.swing.SwingUtilities.invokeLater( new Blimp( null ) ); |
|
| 1697 |
+ return; |
|
| 1698 |
+ } |
|
| 1699 |
+ |
|
| 1700 |
+ //running interactively - load initial file |
|
| 1701 |
+ if( args.length == 1 && ! args[0].substring( 0, 1 ).equals( "-" ) ) |
|
| 1702 |
+ {
|
|
| 1703 |
+ javax.swing.SwingUtilities.invokeLater( new Blimp( args[0] ) ); |
|
| 1704 |
+ return; |
|
| 1705 |
+ } |
|
| 1706 |
+ |
|
| 1707 |
+ //running as command line tool |
|
| 1708 |
+ System.out.println( "BlinkenLightsInteractiveMovieProgram\n" + |
|
| 1709 |
+ "version 0.3 date 2004-11-12\n" + |
|
| 1710 |
+ "Copyright (C) 2004: Stefan Schuermans <1stein@schuermans.info>\n" + |
|
| 1711 |
+ "Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html\n" + |
|
| 1712 |
+ "a blinkenarea.org project\n" + |
|
| 1713 |
+ "powered by eventphone.de\n" ); |
|
| 1714 |
+ |
|
| 1715 |
+ //initialize patterns |
|
| 1716 |
+ sizePattern = Pattern.compile( "^([0-9]+)x([0-9]+)-([0-9]+)/([0-9]+)$" ); |
|
| 1717 |
+ dimPattern = Pattern.compile( "^([0-9]+)x([0-9]+)$" ); |
|
| 1718 |
+ |
|
| 1719 |
+ //get initial movie |
|
| 1720 |
+ movie = new BlinkenMovie( 0, 0, 0, 0 ); |
|
| 1721 |
+ |
|
| 1722 |
+ //process parameters |
|
| 1723 |
+ for( i = 0; i < args.length; i++ ) |
|
| 1724 |
+ {
|
|
| 1725 |
+ |
|
| 1726 |
+ if( args[i].equals( "-h" ) || args[i].equals( "--help" ) ) |
|
| 1727 |
+ {
|
|
| 1728 |
+ System.out.println( "interactive movie editor:\n" + |
|
| 1729 |
+ " java Blimp [<initial-file>]\n" + |
|
| 1730 |
+ "\n" + |
|
| 1731 |
+ "command line tool:\n" + |
|
| 1732 |
+ " java Blimp <parameter> [<parameter> [...]]\n" + |
|
| 1733 |
+ "parameters:\n" + |
|
| 1734 |
+ " -i / --input <file> load movie\n" + |
|
| 1735 |
+ " -r / --resize <width>x<height>-<channels>/<colors> resize movie\n" + |
|
| 1736 |
+ " -s / --scale <width>x<height> scale movie\n" + |
|
| 1737 |
+ " -o / --output <file> save movie\n" + |
|
| 1738 |
+ "\n" ); |
|
| 1739 |
+ } |
|
| 1740 |
+ |
|
| 1741 |
+ else if( args[i].equals( "-i" ) || args[i].equals( "--input" ) ) |
|
| 1742 |
+ {
|
|
| 1743 |
+ if( i + 1 >= args.length ) |
|
| 1744 |
+ {
|
|
| 1745 |
+ System.out.println( "parameter \"-i\" / \"--input\" requires an argument" ); |
|
| 1746 |
+ break; |
|
| 1747 |
+ } |
|
| 1748 |
+ i++; |
|
| 1749 |
+ if( ! movie.load( args[i] ) ) |
|
| 1750 |
+ {
|
|
| 1751 |
+ System.out.println( "movie \"" + args[i] + "\" could not be loaded..." ); |
|
| 1752 |
+ break; |
|
| 1753 |
+ } |
|
| 1754 |
+ System.out.println( "movie \"" + args[i] + "\" was loaded successfully..." ); |
|
| 1755 |
+ } |
|
| 1756 |
+ |
|
| 1757 |
+ else if( args[i].equals( "-r" ) || args[i].equals( "--resize" ) ) |
|
| 1758 |
+ {
|
|
| 1759 |
+ if( i + 1 >= args.length ) |
|
| 1760 |
+ {
|
|
| 1761 |
+ System.out.println( "parameter \"-r\" / \"--resize\" requires an argument" ); |
|
| 1762 |
+ break; |
|
| 1763 |
+ } |
|
| 1764 |
+ i++; |
|
| 1765 |
+ txtOld = movie.getWidth( ) + "x" + |
|
| 1766 |
+ movie.getHeight( ) + "-" + |
|
| 1767 |
+ movie.getChannels( ) + "/" + |
|
| 1768 |
+ (movie.getMaxval( ) + 1); |
|
| 1769 |
+ if( ! (sizeMatcher = sizePattern.matcher( args[i] )).find( ) ) |
|
| 1770 |
+ {
|
|
| 1771 |
+ System.out.println( "invalid format \"" + args[i] + "\"of size (<width>x<height>-<channles>/<colors>)" ); |
|
| 1772 |
+ break; |
|
| 1773 |
+ } |
|
| 1774 |
+ movie.resize( Integer.parseInt( sizeMatcher.group( 2 ) ), |
|
| 1775 |
+ Integer.parseInt( sizeMatcher.group( 1 ) ), |
|
| 1776 |
+ Integer.parseInt( sizeMatcher.group( 3 ) ), |
|
| 1777 |
+ Integer.parseInt( sizeMatcher.group( 4 ) ) - 1 ); |
|
| 1778 |
+ txtNew = movie.getWidth( ) + "x" + |
|
| 1779 |
+ movie.getHeight( ) + "-" + |
|
| 1780 |
+ movie.getChannels( ) + "/" + |
|
| 1781 |
+ (movie.getMaxval( ) + 1); |
|
| 1782 |
+ System.out.println( "resized movie from \"" + txtOld + "\" to \"" + txtNew + "\"..." ); |
|
| 1783 |
+ } |
|
| 1784 |
+ |
|
| 1785 |
+ else if( args[i].equals( "-s" ) || args[i].equals( "--scale" ) ) |
|
| 1786 |
+ {
|
|
| 1787 |
+ if( i + 1 >= args.length ) |
|
| 1788 |
+ {
|
|
| 1789 |
+ System.out.println( "parameter \"-s\" / \"--scale\" requires an argument" ); |
|
| 1790 |
+ break; |
|
| 1791 |
+ } |
|
| 1792 |
+ i++; |
|
| 1793 |
+ txtOld = movie.getWidth( ) + "x" + |
|
| 1794 |
+ movie.getHeight( ); |
|
| 1795 |
+ if( ! (dimMatcher = dimPattern.matcher( args[i] )).find( ) ) |
|
| 1796 |
+ {
|
|
| 1797 |
+ System.out.println( "invalid format \"" + args[i] + "\" of dimension (<width>x<height>)" ); |
|
| 1798 |
+ break; |
|
| 1799 |
+ } |
|
| 1800 |
+ movie.scale( Integer.parseInt( dimMatcher.group( 2 ) ), |
|
| 1801 |
+ Integer.parseInt( dimMatcher.group( 1 ) ) ); |
|
| 1802 |
+ txtNew = movie.getWidth( ) + "x" + |
|
| 1803 |
+ movie.getHeight( ); |
|
| 1804 |
+ System.out.println( "scaled movie from \"" + txtOld + "\" to \"" + txtNew + "\"..." ); |
|
| 1805 |
+ } |
|
| 1806 |
+ |
|
| 1807 |
+ else if( args[i].equals( "-o" ) || args[i].equals( "--output" ) ) |
|
| 1808 |
+ {
|
|
| 1809 |
+ if( i + 1 >= args.length ) |
|
| 1810 |
+ {
|
|
| 1811 |
+ System.out.println( "parameter \"-o\" / \"--output\" requires an argument" ); |
|
| 1812 |
+ break; |
|
| 1813 |
+ } |
|
| 1814 |
+ i++; |
|
| 1815 |
+ if( ! movie.save( args[i] ) ) |
|
| 1816 |
+ {
|
|
| 1817 |
+ System.out.println( "movie \"" + args[i] + "\" could not be saved..." ); |
|
| 1818 |
+ break; |
|
| 1819 |
+ } |
|
| 1820 |
+ System.out.println( "movie \"" + args[i] + "\" was saved successfully..." ); |
|
| 1821 |
+ } |
|
| 1822 |
+ |
|
| 1823 |
+ else |
|
| 1824 |
+ System.out.println( "unknown parameter \"" + args[i] + "\" - use \"-h\" or \"--help\" to get help" ); |
|
| 1825 |
+ |
|
| 1826 |
+ } //for( i... |
|
| 1610 | 1827 |
} |
| 1611 | 1828 |
|
| 1612 | 1829 |
} //public class Blimp |
| ... | ... |
@@ -1,5 +1,5 @@ |
| 1 | 1 |
/* BlinkenLightsInteractiveMovieProgram |
| 2 |
- * version 0.2 date 2004-11-10 |
|
| 2 |
+ * version 0.3 date 2004-11-12 |
|
| 3 | 3 |
* Copyright (C) 2004: Stefan Schuermans <1stein@schuermans.info> |
| 4 | 4 |
* Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
| 5 | 5 |
* a blinkenarea.org project |
| ... | ... |
@@ -1,5 +1,5 @@ |
| 1 | 1 |
/* BlinkenLightsInteractiveMovieProgram |
| 2 |
- * version 0.2 date 2004-11-10 |
|
| 2 |
+ * version 0.3 date 2004-11-12 |
|
| 3 | 3 |
* Copyright (C) 2004: Stefan Schuermans <1stein@schuermans.info> |
| 4 | 4 |
* Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
| 5 | 5 |
* a blinkenarea.org project |
| ... | ... |
@@ -245,6 +245,104 @@ public class BlinkenFrame |
| 245 | 245 |
this.data = data; |
| 246 | 246 |
} |
| 247 | 247 |
|
| 248 |
+ public void scale( int height, int width ) |
|
| 249 |
+ {
|
|
| 250 |
+ byte[][][] data; |
|
| 251 |
+ double scaleHor, scaleVer, ox, oy, ox1, oy1, val; |
|
| 252 |
+ int c, nx, ny, x, y, oxi, oyi, ox1i, oy1i; |
|
| 253 |
+ |
|
| 254 |
+ if( height < 1 ) height = 1; |
|
| 255 |
+ if( height > 1024 ) height = 1024; |
|
| 256 |
+ if( width < 1 ) width = 1; |
|
| 257 |
+ if( width > 1024 ) width = 1024; |
|
| 258 |
+ |
|
| 259 |
+ if( height == this.height && |
|
| 260 |
+ width == this.width ) |
|
| 261 |
+ return; |
|
| 262 |
+ |
|
| 263 |
+ scaleHor = (double)width / (double)this.width; |
|
| 264 |
+ scaleVer = (double)height / (double)this.height; |
|
| 265 |
+ |
|
| 266 |
+ //allocate new data array |
|
| 267 |
+ data = new byte[height][width][channels]; |
|
| 268 |
+ |
|
| 269 |
+ //scale every channel |
|
| 270 |
+ for( c = 0; c < channels; c++ ) |
|
| 271 |
+ {
|
|
| 272 |
+ for( ny = 0; ny < height; ny++ ) |
|
| 273 |
+ {
|
|
| 274 |
+ for( nx = 0; nx < width; nx++ ) |
|
| 275 |
+ {
|
|
| 276 |
+ oy = (double)ny / scaleVer; //sub-pixel exact range in old picture |
|
| 277 |
+ ox = (double)nx / scaleHor; |
|
| 278 |
+ oy1 = (double)(ny + 1) / scaleVer - 0.000001; |
|
| 279 |
+ ox1 = (double)(nx + 1) / scaleHor - 0.000001; |
|
| 280 |
+ if( oy < 0 || ox < 0 || oy1 >= this.height || ox1 >= this.width) //out of old picture |
|
| 281 |
+ data[ny][nx][c] = 0; |
|
| 282 |
+ else |
|
| 283 |
+ {
|
|
| 284 |
+ oyi = (int)oy; |
|
| 285 |
+ oxi = (int)ox; |
|
| 286 |
+ oy1i = (int)oy1; |
|
| 287 |
+ ox1i = (int)ox1; |
|
| 288 |
+ if( oyi == oy1i ) |
|
| 289 |
+ {
|
|
| 290 |
+ if( oxi == ox1i) //one source pixel |
|
| 291 |
+ {
|
|
| 292 |
+ val = (double)((int)this.data[oyi][oxi][c] & 0xFF); |
|
| 293 |
+ } |
|
| 294 |
+ else //one line of source pixels |
|
| 295 |
+ {
|
|
| 296 |
+ val = (double)((int)this.data[oyi][oxi][c] & 0xFF) * (1 - ox + oxi) |
|
| 297 |
+ + (double)((int)this.data[oyi][ox1i][c] & 0xFF) * (ox1 - ox1i); |
|
| 298 |
+ for( x = oxi + 1; x < ox1i; x++ ) |
|
| 299 |
+ val += (double)((int)this.data[oyi][x][c] & 0xFF); |
|
| 300 |
+ val /= ox1 - ox; |
|
| 301 |
+ } |
|
| 302 |
+ } |
|
| 303 |
+ else //one column of source pixels |
|
| 304 |
+ {
|
|
| 305 |
+ if( oxi == ox1i ) |
|
| 306 |
+ {
|
|
| 307 |
+ val = (double)((int)this.data[oyi][oxi][c] & 0xFF) * (1 - oy + oyi) |
|
| 308 |
+ + (double)((int)this.data[oy1i][oxi][c] & 0xFF) * (oy1 - oy1i); |
|
| 309 |
+ for( y = oyi + 1; y < oy1i; y++ ) |
|
| 310 |
+ val += (double)((int)this.data[y][oxi][c] & 0xFF); |
|
| 311 |
+ val /= oy1 - oy; |
|
| 312 |
+ } |
|
| 313 |
+ else //rectangle of source pixels |
|
| 314 |
+ {
|
|
| 315 |
+ val = (double)((int)this.data[oyi][oxi][c] & 0xFF) * (1 - oy + oyi) * (1 - ox + oxi) |
|
| 316 |
+ + (double)((int)this.data[oyi][ox1i][c] & 0xFF) * (1 - oy + oyi) * (ox1 - ox1i) |
|
| 317 |
+ + (double)((int)this.data[oy1i][oxi][c] & 0xFF) * (oy1 - oy1i) * (1 - ox + oxi) |
|
| 318 |
+ + (double)((int)this.data[oy1i][ox1i][c] & 0xFF) * (oy1 - oy1i) * (ox1 - ox1i); |
|
| 319 |
+ for( y = oyi + 1; y < oy1i; y++ ) |
|
| 320 |
+ {
|
|
| 321 |
+ val += (double)((int)this.data[y][oxi][c] & 0xFF) * (1 - ox + oxi) |
|
| 322 |
+ + (double)((int)this.data[y][ox1i][c] & 0xFF) * (ox1 - ox1i); |
|
| 323 |
+ } |
|
| 324 |
+ for( x = oxi + 1; x < ox1i; x++ ) |
|
| 325 |
+ {
|
|
| 326 |
+ val += (double)((int)this.data[oyi][x][c] & 0xFF) * (1 - oy + oyi) |
|
| 327 |
+ + (double)((int)this.data[oy1i][x][c] & 0xFF) * (oy1 - oy1i); |
|
| 328 |
+ } |
|
| 329 |
+ for( y = oyi + 1; y < oy1i; y++ ) |
|
| 330 |
+ for( x = oxi + 1; x < ox1i; x++ ) |
|
| 331 |
+ val += (double)((int)this.data[y][x][c] & 0xFF); |
|
| 332 |
+ val /= (oy1 - oy) * (ox1 - ox); |
|
| 333 |
+ } |
|
| 334 |
+ } |
|
| 335 |
+ data[ny][nx][c] = (byte)(int)(val + 0.5); |
|
| 336 |
+ } |
|
| 337 |
+ } //for( nx ... |
|
| 338 |
+ } //for( ny ... |
|
| 339 |
+ } //for( c ... |
|
| 340 |
+ |
|
| 341 |
+ this.height = height; |
|
| 342 |
+ this.width = width; |
|
| 343 |
+ this.data = data; |
|
| 344 |
+ } |
|
| 345 |
+ |
|
| 248 | 346 |
public String toString( ) |
| 249 | 347 |
{
|
| 250 | 348 |
String str = ""; |
| ... | ... |
@@ -1,5 +1,5 @@ |
| 1 | 1 |
/* BlinkenLightsInteractiveMovieProgram |
| 2 |
- * version 0.2 date 2004-11-10 |
|
| 2 |
+ * version 0.3 date 2004-11-12 |
|
| 3 | 3 |
* Copyright (C) 2004: Stefan Schuermans <1stein@schuermans.info> |
| 4 | 4 |
* Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
| 5 | 5 |
* a blinkenarea.org project |
| ... | ... |
@@ -1,5 +1,5 @@ |
| 1 | 1 |
/* BlinkenLightsInteractiveMovieProgram |
| 2 |
- * version 0.2 date 2004-11-10 |
|
| 2 |
+ * version 0.3 date 2004-11-12 |
|
| 3 | 3 |
* Copyright (C) 2004: Stefan Schuermans <1stein@schuermans.info> |
| 4 | 4 |
* Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
| 5 | 5 |
* a blinkenarea.org project |
| ... | ... |
@@ -1,5 +1,5 @@ |
| 1 | 1 |
/* BlinkenLightsInteractiveMovieProgram |
| 2 |
- * version 0.2 date 2004-11-10 |
|
| 2 |
+ * version 0.3 date 2004-11-12 |
|
| 3 | 3 |
* Copyright (C) 2004: Stefan Schuermans <1stein@schuermans.info> |
| 4 | 4 |
* Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
| 5 | 5 |
* a blinkenarea.org project |
| ... | ... |
@@ -1,5 +1,5 @@ |
| 1 | 1 |
/* BlinkenLightsInteractiveMovieProgram |
| 2 |
- * version 0.2 date 2004-11-10 |
|
| 2 |
+ * version 0.3 date 2004-11-12 |
|
| 3 | 3 |
* Copyright (C) 2004: Stefan Schuermans <1stein@schuermans.info> |
| 4 | 4 |
* Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
| 5 | 5 |
* a blinkenarea.org project |
| ... | ... |
@@ -1,5 +1,5 @@ |
| 1 | 1 |
/* BlinkenLightsInteractiveMovieProgram |
| 2 |
- * version 0.2 date 2004-11-10 |
|
| 2 |
+ * version 0.3 date 2004-11-12 |
|
| 3 | 3 |
* Copyright (C) 2004: Stefan Schuermans <1stein@schuermans.info> |
| 4 | 4 |
* Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
| 5 | 5 |
* a blinkenarea.org project |
| ... | ... |
@@ -1,5 +1,5 @@ |
| 1 | 1 |
/* BlinkenLightsInteractiveMovieProgram |
| 2 |
- * version 0.2 date 2004-11-10 |
|
| 2 |
+ * version 0.3 date 2004-11-12 |
|
| 3 | 3 |
* Copyright (C) 2004: Stefan Schuermans <1stein@schuermans.info> |
| 4 | 4 |
* Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
| 5 | 5 |
* a blinkenarea.org project |
| ... | ... |
@@ -290,6 +290,22 @@ public class BlinkenMovie |
| 290 | 290 |
frames[i].resize( height, width, channels, maxval ); |
| 291 | 291 |
} |
| 292 | 292 |
|
| 293 |
+ public void scale( int height, int width ) |
|
| 294 |
+ {
|
|
| 295 |
+ int i; |
|
| 296 |
+ |
|
| 297 |
+ if( height < 1 ) height = 1; |
|
| 298 |
+ if( height > 1024 ) height = 1024; |
|
| 299 |
+ if( width < 1 ) width = 1; |
|
| 300 |
+ if( width > 1024 ) width = 1024; |
|
| 301 |
+ |
|
| 302 |
+ this.height = height; |
|
| 303 |
+ this.width = width; |
|
| 304 |
+ |
|
| 305 |
+ for( i = 0; i < frameCnt; i++ ) |
|
| 306 |
+ frames[i].scale( height, width ); |
|
| 307 |
+ } |
|
| 308 |
+ |
|
| 293 | 309 |
public String toString( ) |
| 294 | 310 |
{
|
| 295 | 311 |
String str = "BlinkenMovie " + width + "x" + height + "-" + channels + "/" + (maxval + 1) + "\n"; |
| ... | ... |
@@ -1,5 +1,5 @@ |
| 1 | 1 |
# BlinkenLightsInteractiveMovieProgram |
| 2 |
-# version 0.2 date 2004-11-10 |
|
| 2 |
+# version 0.3 date 2004-11-12 |
|
| 3 | 3 |
# Copyright (C) 2004: Stefan Schuermans <1stein@schuermans.info> |
| 4 | 4 |
# Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
| 5 | 5 |
# a blinkenarea.org project |