Exemplo n.º 1
0
PERROR InitFreeSelection( FRAME *frame )
{
    struct Selection *selection = &frame->selection;
    FRAME *mask = selection->mask;

    D(bug("InitFreeSelection(%08X)\n",frame));

    if( !mask || NOTSAMESIZE( mask, frame ) ) {

        if( mask ) RemFrame( mask, globxd );

        mask = MakeFrame( frame, globxd );
        mask->pix->components = 1;
        mask->pix->colorspace = CS_UNKNOWN;

        if( InitFrame( mask, globxd ) != PERR_OK )
            return PERR_ERROR;

        frame->selection.mask = mask;
    }

    if( !selection->vertices ) {
        if( NULL == (selection->vertices = smalloc( sizeof(Point) * 1024 ))) {
            Panic( "Can't alloc vertices!!!" );
        }
        selection->nMaxVertices = 1024;
    }

    selection->ButtonDown        = FreeButtonDown;
    selection->ButtonUp          = FreeButtonUp;
    // s->ControlButtonDown = LassoRectControlButtonDown;
    selection->DrawSelection     = FreeDraw;
    selection->EraseSelection    = FreeErase;
    selection->MouseMove         = FreeMouseMove;
    selection->IsInArea          = FreeIsInArea;
    //s->Rescale           = LassoRectRescale;
    //s->Copy              = LassoRectCopy;

    return PERR_OK;
}
Exemplo n.º 2
0
FRAME *DoTransparency( FRAME *frame, struct Values *v, struct PPTBase *PPTBase)
{
    FRAME *newframe = NULL;
    BOOL  hasalpha = FALSE;
    ULONG tol;

    tol = SQR(v->tolerance);

    if( frame->pix->colorspace == CS_ARGB )
        hasalpha = TRUE;

    // PDebug(MYNAME": Exec()\n");

    newframe = MakeFrame( frame );
    if(newframe) {
        newframe->pix->colorspace = CS_ARGB;
        newframe->pix->components = 4;

        if( InitFrame( newframe ) == PERR_OK ) {
            WORD row;

            InitProgress(frame,"Setting up transparency...",0,frame->pix->height);

            for( row = 0; row < frame->pix->height; row++ ) {
                RGBPixel *cp;
                ARGBPixel *dcp, *acp;
                WORD col;
                BOOL isin;

                if( Progress(frame, row) ) {
                    RemFrame(newframe);
                    newframe = NULL;
                    break;
                }

                cp = (RGBPixel *)GetPixelRow( frame, row );
                acp = (ARGBPixel *)cp;
                dcp = (ARGBPixel *)GetPixelRow( newframe, row );

                /*
                 *  Loopety loop.  If the pixel to be set is exactly
                 *  the color, then set the transparency.
                 */

                for( col = 0; col < frame->pix->width; col++ ) {
                    ULONG dist;

                    /*
                     *  Check if we're inside selbox
                     */

                    if( row >= frame->selbox.MinY && row < frame->selbox.MaxY &&
                        col >= frame->selbox.MinX && col < frame->selbox.MaxX ){
                        isin = TRUE;
                    } else {
                        isin = FALSE;
                    }

                    /*
                     *  Set the alpha channel, if we're inside the selbox
                     */
                    if( hasalpha ) {
                        dist = SQR((WORD)((WORD)acp->r - v->r))+
                               SQR((WORD)((WORD)acp->g - v->g))+
                               SQR((WORD)((WORD)acp->b - v->b));

                        if( (v->mode == MODE_ALL || dist <= tol) && isin)
                        {
                            dcp->a = (UBYTE) v->transp;
                        } else {
                            dcp->a = acp->a; /* Retain transparency */
                        }
                        dcp->r = acp->r;
                        dcp->g = acp->g;
                        dcp->b = acp->b;
                        acp++;
                        dcp++;
                    } else {
                        dist = SQR((WORD)((WORD)cp->r - v->r))+
                               SQR((WORD)((WORD)cp->g - v->g))+
                               SQR((WORD)((WORD)cp->b - v->b));

                        if( (v->mode == MODE_ALL || dist <= tol) && isin)
                        {
                            dcp->a = (UBYTE) v->transp;
                        } else {
                            dcp->a = 0; /* No transparency */
                        }
                        dcp->r = cp->r;
                        dcp->g = cp->g;
                        dcp->b = cp->b;
                        cp++;
                        dcp++;
                    }
                }

                PutPixelRow( newframe, row, dcp );
            }

            FinishProgress(frame);

        } else {
            RemFrame(newframe);
            newframe = NULL;
        }
    }

    return newframe;

}
Exemplo n.º 3
0
int CTransfer::SendMetering(CMobileClient *pClient, char *pszFileName)
{
	CChunk			chunk;
	char			szBuffer[128];
	char			*pFrame;
	BYTE			nSeq = 0;
	IF4_CTRL_FRAME	*pCtrl;
	METERINGDATA    *pList;
	int				nRetry = 0, len, nSize;
	int				fd=0, n, nState, nLength=0;
	int				nResult = -1;
	int				nLine = 0;

	m_nGoodLine = 0;	
	for(nState=STATE_ENQ; (!m_bExitSignalPending) && (nState!=STATE_DONE);)
	{
		switch(nState) {
		  case STATE_ENQ :
			   if (!pClient->ReadPacketFromModem(szBuffer, &n, 5000))
				   return SENDERR_RECV_TIMEOUT;

			   pCtrl = (IF4_CTRL_FRAME *)szBuffer;
			   if ((pCtrl->hdr.svc != IF4_SVC_CONTROL) || (pCtrl->code != IF4_ENQ))
			   {
				   XDEBUG("CIRCUIT: Not ENQ, return.\r\n");
				   return SENDERR_NO_ENQ;
			   }

			   XDEBUG("CIRCUIT: Recv 'ENQ'\r\n");
			   fd = open(pszFileName, O_RDONLY);
			   if (fd <= 0)
			   {	
			   	   printf("CIRCUIT: File Open error '%s'\r\n", pszFileName);
				   return SENDERR_FILE_OPEN_ERROR;
			   }
			   nSeq = 0;
			   chunk.Flush();
			   nState = STATE_READ_PACKET;
			   break;

		  case STATE_READ_PACKET :
               nLength = read(fd, m_pszReadBuffer, sizeof(METERINGDATA));
			   XDEBUG("CIRCUIT: Read header %d bytes\r\n", nLength);

			   if (nLength == (int)sizeof(METERINGDATA))
			   {
            	   pList = (METERINGDATA *)m_pszReadBuffer;
				   nSize = pList->length - sizeof(TIMESTAMP);
				   n = read(fd, m_pszReadBuffer+sizeof(METERINGDATA), nSize);
			   	   XDEBUG("CIRCUIT: Read data %d bytes\r\n", n);
				   if (n == nSize) 
				   {
			   		   nLine++;
				       nLength += n;
			   		   nState = STATE_SEND_PACKET;
			   	   	   XDEBUG("CIRCUIT[%d]: Total data %d bytes\r\n", nLine, nLength);
					   break;
				   }
			   }
			   XDEBUG("CIRCUIT: End of file\r\n");
			   nState = STATE_OK;
			   break;

		  case STATE_SEND_PACKET :
			   if (m_nSentLine >= nLine)
			   {
			   	   XDEBUG("CIRCUIT: Skip packet. (Join=%d, Line=%d, Length=%0d)\r\n", m_nSentLine, nLine, nLength);
			   	   nState = STATE_READ_PACKET;
				   break;
			   }

			   XDEBUG("CIRCUIT: Send packet. (Length=%0d)\r\n", nLength);
			   pFrame = (char *)MALLOC(sizeof(IF4_DATA_FRAME)+nLength+20);
			   if (pFrame != NULL)
			   {
				   len = MakeFrame(pFrame, m_pszReadBuffer, nLength, nSeq);
		   	   	   pClient->WriteToModem(pFrame, len);
				   FREE(pFrame);
			   }
		   	   nState = STATE_RECV_ACK;
			   break;

		  case STATE_RECV_ACK :
			   XDEBUG("CIRCUIT: Waitting for reply.\r\n");
			   if (!pClient->ReadPacketFromModem(szBuffer, &n, 10000))
			   {
			   	   XDEBUG("CIRCUIT: Waitting timeout.\r\n");
				   nResult = SENDERR_NO_RESPNOSE;
				   nRetry++;
				   if (nRetry <= 3)
				   {
					   nState = STATE_SEND_PACKET;
					   break;
				   }
				   nState = STATE_ERROR;
				   break;
			   }

			   pCtrl = (IF4_CTRL_FRAME *)szBuffer;
			   if (pCtrl->hdr.svc != IF4_SVC_CONTROL)
			   {
				   XDEBUG("CIRCUIT: Not control frame.\r\n");
				   nResult = SENDERR_UNKNOWN_RESPONSE;
				   nRetry++;
				   if (nRetry <= 3)
				   {
					   nState = STATE_SEND_PACKET;
					   break;
				   }
				   nState = STATE_ERROR;
				   break;
			   }
			
			   switch(pCtrl->code) {
			     case IF4_NAK :
			          XDEBUG("CIRCUIT: Recv 'NAK'\r\n");
					  nResult = SENDERR_NAK;
				      nRetry++;
				      if (nRetry <= 3)
				      {
					      nState = STATE_SEND_PACKET;
					      break;
				      }
					  nState = STATE_ERROR;
				      break;

				 case IF4_ACK :
				      XDEBUG("CIRCUIT: Recv 'ACK'\r\n");
					  nSeq++;
					  m_nGoodLine++;
					  m_nSentLine++;
			   		  chunk.Flush();
			   		  nState = STATE_READ_PACKET;
				      break;

				 case IF4_EOT :
				      XDEBUG("CIRCUIT: Recv 'EOT'\r\n");
			   		  nState = STATE_OK;
				      break;

				 default :
			   		  nState = STATE_ERROR;
				      break;
			   }
			   break;

		  case STATE_OK :
			   close(fd);
			   SendEot(pClient);
			   usleep(3000000);
			   nResult = 0;
			   nState = STATE_DONE;
			   break;

		  case STATE_ERROR :
			   close(fd);
			   SendEot(pClient);
			   usleep(3000000);
			   nState = STATE_DONE;
			   break;
		}
	}
	return nResult;
}