Skip to content

Instantly share code, notes, and snippets.

@vinipsmaker
Created March 11, 2014 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinipsmaker/9479068 to your computer and use it in GitHub Desktop.
Save vinipsmaker/9479068 to your computer and use it in GitHub Desktop.
Copy pixels of one image to another. Second image has only one line.
// This software assumes that all input files have 4 channels (RGB + Alpha)
// and the output.png file only has one line and the total number of pixels in
// both files is equal.
// Use GIMP to create such files.
#include <gdkmm/pixbuf.h>
#include <glibmm/init.h>
#include <gdkmm/wrap_init.h>
#include <cstdlib>
int main(int, char const *[])
{
Glib::init();
Gdk::wrap_init();
Glib::RefPtr<Gdk::Pixbuf> input
= Gdk::Pixbuf::create_from_file("/home/vinipsmaker/Downloads/input.png");
Glib::RefPtr<Gdk::Pixbuf> output
= Gdk::Pixbuf::create_from_file("/home/vinipsmaker/Downloads/output.png");
guint8 *input_iterator = input->get_pixels();
guint8 *output_iterator = output->get_pixels();
const int input_rowpadding
= input->get_rowstride() - input->get_width() * 4;
for ( int i = 0 ; i != input->get_height() ; ++i ) {
for ( int j = 0 ; j != input->get_width() ; ++j ) {
for ( int k = 0 ; k != 4 ; ++k )
output_iterator[k] = input_iterator[k];
input_iterator += 4;
output_iterator += 4;
}
input_iterator += input_rowpadding;
}
output->save("/home/vinipsmaker/Downloads/output2.png", "png");
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment