SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Studio
Forum Rules FAQs Community Downloads Today's Posts Search

Notices

SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 10-14-2008, 05:34 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Question Any idea on why "native" sage thumbnail is missing color?

I wrote a servlet that serves up the SageTV thumbnail for a given media file. The image that it returns is the correct image, but the color is all wrong. Any ideas on how I can "correct" the image so that it has the correct color?

Here the source code and 2 images. The first is the image that this code is returning... the second image is the image that I would expect...

Code:
	private void writeSageImage(String mediaFileId, HttpServletResponse resp) throws Exception {
		// get the media file that we are going to be using
		Object sagefile = MediaFileAPI.GetMediaFileForID(Integer.parseInt(mediaFileId));
		Object sageImage = MediaFileAPI.GetThumbnail(sagefile);

                // find a method in the sage image that returns a RawImage
		Method method = null;
		Method m[]  = sageImage.getClass().getMethods();
		for (int i=0;i<m.length;i++) {
			if (sage.media.image.RawImage.class.equals(m[i].getReturnType())) {
				// potential contender
				method = m[i];
				break;
			}
		}
		
		if (method == null) throw new Exception("No Method to return image!");
		
		RawImage rimg  = (RawImage) method.invoke(sageImage, new Object[] {0});
		BufferedImage img =rimg.convertToBufferedImage();
		resp.setContentType("image/jpeg");
		OutputStream os = resp.getOutputStream();
		ImageIO.write((RenderedImage) img, "jpeg", os);
		os.flush();
	}
Thanks for any help.
Attached Images
File Type: png badcolor.png (29.4 KB, 295 views)
File Type: png goodcolor.png (38.7 KB, 271 views)
Reply With Quote
  #2  
Old 10-14-2008, 08:53 PM
MeInMaui's Avatar
MeInMaui MeInMaui is offline
SageTVaholic
 
Join Date: Feb 2005
Location: Maui. HI
Posts: 4,203
If you look at the perimeter in the original image it is white (R=255, G=255, B=255 ), but in the bad image the RGB values are R=255, G=128, B=128. In the black areas the bad image values are R=0, G=128, B=128.

It almost looks like there was some bit shifting (by 8 bits?) or something like that happening. Maybe if you took a look at both images in a hex editor, you might see a pattern.

Aloha,
Mike
__________________
"Everything doesn't exist. I'm thirsty." ...later... "No, it's real!!! I'm full."
- Nikolaus (4yrs old)
Reply With Quote
  #3  
Old 10-14-2008, 11:15 PM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
I'm not familiar with most of those classes and methods, but the things I'd be looking at are:

1. Is "image/jpeg" really the correct content type for the object you're getting back from the undocumented method you're invoking?

2. I don't see the OutputStream being closed anywhere (although you do flush it).

3. Could there be some sort of text v. binary stream confusion that's causing inappropriate CRLF translation?
__________________
-- Greg
Reply With Quote
  #4  
Old 10-15-2008, 09:19 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by MeInMaui
It almost looks like there was some bit shifting (by 8 bits?) or something like that happening. Maybe if you took a look at both images in a hex editor, you might see a pattern.
I was wondering if it was some "common" image transformation pattern that I wasn't aware of... I don't think I have enough time to really figure it out... I'm not a graphics person

Quote:
Originally Posted by gkusnick
1. Is "image/jpeg" really the correct content type for the object you're getting back from the undocumented method you're invoking?
The IOImage.write() method translates the internal java buffered image (raster) to whatever type you specify. I'm telling it to create a "jpeg" to the content type is correct for the type that I'm creating... And yeah... i'm not happy about having to resort to using undocumented methods via reflection... but I didn't see any other obvious way to get a java BufferedImage from a Sage Image... I also reimplemented the method to only return user contributed media images, but I'd a like a way to use both methods in case the user contributed images don't exist.

Quote:
Originally Posted by gkusnick
2. I don't see the OutputStream being closed anywhere (although you do flush it).
As a programming practice... I make it point not to close streams that i don't create. The servlet container created the stream, and it will close it. But i'll try a run with the close in there to see if it makes a difference.

