Skip to content

Commit

Permalink
UltraKiss 3.5.2 update 2
Browse files Browse the repository at this point in the history
  • Loading branch information
William authored and William committed Jun 22, 2023
1 parent a1bb74f commit a7f87fc
Show file tree
Hide file tree
Showing 23 changed files with 498 additions and 200 deletions.
21 changes: 16 additions & 5 deletions src/Kisekae/ArchiveFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -581,10 +581,11 @@ static boolean hasPalette(String name)

// Returns the archive file entry for the specified name, or null.
// The archive file entry represents one element in the archive file
// or the file directory.
// or the file directory. We can search on the filename only in case
// the archive file had directory entries and the pathname search fails.


ArchiveEntry getEntry(String pathname)
ArchiveEntry getEntry(String pathname) { return getEntry(pathname,false) ; }
ArchiveEntry getEntry(String pathname ,boolean nameonly)
{
if (pathname == null) return null ;
if (contents == null) return null ;
Expand All @@ -611,14 +612,24 @@ ArchiveEntry getEntry(String pathname)
s = s.replace('\\',File.separatorChar) ;

// Find the file in the archive contents. If the entry exists in our
// hash table, return it. Otherwise search the contents vector.
// hash table, return it. Otherwise search the contents vector.
// Our archive entry can have path information. An expansion set may not.
// We allow for a search on filename only.

Object o = key.get(s.toLowerCase()) ;
if (o instanceof ArchiveEntry) return (ArchiveEntry) o ;
for (int i = 0 ; i < contents.size() ; i++)
{
ArchiveEntry h = (ArchiveEntry) contents.elementAt(i) ;
if (s.equalsIgnoreCase(h.getPath())) return (h) ;
String path = h.getPath() ;
if (nameonly)
{
int n = path.lastIndexOf(File.separatorChar) ;
if (n >= 0) path = path.substring(n+1) ;
n = s.lastIndexOf(File.separatorChar) ;
if (n >= 0) s = s.substring(n+1) ;
}
if (s.equalsIgnoreCase(path)) return (h) ;
}

// If we were searching in an archive file, return a no find result.
Expand Down
4 changes: 2 additions & 2 deletions src/Kisekae/Audio.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ abstract class Audio extends KissObject
protected boolean restart = false ; // True if restart play after stop
protected boolean hascallback = false ; // True if callback listener set
protected boolean format = false ; // True if unknown media format
protected boolean converted = false ; // True if converted to JMF

// Our end of media callback button that other components can attach
// listeners to.
Expand Down Expand Up @@ -564,10 +565,9 @@ void showError(String s)
{
errormessage = s ;
MainFrame frame = Kisekae.getMainFrame() ;
if (line > 0) s = "Line [" + line + "] " + s ;
if (line > 0) s = "[Line " + line + "] " + s ;
if (loader != null) loader.showError(s) ;
else frame.showStatus(errormessage) ;
System.out.println(s) ;
}


Expand Down
3 changes: 1 addition & 2 deletions src/Kisekae/BmpCel.java
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ void load(Vector includefiles)
String s = e.getMessage() ;
if (s == null) s = e.toString() ;
showError("I/O Exception, Cel " + file + ", " + s) ;
System.out.println(e.toString()) ;
}

