LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-20-2005, 09:09 PM   #1
evilmrhenry
Member
 
Registered: Oct 2003
Distribution: Knoppix
Posts: 103

Rep: Reputation: 15
SDL blit only displays first line repeated


I'm trying to load an unusual image file format using SDL_CreateRGBSurfaceFrom, but when I go to display the image, (blit it onto the screen) only the first file of the image is displayed, repeated over every line. (I've tried the SDL_LoadBMP function, and that does not have the problem.) However, when I look at the actual pixel data, and the other data in the SDL image, there is nothing obviously wrong.

The following is the relevant code from the program:
Code:
	//Load the palette.
	struct RGB { unsigned char red, green, blue; };
	typedef struct RGB color;
	color TPaletteTemp[256];

	void *tempPic[512];

	unsigned int width = 0, height = 0;

	int f;
	int i = 0;
	int j = 0;
	f = open( "CDOGS.PX", O_RDONLY);

	if (f >= 0)
	{
		read( f, TPaletteTemp, sizeof( TPaletteTemp));
		for (j=0; j<256; j++)
		{
			palette[j].r = TPaletteTemp[j].red*4;
			palette[j].g = TPaletteTemp[j].green*4;
			palette[j].b = TPaletteTemp[j].blue*4;
		}
	}

	//Load the pictures.
	unsigned short int size;
	i=0;
	while (f && i<512)
	{
		read( f, &size, 2);
		if (size)
		{
			read( f, &width, 2);
			read( f, &height, 2);

			tempPic[i] = malloc( size-4);
			read( f, tempPic[i], size-4);
			pics[i] = *SDL_CreateRGBSurfaceFrom(tempPic[i],
				width, height, 8, 0,
				0xff0000, 0x00ff00, 0x0000ff, 0x000000);
			SDL_SetPalette(&pics[i], SDL_LOGPAL|SDL_PHYSPAL, palette, 0, 256);
		}
		i++;
	}

	for (j=0; j<256; j++)
	{
		int i;

		SDL_Rect dest;
		dest.x = (j/16)*32;
		dest.y = (j%16)*32;
		dest.w = pics[j].w;
		dest.h = pics[j].h;
		i = SDL_BlitSurface(&pics[j], NULL, screen, &dest);
		if (i < 0)
		{printf("error in sprite display\n");}
	}
	SDL_UpdateRect(screen, 0, 0, 0, 0);
This is an example of what the problem looks like:
http://emhsoft.net/SDL_problem.png

And this is a zip file containing all of the relevant code:
http://emhsoft.net/SDL_problem.zip

CDOGS.PX=The actual file I'm trying to load.
cdogspx.txt=An english description of the file format.
palette.py=A python program that does load the image correctly.
test.c, makefile=The program in question.
 
Old 01-21-2005, 05:15 PM   #2
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
Code:
pics[i] = *SDL_CreateRGBSurfaceFrom(tempPic[i], width, height, 8, 0 - should be width, 0xff0000, 0x00ff00, 0x0000ff, 0x000000);
I think this will fix your problem. The parameter you've set to 0 is supposed to be the 'pitch', which is the length of one pixel row measured in bytes. Since your pixels are 8-bit, it should be the same as 'width'.
 
Old 01-21-2005, 05:46 PM   #3
evilmrhenry
Member
 
Registered: Oct 2003
Distribution: Knoppix
Posts: 103

Original Poster
Rep: Reputation: 15
And it did. Thank you.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ text file line by line/each line to string/array Dimitris Programming 15 03-11-2008 08:22 AM
Trying to program an SDL application but cannot find the SDL.h file:SuSE 9.2&KDevelop pujolasdf Linux - Newbie 4 03-13-2005 07:50 AM
Repeated seg faults Tick Linux - General 5 07-29-2004 07:09 PM
Repeated Use of fsck: Trouble? bezaleel Linux - Hardware 1 01-19-2004 10:21 PM
Repeated OpenOffice Failure kajensen Linux - Software 2 09-24-2003 03:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration