Voyager - Image viewer in Vala

Programming issues and discussion
simargl
Site Admin
Posts: 466
Joined: 16 May 2013, 10:54
Contact:

Re: Voyager - Image viewer in Vala

Postby simargl » 04 Aug 2014, 17:25

Here it is_ for a test:

Code: Select all

// valac test.vala --pkg gtk+-3.0 --target-glib=2.38

int main()
{
    Gdk.Pixbuf pix = new Gdk.Pixbuf.from_file("/usr/share/backgrounds/default.jpg");
   
    Gdk.Pixbuf pixr = pix.rotate_simple(Gdk.PixbufRotation.CLOCKWISE);
    // save rotated 270
    pixr.save("/root/default270.jpg", "jpeg", null);

    pixr = pixr.rotate_simple(Gdk.PixbufRotation.COUNTERCLOCKWISE);
    // save rotated 0
    pixr.save("/root/default0.jpg", "jpeg", null);
   
    return 0;
}

You will notice that newly created image is much smaller file size...

john3voltas
Expert
Posts: 266
Joined: 19 May 2013, 21:53

Re: Voyager - Image viewer in Vala

Postby john3voltas » 04 Aug 2014, 22:59

simargl wrote:Here it is_ for a test

Eeeer...sorry Sim but, what do I do with that code? I don't know how to compile in Vala.
EDIT: then again, I've been following a tutorial and it says that if I have valac installed it can be run just by using "valac name_of_the_program.vala". Do we have valac compiler installed? I'm asking because I'm not on my computer with alphaos right now.

simargl wrote:You will notice that newly created image is much smaller file size...

What do you mean? You've tested it yourself and you noticed that it is lossy? If so, what about the imagemagick approach? Would it mean much space in the iso?

efgee
Expert
Posts: 115
Joined: 29 Dec 2013, 20:58

Re: Voyager - Image viewer in Vala

Postby efgee » 06 Aug 2014, 01:01

What sim did is load a jpeg file and save the image twice: one rotated clockwise and the other counterclockwise.
The sizes are smaller because jpeg can be saved in different compression ratios.

A word about jpeg and loss-less:
If you load a jpeg the image is not loss-less because jpeg is lossy to start with.
When an jpeg file is loaded into a memory buffer you get the pixels, but from a lossy image.
(because the buffer was filled by a jpeg)

The only way to get a loss-less image rotated:
If you have a raw file from a camera and load it into a memory buffer you get raw pixels in a loss-less format.

Therefore:
Because the image information in a jpeg file is lossy the memory buffer will never be loss-less.
(because the original file was lossy...)

However once an image file is loaded into a memory buffer and image information is rotated the information is the same, just rotated...
If you save the buffer to a file and choose a jpeg format you can specify the compression ratio.
But nevertheless jpeg is lossy no matter which compression ratio is chosen.

Bottom line:
The image rotation function itself is loss-less in the sense that no image information is lost during rotation, but saving the image information to a jpeg file is lossy...

ValaDoc says:
JPEG images can be saved with a "quality" parameter; its value should be in the range [0,100]


If loss-less is needed a different file format needs to be chosen.

john3voltas
Expert
Posts: 266
Joined: 19 May 2013, 21:53

Re: Voyager - Image viewer in Vala

Postby john3voltas » 06 Aug 2014, 12:43

efgee wrote:The only way to get a loss-less image rotated:
If you have a raw file from a camera and load it into a memory buffer you get raw pixels in a loss-less format.

Sorry but I don't see how that can be the only way.
I've posted here a link to a page that has lots of utilities that allow you to rotate losslessly.

Picture this: you take a photo with a camera and the camera doesn't have RAW as an option. The camera's single option is high quality Jpeg. When you open that image on an image viewer that's Jpeg file is your equivalent to the RAW file because since the camera doesn't support RAW it you will never get access to RAW. That Jpeg is your RAW.
So let's focus on this high quality Jpeg image that the camera outputted to the SD card. Let's say that each photo is 5MB and has 14 megapixels.
We need to:
- open the high quality Jpeg
- grab those 14 megapixels
- put them on some kind of a buffer in the OS
- use a transformation routine that shifts/rotates the pixels in 90 degrees without changing their values
- grab those same 14 megapixels that now have been rotated and put them back in their original container
Right in the end of this process (last step above) we can't call the Jpeg save instruction because it will recompress the image and that's when it looses quality. We simply have to open the file grab the pixels, transform them (rotate), put them back in the file and close the file.
How that's done? Don't honestly know but I know that there are a lot of tools out there that can do just that.
Bottom line: when I say lossless I mean that it needs to be lossless when compared to the original picture before being rotated.
It would be great if Voyager could do the same because most image viewers (even Windows image viewer) can do just that.

efgee
Expert
Posts: 115
Joined: 29 Dec 2013, 20:58

Re: Voyager - Image viewer in Vala

Postby efgee » 07 Aug 2014, 06:02

@john3voltas
It looks like I lost you with my convoluted post, sorry for that.

I said:
Bottom line:
The image rotation function itself is loss-less in the sense that no image information is lost during rotation, but saving the image information to a jpeg file is lossy...

This matches what you are expecting.
Just take into account that there will be losses while saving the buffer back into a new jpeg file.
Not sure what happens if the quality is set to 100 while saving...

However there is still the possibility to save in a different file format. :mrgreen:

john3voltas
Expert
Posts: 266
Joined: 19 May 2013, 21:53

Re: Voyager - Image viewer in Vala

Postby john3voltas » 07 Aug 2014, 11:33

What you're saying seems reasonable but there are literally dozens of applications that can:
- take a Jpeg image (lossy)
- rotate it
- save the result to the same Jpeg or to another Jpeg file without loosing any information when compared to the initial Jpeg image. Thus lossless rotation.
There just has to be a way around that.
Cheers


Return to “Scripting and Programming”

Who is online

Users browsing this forum: No registered users and 3 guests

cron