image.cpp.txt

(2 KB) Pobierz
#include <cstdlib>
#include <iostream>
#include "image.hpp"

using namespace std;


image CreateImage()        //tworzenie struktury
{
      int height,width;
      
      cout << "podaj szerokosc :";
      cin>>  height;       
      cout << "podaj wysokosc  :";   
      cin>> width;
      image Myimage;
      
      Myimage.h=height;
      Myimage.w=width;    
      
      if (height&&width) {
          Myimage.Image = new unsigned char* [width];
          for(int i=0; i<width; i++)
          {
              Myimage.Image[i] = new unsigned char [height];                      
          }
      }else{
          Myimage.Image=NULL;                          //pusty obraz
      }     
          return Myimage;          
}

void DeleteImage (image Myimage)                       //usuwanie struktury
{      
      for(int i=0; i<Myimage.w; i++)		//wazna kolejnosc: najpierw tablice, p?zniej tablica wskaznik?w
      {
          delete[] Myimage.Image[i];                      
      } 
      delete[] Myimage.Image;
}

void fillInImage ( image* Myimage)
{
     char value;
     do{
         cout<<"podaj wartosc w zakresie 0...255  :"<<endl;         
         cin>>value;
     }while( (value>255) || (value<0) );     
      for(int i=0; i< (Myimage->w); i++)
      {
          for(int j=0; j< (Myimage->h); j++)    
          {    
              Myimage->Image[j][i]=value;       
          }
          cout<<endl;                      
      }
}     
     
void DisplayImage ( image* Myimage)                               //wyswietlanie
{
     for(int i=0; i<Myimage->w; i++)                             
      {
          for(int j=0; j<Myimage->h; j++)    
          {    
               printf("%2c",Myimage->Image[j][i]);       
          }
          cout<<endl;                      
      }         
}

void ReadPixel ( image* Myimage )
{
     int w,h;
                        do{
                          cout << "podaj szerokosc :";
                          cin>>  h;       
                          cout << "podaj wysokosc  :";   
                          cin>> w;
                        }while( w>=(Myimage->w) || h>=(Myimage->h)  );    
     printf( "wartosc piksela wynosi  : %i\n\n",Myimage->Image[h][w]);    
}

void WritePixel ( image* Myimage )
{
     int w,h,value;
                        do{
                          cout << "podaj szerokosc :";
                          cin>>  h;       
                          cout << "podaj wysokosc  :";   
                          cin>> w;
                          cout << "podaj wartosc   :";   
                          cin>> value;
                        }while( w>=(Myimage->w) || h>=(Myimage->h) || (value>255) );    
                        Myimage->Image[h][w]=value;
                        cout << "wykonano"<<endl;
   
}

void SizeImage ( image* Myimage )
{    
     cout << "wysokosc obrazu: "<<Myimage->h<<", szerokosc: "<<Myimage->w<<endl<<endl;   
}
Zgłoś jeśli naruszono regulamin