Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - AGP

Pages: 1 ... 96 97 [98] 99 100 ... 116
1456
Support / Re: Very Very Simple C Question
« on: June 22, 2009, 03:30:11 am »
I thought this represented the index in the char array, or why would *cursor->canvas++ be possible? It must then be the char, and the compiler treats *cursor->canvas++ as a shortcut to increasing the index. What I needed ws to tell it not to go outside the bounds of the string, so I changed the code to keep track via a separate int.

EDIT: But the source of the crash had actually been strlen itself, since the string for a reason I hadn't seen was NULL.

1457
Support / Re: Very Very Simple C Question
« on: June 22, 2009, 12:52:55 am »
OK, here's another question: why doesn't
Code: [Select]
if(*cursor->canvas < strlen(cursor->canvas))work? It seems to crash my program (no message, I just have to CTRL-C out of it).

1458
Support / Re: Very Very Simple C Question
« on: June 21, 2009, 04:25:14 am »
Including stdio.h did it. So thanks again.

1459
Support / Re: Very Very Simple C Question
« on: June 21, 2009, 04:21:13 am »
Oh, and while (cursor->next != NULL) is giving me a "NULL undeclared; first use in this function" message (same for lower-case). So what's the C equivalent? I think I do remember testing for 0 or something but a quick Google seems to have suggested I could use NULL. But gcc won't take it, so what's the equivalent?

1460
Support / Re: Very Very Simple C Question
« on: June 21, 2009, 04:07:55 am »
Man, C can be so weird! It now compiles, except for the fact that it tells me that I'm returning the address of a local variable (so I just put it outside the function but I wanted to mention it anyway). Thanks again, pal.

1461
Support / Re: Very Very Simple C Question
« on: June 21, 2009, 02:33:37 am »
Same here, pal! Java and C# rot our brains. : -) But no, unfortunately I have to use what I have. It's an assignment, and not even mine at that, but I'm trying to re-learn this so I can pass it on to my friend.

1462
Support / Re: Very Very Simple C Question
« on: June 21, 2009, 01:28:51 am »
a.title = title can't be right. It looks weird even to me and besides gcc has a problem with it. : -)

1463
Support / Re: Very Very Simple C Question
« on: June 21, 2009, 12:28:42 am »
Another quick pointer question. Given:
Code: [Select]
struct animation {//LIST
      char title[80];
      int lines;
      int columns;
      Frame* start; // (HEAD)
      Frame* end; // (TAIL)
};
struct frame {//NODE
      char* canvas;
      Frame* next;
};
typedef struct animation Animation;
typedef struct frame Frame;
How do I implement the following method, specifically assigning the title (allocated with []) to to its char* pointer?
Code: [Select]
Animation* createAnimation(char* title, int lin, int col) {
Animation a;
a.title = title;
a.lines = lin;
a.columns = col;
return &a;//THIS IS RIGHT, RIGHT?
}

1464
Support / Re: Very Very Simple C Question
« on: June 20, 2009, 11:52:46 pm »
Got it, thanks a lot. But I would still, then have to put in
Code: [Select]
struct animation {
    variables
};

in my .c file from what I understand.

1465
Support / Very Very Simple C Question
« on: June 20, 2009, 07:27:27 pm »
I figure at the very least paulscode and Egon will know: what does the line "typedef struct animation Animation" do in a header file? I see no other defining reference to animation (lower or upper case) anywhere in this little assignment. I haven't done C programming in so long, I forgot more than I knew I had known. And to clarify, the assignment uses Animation* pointers a lot, I meant that this line is the only part that defines it.

1466
Support / Re: Using FrameBuffer's Graphics With AWTGLCanvas
« on: June 19, 2009, 09:04:02 pm »
Thanks. And well, I would add generally-useful trigonometric functions. The difference between SimpleVector and Math would be that Math doesn't assume specific use. You can create a SimpleVector instance just to get the result of a function and apply as you will to your object, but that's counter-intuitive. With Math, you can have your objects oriented however you want to, for instance, and all you're really doing is calculating the product of your input (as opposed to necessarily applying a certain way).

1467
Support / Re: Using FrameBuffer's Graphics With AWTGLCanvas
« on: June 19, 2009, 05:21:16 pm »
Egon, if you're thinking of making a separate download with utilities such as a gif loader, why not include my previously-requested Math class?

