lerArquivo
#include
#include
#include "lerArquivo.h"
#define MAX 5
PGM *LePGM(char* entrada){ FILE *arq; int i,j,k; char buff[MAX]; PGM *img;
img = (PGM*)malloc(sizeof (struct PGM));
arq = fopen(entrada,"r"); fgets(buff,MAX,k); fgets(buff,MAX,k); &img->c = atoi(strtok(buf, " ")); &img->l = atoi(strtok(buf, " ")); &img->k = atoi(strtok(buf, " "));
img->dados = (unsigned char **) malloc (img->l*sizeof(unsigned char *)); for (i=0; il; i++) { img->dados[i] = (unsigned char*) malloc (img->c*sizeof(unsigned char)); } for(i=0; il; i++){ for(j=0; jc; j++){ fscanf(arq,"%u", &img->dados[i][j]); } } fclose(arq); return (img);
}
void SalvaPGM(PGM *img, char* saida){ FILE* arqout; int i,j;
arqout = fopen(saida,"w+"); fprintf(arqout,"P2\n"); fprintf(arqout,"%d %d %d\n",img->c, img->l, 255); for(i=0;il;i++){ for(j=0;jc;j++){ fprintf(arqout,"%u ",img->dados[i][j]); } fprintf(arqout,"\n"); }
}
#include
#include
#include
#include "espelhamento.h"
void EspelhamentoVertical(PGM *img, PGM *saida)
{
int i,j; saida->l = img->l; saida->c = img->c; for(i=0; il; i++) { for(j=0; jc; j++) { saida->dados[i][j] = img->dados[i][img->c-j-1]; } }
}
void EspelhamentoHorizontal(PGM *img, PGM *saida)
{
int i,j; saida->l = img->l; saida->c = img->c; for(i=0; il; i++) { for(j=0; jc; j++) { saida->dados[i][j] = img->dados[img->l-i-1][j]; } }
}
#include
#include
#include // necessário para algumas operações com arquivos
#include // necessário para strtok()
#include
#define MAX 20 // maximo de caracteres a serem lidos int main()
{
int k=0; int i,j,n; char buf[MAX] FILE *arq; FILE