#include "../const.h"
#include "MapOnExpanded.h"
#include "BMP.h"


// This function maps every pixel in the image argument onto the expanded image resolution
bool
MapOnExpanded(const Image& image, Image& exp)
{

int x, y, x1, y1;

#ifdef FUNC_TRACK
PRN(("Starting MapOnExpanded\n"));
#endif

exp = Image(WIDTH_EH, HEIGHT_EH, 0, 0);
if (exp.data == NULL)
   return false;

for (x = 0; x < image.width; x++) {
     for (y = 0; y < image.height; y++) {
            for (x1 = (4 * (x + image.offsetX)); x1 < (4 * (x + image. offsetX + 1)); x1++) {
                for (y1 = (4 * (y + image.offsetY)); y1 < (4 * (y + image.offsetY + 1)); y1++)  {
                    exp.data[x1][y1] = image.data[x][y];
                }
            }

      }
}

#ifdef FUNC_TRACK
PRN(("Ending MapOnExpanded\n"));
#endif

return true;

}

// This function maps the extremes of a bounding box onto the expanded image resolution
void
MapBBOnExpanded(int*& bounding_box)
{

int i;

#ifdef FUNC_TRACK
PRN(("Starting MapBBOnExpanded\n"));
#endif

for (i = 0; i < 4; i++) {
    bounding_box[i] *= 4;
}


#ifdef FUNC_TRACK
PRN(("Ending MapBBOnExpanded\n"));
#endif

return;

}


// This function simultaneously maps all images of interest onto the expanded image resolution.
// It also returns the expanded face bounding box.
bool
ExpandImages(const Image& mouth, const Image& eye_left, const Image& eye_right, 
             Image& mouth_exp, Image& eye_left_exp, Image& eye_right_exp, int*& face_bb)
{

bool result;

#ifdef FUNC_TRACK
PRN(("Starting ExpandImages\n"));
#endif

result = MapOnExpanded(mouth, mouth_exp);
if (!result)
   return false;
result = MapOnExpanded(eye_left, eye_left_exp);
if (!result)
   return false;
result = MapOnExpanded(eye_right, eye_right_exp);
if (!result)
   return false;
MapBBOnExpanded(face_bb);


#ifdef FUNC_TRACK
PRN(("Ending ExpandImages\n"));
#endif

return true;

}




