Use PNG Files

      Use PNG Files

      Hello,

      I just started my journey in homebrews for the Wii and am wondering how to load png files from png images directly? All I could find was a tutorial for jpeg which required you to run the image through a conversion tool that creates a .s file for each image:
      Example:

      Source Code

      1. .rodata
      2. .balign 32
      3. .globl piclength
      4. .globl picdata
      5. piclength: .long picdataend - picdata
      6. picdata:
      7. .incbin "../images/hello.jpg"
      8. picdataend:
      Is there an easier way to do thisthat doesn't involve mixing powerpc assembly code for each image?
      So what exactly do you want to do, load JPEG/PNG files from the SD card or USB drive during homebrew execution, or do you want to bundle JPEG/PNG files into your program (like you're doing now) just without having to run that conversion tool?

      For the former you can use libfat ( wiibrew.org/wiki/Libfat ) which is part of libogc to read files from SD or USB.
      For the latter, you can add a makefile target that will automatically execute that conversion tool each time you compile your application.

      DevkitPro Archiv (alte Versionen / old versions): wii.leseratte10.de/devkitPro/
      Want to donate for Wiimmfi and Wii-Homebrew.com? Patreon / PayPal

      Dieser Beitrag wurde bereits 0 mal editiert, zuletzt von Leseratte ()

      Leseratte wrote:

      So what exactly do you want to do, load JPEG/PNG files from the SD card or USB drive during homebrew execution, or do you want to bundle JPEG/PNG files into your program (like you're doing now) just without having to run that conversion tool?

      For the former you can use libfat ( wiibrew.org/wiki/Libfat ) which is part of libogc to read files from SD or USB.
      For the latter, you can add a makefile target that will automatically execute that conversion tool each time you compile your application.
      Thanks for that link. I looked at the examples but, none of them shows how to load a png file off the sd/usb card. Here is an example of what I want to do:

      Source Code

      1. #include <libfat.h>
      2. fatInit();
      3. public bool Image::load(string file) {
      4. }

      Nothing special just load an image to a variable to be used to render the image later. For comparison here is the java version of the code I am trying to convert:

      Java Source Code

      1. package org.homebrew.engine;
      2. import java.awt.Graphics;
      3. import java.awt.Image;
      4. import java.awt.MediaTracker;
      5. import java.awt.Rectangle;
      6. import java.awt.Toolkit;
      7. import org.havi.ui.HScene;
      8. /**
      9. * This class contains all the methods for displaying an image on screen. It is an extends the BaseGameObject
      10. * class.
      11. */
      12. public final class ImageEntity extends BaseGameEntity {
      13. // entity image
      14. protected Image img;
      15. protected HScene hscene;
      16. protected Graphics g;
      17. /**
      18. * class constructor
      19. * @param hscene scene to add to for drawing purposes
      20. */
      21. public ImageEntity(final HScene hscene) {
      22. this.hscene = hscene;
      23. img = null;
      24. setAlive(true);
      25. }
      26. /**
      27. * Returns the image to display
      28. * @return Image Image to display
      29. */
      30. public final Image getImage() {
      31. return img;
      32. }
      33. /**
      34. * Sets the image to display
      35. * @param img Image to display
      36. */
      37. public final void setImage(final Image img) {
      38. this.img = img;
      39. }
      40. /**
      41. * returns the width of the image
      42. * @return int images width
      43. */
      44. public final int width() {
      45. return img.getWidth(hscene);
      46. }
      47. /**
      48. * returns the height of the image
      49. * @return int images height
      50. */
      51. public final int height() {
      52. return img.getHeight(hscene);
      53. }
      54. /**
      55. * returns the x coordinate of the center of the image
      56. * @return int x coordinate of the center of the image
      57. */
      58. public final int getCenterX() {
      59. return getX() + width() / 2;
      60. }
      61. /**
      62. * returns the y coordinate of the center of the image
      63. * @return int y coordinate of the center of the image
      64. */
      65. public final int getCenterY() {
      66. return getY() + height() / 2;
      67. }
      68. /**
      69. * Sets the graphic context for the image
      70. * @param g new graphic context to use
      71. */
      72. public final void setGraphics(final Graphics g) {
      73. this.g = g;
      74. }
      75. /**
      76. * loads an image to display
      77. * @param filename filename of image to load
      78. */
      79. public final void load(final String filename) {
      80. try {
      81. Toolkit tk = Toolkit.getDefaultToolkit();
      82. img = tk.getImage(this.getClass().getResource(filename));
      83. MediaTracker mt = new MediaTracker(this.hscene);
      84. mt.addImage(img,1);
      85. mt.waitForAll();
      86. } catch (Exception e) {
      87. System.err.println("Couldn't load Image: " + filename + "\n");
      88. System.err.println("Exception: " + e.toString() + "\n");
      89. System.err.println("StackTrace: ");
      90. e.printStackTrace();
      91. }
      92. }
      93. /**
      94. * Draws the image on the screen on its x and y coordinate
      95. * @param g graphics context to use for drawing
      96. */
      97. public final void draw(final Graphics g) {
      98. if (img!=null) g.drawImage(img, getX(),getY(), null);
      99. }
      100. /**
      101. * Returns the bounding rectangle for the image
      102. * @return Rectangle bounding rectangle of image
      103. */
      104. public final Rectangle getBounds() {
      105. Rectangle r;
      106. r = new Rectangle((int)getX(), (int)getY(), (int)width(), (int)height());
      107. return r;
      108. }
      109. }
      Display All

      The post was edited 1 time, last by Alien 51 Software ().