Ruby .read image upside down?

C

Chris Metcalfe

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
 
C

Chris Metcalfe

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?
 
L

Leslie Viljoen

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
 
C

Chris Metcalfe

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top