From a096d1b1ffaa22585322c3e2619e88c0030de566 Mon Sep 17 00:00:00 2001 From: Raghuram Subramani Date: Mon, 6 Jan 2025 06:38:28 -0500 Subject: clang-format for readability --- libwinnie/src/pixmap.cc | 228 +++++++++++++++++++++++++----------------------- 1 file changed, 118 insertions(+), 110 deletions(-) (limited to 'libwinnie/src/pixmap.cc') diff --git a/libwinnie/src/pixmap.cc b/libwinnie/src/pixmap.cc index 8e50fa3..35fb16e 100644 --- a/libwinnie/src/pixmap.cc +++ b/libwinnie/src/pixmap.cc @@ -19,159 +19,167 @@ along with this program. If not, see . Author: Eleni Maria Stea */ +#include "pixmap.h" +#include #include #include -#include -#include "pixmap.h" Pixmap::Pixmap() { - width = height = 0; - pixels = 0; + width = height = 0; + pixels = 0; } Pixmap::Pixmap(const Pixmap &pixmap) { - width = height = 0; - pixels = 0; - set_image(pixmap.width, pixmap.height, pixmap.pixels); + width = height = 0; + pixels = 0; + set_image(pixmap.width, pixmap.height, pixmap.pixels); } -Pixmap &Pixmap::operator=(const Pixmap &pixmap) +Pixmap & +Pixmap::operator=(const Pixmap &pixmap) { - if(this != &pixmap) { - set_image(pixmap.width, pixmap.height, pixmap.pixels); - } + if (this != &pixmap) { + set_image(pixmap.width, pixmap.height, pixmap.pixels); + } - return *this; + return *this; } Pixmap::~Pixmap() { - if(pixels) { - delete [] pixels; - } + if (pixels) { + delete[] pixels; + } } -int Pixmap::get_width() const +int +Pixmap::get_width() const { - return width; + return width; } -int Pixmap::get_height() const +int +Pixmap::get_height() const { - return height; + return height; } -Rect Pixmap::get_rect() const +Rect +Pixmap::get_rect() const { - Rect rect(0, 0, width, height); - return rect; + Rect rect(0, 0, width, height); + return rect; } -bool Pixmap::set_image(int x, int y, unsigned char *pix) +bool +Pixmap::set_image(int x, int y, unsigned char *pix) { - delete [] pixels; + delete[] pixels; - pixels = new unsigned char[x * y * 4]; - width = x; - height = y; + pixels = new unsigned char[x * y * 4]; + width = x; + height = y; - if(pix) { - memcpy(pixels, pix, x * y * 4); - } - return true; + if (pix) { + memcpy(pixels, pix, x * y * 4); + } + return true; } -const unsigned char *Pixmap::get_image() const +const unsigned char * +Pixmap::get_image() const { - return pixels; + return pixels; } -unsigned char *Pixmap::get_image() +unsigned char * +Pixmap::get_image() { - return pixels; + return pixels; } -bool Pixmap::load(const char *fname) +bool +Pixmap::load(const char *fname) { - FILE *fp; - int hdrline = 0; - - if(!(fp = fopen(fname, "rb"))) { - fprintf(stderr, "failed to open pixmap: %s: %s\n", fname, strerror(errno)); - return false; - } - - /* read ppm header */ - while(hdrline < 3) { - char buf[64]; - - if(!fgets(buf, sizeof buf, fp)) - goto err; - - /* skip comments */ - if(buf[0] == '#') - continue; - - switch(hdrline++) { - case 0: - /* first header line should be P6 */ - if(strcmp(buf, "P6\n") != 0) - goto err; - break; - - case 1: - /* second header line contains the pixmap dimensions */ - if(sscanf(buf, "%d %d", &width, &height) != 2) - goto err; - break; - } - } - - set_image(width, height, 0); - - for(int i=0; i