Esempio n. 1
0
int main( int argc, char const * const argv[] )
{
   if( 2 <= argc )
   {
      image_t image ;
      if( imageFromFile( argv[1], image ) )
      {
         unsigned x = 0 ;
         if( 3 <= argc )
            x = strtoul( argv[2], 0, 0 );

         unsigned y = 0 ;
         if( 4 <= argc )
            y = strtoul( argv[3], 0, 0 );
#ifdef __DAVINCIFB__
#else
         getFB().render( x, y, 
                         image.width_, image.height_, 
                         (unsigned short *)image.pixData_ );
#endif
      }
      else
         perror( argv[1] );
   }
   else
      fprintf( stderr, "Usage: imgFile fileName [x [y]]\n" );
   return 0 ;
}   
Esempio n. 2
0
void uiState_t :: setState
   ( input_e input,
     bool    setNotCleared )
{
   unsigned char const imgBits  = lock_e | gateOpen_e ;
   unsigned char const oldState = state_ ;
   if( setNotCleared )
      state_ |= input ;
   else
      state_ &= ~input ;

   if( ( oldState & imgBits ) != ( state_ & imgBits ) )
   {
      image_t const &image = *images_[state_ & imgBits];
      if( image.pixData_ )
         getFB().render( 0, 0, image.width_, image.height_, (unsigned short *)image.pixData_ );
      if( state_ & touch_e )
      {
         invertScreen();
      }
   }
   else if( ( state_ & touch_e ) != ( oldState & touch_e ) )
   {
      invertScreen();
   }
}
Esempio n. 3
0
static void invertScreen( void )
{
   fbDevice_t &fb = getFB();
   unsigned long *fbMem = (unsigned long *)fb.getMem();
   unsigned long longs = fb.getMemSize()/sizeof(fbMem[0]);

   while( 0 < longs-- )
   {
      *fbMem = ~(*fbMem);
      fbMem++ ;
   }
}
Esempio n. 4
0
jsMouse_t::jsMouse_t( char const *devName )
   : inputPoll_t( pollHandlers_, devName )
   , curBox_( 0 )
   , down_( false )
   , wheel_( 0 )
{
   if( !isOpen() ){
      perror( devName );
      return ;
   }
   printf( "%s\n", __PRETTY_FUNCTION__ );
   assert( cursor_ );
   
   fbDevice_t &fb = getFB();
   cursor_->setPos(fb.getWidth()/2, fb.getWidth()/2);
   cursor_->activate();
}
int main()
{
	// Initialize services
	srvInit();
	aptInit();
	hidInit(NULL);
	gfxInitDefault();

	// Main loop
	while (aptMainLoop())
	{
		//As nop90 suggested
		getFB();

		//Gets input (keys and touch)
		getInput();

		//Prints the GUI
		printGUI();  

		//Do stuff
		app();

		//Exit code
		if (input & KEY_START) break;
	
		// Flush and swap framebuffers
		gfxFlushBuffers();
		gfxSwapBuffers();

		//Wait for VBlank
		gspWaitForVBlank();

	}

	// Exit services
	gfxExit();
	hidExit();
	aptExit();
	srvExit();
	return 0;
}
Esempio n. 6
0
int main( int argc, char const * const argv[] )
{
    printf( "Hello, %s\n", argv[0] );
    fbDevice_t &fb = getFB();

    if( 3 < argc )
    {
        unsigned long offset = strtoul( argv[1],0,0 );
        unsigned long numPixels = strtoul( argv[2],0,0 );
        unsigned short pixValue = strtoul(argv[3],0,0);

        unsigned short *vidMem = (unsigned short *)
                                 ((unsigned long)fb.getMem()+offset);
        for( unsigned i = 0 ; i < numPixels ; i++ )
            *vidMem++ = pixValue ;
    }
    else
        fprintf( stderr, "Usage: videoSet offset(bytes) pixelCount value\n" );

    return 0 ;
}
Esempio n. 7
0
static JSBool
jsDisableMouse( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval )
{
	*rval = JSVAL_FALSE ;
#if defined(KERNEL_FB_SM501) && (KERNEL_FB_SM501 == 1)
	fbDevice_t &fb = getFB();
	unsigned long reg = SMIPCURSOR_ADDR ;
	int res = ioctl( fb.getFd(), SM501_READREG, &reg );
	if( 0 == res ){
		struct reg_and_value rv ;
		rv.reg_ = SMIPCURSOR_ADDR ;
		rv.value_ = reg & ~0x80000000 ;
		res = ioctl( fb.getFd(), SM501_WRITEREG, &rv );
		if( 0 == res ){
			*rval = true ;
		}
		else
                        JS_ReportError( cx, "saving SM-501 CURSORADDR\n" );

	}
	else
		JS_ReportError( cx, "reading SM-501 CURSORADDR\n" );
#else
                                if( 0 != cursor_ ){
                                   delete cursor_ ;
                                   cursor_ = 0 ;
                                }
                                if( 0 != mouse_ ){
                                   delete mouse_ ;
                                   mouse_ = 0 ;
                                   printf( "%s:deleted mouse\n", __PRETTY_FUNCTION__ );
                                }

				*rval = JSVAL_TRUE ;
#endif
	
	return JS_TRUE ;
}
Esempio n. 8
0
int main( int argc, char const * const argv[] )
{
   fbDevice_t &fb = getFB();
   image_t img ;
   memset( &img, 0, sizeof( img ) );
   
   if( 1 < argc )
   {
      if( imageFromFile( argv[1], img ) )
         printf( "%s: %u x %u pixels\n", argv[1], img.width_, img.height_ );
      else
         perror( argv[1] );
      
   }
   else
   {
      img.pixData_ = fb.getRow(0);
      img.width_   = fb.getWidth();
      img.height_  = fb.getHeight();
      img.alpha_   = 0 ;
   }

   if( img.pixData_ )
   {
      dither_t dither( (unsigned short const *)img.pixData_, img.width_, img.height_ );
      unsigned bpl = bitmap_t::bytesPerRow(img.width_);

      unsigned char * const bitmapBytes = new unsigned char[bpl*img.height_];
      bitmap_t bmp( bitmapBytes, img.width_, img.height_ );
      for( unsigned row = 0 ; row < img.height_ ; row++ )
      {
         unsigned char mask = 0x80 ;
         unsigned char *outRow = bitmapBytes+row*bpl ;
         for( unsigned col = 0 ; col < img.width_ ; col++ )
         {
            if( dither.isBlack(col,row) )
               *outRow |= mask ;
            else
               *outRow &= ~mask ;

            mask >>= 1 ;
            if( 0 == mask ){
               mask = 0x80 ;
               outRow++ ;
            }
         } // each column
      } // each row

      void const *outData ;
      unsigned outSize ;
      if( bitmapToPNG( bmp, outData, outSize ) )
      {
         printf( "%u bytes of output\n", outSize );
         char const *outFile = ( 2 < argc ) ? argv[2] : "/tmp/img.png" ;
         FILE *fOut = fopen( outFile, "wb" );
         if( fOut )
         {
            fwrite( outData, 1, outSize, fOut );
            fclose( fOut );
            printf( "%u bytes written to %s\n", outSize, outFile );
         }
         else
            perror( outFile );
         free((void *)outData);
      }
      else
         printf( "Error converting bitmap\n" );
   }
Esempio n. 9
0
void jsMouse_t::onData( struct input_event const &event )
{
   assert( cursor_ );

   cursor_->getPos(x_,y_);

   switch( event.type ){
      case EV_SYN:
         cursor_->setPos(x_,y_);
         if( down_ ){
            press();
         }
         if( 0 != wheel_ ){
            printf( "wheel motion: %d\n", wheel_ );
            if( JSVAL_VOID != onWheelCode_ ){
               jsval args[2] = {
                  INT_TO_JSVAL(wheel_)
               ,  JSVAL_NULL
               };
               printf( "call handler here\n" );
               executeCode(JS_GetGlobalObject(execContext_),onWheelCode_, __func__, 1,args);
            } else
               printf( "No wheel handler\n" );
            wheel_ = 0 ;
         }
         break;
      case EV_REL: {
         if( (REL_X==event.code) || (REL_Y==event.code) ){
                 fbDevice_t &fb = getFB();
                 int value = (int)event.value ;
                 int pos = (int)( (REL_X == event.code) ? x_ : y_ );
                 int max = (int)( (REL_X == event.code) ? fb.getWidth() : fb.getHeight() ) - 1 ;
                 pos += value ;
                 if( 0 > pos )
                    pos = 0 ;
                 else if( max < pos ){
                    pos = max ;
                 }
                 if( REL_X == event.code )
                    x_ = pos ;
                 else
                    y_ = pos ;
                 cursor_->setPos(x_,y_);
         } else if(REL_WHEEL==event.code){
                 wheel_ += (int)event.value ;
         } else 
                 printf( "Unknown rel value, code 0x%x, value 0x%x\n", event.code, event.value );
         break;
      }
      case EV_KEY: {
         int down = event.value ;
         int left = ( event.code == LMOUSEBUTTON );
#if defined(KERNEL_FB_DAVINCI) && (KERNEL_FB_DAVINCI == 1)
         if( down ){
            cursor_->setWidth(SMALL);
            cursor_->setHeight(SMALL);
         }
         else {
            cursor_->setWidth(BIG);
            cursor_->setHeight(BIG);
         }
#endif

         if( left && ( down_ != down ) ){
            if( down ){
               press();
            }
            else {
               release();
            }
            down_ = down ;
         } // left button state changed

         break;
      }
      default:
         inputPoll_t::onData(event);
   }
}
Esempio n. 10
0
sm501alpha_t::sm501alpha_t( 
	mode_t mode,
	unsigned x, 
	unsigned y,
	unsigned w,
	unsigned h )
   : mode_( mode )
   , fd_( open( "/dev/" SM501ALPHA_CLASS, O_RDWR ) )
   , pos_( makeRect(0,0,0,0) )
   , ram_( 0 )
   , ramOffs_( 0 )
{
   if( isOpen() ){
      fcntl( fd_, F_SETFD, FD_CLOEXEC);
      fbDevice_t &fb = getFB();

      if( 0 == w ){
              w = fb.getWidth();
	      if( 0 != x )
		      w	-= x ;
      }
      if( 0 == h ){
              h = fb.getHeight();
	      if( 0 != y )
		      h	-= y ;
      }

      struct sm501_alphaPlane_t plane ;

      plane.xLeft_  = pos_.xLeft_   = x ;
      plane.yTop_   = pos_.yTop_    = y ;
      plane.width_  = pos_.width_   = w ;
      plane.height_ = pos_.height_  = h ;
      plane.mode_   = mode ;
      plane.planeOffset_ = 0 ;

      unsigned short const adder = (2<<11)|(4<<5)|2 ;
      unsigned short *outWords = (unsigned short *)plane.palette_ ;
      unsigned short palVal = 0 ;
      
//      printf( "color palette:\n" );
      for( unsigned i = 0 ; i < 16 ; i++ ){
//         printf( "   %04x\n", palVal );
         *outWords++ = palVal ;
         palVal += adder ;
      }
      
      outWords[-1] = 0xFFFF ; // make it truly white

      int rval = ioctl( fd_, SM501ALPHA_SETPLANE, &plane );
      if( 0 == rval ){
         unsigned bytes = plane.width_*plane.height_*2 ;
         printf( "mapping %u bytes of RAM\n", bytes );
         ram_ = (unsigned char *)mmap( 0, bytes, PROT_READ|PROT_WRITE, MAP_SHARED, fd_, 0 );
         if( MAP_FAILED == ram_ ){
            perror( "mmap sm501alpha" );
            ram_ = 0 ;
         }
         ramOffs_ = plane.planeOffset_ ;
         return ;
      }
      else
         perror( "SM501ALPHA_SETPLANE" );
      close( fd_ );
      fd_ = 0 ;
   }
}
Esempio n. 11
0
bool imagePNG( void const    *inData,     // input
               unsigned long  inSize,     // input
               void const    *&pixData,   // output
               unsigned short &width,     // output
               unsigned short &height,    // output
               void const    *&alpha )    // output : 0 if none, delete [] when done
{
   pixData = alpha = 0 ; width = height = 0 ;

   png_bytep pngData = (png_bytep)inData ;
   unsigned const pngLength = inSize ;
   if( 8 < pngLength )
   {
      if( 0 == png_sig_cmp( pngData, 0, pngLength ) )
      {
         png_structp png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING, 0, 0, 0 );
         {
            if( png_ptr )
            {
               png_infop info_ptr = png_create_info_struct(png_ptr);
               if( info_ptr )
               {
                  png_infop end_info = png_create_info_struct(png_ptr);
                  if( end_info )
                  {
                     if( 0 == setjmp( png_jmpbuf( png_ptr ) ) )
                     {
                        pngData_t pngFile ;
                        pngFile.data_   = pngData ;
                        pngFile.length_ = pngLength ;
                        
                        png_set_read_fn( png_ptr, &pngFile, pngRead );

                        png_read_info(png_ptr, info_ptr);
#ifdef __STANDALONE__
dumpPNGInfo( info_ptr );
#endif
                        int interlace_type, compression_type, filter_type;
                        png_uint_32 lWidth, lHeight;
                        int bit_depth, color_type;

                        png_get_IHDR( png_ptr, info_ptr, &lWidth, &lHeight,
                                      &bit_depth, &color_type, &interlace_type,
                                      &compression_type, &filter_type);
                        if( PNG_COLOR_MASK_PALETTE == ( PNG_COLOR_MASK_PALETTE & color_type ) )
                           png_set_palette_to_rgb( png_ptr );

                        png_read_update_info(png_ptr, info_ptr);

                        png_bytep *const row_pointers = new png_bytep[lHeight];
                        unsigned const rowBytes = png_get_rowbytes( png_ptr, info_ptr );

                        for( unsigned row = 0; row < lHeight; row++ )
                        {
                           row_pointers[row] = (png_bytep)png_malloc( png_ptr, rowBytes );
                        }
                        
                        png_read_image( png_ptr, row_pointers );

                        width  = (unsigned short)lWidth ;
                        height = (unsigned short)lHeight ;

                        fbDevice_t &fb = getFB();

                        unsigned char *const alphaChannel = ( color_type & PNG_COLOR_MASK_ALPHA )
                                                            ? new unsigned char [ width*height ]
                                                            : 0 ;

                        unsigned short *const pixMap = new unsigned short [ width*height ];
                        for( unsigned row = 0 ; row < height ; row++ )
                        {
                           unsigned char const *imgRow = row_pointers[row];
                           for( unsigned column = 0 ; column < width ; column++, imgRow += info_ptr->channels )
                           {
                              pixMap[row*width+column] = fb.get16( imgRow[0], imgRow[1], imgRow[2] );
                              if( alphaChannel )
                                 alphaChannel[row*width+column] = imgRow[3];
                           }
                        }

                        pixData = pixMap ;
                        alpha   = alphaChannel ;

                        for( unsigned row = 0; row < lHeight ; row++ )
                           png_free( png_ptr, row_pointers[row] );
                        
                        delete [] row_pointers ;
                     }
                     else
                        fprintf( stderr, "Internal PNG error\n" );

                     png_destroy_read_struct( &png_ptr, &info_ptr, &end_info );
                  }
               }
               else
                  png_destroy_read_struct( &png_ptr, 0, 0 );
            }
         }
      }
      else
         fprintf( stderr, "Not a PNG file\n" );
   }
   else
      fprintf( stderr, "PNG too short!\n" );

   return 0 != pixData ;

}
Esempio n. 12
0
/**
 * WAIT
 */