1468
Support / Re: Using FrameBuffer's Graphics With AWTGLCanvas
« on: June 19, 2009, 12:30:15 am »
And here's the cleverer approach by Alexander Hristov under the lesser general public license (which probably means you can use on jPCT but I haven't read it). The first is the tester I wrote (ArrayIndexOutOfBoundsException will be thrown if your gif doesn't have at least 4 frames), and the second is his FrameReader.

Code: [Select]
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.*;

public class FrameReaderTester extends Frame implements WindowListener {
      private BufferedImage[] frames;
      private int currentFrame = 0;
      public FrameReaderTester(String fileName) {
this.setTitle("AGP's");
try {
      frames = FrameReader.getAllFrames(new FileInputStream(fileName));
}
catch (IOException e) {System.err.println("Shit happened: "+e.getMessage());}
this.addWindowListener(this);
this.setSize(800, 600);
this.setVisible(true);
      }

      public void paint(Graphics g) {
g.drawImage(frames[0], 10, 30, null);
g.drawImage(frames[1], 20+frames[0].getWidth(), 30, null);
g.drawImage(frames[2], 10, 40+frames[0].getHeight(), null);
g.drawImage(frames[3], 20+frames[0].getWidth(), 40+frames[1].getHeight(), null);
      }

      public void windowClosing(WindowEvent e) {
if (e.getWindow().equals(this)) {
      this.dispose();
      System.exit(0);
}
      }
      public void windowClosed(WindowEvent e) {}
      public void windowOpened(WindowEvent e) {}
      public void windowActivated(WindowEvent e) {}
      public void windowDeactivated(WindowEvent e) {}
      public void windowIconified(WindowEvent e) {}
      public void windowDeiconified(WindowEvent e) {}
      public static void main(String[] args) {
if (args == null || args.length == 0)
      return;
new FrameReaderTester(args[0]);
      }
}

Code: [Select]
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;

import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
import javax.imageio.spi.IIORegistry;
import javax.imageio.spi.ImageInputStreamSpi;
import javax.imageio.spi.ImageReaderSpi;
import javax.imageio.spi.ServiceRegistry;
import javax.imageio.stream.ImageInputStream;

class FrameReader {
  public static BufferedImage[] getAllFrames(InputStream in) throws IOException {
    IIORegistry providers = IIORegistry.getDefaultInstance();
    Iterator it = providers.getServiceProviders(ImageInputStreamSpi.class,true);
    ImageInputStream imgStream = null;
   
    // Create an ImageInputStream with the first appropriate SPI
    while (it.hasNext()) {
      ImageInputStreamSpi spi = (ImageInputStreamSpi)it.next();
      if (spi.getInputClass().isInstance(in)) {
        imgStream = spi.createInputStreamInstance(in);
        break;
      }
    }
    if (imgStream == null)
      throw new IOException("No appropriate SPI for this input stream ");
   
    it = providers.getServiceProviders(
        ImageReaderSpi.class, new CanDecodeFilter(imgStream),true);
    if (!it.hasNext())
      throw new IOException("No class can read this image format");
   
    ImageReaderSpi readerSpi = (ImageReaderSpi)it.next();
    ImageReader reader = readerSpi.createReaderInstance();
    ImageReadParam param = reader.getDefaultReadParam();
   
    reader.setInput(imgStream, false, true);
    int numFrames = reader.getNumImages(true);
    BufferedImage[] frames = new BufferedImage[numFrames];
    for (int i = 0; i < numFrames; i++) {
      frames[i] = reader.read(i,param);
    }
   
    imgStream.close();
    reader.dispose();
    return frames;
  }
 
  static class CanDecodeFilter implements ServiceRegistry.Filter {
    ImageInputStream stream;
    public CanDecodeFilter(ImageInputStream stream) {
      this.stream = stream;
    }
    public boolean filter(Object element) {
      try {
          ImageReaderSpi spi = (ImageReaderSpi)element;
          boolean canDecode = false;
          stream.mark();
          canDecode = spi.canDecodeInput(stream);
          stream.reset();
          return canDecode;
      } catch (IOException e) {
          return false;
      }
    }
  }
}

1469
Support / Re: Using FrameBuffer's Graphics With AWTGLCanvas
« on: June 19, 2009, 12:09:44 am »
I did this so far, but I have to do something else now. I might get back to it tonight. What I don't get about the Wikipedia article I found (http://en.wikipedia.org/wiki/Graphics_Interchange_Format) is whether I'm looking for a black (0, 0, 0) value and then a white (255, 255, 255) to determine the beginning and end of the color table or whether it's something else. This approach might be overkill anyway. There might be a cleverer way to find the individual frames with the provided Gif loaders.

Code: [Select]
import java.io.*;

public class AnimatedGIF {
      private static boolean animated;
      private static int width, height;
      private static int backColor;
      private static Pixel[] colorTable;//I THINK THE COLOR TABLE IS 24 BITS/PIXEL
      private static int[] thePixels;

      private static void readGIF(String[] args) throws IOException {
byte[] staticAnimated = new byte[6];
FileInputStream inStream =  new FileInputStream(args[0]);
inStream.read(staticAnimated);
if (staticAnimated[4] == 57)//IS IT GIF87a (STATIC) OR GIF89a (ANIMATED)?
      animated = true;
else animated = false;
byte[] twoBytes = new byte[2];
inStream.read(twoBytes);
width = fromSignedByte(twoBytes[0]) +fromSignedByte(twoBytes[1])*256;
inStream.read(twoBytes);
height = fromSignedByte(twoBytes[0]) +fromSignedByte(twoBytes[1])*256;
inStream.read(twoBytes);
backColor = twoBytes[1];//SKIPPED THE GCT BYTE ON PURPOSE (WHO CARES?)
System.out.println("Multiple Images: "+animated);
System.out.println("Width: "+width +", Height: "+height);
      }
      private static int fromSignedByte(byte signedBastard) {
int value = 0;
for (int i = 7; i >= 0; i--) {
     if ((signedBastard & (1 << i)) > 0) //IF (BYTE TOPRINT ANDED WITH A BYTE WHOSE ONLY BIT 1 IS ON POSITION i) > 0, ADD
value += (int)Math.pow(2.0, (double)i);
}
return value;
      }

      public static void main(String[] args) {
if (args == null || args.length == 0) {
      System.err.println("USAGE: java AnimatedGIF [filename]");
      System.exit(1);
}
try {
      readGIF(args);
}
catch (IOException e) {System.err.println("Problem loading file: "+e.getMessage());}
      }
}

class Pixel {
      protected int red, green, blue;
      public Pixel(byte[] pixel) {
red = pixel[0];
green = pixel[1];
blue = pixel[2];
      }
}

1470
Support / Re: Using FrameBuffer's Graphics With AWTGLCanvas
« on: June 18, 2009, 09:54:59 pm »
I can probably figure it out quickly enough. I'll report back with any findings soon.

Pages: 1 ... 96 97 [98] 99 100 ... 116