Witam, mam do napisania program:
Należy napisać następującą strukturę i funkcje służące do pracy z obrazem:
- Strukturę Image zawierającą tablicę obrazu oraz informacje o jego szerokości i
wysokości - Funkcję tworzącą strukturę Image:
struct Image CreateImage(int width, int height); - Metodę nadającą tą samą jasność wszystkim pikselom w obrazie, np.:
void fillInImage(struct Image* image, unsigned char
value)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
typedef unsigned char byte;
typedef struct { // stuktura obraz zawierajaca tablice i info o wys i szer
int height;
int width;
byte **Ptab;
}Image;
Image CreateImage(int width, int height) // f-cja tworzaca strukture
{
byte **PTab = (byte**) malloc(height*sizeof(byte*));
for (i=0; i<height; i++)
PTab[i] = (byte*) malloc (width* sizeof(byte));
return ??;
}
int main(int argc, char *argv[]) {
srand(time(0));
int h=0, w=0;
int i=0, j=0;
printf ("Podaj wysokosc obrazu: ");
scanf ("%d", &h);
printf ("Podaj szerokosc obrazu: ");
scanf ("%d", &w);
CreateImage(h,w);
/* for (i=0; i<height; i++)
{
for (j=0; j<width; j++)
PTab[i][j]=rand()%255;
}
for (i=0; i<height; i++)
{
for (j=0; j<width; j++)
printf ("\t %03u ", PTab[i][j]);
printf("\n");
}
for (i=0; i<height; i++)
free(PTab[i]);
free(PTab);
*/
system("PAUSE");
return 0;
}
Problem w tym ze nie bardzo wiem jak ta srukture stworzyc za pomoca funkcji? Co ta funkcja ma zwracac i w jaki sposob aby utworzyc nowa strukture?
karolinaa