Initial revision
[old-projects.git] / ekit / com / hexidec / util / CMUScodec.java
1 /* GNU General Public License CMUScodec Copyright (C) 2002 Howard A Kistler This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.hexidec.util; import java.awt.AWTException; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; /** CMUScodec * * Utility for reading (and eventually converting) Deluxe Music * Construction Set (DMCS) files * * @author Howard Kistler * @version 0.1 * * VERSION HISTORY * 0.1 (03/13/2002) - initial creation (03/13/2002) */ public class CMUScodec { // Constants ----------------------------------------------------------------------------> /* CMUS File Structure FILE HEADER ==================== (At the beginning of each file) IFF Form Chunk 4 bytes - FORM 4 bytes - ? 4 bytes - CMUS Score Header Chunk 4 bytes - SCHD 10 bytes - 00 00 00 1A 00 02 00 00 00 02 2 bytes - (significant number[s]?) 2 bytes - 00 04 (# of channels maybe?) 2 bytes - Ch 12 bytes - 00 00 00 00 00 00 0C E6 00 00 0C E6 2 bytes - (2 byte significant number, or 00 and 1 byte significant?) DSCR HEADER BLOCK 4 bytes - DSCR 14 bytes - ? Staff Table Chunk 4 bytes - STAF X bytes - ? (1 entry per staff in score) DSTF HEADER BLOCK 4 bytes - DSTF X bytes - ? LFON HEADER BLOCK 4 bytes - LFON 4 bytes - 00 00 00 0F 4 bytes - 00 00 00 08 X bytes - Font Name 2 bytes - 00 00 SONG BODY ==================== TRCK BLOCKS 4 bytes - TRCK X bytes - track data INSTRUMENT BLOCK ==================== Each Instrument Contains: 4 bytes - FORM 4 bytes - (number?) 8 bytes - INSTINHD 4 bytes - 00 00 00 0A 1 byte - Instrument Number 1 byte - (zero pad?) 8 bytes - 00 00 FF FF 40 00 00 00 4 bytes - NAME 4 bytes - Name Byte Count Y bytes - Name Bytes (Y = value from above) 1 byte - (zero pad?) [Optional Instrument Path] 4 bytes - SFIL 4 bytes - Path Byte Count Y bytes - Path Bytes (Y = value from above) 1 byte - (zero pad) */ // Decoder Vars private static byte[] bData; private static int iPlace; // Public Vartypes ----------------------------------------------------------------------> public final static int FILETYPE_DMCS = 0; public final static int FILETYPE_CMUS = 1; public final static int FILETYPE_SMUS = 2; public final static int FILETYPE_TEXT = 3; public final static int FILETYPE_FINALE = 4; private final static byte NUL = (byte)0; // Constructor --------------------------------------------------------------------------> public CMUScodec() { } // Decode Method ------------------------------------------------------------------------> public static void decode(String sourceFile, String destFile) throws FileNotFoundException, IOException, AWTException { convertToTextFile(sourceFile, destFile); } // Encode Method ------------------------------------------------------------------------> public static void encode(String sourceFile, String destFile, int fileType) throws FileNotFoundException, IOException, AWTException { // String newFormat = convertToFormat(sourceFile, fileType); // writeToDMCSFile(newFormat, destFile); } // CMUS-to-TEXT File Conversion --------------------------------------------------------> protected static void convertToTextFile(String inFile, String outFile) throws IOException { File srcFile = new File(inFile); FileInputStream fis = new FileInputStream(srcFile); int filesize = (int)(srcFile.length()); bData = new byte[filesize]; iPlace = 0; int iCounter = 0; while(iCounter < filesize) { bData[iCounter] = (byte)(fis.read()); iCounter++; } fis.close(); FileWriter fw = new FileWriter(new File(outFile)); String sOutput = "FILE SIZE : " + srcFile.length() + "\r"; fw.write(sOutput, 0, sOutput.length()); sOutput = "BYTES READ : " + iCounter + "\r"; fw.write(sOutput, 0, sOutput.length()); sOutput = "====================\rFILE CONTENTS\r====================\r"; fw.write(sOutput, 0, sOutput.length()); while(iPlace < iCounter) { String chunk = "" + (char)(bData[iPlace++]) + (char)(bData[iPlace++]) + (char)(bData[iPlace++]) + (char)(bData[iPlace++]); if (chunk.equals("FORM")) { parseFORM(fw); } else if(chunk.equals("SCHD")) { parseSCHD(fw); } else if(chunk.equals("DSCR")) { parseDSCR(fw); } else if(chunk.equals("STAF")) { parseSTAF(fw); } else if(chunk.equals("DSTF")) { parseDSTF(fw); } else if(chunk.equals("LFON")) { parseLFON(fw); } else if(chunk.equals("TRCK")) { parseTRCK(fw); } else if(chunk.equals("INHD")) { parseINHD(fw); } else if(chunk.equals("NAME")) { parseNAME(fw); } else if(chunk.equals("SFIL")) { parseSFIL(fw); } else { sOutput = "UNKNOWN CHUNK : " + chunk + "\r"; fw.write(sOutput, 0, sOutput.length()); iPlace = iCounter; break; } } /* 4 bytes - FORM 4 bytes - (number?) 4 bytes - INST 4 bytes - type : INHD, SFIL, SHAR or others 4 bytes - 00 00 00 0A 1 byte - Instrument Number 1 byte - (zero pad?) 8 bytes - 00 00 FF FF 40 00 00 00 4 bytes - NAME 4 bytes - Name Byte Count Y bytes - Name Bytes (Y = value from above) 1 byte - (zero pad?) [Optional Instrument Path] 4 bytes - SFIL 4 bytes - Path Byte Count Y bytes - Path Bytes (Y = value from above) 1 byte - (zero pad) */ fw.flush(); fw.close(); } // Chunk Parsing Methods----------------------------------------------------------------> private static void parseFORM(FileWriter fw) throws IOException { String sOutput = "--------------------\rFORM CHUNK\r--------------------\r"; fw.write(sOutput, 0, sOutput.length()); sOutput = "FORM BLOCK : FORM\r"; fw.write(sOutput, 0, sOutput.length()); int iSize = (int)( ((bData[iPlace++]) << 24) + ((bData[iPlace++]) << 16) + ((bData[iPlace++]) << 8) + ((bData[iPlace++]) ) ); sOutput = "SIZE BLOCK : " + iSize + "\r"; fw.write(sOutput, 0, sOutput.length()); sOutput = "TYPE BLOCK : " + (char)(bData[iPlace++]) + (char)(bData[iPlace++]) + (char)(bData[iPlace++]) + (char)(bData[iPlace++]) + "\r"; fw.write(sOutput, 0, sOutput.length()); } private static void parseSCHD(FileWriter fw) throws IOException { String sOutput = "--------------------\rSCORE HEADER CHUNK\r--------------------\r"; fw.write(sOutput, 0, sOutput.length()); sOutput = "SCHD BLOCK : SCHD\r"; fw.write(sOutput, 0, sOutput.length()); int iData = (int)( ((bData[iPlace++]) << 8) + ((bData[iPlace++]) ) ); sOutput = "WORD BLOCK 1 : " + iData + "\r"; fw.write(sOutput, 0, sOutput.length()); iData = (int)( ((bData[iPlace++]) << 8) + ((bData[iPlace++]) ) ); sOutput = "WORD BLOCK 2 : " + iData + "\r"; fw.write(sOutput, 0, sOutput.length()); iData = (int)( ((bData[iPlace++]) << 8) + ((bData[iPlace++]) ) ); sOutput = "WORD BLOCK 3 : " + iData + "\r"; fw.write(sOutput, 0, sOutput.length()); iData = (int)( ((bData[iPlace++]) << 8) + ((bData[iPlace++]) ) ); sOutput = "WORD BLOCK 4 : " + iData + "\r"; fw.write(sOutput, 0, sOutput.length()); iData = (int)( ((bData[iPlace++]) << 8) + ((bData[iPlace++]) ) ); sOutput = "WORD BLOCK 5 : " + iData + "\r"; fw.write(sOutput, 0, sOutput.length()); sOutput = "BYTE 6a: " + bData[iPlace++] + "\r"; fw.write(sOutput, 0, sOutput.length()); sOutput = "BYTE 6b: " + bData[iPlace++] + "\r"; fw.write(sOutput, 0, sOutput.length()); iData = (int)( ((bData[iPlace++]) << 8) + ((bData[iPlace++]) ) ); sOutput = "WORD BLOCK 7+: " + iData + "\r"; fw.write(sOutput, 0, sOutput.length()); sOutput = "Ch BLOCK : " + (char)(bData[iPlace++]) + (char)(bData[iPlace++]) + "\r"; fw.write(sOutput, 0, sOutput.length()); for(int i = 0; i < 6; i++) { iData = (int)( ((bData[iPlace++]) << 8) + ((bData[iPlace++]) ) ); sOutput = "SUB WORD " + (i + 1) + ": " + iData + "\r"; fw.write(sOutput, 0, sOutput.length()); } iData = (int)( ((bData[iPlace++]) << 8) + ((bData[iPlace++]) ) ); sOutput = "SUB WORD 7 : " + iData + "\r"; fw.write(sOutput, 0, sOutput.length()); } private static void parseDSCR(FileWriter fw) throws IOException { String sOutput = "--------------------\rDSCR CHUNK\r--------------------\r"; fw.write(sOutput, 0, sOutput.length()); sOutput = "DSCR BLOCK : DSCR\r"; fw.write(sOutput, 0, sOutput.length()); for(int i = 0; i < 7; i++) { int iData = (int)( ((bData[iPlace++]) << 8) + ((bData[iPlace++]) ) ); sOutput = "DSCR WORD " + i + ": " + iData + "\r"; fw.write(sOutput, 0, sOutput.length()); } } private static void parseSTAF(FileWriter fw) throws IOException { String sOutput = "--------------------\rSTAFF TABLE CHUNK\r--------------------\r"; fw.write(sOutput, 0, sOutput.length()); sOutput = "STAF BLOCK : STAF\r"; fw.write(sOutput, 0, sOutput.length()); int iStaffLeadByte = (int)( (bData[iPlace++] << 8) + (bData[iPlace++] ) ); sOutput = "STAF Lead Byte : " + iStaffLeadByte + "\r"; fw.write(sOutput, 0, sOutput.length()); int iStaffByteCount = (int)( (bData[iPlace++] << 8) + (bData[iPlace++] ) ); sOutput = "STAF Byte Count : " + iStaffByteCount + "\r"; fw.write(sOutput, 0, sOutput.length()); for(int i = 0; i < iStaffByteCount; i++) { sOutput = "STAF Byte " + (i+1) + " : " + bData[iPlace++] + "\r"; fw.write(sOutput, 0, sOutput.length()); } } private static void parseDSTF(FileWriter fw) throws IOException { String sOutput = "--------------------\rDSTF CHUNK\r--------------------\r"; fw.write(sOutput, 0, sOutput.length()); sOutput = "DSTF BLOCK : DSTF\r"; fw.write(sOutput, 0, sOutput.length()); int iDstaffLeadByte = (int)( (bData[iPlace++] << 8) + (bData[iPlace++] ) ); sOutput = "DSTF Lead Byte : " + iDstaffLeadByte + "\r"; fw.write(sOutput, 0, sOutput.length()); int iDstaffByteCount = (int)( (bData[iPlace++] << 8) + (bData[iPlace++] ) ); sOutput = "DSTF Byte Count : " + iDstaffByteCount + "\r"; fw.write(sOutput, 0, sOutput.length()); for(int i = 0; i < iDstaffByteCount; i++) { sOutput = "DSTF Byte " + (i+1) + " : " + bData[iPlace++] + "\r"; fw.write(sOutput, 0, sOutput.length()); } } private static void parseLFON(FileWriter fw) throws IOException { String sOutput = "--------------------\rLYRIC FONT CHUNK\r--------------------\r"; fw.write(sOutput, 0, sOutput.length()); sOutput = "LFON BLOCK : LFON\r"; fw.write(sOutput, 0, sOutput.length()); int iFontNumber = (int)( ((bData[iPlace++]) << 24) + ((bData[iPlace++]) << 16) + ((bData[iPlace++]) << 8) + ((bData[iPlace++]) ) ); sOutput = "FONT NUMBER : " + iFontNumber + "\r"; fw.write(sOutput, 0, sOutput.length()); int iFontHeight = (int)( ((bData[iPlace++]) << 24) + ((bData[iPlace++]) << 16) + ((bData[iPlace++]) << 8) + ((bData[iPlace++]) ) ); sOutput = "FONT HEIGHT : " + iFontHeight + "\r"; fw.write(sOutput, 0, sOutput.length()); sOutput = "Font Name : "; while(bData[iPlace++] != NUL) { sOutput = sOutput + (char)(bData[iPlace-1]); } sOutput = sOutput + "\r"; fw.write(sOutput, 0, sOutput.length()); sOutput = "[TERMNUL] : " + bData[iPlace++] + "\r"; fw.write(sOutput, 0, sOutput.length()); } private static void parseTRCK(FileWriter fw) throws IOException { String sOutput = "--------------------\rTRACK CHUNK\r--------------------\r"; fw.write(sOutput, 0, sOutput.length()); sOutput = "TRCK BLOCK : TRCK\r"; fw.write(sOutput, 0, sOutput.length()); int iTrackLeadByte = (int)( (bData[iPlace++] << 8) + (bData[iPlace++] ) ); sOutput = "TRCK Lead Byte : " + iTrackLeadByte + "\r"; fw.write(sOutput, 0, sOutput.length()); int iTrackByteCount = (int)( (bData[iPlace++] << 8) + (bData[iPlace++] ) ); sOutput = "TRCK Byte Count : " + iTrackByteCount + "\r"; fw.write(sOutput, 0, sOutput.length()); int iTrackStaff = (int)( (bData[iPlace++] << 8) + (bData[iPlace++] ) ); sOutput = "TRCK Staff : " + iTrackStaff + "\r"; fw.write(sOutput, 0, sOutput.length()); int iTrackTrack = (int)( (bData[iPlace++] << 8) + (bData[iPlace++] ) ); sOutput = "TRCK Track : " + iTrackTrack + "\r"; fw.write(sOutput, 0, sOutput.length()); int iTrackFlags = (int)( (bData[iPlace++] << 8) + (bData[iPlace++] ) ); sOutput = "TRCK Flags : " + iTrackFlags + "\r"; fw.write(sOutput, 0, sOutput.length()); int iTrackTransposition = (int)( (bData[iPlace++] << 8) + (bData[iPlace++] ) ); sOutput = "TRCK Trans : " + iTrackTransposition + "\r"; fw.write(sOutput, 0, sOutput.length()); for(int i = 0; i < iTrackByteCount - 8;) { int iItemLength = (int)(bData[iPlace++]); sOutput = "ITEM LEN : " + iItemLength + "\r"; fw.write(sOutput, 0, sOutput.length()); i++; sOutput = "ITEM TYPE : " + bData[iPlace++] + "\r"; fw.write(sOutput, 0, sOutput.length()); i++; int iItemXPos = (int)( (bData[iPlace++] << 8) + (bData[iPlace++] ) ); sOutput = "ITEM XPOS : " + iItemXPos + "\r"; fw.write(sOutput, 0, sOutput.length()); i++;i++; int iItemStart = (int)( (bData[iPlace++] << 8) + (bData[iPlace++] ) ); sOutput = "ITEM START: " + iItemStart + "\r"; fw.write(sOutput, 0, sOutput.length()); i++;i++; for(int j = 0; j < iItemLength - 3; j++) { int iItemData = (int)( (bData[iPlace++] << 8) + (bData[iPlace++] ) ); sOutput = "ITEM WORD " + j + " : " + iItemData + "\r"; fw.write(sOutput, 0, sOutput.length()); i++;i++; } } } private static void parseINHD(FileWriter fw) throws IOException { String sOutput = "--------------------\rINSTRUMENT HEADER CHUNK\r--------------------\r"; fw.write(sOutput, 0, sOutput.length()); sOutput = "INHD BLOCK : INHD\r"; fw.write(sOutput, 0, sOutput.length()); int iPadding = (int)( (bData[iPlace++] << 8) + (bData[iPlace++] ) ); sOutput = "(HEADPAD) : " + iPadding + "\r"; fw.write(sOutput, 0, sOutput.length()); byte instrumentNumber = bData[iPlace++]; sOutput = "INST # : " + instrumentNumber + "\r"; fw.write(sOutput, 0, sOutput.length()); byte instrumentFlags = bData[iPlace++]; sOutput = "INST FLAGS : " + instrumentFlags + "\r"; fw.write(sOutput, 0, sOutput.length()); int instrumentTune = (int)( (bData[iPlace++] << 8) + (bData[iPlace++] ) ); sOutput = "INST TUNE : " + instrumentTune + "\r"; fw.write(sOutput, 0, sOutput.length()); int instrumentVolume = (int)( (bData[iPlace++] << 8) + (bData[iPlace++] ) ); sOutput = "INST VOL : " + instrumentVolume + "\r"; fw.write(sOutput, 0, sOutput.length()); byte instrumentPan = bData[iPlace++]; sOutput = "INST PAN : " + instrumentNumber + "\r"; fw.write(sOutput, 0, sOutput.length()); byte instrumentMIDIChannel = bData[iPlace++]; sOutput = "MIDI CHAN : " + instrumentNumber + "\r"; fw.write(sOutput, 0, sOutput.length()); byte instrumentMIDIPreset = bData[iPlace++]; sOutput = "MIDI PRESET : " + instrumentNumber + "\r"; fw.write(sOutput, 0, sOutput.length()); byte instrumentMIDIPort = bData[iPlace++]; sOutput = "MIDI PORT : " + instrumentNumber + "\r"; fw.write(sOutput, 0, sOutput.length()); iPadding = (int)( (bData[iPlace++] << 8) + (bData[iPlace++] ) ); sOutput = "(TAILPAD) : " + iPadding + "\r"; fw.write(sOutput, 0, sOutput.length()); } private static void parseNAME(FileWriter fw) throws IOException { String sOutput = "--------------------\rINSTRUMENT NAME CHUNK\r--------------------\r"; fw.write(sOutput, 0, sOutput.length()); sOutput = "NAME BLOCK : NAME\r"; fw.write(sOutput, 0, sOutput.length()); int iNameHeadInt = (int)( (bData[iPlace++] << 8) + (bData[iPlace++] ) ); sOutput = "NAME HEAD : " + iNameHeadInt + "\r"; fw.write(sOutput, 0, sOutput.length()); int iNameByteCount = (int)( (bData[iPlace++] << 8) + (bData[iPlace++] ) ); sOutput = "NAME BYTES : " + iNameByteCount + "\r"; fw.write(sOutput, 0, sOutput.length()); sOutput = "Instrument Name : "; for(int i = 1; i < iNameByteCount; i++) { sOutput = sOutput + (char)(bData[iPlace++]); } sOutput = sOutput + "\r"; fw.write(sOutput, 0, sOutput.length()); sOutput = "(PADNUL1) : " + bData[iPlace++] + "\r"; fw.write(sOutput, 0, sOutput.length()); if((int)(iNameByteCount / 2.0) < (iNameByteCount / 2.0)) { sOutput = "(PADNUL2) : " + bData[iPlace++] + "\r"; fw.write(sOutput, 0, sOutput.length()); } } private static void parseSFIL(FileWriter fw) throws IOException { String sOutput = "--------------------\rINSTRUMENT SAMPLE FILE CHUNK\r--------------------\r"; fw.write(sOutput, 0, sOutput.length()); sOutput = "SFIL BLOCK : SFIL\r"; fw.write(sOutput, 0, sOutput.length()); int iSampleFileBytes = (int)( ((bData[iPlace++]) << 24) + ((bData[iPlace++]) << 16) + ((bData[iPlace++]) << 8) + ((bData[iPlace++]) ) ); sOutput = "SFIL BYTES : " + iSampleFileBytes + "\r"; fw.write(sOutput, 0, sOutput.length()); sOutput = "Sample File Name : "; for(int i = 1; i < iSampleFileBytes; i++) { sOutput = sOutput + (char)(bData[iPlace++]); } sOutput = sOutput + "\r"; fw.write(sOutput, 0, sOutput.length()); sOutput = "(PADNUL) : " + bData[iPlace++] + "\r"; fw.write(sOutput, 0, sOutput.length()); } // File Write Method -------------------------------------------------------------------> protected static void writeToDMCSFile(String fileData, String outFile) throws IOException { /* FileOutputStream fos = new FileOutputStream(new File(outFile)); byte FileSizeByte1 = (byte)(fileData.length() & 0xFF); byte FileSizeByte2 = (byte)((fileData.length() >> 8) & 0xFF); byte FileSizeByte3 = (byte)((fileData.length() >> 16) & 0xFF); byte FileSizeByte4 = (byte)((fileData.length() >> 24) & 0xFF); byte[] DMCSFileHeader = new byte[] { FileHeaderFormWord[0], FileHeaderFormWord[1], FileHeaderFormWord[2], FileHeaderFormWord[3], FileSizeByte1, FileSizeByte2, FileSizeByte3, FileSizeByte4, FileHeaderTypeWord[0], FileHeaderTypeWord[1], FileHeaderTypeWord[2], FileHeaderTypeWord[3], FileHeaderOSAMWord[0], FileHeaderOSAMWord[1], FileHeaderOSAMWord[2], FileHeaderOSAMWord[3], FileHeaderTailWord[0], FileHeaderTailWord[1], FileHeaderTailWord[2], FileHeaderTailWord[3] }; fos.write(DMCSFileHeader); byte BitmapWidthByte1 = (byte)(IntBitmapWidth & 0xFF); byte BitmapWidthByte2 = (byte)((IntBitmapWidth >> 8) & 0xFF); byte BitmapWidthByte3 = (byte)((IntBitmapWidth >> 16) & 0xFF); byte BitmapWidthByte4 = (byte)((IntBitmapWidth >> 24) & 0xFF); byte BitmapHeightByte1 = (byte)(IntBitmapHeight & 0xFF); byte BitmapHeightByte2 = (byte)((IntBitmapHeight >> 8) & 0xFF); byte BitmapHeightByte3 = (byte)((IntBitmapHeight >> 16) & 0xFF); byte BitmapHeightByte4 = (byte)((IntBitmapHeight >> 24) & 0xFF); byte BitmapImageSizeByte1 = (byte)(IntBitmapSize & 0xFF); byte BitmapImageSizeByte2 = (byte)((IntBitmapSize >> 8) & 0xFF); byte BitmapImageSizeByte3 = (byte)((IntBitmapSize >> 16) & 0xFF); byte BitmapImageSizeByte4 = (byte)((IntBitmapSize >> 24) & 0xFF); byte[] BitmapBodyHeader = new byte[] { InfoHeaderSizeByte1, InfoHeaderSizeByte2, InfoHeaderSizeByte3, InfoHeaderSizeByte4, BitmapWidthByte1, BitmapWidthByte2, BitmapWidthByte3, BitmapWidthByte4, BitmapHeightByte1, BitmapHeightByte2, BitmapHeightByte3, BitmapHeightByte4, BitmapPlanesByte1, BitmapPlanesByte2, BitmapBitCountByte1, BitmapBitCountByte2, BitmapCompressionByte1, BitmapCompressionByte2, BitmapCompressionByte3, BitmapCompressionByte4, BitmapImageSizeByte1, BitmapImageSizeByte2, BitmapImageSizeByte3, BitmapImageSizeByte4, BitmapXPixelsPerMByte1, BitmapXPixelsPerMByte2, BitmapXPixelsPerMByte3, BitmapXPixelsPerMByte4, BitmapYPixelsPerMByte1, BitmapYPixelsPerMByte2, BitmapYPixelsPerMByte3, BitmapYPixelsPerMByte4, BitmapColorsUsedByte1, BitmapColorsUsedByte2, BitmapColorsUsedByte3, BitmapColorsUsedByte4, BitmapColorsImportantByte1, BitmapColorsImportantByte2, BitmapColorsImportantByte3, BitmapColorsImportantByte4 }; fos.write(BitmapBodyHeader); int bodySize = IntBitmapWidth * IntBitmapHeight; int bitPad = 4 - ((IntBitmapWidth * 3) % 4); if(bitPad == 4) { bitPad = 0; } int countRow = 1; int indexRow = bodySize - IntBitmapWidth; int indexLastRow = indexRow; byte[] rgbArray = new byte[3]; for(int i = 0; i < bodySize; i++) { int colorValue = PixelMap[indexRow]; rgbArray[0] = (byte)(colorValue & 0xFF); // red rgbArray[1] = (byte)((colorValue >> 8) & 0xFF); // green rgbArray[2] = (byte)((colorValue >> 16) & 0xFF); // blue fos.write(rgbArray); if(countRow == IntBitmapWidth) { // pad row to 4 bits requirement for(int p = 0; p < bitPad; p++) { fos.write(0x00); } countRow = 1; indexRow = indexLastRow - IntBitmapWidth; indexLastRow = indexRow; } else { countRow++; } indexRow++; } fos.flush(); fos.close(); */ } public static void main(String[] args) { if(args.length < 3) { System.out.println("USAGE : CMUScodec -action input output"); } else { if(args[0].equals("-t")) { try { decode(args[1], args[2]); } catch(Exception e) { System.out.println(e); } } else { System.out.println("action " + args[0] + "not yet supported"); } } } }