// Watch for general Kiss exceptions.
Expand Down Expand Up @@ -1132,7 +1131,7 @@ void showError(String s)
{
errormessage = s ;
int line = getLine() ;
if (line > 0) s = "Line [" + line + "] " + s ;
if (line > 0) s = "[Line " + line + "] " + s ;
if (loader != null) loader.showError(s) ;
else System.out.println(s) ;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Kisekae/Cel.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ abstract class Cel extends KissObject
protected int multipalette = 0 ; // The cel multipalette in use
protected int transparency = 0 ; // The cel transparency
protected int inittransparency = 0 ; // The cel initial transparency
protected int transparentindex = -1 ; // The cel transparent index
protected int transparentindex = -1 ; // The cel transparent index
protected int background = -1 ; // The cel background index
protected int maxloop = 0 ; // The cel maximum loop count
protected int loop = 0 ; // The cel animation loop count
Expand Down Expand Up @@ -471,6 +471,7 @@ void setPalette(Palette p)
{
palette = p ;
truecolor = (palette == null) ;
if (p != null) setTransparentIndex(p.getTransparentIndex()) ;
}

// Set the cel palette identifier value.
Expand Down Expand Up @@ -2146,7 +2147,8 @@ else if (rgb != transparentRgb) {
palette = new Palette(zip,file) ;
int [] back = new int[1] ;
int [] trans = new int[1] ;
back[0] = backgroundIndex ;
// back[0] = backgroundIndex ;
back[0] = transparentIndex ;
trans[0] = transparentIndex ;
palette.setPalette(a,r,g,b,1,colors,back,trans) ;
palette.setIdentifier(new Integer(-1));
Expand Down
7 changes: 6 additions & 1 deletion src/Kisekae/ColorSizePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ public void actionPerformed(ActionEvent evt)
if (source == OK)
{
int m = getColorSize() ;
if (parent != null) parent.changeColorCount(m,getQuick()) ;
if (parent == null) return ;

parent.changeColorCount(m,getQuick()) ;
parent.setChanged(true) ;
parent.updateTransformedImage() ;
parent.applyTransformedImage() ;
return ;
}

Expand Down
28 changes: 15 additions & 13 deletions src/Kisekae/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -2745,28 +2745,30 @@ void close(boolean restart, boolean resetoptions)
audioCount = 0 ;
videoCount = 0 ;

// Reset initial options.
// Reset initial options. If we are not resetting options then the
// configuration may be reused. We retain the zip file reference on
// reuse so that cels and other objects can be reloaded.

if (resetoptions)
{
MainFrame mf = Kisekae.getMainFrame() ;
OptionsDialog options = (mf != null) ? mf.getOptionsDialog() : null ;
if (options != null) options.resetOptions() ;
if (mf != null) mf.updateMenuOptions() ;
}

// Close the parent archive file.
// Close the parent archive file.

if (zip != null)
{
try {
zip.close() ;
zip.flush() ;
}
catch (IOException e) { }
}
zip = null ;
ze = null ;
if (zip != null)
{
try {
zip.close() ;
zip.flush() ;
}
catch (IOException e) { }
}
zip = null ;
ze = null ;
}

// Invoke the garbage collector.

Expand Down
2 changes: 1 addition & 1 deletion src/Kisekae/FKissAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ else if (child != null)
Enumeration enum1 = a.getEvents() ;
while (enum1 != null && enum1.hasMoreElements())
a1.addEvent((Vector) enum1.nextElement()) ;
a.close() ;
// a.close() ; // problematic if expansion set load for JMF
Vector sounds = (config != null) ? config.getSounds() : null ;
int n = (sounds != null) ? sounds.indexOf(a) : -1 ;
if (n >= 0) sounds.setElementAt(a1,n) ;
Expand Down
9 changes: 6 additions & 3 deletions src/Kisekae/FileLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ final class FileLoader extends KissFrame

private boolean active = true ; // True if frame has focus
private boolean reload = false ; // True if reload configuration
private boolean expansion = false ; // True if loading expansion set
private boolean interrupted = false ; // True if load is interrupted
private boolean fatal = false ; // True if fatal error
private int errors = 0 ; // Count of showError calls
Expand Down Expand Up @@ -149,6 +150,7 @@ public FileLoader(MainFrame frame, Configuration c, ArchiveFile zip, ArchiveEntr
{
this(frame,zip,ze) ;
config = c ;
expansion = true ;
if (OptionsDialog.getDebugControl() && config != null)
System.out.println("Expanding configuration " + config) ;
}
Expand Down Expand Up @@ -320,7 +322,8 @@ public void run()
if (stop) return ;
MainFrame mf = Kisekae.getMainFrame() ;
OptionsDialog options = mf.getOptionsDialog() ;
if (!reload && options != null) options.resetOptions() ;
if (!reload && !expansion && options != null)
options.resetOptions() ;
config.setLoader(this) ;
showStatus(Kisekae.getCaptions().getString("ReadConfigStatus")) ;
config.read() ;
Expand Down Expand Up @@ -862,8 +865,8 @@ void showText(String s)
void showError(String s, String highlite)
{
errors = errors + 1 ;
if (errors == 26) showText("More than 25 errors, errors are suppressed.") ;
if (errors >= 26) return ;
if (errors == 101) showText("More than 100 errors, errors are suppressed.") ;
if (errors >= 101) return ;
StyledDocument doc = TextWindow.getStyledDocument() ;
Position pos = doc.getEndPosition() ;
if (errorpos < 0) errorpos = pos.getOffset() - 1 ;
Expand Down
78 changes: 69 additions & 9 deletions src/Kisekae/GifCel.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,28 @@ int write(FileWriter fw, OutputStream out, String type) throws IOException
Point offset = encoder.getOffset() ;
for (int i = 0 ; i < frames.size() ; i++)
{
GifFrame cf = (GifFrame) frames.elementAt(i) ;
encoder = new GifEncoder(fw,cf,out) ;
if (i == 0) encoder.setOffset(offset) ;
encoder.encode() ;
bytes += encoder.getBytesWritten() ;
try
{
GifFrame cf = (GifFrame) frames.elementAt(i) ;
Image img = cf.getImage() ;
encoder = new GifEncoder(fw,img,out,cf) ;
if (i == 0) encoder.setOffset(offset) ;
encoder.encode() ;
bytes += encoder.getBytesWritten() ;
}
catch (IOException e)
{
if ("Too many colors for a GIF image".equals(e.getMessage()))
{
Object [] reduced = this.dither(256) ;
Image img = (Image) reduced[0] ;
encoder = new GifEncoder(fw,img,null,0,null,
transparentcolor,backgroundcolor,transparency,out) ;
encoder.encode() ;
bytes += encoder.getBytesWritten() ;
}
else throw e ;
}
}
}

Expand Down Expand Up @@ -314,6 +331,28 @@ void setImage(Image img)
cf.setImage(img);
}

// Set the palette. Establishes the global palette arrays.

void setPalette(Palette p)
{
super.setPalette(p) ;
if (p == null) return ;
Object [] palettedata = p.getPaletteData() ;
globalpalette[0] = palettedata[1] ; // red
globalpalette[1] = palettedata[2] ; // green
globalpalette[2] = palettedata[3] ; // blue
if (frames == null) return ;

// Propagate to all frames using the global palette.

for (int i = 0 ; i < frames.size() ; i++)
{
GifFrame cf = (GifFrame) frames.elementAt(i) ;
if (!cf.isLocalColorTable())
cf.setLocalPalette(false) ;
}
}

// Set the cel loop count.

void setLoopLimit(int n)
Expand Down Expand Up @@ -358,7 +397,8 @@ void setTransparentIndex(int n)
for (int i = 0 ; i < frames.size() ; i++)
{
cf = (GifFrame) frames.elementAt(i) ;
cf.setTransparentIndex(n) ;
if (!cf.isLocalColorTable())
cf.setTransparentIndex(n) ;
}
}
}
Expand Down Expand Up @@ -768,7 +808,7 @@ void load(Vector includefiles)
error = true ;
String s = e.getMessage() ;
if (s == null) s = e.toString() ;
showError("I/O Exception: " + s + "\n" + file) ;
showError("I/O Exception: " + s + "," + file) ;
e.printStackTrace() ;
}
if (error) image = null ;
Expand Down Expand Up @@ -1157,8 +1197,28 @@ void showError(String s)
{
errormessage = s ;
int line = getLine() ;
if (line > 0) s = "Line [" + line + "] " + s ;
if (line > 0) s = "[Line " + line + "] " + s ;
if (loader != null) loader.showError(s) ;
else System.out.println(s) ;
}
}