int handleWAIT(sessionid_t sessionid, bus_t bus, char *device,
               char *parameter, char *reply, size_t length)
{
    struct timeval time;
    int rc = SRCP_UNSUPPORTEDDEVICEGROUP;
    *reply = 0x00;
    gettimeofday(&time, NULL);

    /* check, if bus has FB's */
    if (bus_has_devicegroup(bus, DG_FB)
        && strncasecmp(device, "FB", 2) == 0) {
        long int port, timeout, nelem;
        int value, waitvalue;
        nelem =
            sscanf(parameter, "%ld %d %ld", &port, &waitvalue, &timeout);
        syslog_bus(bus, DBG_INFO, "wait: %d %d %d", port, waitvalue,
                   timeout);
        if (nelem >= 3) {
            if (getFB(bus, port, &time, &value) == SRCP_OK
                && value == waitvalue) {
                rc = infoFB(bus, port, reply, length);
            }
            else {
                /* we exactly wait for 1/20 seconds */
                timeout *= 20;
                do {
                    if (usleep(50000) == -1) {
                        syslog_bus(bus, DBG_ERROR,
                                   "usleep() failed: %s (errno = %d)\n",
                                   strerror(errno), errno);
                    }
                    getFB(bus, port, &time, &value);
                    timeout--;
                }
                while ((timeout >= 0) && (value != waitvalue));

                if (timeout < 0) {
                    gettimeofday(&time, NULL);
                    rc = srcp_fmt_msg(SRCP_TIMEOUT, reply, time);
                }
                else {
                    rc = infoFB(bus, port, reply, length);
                }
            }
        }
        else {
            rc = srcp_fmt_msg(SRCP_LISTTOOSHORT, reply, time);
        }
    }

    else if (bus_has_devicegroup(bus, DG_TIME)
             && strncasecmp(device, "TIME", 4) == 0) {
        long d, h, m, s;
        int nelem;
        nelem = sscanf(parameter, "%ld %ld %ld %ld", &d, &h, &m, &s);
        if (nelem >= 4) {
            if (time_is_available()) {
                /*FIXME: race condition */
                bool mustwait;
                vtime_t vt;
                getTIME(&vt);
                do {
                    mustwait = (((d * 24 + h) * 60 + m) * 60 + s) >=
                        (((vt.day * 24 + vt.hour) * 60 +
                          vt.min) * 60 + vt.sec);

                    /* wait 10ms real time.. */
                    if (mustwait) {
                        if (usleep(10000) == -1) {
                            syslog_bus(bus, DBG_ERROR,
                                       "usleep() failed: %s (errno = %d)\n",
                                       strerror(errno), errno);
                        }
                        getTIME(&vt);
                    }
                }
                while (mustwait);
                rc = infoTIME(reply);
            }
            else {
                rc = srcp_fmt_msg(SRCP_NODATA, reply, time);
            }
        }
        else {
            rc = srcp_fmt_msg(SRCP_LISTTOOSHORT, reply, time);
        }
    }
    return rc;
}
Esempio n. 13
0
JSBool
jsFadeTick( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval )
{
   *rval = JSVAL_FALSE ;
   
   if( 0 == argc )
   {
      jsval stVal ;
      jsval durVal ;
      jsval lhVal ;
      jsval rhVal ;
      jsval xVal, yVal ;
      if( JS_GetProperty( cx, obj, "startTick", &stVal ) 
          &&
          JS_GetProperty( cx, obj, "duration", &durVal ) 
          &&
          JS_GetProperty( cx, obj, "src", &lhVal )
          &&
          JS_GetProperty( cx, obj, "dest", &rhVal )
          &&
          JS_GetProperty( cx, obj, "x", &xVal )
          &&
          JS_GetProperty( cx, obj, "y", &yVal ) )
      {
         unsigned long const start = JSVAL_TO_INT( stVal );
         unsigned long const duration = JSVAL_TO_INT( durVal );
         unsigned long const msNow = now_ms();
         unsigned long const end = start+duration ;
         if( msNow < end )
         {
            unsigned long const _256ths = ((msNow-start)*256)/duration ;
//printf( "0x%02x /256ths\n", _256ths ); fflush( stdout );
      
            JSObject *const src = JSVAL_TO_OBJECT( lhVal );
            JSObject *const dest = JSVAL_TO_OBJECT( rhVal );
            jsval widthVal, heightVal, srcPixVal, destPixVal ;
            if( JS_GetProperty( cx, src, "width", &widthVal )
                &&
                JS_GetProperty( cx, src, "height", &heightVal )
                &&
                JS_GetProperty( cx, src, "pixBuf", &srcPixVal )
                &&
                JSVAL_IS_STRING( srcPixVal ) 
                &&
                JS_GetProperty( cx, dest, "pixBuf", &destPixVal )
                &&
                JSVAL_IS_STRING( destPixVal ) 
            )
            {
               int width  = JSVAL_TO_INT( widthVal ); 
               int height = JSVAL_TO_INT( heightVal );
               JSString *srcPixStr = JSVAL_TO_STRING( srcPixVal );
               unsigned short const *const srcPixMap = (unsigned short *)JS_GetStringBytes( srcPixStr );
               unsigned const srcLen = JS_GetStringLength( srcPixStr );

               JSString *destPixStr = JSVAL_TO_STRING( destPixVal );
               unsigned short const *const destPixMap = (unsigned short *)JS_GetStringBytes( destPixStr );
               unsigned const destLen = JS_GetStringLength( destPixStr );
               if( ( srcLen == destLen ) 
                   &&
                   ( srcLen == width * height * sizeof( srcPixMap[0] ) ) )
               {
                  fbDevice_t &fb = getFB();
         
                  fb.blend( JSVAL_TO_INT( xVal ), JSVAL_TO_INT( yVal ), width, height, srcPixMap, destPixMap, _256ths );
                  *rval = JSVAL_TRUE ;
               }
               else
                  JS_ReportError( cx, "Invalid pixMap(s)\n" );
            }
            else
               JS_ReportError( cx, "Object not initialized, can't draw\n" );
         }
         else
         {
            JSObject *dest = JSVAL_TO_OBJECT( rhVal );
            jsval params[2] = { xVal, yVal };
            jsImageDraw( cx, dest, 2, params, rval );
         } // just draw end item
      }
      else
         JS_ReportError( cx, "getting timeProperties" );
   } // need msNow parameter
   else
      JS_ReportError( cx, "Usage: fade.tick()" );

   return JS_TRUE ;
}
Esempio n. 14
0
static JSBool fade( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval )
{
   *rval = JSVAL_FALSE ;
   if( ( 5 == argc ) 
       && 
       JSVAL_IS_OBJECT( argv[0] )
       && 
       JSVAL_IS_OBJECT( argv[1] )
       && 
       JSVAL_IS_INT( argv[2] )
       && 
       JSVAL_IS_INT( argv[3] )
       && 
       JSVAL_IS_INT( argv[4] ) )
   {
      JSObject *thisObj = JS_NewObject( cx, &jsFadeClass_, NULL, NULL );

      if( thisObj )
      {
         *rval = OBJECT_TO_JSVAL( thisObj ); // root
         JSObject *const src = JSVAL_TO_OBJECT( argv[0] );
         JSObject *const dest = JSVAL_TO_OBJECT( argv[1] );
         jsval lhWidth, lhHeight,
               rhWidth, rhHeight ;
         if( JS_GetProperty( cx, src, "width", &lhWidth )
             &&
             JS_GetProperty( cx, src, "height", &lhHeight )
             &&
             JS_GetProperty( cx, dest, "width", &rhWidth )
             &&
             JS_GetProperty( cx, dest, "height", &rhHeight ) )
         {
            if( ( JSVAL_TO_INT( lhWidth ) == JSVAL_TO_INT( rhWidth ) )
                &&
                ( JSVAL_TO_INT( lhHeight ) == JSVAL_TO_INT( rhHeight ) ) )
            {
               int const duration = JSVAL_TO_INT( argv[2] );
               if( 0 < duration )
               {
                  int const x = JSVAL_TO_INT( argv[3] );
                  int const y = JSVAL_TO_INT( argv[4] );
                  fbDevice_t &fbDev = getFB();
                  if( ( 0 <= x ) && ( 0 <= y ) 
                      &&
                      ( fbDev.getWidth() > x )
                      &&
                      ( fbDev.getHeight() > y ) )
                  {
                     for( int i = 0 ; i < argc ; i++ )
                        JS_DefineProperty( cx, thisObj, 
                                           fadeProperties_[i].name, 
                                           argv[i], 0, 0,  JSPROP_ENUMERATE|JSPROP_PERMANENT|JSPROP_READONLY );
                     unsigned long const tickNow = now_ms();
                     JS_DefineProperty( cx, thisObj, fadeProperties_[argc].name, INT_TO_JSVAL( tickNow ),
                                        0, 0,  JSPROP_ENUMERATE|JSPROP_PERMANENT|JSPROP_READONLY );
                  }
               }
               else
                  JS_ReportError( cx, "duration must be > 0" );
            }
            else
               JS_ReportError( cx, "fade: images must be the same size\n"
                                   "%d/%d, %d/%d\n",
                               JSVAL_TO_INT( lhWidth ), JSVAL_TO_INT( rhWidth ),
                               JSVAL_TO_INT( lhHeight ), JSVAL_TO_INT( rhHeight ) );
         }
         else
            JS_ReportError( cx, "fade: getting image sizes" );
      }
      else
         JS_ReportError( cx, "Error allocating fade" );
   }
   else
      JS_ReportError( cx, "Usage : new fade( srcImg, destImg, durationMs );" );
      
   return JS_TRUE ;

}
Esempio n. 15
0
static JSBool
jsAlphaMapDraw( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval )
{
   *rval = JSVAL_FALSE ;

   JSObject *imageObj = 0 ;
   if( ( 3 <= argc )
       &&
       ( 4 >= argc )
       &&
       JSVAL_IS_INT( argv[0] )
       &&
       JSVAL_IS_INT( argv[1] )
       &&
       JSVAL_IS_INT( argv[2] ) 
       &&
       ( ( 3 == argc )
         ||
         ( JSVAL_IS_OBJECT( argv[3] ) 
           &&
           ( 0 != ( imageObj = JSVAL_TO_OBJECT( argv[3] ) ) ) ) )
       )
   {
      fbDevice_t &fb = getFB();
      unsigned char *imageMem = 0 ;
      unsigned short  imageWidth = 0 ;
      unsigned short  imageHeight = 0 ;
      unsigned short  imageStride = 0;

      if( 3 == argc )
      {
#ifdef KERNEL_FB
         imageMem = (unsigned char *)fb.getRow(0);
         imageWidth = fb.getWidth();
         imageHeight = fb.getHeight();
         imageStride = fb.getStride();
#else
         JS_ReportError( cx, "draw alphaMap onto screen" );
         return JS_TRUE ;
#endif
      }
      else
      {
         jsval     vPixMap ;
         jsval     vWidth ;
         jsval     vHeight ;
         JSString *sPixMap ;
      
         if( JS_GetProperty( cx, imageObj, "pixBuf", &vPixMap )
             &&
             JSVAL_IS_STRING( vPixMap )
             &&
             ( 0 != ( sPixMap = JSVAL_TO_STRING( vPixMap ) ) )
             &&
             JS_GetProperty( cx, imageObj, "width", &vWidth )
             &&
             JSVAL_IS_INT( vWidth )
             &&
             JS_GetProperty( cx, imageObj, "height", &vHeight )
             &&
             JSVAL_IS_INT( vHeight ) )
         {
            unsigned const bmWidth    = JSVAL_TO_INT( vWidth );
            unsigned       bmHeight   = JSVAL_TO_INT( vHeight );
            if( JS_GetStringLength( sPixMap ) == bmWidth*bmHeight*2 )
            {
               imageMem = (unsigned char *)JS_GetStringBytes( sPixMap );
               imageWidth  = bmWidth ;
               imageHeight = bmHeight ;
               imageStride = imageWidth << 1;
            }
            else
               JS_ReportError( cx, "Error getting pixel data" );
         }
         else
            JS_ReportError( cx, "Invalid image" );
         
         if( !imageMem )
            return JS_TRUE ;
      }

      int const specX = JSVAL_TO_INT( argv[0] );
      int const specY = JSVAL_TO_INT( argv[1] );
      unsigned const rgb   = JSVAL_TO_INT( argv[2] );

      jsval     vPixMap ;
      jsval     vWidth ;
      jsval     vHeight ;
      JSString *sPixMap ;

      if( JS_GetProperty( cx, obj, "pixBuf", &vPixMap )
          &&
          JSVAL_IS_STRING( vPixMap )
          &&
          ( 0 != ( sPixMap = JSVAL_TO_STRING( vPixMap ) ) )
          &&
          JS_GetProperty( cx, obj, "width", &vWidth )
          &&
          JSVAL_IS_INT( vWidth )
          &&
          JS_GetProperty( cx, obj, "height", &vHeight )
          &&
          JSVAL_IS_INT( vHeight ) )
      {
         unsigned       bmWidth    = JSVAL_TO_INT( vWidth );
         unsigned const bmHeight   = JSVAL_TO_INT( vHeight );

         //printf( "string gets drawn here\n"
         //        "x        %u\n"
         //        "y        %u\n"
         //        "rgb      0x%06x\n"
         //        "w        %u\n"
         //        "h        %u\n", specX, specY, rgb, bmWidth, bmHeight );
                 
         //
         // user specifies position of baseline, adjust to top of bitmap
         //
         unsigned bmStartY = 0 ;
         int screenStartY = specY ;
         if( 0 > screenStartY )
         {
            bmStartY = ( 0-screenStartY );
            screenStartY = 0 ;
         } // starts off the screen, walk down in alphaMap

         unsigned bmStartX = 0 ;
         int screenStartX = specX ;
         if( 0 > screenStartX )
         {
            bmStartX = ( 0 - screenStartX );
            screenStartX  = 0 ;
         } // starts off the screen, walk right in alphaMap

         if( ( bmWidth > bmStartX ) 
             && 
             ( screenStartX <= imageWidth ) 
             && 
             ( screenStartY < imageHeight )
             &&
             ( bmStartY < bmWidth ) )
         {
            //
            // point row at start row/col
            //
            unsigned char *inRow = (unsigned char *)JS_GetStringBytes( sPixMap )
                                       + (bmWidth*bmStartY) + bmStartX ;
            unsigned const maxHeight = bmHeight-bmStartY ;
            unsigned const red   = (unsigned char)( rgb >> 16 );
            unsigned const green = (unsigned char)( rgb >> 8 );
            unsigned const blue  = (unsigned char)rgb ;
            fb.antialias( inRow,
                          bmWidth,
                          maxHeight,
                          screenStartX,
                          screenStartY,
                          screenStartX+bmWidth-1,
                          screenStartY+maxHeight-1,
                          red, green, blue,
                          imageMem, imageWidth, imageHeight, imageStride);
         } // room for something