Example #1
0
/*****************************************************************************\
 image:MatchColorSpace(image2)
\*****************************************************************************/
static int imluaImageMatchColorSpace (lua_State *L)
{
  imImage *image1 = imlua_checkimage(L, 1);
  imImage *image2 = imlua_checkimage(L, 2);

  lua_pushboolean(L, imImageMatchColorSpace(image1, image2));
  return 1;
}
Example #2
0
/*****************************************************************************\
 image:MergeAttributes(dst_image)
\*****************************************************************************/
static int imluaImageMergeAttributes (lua_State *L)
{
  imImage *src_image = imlua_checkimage(L, 1);
  imImage *dst_image = imlua_checkimage(L, 2);

  imImageMergeAttributes(src_image, dst_image);
  return 0;
}
Example #3
0
/*****************************************************************************\
 image:CopyData()
\*****************************************************************************/
static int imluaImageCopyData (lua_State *L)
{
  imImage* src_image = imlua_checkimage(L, 1);
  imImage* dst_image = imlua_checkimage(L, 2);

  imlua_match(L, src_image, dst_image);
  imImageCopyData(src_image, dst_image);
  return 0;
}
Example #4
0
static int ImageFromImImage(lua_State *L)
{
  imImage* im_image = imlua_checkimage(L, 1);
  Ihandle* image = IupImageFromImImage(im_image);
  iuplua_pushihandle(L, image);
  return 1;
}
Example #5
0
static int imluaImageMakeGray (lua_State *L)
{
  imImage *image = imlua_checkimage(L, 1);
  imlua_checkdatatype(L, 1, image, IM_BYTE);
  imImageMakeGray(image);
  return 0;
}
Example #6
0
static int GetImageNativeHandle(lua_State *L)
{
  imImage* im_image = imlua_checkimage(L, 1);
  void* native_handle = IupGetImageNativeHandle(im_image);
  lua_pushlightuserdata(L, native_handle);
  return 1;
}
Example #7
0
/*****************************************************************************\
 image:Clone()
\*****************************************************************************/
static int imluaImageClone (lua_State *L)
{
  imImage* image = imlua_checkimage(L, 1);
  imImage *new_image = imImageClone(image);
  imlua_pushimage(L, new_image);
  return 1;
}
Example #8
0
/*****************************************************************************\
 image indexing
\*****************************************************************************/
static int imluaImage_index (lua_State *L)
{
  imImage *image = imlua_checkimage(L, 1);

  if (lua_isnumber(L, 2))
  {
    /* handle numeric indexing */
    int channel = luaL_checkint(L, 2);

    /* create channel */
    int depth = image->has_alpha? image->depth+1: image->depth;
    if (channel < 0 || channel >= depth)
      luaL_argerror(L, 2, "invalid channel, out of bounds");

    imlua_newimagechannel(L, image, channel);
  }
  else if (lua_isstring(L, 2))
  {
    /* get raw method */
    lua_getmetatable(L, 1);
    lua_pushvalue(L, 2);
    lua_rawget(L, -2);
  }
  else
  {
    lua_pushnil(L);
  }

  return 1;
}
Example #9
0
/*****************************************************************************\
 file:SaveImage()
\*****************************************************************************/
static int imluaFileSaveImage (lua_State *L)
{
  imFile *ifile = imlua_checkfile(L, 1);
  imImage *image = imlua_checkimage(L, 2);

  imlua_pusherror(L, imFileSaveImage(ifile, image));
  return 1;
}
Example #10
0
/*****************************************************************************\
 image:GetPalette()
\*****************************************************************************/
static int imluaImageGetPalette (lua_State *L)
{
  imImage *image = imlua_checkimage(L, 1);
  long* color = malloc(sizeof(long) * 256);
  memcpy(color, image->palette, sizeof(long) * 256);
  imlua_pushpalette(L, color, 256);
  return 1;
}
Example #11
0
/*****************************************************************************\
 image:Reshape()
\*****************************************************************************/
static int imluaImageReshape (lua_State *L)
{
  imImage* im = imlua_checkimage(L, 1);
  int width = luaL_checkint(L, 2);
  int height = luaL_checkint(L, 3);

  imImageReshape(im, width, height);
  return 0;
}
Example #12
0
/*****************************************************************************\
 image:Save(filename, format)
\*****************************************************************************/
static int imluaImageSave (lua_State *L)
{
  imImage *image = imlua_checkimage(L, 1);
  const char *file_name = luaL_checkstring(L, 2);
  const char *format = imlua_checkformat(L, 3);

  imlua_pusherror(L, imFileImageSave(file_name, format, image));
  return 1;
}
Example #13
0
/*****************************************************************************\
 image:SetPalette
\*****************************************************************************/
static int imluaImageSetPalette (lua_State *L)
{
  imImage *image = imlua_checkimage(L, 1);
  imluaPalette *pal = imlua_checkpalette(L, 2);
  long* palette = (long*)malloc(sizeof(long)*256);
  memcpy(palette, pal->color, pal->count*sizeof(long));
  imImageSetPalette(image, palette, pal->count);
  return 0;
}
Example #14
0
static int imluaImageSetGray(lua_State *L)
{
  imImage *image = imlua_checkimage(L, 1);
  if (image->color_space != IM_MAP && 
      image->color_space != IM_BINARY)
      luaL_argerror(L, 1, "color space must be Map or Binary");
  imlua_checkdatatype(L, 1, image, IM_BYTE);
  imImageSetGray(image);
  return 0;
}
Example #15
0
/*****************************************************************************\
 image:CopyPlane()
\*****************************************************************************/
static int imluaImageCopyPlane(lua_State *L)
{
  imImage* src_image = imlua_checkimage(L, 1);
  int src_plane = luaL_checkint(L, 2);
  imImage* dst_image = imlua_checkimage(L, 3);
  int dst_plane = luaL_checkint(L, 4);
  int src_depth, dst_depth;

  imlua_matchdatatype(L, src_image, dst_image);

  src_depth = src_image->has_alpha? src_image->depth+1: src_image->depth;
  if (src_plane < 0 || src_plane >= src_depth)
    luaL_argerror(L, 2, "invalid source channel, out of bounds");

  dst_depth = dst_image->has_alpha? dst_image->depth+1: dst_image->depth;
  if (dst_plane < 0 || dst_plane >= dst_depth)
    luaL_argerror(L, 4, "invalid destiny channel, out of bounds");

  imImageCopyPlane(src_image, src_plane, dst_image, dst_plane);
  return 0;
}
Example #16
0
/*****************************************************************************\
 file:LoadBitmapFrame()
\*****************************************************************************/
static int imluaFileLoadBitmapFrame (lua_State *L)
{
  imFile *ifile = imlua_checkfile(L, 1);
  int index = luaL_checkinteger(L, 2);
  imImage *image = imlua_checkimage(L, 3);
  int error;

  imFileLoadBitmapFrame(ifile, index, image, &error);
  imlua_pusherror(L, error);

  return 1;
}
Example #17
0
/*****************************************************************************\
 vc:OneFrame(image)
\*****************************************************************************/
static int imluaVideoCaptureOneFrame (lua_State *L)
{
  imVideoCapture *vc = imlua_checkvideocapture(L, 1);
  imImage *image = imlua_checkimage(L, 2);

  if (!(image->color_space == IM_RGB || image->color_space == IM_GRAY))
    luaL_argerror(L, 2, "image must be of RGB or Gray color spaces");
  imlua_checkdatatype(L, 2, image, IM_BYTE);

  lua_pushboolean(L, imVideoCaptureOneFrame(vc, image->data[0], image->color_space));

  return 1;
}
Example #18
0
/*****************************************************************************\
 image:GetOpenGLData()
\*****************************************************************************/
static int imluaImageGetOpenGLData (lua_State *L)
{
  int format;
  imbyte* gldata;
  imImage *image = imlua_checkimage(L, 1);

  gldata = imImageGetOpenGLData(image, &format);
  if (!gldata)
  {
    lua_pushnil(L);
    return 1;
  }

  lua_pushlightuserdata(L, gldata);
  lua_pushinteger(L, format);
  return 2;
}
Example #19
0
/*****************************************************************************\
 image:GetAttributeList()
\*****************************************************************************/
static int imluaImageGetAttributeList (lua_State *L)
{
  int i, attrib_count;
  char **attrib;

  imImage* image = imlua_checkimage(L, 1);

  imImageGetAttributeList(image, NULL, &attrib_count);

  attrib = (char**) malloc(attrib_count * sizeof(char*));

  imImageGetAttributeList(image, attrib, &attrib_count);

  lua_createtable(L, attrib_count, 0);
  for (i = 0; i < attrib_count; i++)
  {
    lua_pushstring(L, attrib[i]);
    lua_rawseti(L, -2, i+1);
  }

  return 1;
}
Example #20
0
/*****************************************************************************\
 image:HasAlpha()
\*****************************************************************************/
static int imluaImageHasAlpha(lua_State *L)
{
  imImage *im = imlua_checkimage(L, 1);
  lua_pushboolean(L, im->has_alpha);
  return 1;
}
Example #21
0
/*****************************************************************************\
 image:ColorSpace()
\*****************************************************************************/
static int imluaImageColorSpace(lua_State *L)
{
  imImage *im = imlua_checkimage(L, 1);
  lua_pushnumber(L, im->color_space);
  return 1;
}
Example #22
0
/*****************************************************************************\
 image:DataType()
\*****************************************************************************/
static int imluaImageDataType(lua_State *L)
{
  imImage *im = imlua_checkimage(L, 1);
  lua_pushnumber(L, im->data_type);
  return 1;
}
Example #23
0
/*****************************************************************************\
 image:SetAttribute(attrib, data_type, data)
\*****************************************************************************/
static int imluaImageSetAttribute (lua_State *L)
{
  int i, count = 0;
  void *data = NULL;

  imImage* image = imlua_checkimage(L, 1);
  const char *attrib = luaL_checkstring(L, 2);
  int data_type = luaL_checkint(L, 3);

  if (!lua_isnil(L, 4))
  {
    if (lua_isstring(L, 4) && data_type != IM_BYTE)
      luaL_argerror(L, 4, "if value is string, then data type must be byte");
    else
    {
      luaL_checktype(L, 4, LUA_TTABLE);
      count = imlua_getn(L, 4);
      data = malloc(imDataTypeSize(data_type) * count);
    }

    switch (data_type)
    {
    case IM_BYTE:
      {
        if (lua_isstring(L, 4))
        {
          const char* str = lua_tostring(L, 4);
          count = strlen(str)+1;
          data = malloc(imDataTypeSize(data_type) * count);
          memcpy(data, str, count);
        }
        else
        {
          imbyte *data_byte = (imbyte*) data;
          for (i = 0; i < count; i++)
          {
            lua_rawgeti(L, 4, i+1);
            data_byte[i] = (imbyte)luaL_checkint(L, -1);
            lua_pop(L, 1);
          }
        }
      }
      break;

    case IM_SHORT:
      {
        short *data_short = (short*) data;
        for (i = 0; i < count; i++)
        {
          lua_rawgeti(L, 4, i+1);
          data_short[i] = (short)luaL_checkint(L, -1);
          lua_pop(L, 1);
        }
      }
      break;

    case IM_USHORT:
      {
        imushort *data_ushort = (imushort*) data;
        for (i = 0; i < count; i++)
        {
          lua_rawgeti(L, 4, i+1);
          data_ushort[i] = (imushort)luaL_checkint(L, -1);
          lua_pop(L, 1);
        }
      }
      break;

    case IM_INT:
      {
        int *data_int = (int*) data;
        for (i = 0; i < count; i++)
        {
          lua_rawgeti(L, 4, i+1);
          data_int[i] = luaL_checkint(L, -1);
          lua_pop(L, 1);
        }
      }
      break;

    case IM_FLOAT:
      {
        float *data_float = (float*) data;
        for (i = 0; i < count; i++)
        {
          lua_rawgeti(L, 4, i+1);
          data_float[i] = (float) luaL_checknumber(L, -1);
          lua_pop(L, 1);
        }
      }
      break;

    case IM_CFLOAT:
      {
        float *data_float = (float*) data;
        for (i = 0; i < count; i++)
        {
          int two;
          float *value = imlua_toarrayfloat(L, -1, &two, 1);
          if (two != 2)
          {
            free(value);
            luaL_argerror(L, 4, "invalid value");
          }

          data_float[i] = value[0];
          data_float[i+1] = value[1];
          free(value);
          lua_pop(L, 1);
        }        
      }
      break;
    }
  }

  imImageSetAttribute(image, attrib, data_type, count, data);
  return 0;
}
Example #24
0
/*****************************************************************************\
 image:SetAlpha()
\*****************************************************************************/
static int imluaImageSetAlpha (lua_State *L)
{
  imImageSetAlpha(imlua_checkimage(L, 1), (float)luaL_checknumber(L, 2));
  return 0;
}
Example #25
0
static int imluaImageRemoveAlpha (lua_State *L)
{
  imImageRemoveAlpha(imlua_checkimage(L, 1));
  return 0;
}
Example #26
0
/*****************************************************************************\
 image:Clear()
\*****************************************************************************/
static int imluaImageClear (lua_State *L)
{
  imImageClear(imlua_checkimage(L, 1));
  return 0;
}
Example #27
0
/*****************************************************************************\
 image:GetAttribute(attrib)
\*****************************************************************************/
static int imluaImageGetAttribute (lua_State *L)
{
  int data_type;
  int i, count;
  const void *data;
  int as_string = 0;

  imImage* image = imlua_checkimage(L, 1);
  const char *attrib = luaL_checkstring(L, 2);

  data = imImageGetAttribute(image, attrib, &data_type, &count);
  if (!data)
  {
    lua_pushnil(L);
    return 1;
  }

  if (data_type == IM_BYTE && lua_isboolean(L, 3))
    as_string = lua_toboolean(L, 3);

  if (!as_string)
    lua_newtable(L);
  
  switch (data_type)
  {
  case IM_BYTE:
    {
      if (as_string)
      {
        lua_pushstring(L, (const char*)data);
      }
      else
      {
        imbyte *data_byte = (imbyte*) data;
        for (i = 0; i < count; i++, data_byte++)
        {
          lua_pushnumber(L, *data_byte);
          lua_rawseti(L, -2, i+1);
        }
      }
    }
    break;

  case IM_SHORT:
    {
      short *data_short = (short*) data;
      for (i = 0; i < count; i++, data_short += 2)
      {
        lua_pushnumber(L, *data_short);
        lua_rawseti(L, -2, i+1);
      }
    }
    break;

  case IM_USHORT:
    {
      imushort *data_ushort = (imushort*) data;
      for (i = 0; i < count; i++, data_ushort += 2)
      {
        lua_pushnumber(L, *data_ushort);
        lua_rawseti(L, -2, i+1);
      }
    }
    break;

  case IM_INT:
    {
      int *data_int = (int*) data;
      for (i = 0; i < count; i++, data_int++)
      {
        lua_pushnumber(L, *data_int);
        lua_rawseti(L, -2, i+1);
      }
    }
    break;

  case IM_FLOAT:
    {
      float *data_float = (float*) data;
      for (i = 0; i < count; i++, data_float++)
      {
        lua_pushnumber(L, *data_float);
        lua_rawseti(L, -2, i+1);
      }
    }
    break;

  case IM_CFLOAT:
    {
      float *data_float = (float*) data;
      for (i = 0; i < count; i++, data_float += 2)
      {
        imlua_newarrayfloat(L, data_float, 2, 1);
        lua_rawseti(L, -2, i+1);
      }        
    }
    break;
  }

  lua_pushnumber(L, data_type);

  return 2;
}
Example #28
0
/*****************************************************************************\
 image:Height()
\*****************************************************************************/
static int imluaImageHeight(lua_State *L)
{
  imImage *im = imlua_checkimage(L, 1);
  lua_pushnumber(L, im->height);
  return 1;
}
Example #29
0
/*****************************************************************************\
 image:Depth()
\*****************************************************************************/
static int imluaImageDepth(lua_State *L)
{
  imImage *im = imlua_checkimage(L, 1);
  lua_pushnumber(L, im->depth);
  return 1;
}
Example #30
0
/*****************************************************************************\
 image:isBitmap()
\*****************************************************************************/
static int imluaImageIsBitmap (lua_State *L)
{
  lua_pushboolean(L, imImageIsBitmap(imlua_checkimage(L, 1)));
  return 1;
}