// El módulo de imágenes con punteros: lo que se copia y lo que no.
#include <stdio.h>

#include "lab/image.h"

void paint_copy(struct image img) {
    img.pixels[0][0] = 99;
    printf("En paint_copy, el primer píxel vale %d\n", img.pixels[0][0]);
}

void paint_first(struct image *img) {
    img->pixels[0][0] = 99;
    printf("En paint_first, el primer píxel vale %d\n", img->pixels[0][0]);
}

// Una fila de la matriz llega como puntero a su primer elemento.
void paint_row(int *row, int width) {
    for (int x = 0; x < width; x++) {
        row[x] = 77;
    }
}

int main(void) {
    struct image img;
    if (!image_load(&img, "lab/images/tiny.pgm")) {
        fprintf(stderr, "No se pudo leer la imagen\n");
        return 1;
    }

    printf("sizeof(img) = %zu, sizeof(&img) = %zu\n", sizeof(img), sizeof(&img));
    image_print(&img);

    paint_copy(img);
    printf("Después de paint_copy:\n");
    image_print(&img);

    paint_first(&img);
    printf("Después de paint_first:\n");
    image_print(&img);

    paint_row(img.pixels[1], img.width);
    printf("Después de paint_row:\n");
    image_print(&img);

    struct image other;
    if (!image_load(&other, "no_existe.pgm")) {
        printf("no_existe.pgm no se pudo leer\n");
    }
    return 0;
}