Quote:
Originally Posted by gkusnick
3. Could there be some sort of text v. binary stream confusion that's causing inappropriate CRLF translation?
Good point... but the servlet container has a getWriter() for sending back text, and getOutputStream() for sending back binary data (which could be text). I'm using the getOutputStream() for this, since it's binary data. I also use the same methodology to send back a raw video stream... and it works well.

Thanks guys for your expertise on this.... If anything else comes to mind let me know. For now, maybe I'll play with some filters and see if it's as simple as applying some simple transformation.

Thanks.
Reply With Quote
  #5  
Old 10-15-2008, 12:41 PM
jreichen's Avatar
jreichen jreichen is offline
Sage Icon
 
Join Date: Jul 2004
Posts: 1,192
Quote:
Originally Posted by stuckless View Post
The IOImage.write() method translates the internal java buffered image (raster) to whatever type you specify. I'm telling it to create a "jpeg" to the content type is correct for the type that I'm creating... And yeah... i'm not happy about having to resort to using undocumented methods via reflection... but I didn't see any other obvious way to get a java BufferedImage from a Sage Image... I also reimplemented the method to only return user contributed media images, but I'd a like a way to use both methods in case the user contributed images don't exist.
Nielm's webserver has a MediaFileThumbnailServlet that does the same thing. It looks like there is a Sage API to return a BufferedImage.

Quote:
Originally Posted by stuckless View Post
Good point... but the servlet container has a getWriter() for sending back text, and getOutputStream() for sending back binary data (which could be text). I'm using the getOutputStream() for this, since it's binary data. I also use the same methodology to send back a raw video stream... and it works well.
Video stream? It might be time for another PM
__________________
Server: Intel Core i5 760 Quad, Gigabyte GA-H57M-USB3, 4GB RAM, Gigabyte GeForce 210, 120GB SSD (OS), 1TB SATA, HD HomeRun.
Extender: STP-HD300, Harmony 550 Remote,
Netgear MCA1001 Ethernet over Coax.
SageTV: SageTV Server 7.1.8 on Ubuntu Linux 11.04, SageTV Placeshifter for Mac 6.6.2, SageTV Client 7.0.15 for Windows, Linux Placeshifter 7.1.8 on Server and Client
, Java 1.6.
Plugins: Jetty, Nielm's Web Server, Mobile Web Interface.

Reply With Quote
  #6  
Old 10-15-2008, 01:20 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by jreichen
It looks like there is a Sage API to return a BufferedImage.
I looked as GetImageAsBufferedImage when I first stated this and it suffered the same fate as the reflection "hack" that I did.

But.... i took a look at nielm's code and I noticed that he's not sending back the format in a "jpg" format, but rather a "png" format. So I changed the code to tell the ImageIO to send back png... and it works as expected....

Thanks for sending this along... now I can remove my "undocumented api" hack.
thanks!

Quote:
Originally Posted by jreichen
Video stream?
yeah... I wanted a simple consistent rest api for accessing the thumbnails and video....
Code:
// return the thumbnail
http://server:8080/sagex/media/thumbnail/MEDIA_FILE_ID

// return media stream
http://server:8080/sagex/media/mediafile/MEDIA_FILE_ID

// return custom properties
http://server:8080/sagex/media/properties/MEDIA_FILE_ID

Last edited by stuckless; 10-15-2008 at 01:27 PM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sage Server with no internet access, need a creative solution wazkaren General Discussion 49 09-19-2008 08:57 PM
Symptoms of a sick and dying wiz.bin roadtoad SageTV Software 1 12-23-2007 01:37 PM
Purevideo color controls irrelevant since upgrade to 1.02-223 FZ1 Hardware Support 5 02-02-2007 12:49 PM
DVD menu indicators missing while plaing DVDs via Sage ripple SageTV Software 5 12-19-2006 12:48 PM
Sage UI disappears during playback Keith SageTV Software 17 03-03-2006 03:31 AM


All times are GMT -6. The time now is 06:15 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.