Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » StreamRasterEncoder puzzle
StreamRasterEncoder puzzle [message #15282] Tue, 15 April 2008 15:07 Go to next message
nixnixnix is currently offline  nixnixnix
Messages: 415
Registered: February 2007
Location: Kelowna, British Columbia
Senior Member
So here's a puzzle for you:

The following piece of code writes all four image types but the resulting PNG and TIF files cannot be read by photoshop elements. They can be read by other less fussy types of image viewer. And here's the bit that's puzzling, when I use the same plugins elsewhere to write TIF and PNG, photoshop reads the resulting files just fine and even with this code, photoshop can read the resulting BMP and JPG files just fine. Can you find the error?


bool RasterLayer::SaveLegendAsImage(String path)
{
	StreamRasterEncoder* pEnc=NULL;
	
	if(path.Find(".jpg") || path.Find(".JPG"))
	{
		pEnc = new JPGEncoder(100);	// top quality		
	}
	else if(path.Find(".png") || path.Find(".PNG"))
	{
		pEnc = new PNGEncoder();	// default 32bpp		
	}
	else if(path.Find(".tif") || path.Find(".TIF"))
	{
		pEnc = new TIFEncoder(); 	// default 24bpp		
	}
	else if(path.Find(".bmp") || path.Find(".BMP"))
	{
		pEnc = new BMPEncoder();	// default 24bpp		
	}
	else
	{
		return false;
	}
	
	ImageDraw id(2000,2000);
	DrawLegend(id);
	
	Image img = id.GetStraight();
	
	pEnc->SaveFile(path,img);
	
	delete pEnc;
	
	return true;
}


Cheers,

Nick

EDIT: the following code (and you can see the different things I've tried commented out) has the same effect

bool RasterLayer::SaveLegendAsImage(String& path)
{
	ImageDraw id(1500,2000);
	DrawLegend(id);
	
//	Image img = id.GetStraight();
//	Image img(id);

	ImageBuffer ib(id);
	Image img(ib);
	
	if(path.Find(".jpg") || path.Find(".JPG"))
	{
		JPGEncoder enc(100);	// top quality	
		if(!enc.SaveFile(path,img))
		{
			PromptOK("problem saving legend");
			return false;	
		}
	}
	else if(path.Find(".png") || path.Find(".PNG"))
	{
		PNGEncoder enc;	// default 32bpp		
		if(!enc.SaveFile(path,img))
		{
			PromptOK("problem saving legend");
			return false;	
		}
	}
	else if(path.Find(".tif") || path.Find(".TIF"))
	{
		TIFEncoder enc; 	// default 24bpp		
		if(!enc.SaveFile(path,img))
		{
			PromptOK("problem saving legend");
			return false;	
		}
	}
	else if(path.Find(".bmp") || path.Find(".BMP"))
	{
		BMPEncoder enc;	// default 24bpp		
		if(!enc.SaveFile(path,img))
		{
			PromptOK("problem saving legend");
			return false;	
		}
	}
	else
	{
		return false;
	}
	
	return true;
}

[Updated on: Tue, 15 April 2008 17:39]

Report message to a moderator

Re: StreamRasterEncoder puzzle [message #15289 is a reply to message #15282] Tue, 15 April 2008 21:11 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
String::Find returns the position. It should be path.Find(".png") >= 0 etc... Wink

Mirek
Re: StreamRasterEncoder puzzle [message #15304 is a reply to message #15289] Wed, 16 April 2008 00:28 Go to previous messageGo to next message
nixnixnix is currently offline  nixnixnix
Messages: 415
Registered: February 2007
Location: Kelowna, British Columbia
Senior Member
oh man that was dumb Embarassed

I usually use String::EndsWith() but for some reason used Find instead.

Thanks. Smile
Re: StreamRasterEncoder puzzle [message #15311 is a reply to message #15282] Wed, 16 April 2008 09:33 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
Mirek: I was still missing the point after your comment, as I thought... if both finds return zero, it will lead only to pEnc be NULL, not to corrupted PNG file.
Then I finally realized (after looking into String.h) the JPEG is always stored no matter what input path does contain, because the Find does return either position OR -1 in case substring is not found. Very Happy
(nixnixnix: looks like I'm even dumber than you Very Happy)

I got a bit surprised from the case sensitivity too, I'm checking the String.h and I see, that except defining stricmp and strnicmp even on POSIX/WINCE platform, there's no other support in U++ for those things.
It feels somewhat awkward to see thing like "if(path.Find(".jpg") || path.Find(".JPG"))" (and I don't mean the hidden bug this time, but the duplicity of "jpg" text).

[Updated on: Wed, 16 April 2008 09:36]

Report message to a moderator

Re: StreamRasterEncoder puzzle [message #15313 is a reply to message #15311] Wed, 16 April 2008 10:12 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
mr_ped wrote on Wed, 16 April 2008 03:33


I got a bit surprised from the case sensitivity too, I'm checking the String.h and I see, that except defining stricmp and strnicmp even on POSIX/WINCE platform, there's no other support in U++ for those things.
It feels somewhat awkward to see thing like "if(path.Find(".jpg") || path.Find(".JPG"))" (and I don't mean the hidden bug this time, but the duplicity of "jpg" text).


Well, I would write it as

if(GetFileExt(ToUpper(path)) == ".JPG")

Mirek
Re: StreamRasterEncoder puzzle [message #15329 is a reply to message #15313] Wed, 16 April 2008 14:44 Go to previous messageGo to next message
nixnixnix is currently offline  nixnixnix
Messages: 415
Registered: February 2007
Location: Kelowna, British Columbia
Senior Member
Thanks, the ToUpper was the bit I was missing.

Hey Mr Ped, its good to know other people can be dumber than me sometimes even if it is only a momentary lapse Smile
Re: StreamRasterEncoder puzzle [message #15330 is a reply to message #15282] Wed, 16 April 2008 15:13 Go to previous message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
Just to be nitpicking a bit... Smile
Quote:

if(GetFileExt(ToUpper(path)) == ".JPG")


the "if(ToUpper(GetFileExt(path)) == ".JPG")" variant is IMHO more optimal. Very Happy Razz
Previous Topic: CtrlPaint Bug: Frame draws outside of Ctrl
Next Topic: theIDE: Passing cmd line argument during DEBUG?
Goto Forum:
  


Current Time: Thu Mar 28 11:52:48 CET 2024

Total time taken to generate the page: 0.01148 seconds