// GifCel clone. We need to clone the frames as the cel clone
// is a shallow clone. Each frame can be modified in the cloned
// copy and we don't want to modify the original frame.

public Object clone()
{
Cel c = (Cel) super.clone() ;
if (frames == null) return c ;
Vector clonedframes = new Vector() ;
for (int i= 0; i< frames.size(); i++)
{
GifFrame cf = (GifFrame) frames.elementAt(i) ;
clonedframes.addElement(cf.clone()) ;
}
frames = clonedframes ;
return c ;
}

}
18 changes: 12 additions & 6 deletions src/Kisekae/GifEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ public GifEncoder(FileWriter fw, Image img, OutputStream out, boolean interlace)

// Constructor for an animated GIF frame.

public GifEncoder(FileWriter fw, GifFrame frame, OutputStream out) throws IOException
public GifEncoder(FileWriter fw, Image img, OutputStream out, GifFrame frame) throws IOException
{
super(fw, frame.getImage(), out) ;
super(fw, img, out) ;
this.frame = frame ;
frameindex = frame.getFrame() ;
this.frameindex = frame.getFrame() ;
}


Expand Down Expand Up @@ -279,7 +279,7 @@ else if (rgb != transparentRgb)
EncoderHashitem item = (EncoderHashitem) colorHash.get(rgb);
if (item == null)
{
if (index >= 256)
if (index > 256)
throw new KissException("Too many colors for a GIF image") ;

// If we have a frame with a palette this pixel should exist.
Expand All @@ -290,10 +290,16 @@ else if (rgb != transparentRgb)
int r = (rgb & 0xff0000) >> 16 ;
int g = (rgb & 0xff00) >> 8 ;
int b = (rgb & 0xff) ;
if (!Kisekae.isBatch()) throw new KissException(
int r1 = (red[transparentIndex] & 0xff) ;
int g1 = (green[transparentIndex] & 0xff) ;
int b1 = (blue[transparentIndex] & 0xff) ;
if ((r != r1) || (g != g1) || (b != b1))
{
if (!Kisekae.isBatch()) throw new KissException(
"frame " + frameindex + " at [" + row + "," + col +
"] image color (" + r + "," + g + "," + b +
") not in palette") ;
") not in palette") ;
}
}

// If we do not have a frame then remember this color.
Expand Down
Loading

0 comments on commit a7f87fc

Please sign in to comment.