/* GEM-View 3.00 PROCESSING Modul: Bild horizontal verdoppeln (verzerren)
   (c) 22.10.1993 by Dieter Fiebelkorn
                     Grner Weg 29a
                     D-45768 Marl
                     (GERMANY)
*/

#include <stdio.h>
#include "image.h"
#include "moduls.h"

unsigned long hdouble2(unsigned short);

Image* gvw_main(PROC_Structure *procS, int verbose)
{
    Image  *image;
    Image  *oimage;
    char   *data;
    char   *src, *dst;
    long    width, height;
    long    x, y, val;
    
    image = procS->image;
    if (image == NULL)
    {
      procS->events.alert(1, "[3][ | No image for process!  | ][  Abort  ]");
      return(NULL);
    }
    data = image->data;
    if (data == NULL)
    {
      procS->events.alert(1, "[3][ | No data in image!  | ][  Abort  ]");
      return(NULL);
    }

    oimage = procS->images.newGEMImage(image->title, 2 * image->unalignwidth, image->height, image->depth);
    if (oimage == NULL)
    {
      procS->events.alert(1, "[3][ | Not enough for new image!  | ][  Abort  ]");
      return(NULL);
    }
    src = data;
    dst = oimage->data;
    for (x = (long)image->rgb.used - 1; x >= 0; x--)
    {
        oimage->rgb.red  [x] = image->rgb.red  [x];
        oimage->rgb.green[x] = image->rgb.green[x];
        oimage->rgb.blue [x] = image->rgb.blue [x];
    }
    oimage->rgb.used = image->rgb.used;
    
    width   = (long)(image->unalignwidth + 7) >> 3;
    height  = (long)image->height * image->depth;
    
    for (y = height; y > 0; y--)
    {
        for (x = width >> 1; x > 0; x--)
            *((unsigned long*)dst)++ = hdouble2(*((unsigned short*)src)++);
        if (width & 0x01) {
            val = hdouble2(*((unsigned short*)src)++);
            *((unsigned short*)dst)++ = *(unsigned short*)&val;
        }
    }
    
    return(oimage);
}
