Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Untaled

Pages: [1]
1
Thanks for the explanation, it makes sens now :D

There's a very neat function (that got added when I proposed unsigned -> sf::Color constructors ;d) in sf::Color called toInteger BTW. You can neatly print them in a one liner using hex:
std::printf("0x%08x\n", pixel.toInteger());
std::cout << "0x" << std::hex << pixel.toInteger() << std::dec << std::endl;

This will be definitly be usefull to keep my code clean

2
How could have
std::cout << std::endl << " new R : " << (int)currentPix.r << ", new G : " << (int)currentPix.g << ", new B : " << (int)currentPix.b;
    std::cout << ", new A : " << (int)currentPix.a << std::endl;
printed out "newR : 238, G : 29, B : 37, A : 254" without 'new' before G, B and A and without space between 'new' and R?

Are you sure you're running right code? Can you provide the BMP file to test?

It did print "new R : 238, new G : 29,  new B : 37,  new A : 254", I just wrote new once in order to align the two lines, sorry if it confused you.
I ran this code before to post, here's the square I'm using : https://puu.sh/CsxIi/320e594419.bmp

The first thing to do is to pick a suitable image format. BMP doesn't support alpha values, try PNG instead.

Thanks you, it seems the problem was here since it works with PNG. I tried again to modify my .bmp without
changing the alpha and it works too :) !

3
#include <iostream>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

int main()
{
    sf::Image input;
    sf::Color currentPix;

        // input.bmp is a 100*100 red square
    input.loadFromFile("input.bmp");

    currentPix = input.getPixel(0,0); // top-left corner red pixel
    std::cout << std::endl << "     R : " << (int)currentPix.r << ",     G : " << (int)currentPix.g << ",     B : " << (int)currentPix.b;
    std::cout << ",     A : " << (int)currentPix.a;

        // Some changes
    currentPix.r++;
    currentPix.g++;
    currentPix.b++;
    currentPix.a--; // I can't use ++ since 255 is the maximum

    input.setPixel(0,0,currentPix);

    std::cout << std::endl << " new R : " << (int)currentPix.r << ", new G : " << (int)currentPix.g << ", new B : " << (int)currentPix.b;
    std::cout << ", new A : " << (int)currentPix.a << std::endl;

    input.saveToFile("output.bmp");
}

 

It shows :       R : 237, G : 28, B : 36, A : 255
               newR : 238, G : 29, B : 37, A : 254

However, when I open the image with gimp and check the color of the pixel I changed, or if I load the file and check the pixel with getPixel(),
the pixel in 0,0 will be {239,28,38,255} instead of the expected {238,29,37,254};.

4
Graphics / Pixel differences between setPixel() and after saveToFile()
« on: January 06, 2019, 01:32:39 pm »
Hello :),

I'm trying to do a program that should hide a message inside an image. I made it like that :

  // Load the image
inputImg.loadFromFile("input.bmp")

  // Load the pixel
currentPixel = inputImg.getPixel(x,y);

  // Change the pixel
(int)currentPixel.r++;
(int)currentPixel.g++;
(int)currentPixel.a--;

  // set the pixel back in the image
inputImg.setPixel(x,y,currentPixel)

  // Save the image once changes are done
inputImg.saveToFile("output.bmp")
 

All seem to work well and when the program is running the pixel values are correct.
However the saved image does't have the correct pixel values, it's slightly off for bmp and totally different for jpg :(.
For exemple I save the pixel in the top-left corner as {222,30,30,255} and the top-left corner pixel of my saved image is {223,30,29,255}.
The problem is that I need it to be exactly the same because I use the parity of values for binary conversation.

So is it possible to do it with sfml ? If so what am I doing wrong ?

Thanks you :D

Pages: [1]