Modules-old/cutil/lua_cutil.cpp
//function for halved yuyv data string
function for halved yuyv data string
function for halved yuyv data string
static int lua_string2userdata2(lua_State *L) {
  uint8_t *dout = (uint8_t *) lua_touserdata(L, 1);
  if ((dout == NULL) || !lua_islightuserdata(L, 1)) {
    return luaL_error(L, "output argument not light user data");
  }
  const char *cdata = luaL_checkstring(L, 2);
  int width = luaL_checkint(L, 3);
  int height = luaL_checkint(L, 4);
  int ind = 0;
  int cind = 0;
  int nbyte = 4; 
  for (int i=0;i<height/2;i++){
    for (int j=0;j<width*nbyte;j++){
      uint8_t bh = cdata[cind] >= 'a' ? 
		cdata[cind] - 'a' + 10 : cdata[cind] - '0';
      uint8_t bl = cdata[cind+1] >= 'a' ? 
		cdata[cind+1] - 'a' + 10 : cdata[cind+1] - '0';
      dout[ind] = (uint8_t)((bh<<4) | bl);
      ind += 1;
      cind += 2;
    }
    for (int j=0;j<width*nbyte;j++){
      dout[ind] = dout[ind-width*nbyte];
      ind += 1;
    }
  }
  return 1;
}
static int lua_string2userdata2 ( lua_State * L ) { uint8_t * dout = ( uint8_t * ) lua_touserdata ( L , 1 ) ; if ( ( dout == NULL ) || ! lua_islightuserdata ( L , 1 ) ) { return luaL_error ( L , " " ) ; } const char * cdata = luaL_checkstring ( L , 2 ) ; int width = luaL_checkint ( L , 3 ) ; int height = luaL_checkint ( L , 4 ) ; int ind = 0 ; int cind = 0 ; int nbyte = 4 ; for ( int i = 0 ; i < height / 2 ; i ++ ) { for ( int j = 0 ; j < width * nbyte ; j ++ ) { uint8_t bh = cdata [ cind ] >= ' ' ? cdata [ cind ] - ' ' + 10 : cdata [ cind ] - ' ' ; uint8_t bl = cdata [ cind + 1 ] >= ' ' ? cdata [ cind + 1 ] - ' ' + 10 : cdata [ cind + 1 ] - ' ' ; dout [ ind ] = ( uint8_t ) ( ( bh << 4 ) | bl ) ; ind += 1 ; cind += 2 ; } for ( int j = 0 ; j < width * nbyte ; j ++ ) { dout [ ind ] = dout [ ind - width * nbyte ] ; ind += 1 ; } } return 1 ; }
function for halved yuyv data string
function for halved yuyv data string
//this function is only used for yuyv //Copy previous line