jpeg on the wii

Post Reply
sktlz_plus
Posts: 3
Joined: Thu May 24, 2012 1:38 am

jpeg on the wii

Post by sktlz_plus » Thu May 24, 2012 9:33 pm

Hi, I'm trying to follow this tutorial
http://www.codemii.com/2008/09/07/tutor ... eg-images/
But I'm having trouble with it.

First it won't compile until I unpack the jpeg libraries into the "powerpc-eabi" folder instead of creating the "powerpc-gecko" folder.

Then I needed to edit the "jpgogc.h" file to point to

Code: Select all

#include <jpeg/jpeglib.h>
instead of

Code: Select all

#include <jpeglib.h>
I think after that the project compiled fine, but when I run the .dol with Dolphin emulator, all I see is a blank screen.

WinterMute
Site Admin
Posts: 1856
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: jpeg on the wii

Post by WinterMute » Tue May 29, 2012 8:47 am

The tutorial is wrong, you'll need to remove the libjpeg files from your devkitPPC install - there should be nothing in there except the files distributed by devkitPro, Sadly there also appears to be no source code for libogc_jpeg which makes it a bit awkward to convert this tutorial into something reasonable - especially since there appear to be wii/cube specific additions over and above the official libjpeg.

We have a selection of prebuilt libraries for wii/gamecube, including libjpeg, found at http://sourceforge.net/projects/devkitp ... tlibs/ppc/ . These archives should be extracted to <path/to>/devkitpro/portlibs/ppc. When using them add $(PORTILIBS) to LIBDIRS in the Makefile & add the appropriate lib to LIBS.

Code: Select all

#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS	:=	-lwiiuse -lbte -logc -ljpeg -lm

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS	:=	$(PORTLIBS)
I don't have time right now to dig into this very deeply (currently moving house) so I haven't managed to put together a working example but I have some code snippets that might help.

Code: Select all

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <jpeglib.h>

// include generated by build
#include "testcard_jpg.h"
...
	struct jpeg_decompress_struct cinfo;
	memset(&cinfo,0,sizeof(cinfo));

	jpeg_mem_src(&cinfo,(u8*)testcard_jpg,testcard_jpg_size);
	jpeg_read_header(&cinfo, TRUE);
	jpeg_start_decompress(&cinfo);

	int row_stride = cinfo.output_width * cinfo.output_components;

	JSAMPARRAY buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);

	while (cinfo.output_scanline < cinfo.output_height) {
	       (void) jpeg_read_scanlines(&cinfo, buffer, 1);
	}
	jpeg_finish_decompress(&cinfo);

The decompressed scanline data will need to be converted from rgb to Y1CbY2Cr in order to display it via XFB, something like this.

Code: Select all

//---------------------------------------------------------------------------------
//	convert two RGB pixels to one Y1CbY2Cr.
//---------------------------------------------------------------------------------
u32	rgb2yuv (u8 r1, u8 g1, u8 b1, u8 r2, u8 g2, u8 b2) {
//---------------------------------------------------------------------------------
	int y1, cb1, cr1, y2, cb2, cr2, cb, cr;

	y1 = (299 * r1 + 587 * g1 + 114 * b1) / 1000;
	cb1 = (-16874 * r1 - 33126 * g1 + 50000 * b1 + 12800000) / 100000;
	cr1 = (50000 * r1 - 41869 * g1 - 8131 * b1 + 12800000) / 100000;
	y2 = (299 * r2 + 587 * g2 + 114 * b2) / 1000;
	cb2 = (-16874 * r2 - 33126 * g2 + 50000 * b2 + 12800000) / 100000;
	cr2 = (50000 * r2 - 41869 * g2 - 8131 * b2 + 12800000) / 100000;

	cb = (cb1 + cb2) >> 1;
	cr = (cr1 + cr2) >> 1;
	return (y1 << 24) | (cb << 16) | (y2 << 8) | cr;
}
The reason you see a blank screen on Dolphin is because the demo writes directly to the framebuffer. If you go into the Graphics configuration, under hacks, select Real External Frame Buffer.
Help keep devkitPro toolchains free, Donate today

Personal Blog

sktlz_plus
Posts: 3
Joined: Thu May 24, 2012 1:38 am

Re: jpeg on the wii

Post by sktlz_plus » Thu Jun 07, 2012 10:58 pm

Thank you for taking the time to replay in such a thorough way. I know what it's like moving out, things can be really hectic. I got dolphin configured properly and am good to go now.

I've run out of free time too (and willpower for me actually, it's really stressful having the idea of what you want in your head, but not being able to implement it before piecing together a million semi-functional tuts). I don't exactly know what to make of the

Code: Select all

// include generated by build
#include "testcard_jpg.h"
part of your code otherwise I'd throw together a tut on it right now, but even still I've got work piling up and should be getting to that. I also thought maybe I'd use textures on those GX shapes from the nehe code, but I've gotta take a break from this stuff for a while.


If you're at all wondering, the project I was starting up was a kind of puzzle game for... instead of children, BABIES! Towards the middle of the project I was thinking "oh man this would make for a platinum wii ware release if I can get someone to buy it" but now I'm thinking the project will just die if I don't show it off in its current state.

Here's where the project is available if your curious
https://github.com/TheNotary/wii_color_game

Thanks again for your help :)

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 22 guests