Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   Related Pages   Examples  

ByteImage.cpp

00001 /* Copyright (c) 2001 C. Grigorescu S.E. Grigorescu */
00002 
00003 #include "ByteImage.h"
00004 
00005 ByteImage &ByteImage::operator&=(const ByteImage &img)
00006 {
00007   if((width!=img.width) || (height!=img.height)) { 
00008     ERROR("The images have different sizes"); 
00009   }
00010     
00011   try { 
00012     Assert<Fatal_error>(img.pixels); 
00013   }
00014   catch(Fatal_error e) {e.print("Invalid data");}
00015 
00016   for(int i=0;i<getSize();i++)
00017     if ((pixels[0][i] == ON) && (img.pixels[0][i] == ON))
00018       pixels[0][i] = ON;
00019     else
00020       pixels[0][i] = OFF;
00021 
00022   return *this;
00023 }
00024 
00025 ByteImage &ByteImage::operator|=(const ByteImage &img)
00026 {
00027   if((width!=img.width) || (height!=img.height)) { 
00028     ERROR("The images have different sizes"); 
00029   }
00030     
00031   try { 
00032     Assert<Fatal_error>(img.pixels); 
00033   }
00034   catch(Fatal_error e) {e.print("Invalid data");}
00035 
00036   for(int i=0;i<getSize();i++)
00037     if ((pixels[0][i] == OFF) && (img.pixels[0][i] == OFF))
00038       pixels[0][i] = OFF;
00039     else
00040       pixels[0][i] = ON;
00041 
00042   return *this;
00043 }
00044 
00045 ByteImage &ByteImage::operator^=(const ByteImage &img)
00046 {
00047   if((width!=img.width) || (height!=img.height)) { 
00048     ERROR("The images have different sizes"); 
00049   }
00050     
00051   try { 
00052     Assert<Fatal_error>(img.pixels); 
00053   }
00054   catch(Fatal_error e) {e.print("Invalid data");}
00055 
00056   for(int i=0;i<getSize();i++)
00057     if (((pixels[0][i] == OFF) && (img.pixels[0][i] == OFF)) ||
00058         ((pixels[0][i] == ON) && (img.pixels[0][i] == ON)))
00059       pixels[0][i] = OFF;
00060     else
00061       pixels[0][i] = ON;
00062   
00063   return *this;
00064 }
00065 
00066 
00067 ByteImage &ByteImage::operator!(void)
00068 {
00069   for(int i=0;i<getSize();i++)
00070     if (pixels[0][i] == OFF)
00071       pixels[0][i] = ON;
00072     else
00073       pixels[0][i] = OFF;
00074   return (*this);
00075 }
00076 
00077 ByteImage &ByteImage::operator=(Image< byte >& img)
00078 {
00079   width = img.getWidth();
00080   height = img.getHeight();
00081   setName(img.getName());
00082   if (img.getWidth()*img.getHeight() != 0)
00083     setPixels(img.getWidth(), img.getHeight(), img.getPixels());
00084   else
00085     pixels = NULL;
00086   return *this;
00087 }
00088 
00089 // Commented because of memory leaks (Stroustroup p.282)
00090 //
00091 //  ByteImage ByteImage::operator&(const ByteImage &img)
00092 //  {
00093 //    if((width!=img.width) || (height!=img.height)) { 
00094 //      ERROR("The images have different sizes"); 
00095 //    }
00096     
00097 //    try { 
00098 //      Assert<Fatal_error>(img.pixels); 
00099 //    }
00100 //    catch(Fatal_error e) {e.print("Invalid data");}
00101 
00102 //    ByteImage rez("rez");
00103 //    rez.makeImage(width, height);
00104 
00105 //    for(int i=0;i<getSize();i++)
00106 //      rez.pixels[0][i] = pixels[0][i] & img.pixels[0][i];
00107 
00108 //    return rez;
00109 //  }
00110 
00111 //  ByteImage ByteImage::operator|(const ByteImage &img)
00112 //  {
00113 //    if(*this!=img) { ERROR("The images have different sizes"); }
00114     
00115 //    try { Assert<Fatal_error>(img.pixels); }
00116 //    catch(Fatal_error e) {e.print();}
00117 
00118 //    ByteImage rez("rez");
00119 //    rez.makeImage(width, height);
00120 
00121 //    for(int i=0;i<getSize();i++)
00122 //      rez.pixels[0][i] = pixels[0][i] | img.pixels[0][i];
00123 
00124 //    return rez;
00125 //  }
00126 
00127 
00128 
00129