Alkalmak‎ > ‎2017-18-as tanév‎ > ‎9. alkalom‎ > ‎

XBM beolvasás

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#include "image.xbm"

/** Felfele kerekíti a/b-t */
int ceil_quotient(int a, int b) {
    return (a - 1) / b + 1;
}

bool getPixel(int x, int y) {
    int index = y * ceil_quotient(image_width, 8) + x / 8;
    int bitindex = x % 8;

    return image_bits[index] >> bitindex & 1;
}

int main(int argc, char** argv) {

    for (int y = 0; y < image_height; ++y) {
        for (int x = 0; x < image_width; ++x) {
            if(getPixel(x, y))
                printf("#");
            else
                printf(" ");
        }
        printf("\n");
    }

    return 0;
}
ċ
Bence Hornák,
2017. nov. 20. 1:25