[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby .read image upside down?

Chris Metcalfe

5/29/2008 6:15:00 PM

Hi,

I'm discorvering a strange issue when reading in an image being sent by
a 3D rendering software. The image data is being passed in a parameter
called 'thumbnail'. We read it into a variable in the responding
controller like so:

if params[:thumbnail] !=nil && params[:thumbnail] != ""
virtual_item.thumbnail = params[:thumbnail].read
virtual_item.thumbnail_content_type =
params[:thumbnail].content_type.chomp
end
--
Posted via http://www.ruby-....

3 Answers

Chris Metcalfe

5/29/2008 6:23:00 PM

0

Sorry the above message posted prematurely.

The code is as follows:

if params[:thumbnail] !=nil && params[:thumbnail] != ""
virtual_item.thumbnail = params[:thumbnail].read
virtual_item.thumbnail_content_type =
params[:thumbnail].content_type.chomp
end

Now the .read function read the image properly. However it is being
stored in the database upside down. The rows of the image are flipped
only vertically, which is strange, and not both vertically and
horizontally backwards. I'm assuming that there is a some 'header'
bytes which describe the image, then the actual pixel data list row by
row. We are reading PNG files.

The 3D rendering software outputs the images the right side up, but once
they have been transfered and saved in the database they are upside
down.

Any ideas on how we can investigate whether the .read function is doing
something strange or prove that truly the params[:thumbnail] parameter
actually contains upside down data?
--
Posted via http://www.ruby-....

Leslie Viljoen

5/29/2008 8:06:00 PM

0

On Thu, May 29, 2008 at 8:23 PM, Chris Metcalfe <contact@prognition.com> wrote:
> Sorry the above message posted prematurely.
>
> The code is as follows:
>
> if params[:thumbnail] !=nil && params[:thumbnail] != ""
> virtual_item.thumbnail = params[:thumbnail].read
> virtual_item.thumbnail_content_type =
> params[:thumbnail].content_type.chomp
> end
>
> Now the .read function read the image properly. However it is being
> stored in the database upside down. The rows of the image are flipped
> only vertically, which is strange, and not both vertically and
> horizontally backwards. I'm assuming that there is a some 'header'
> bytes which describe the image, then the actual pixel data list row by
> row. We are reading PNG files.
>
> The 3D rendering software outputs the images the right side up, but once
> they have been transfered and saved in the database they are upside
> down.
>
> Any ideas on how we can investigate whether the .read function is doing
> something strange or prove that truly the params[:thumbnail] parameter
> actually contains upside down data?

Can you save the data back from the database in a file and then look at a
hex dump of it? I assume you store the PNG file intact and are not trying
to interpret it at all?
If you can save the file you can look at the bytes using Hexer on Linux or
XVI32 on Windows, and compare the bytes to the PNG file.

If you are using Ruby under Windows there's one trick I know of:
binary files need 'binmode' to be set to true in order for them to be
read properly. But that probably wouldn't invert them.

Les

Chris Metcalfe

6/11/2008 6:40:00 PM

0

Still no luck. I've looked at the .read function and dumped its
contents into a file and the image is still flipped when I view it.

It seems that once the .read function is performed the data is
interpreted and the rows are inverted.

I've come to the solution that there is a bug in the way the .read
function works in ruby, or there is a bug in Unity (the 3D engine)
sending the rendered image.

The .read seems to work fine when uploading an image through the
browser, however we run into the vertical flip problem when images are
sent from Unity.

Any thought?
--
Posted via http://www.ruby-....