Exemplo n.º 1
0
Local
FRAME *EasyFilter( FRAME *frame, EFFECT *effect, EXTBASE *PPTBase )
{
    FPTR X_EasyExec;
    char *X_EasyTitle, buf[80];
    APTR UtilityBase = PPTBase->lb_Utility;

    D(bug("EasyFilter()\n"));

    /* Init variables */
    sprintf(buf,XGetStr(mEXECUTING_EASYEXEC),effect->info.nd.ln_Name);
    X_EasyExec  = (FPTR)GetTagData( PPTX_EasyExec, NULL, effect->info.tags );
    X_EasyTitle = (char *)GetTagData( PPTX_EasyTitle, (ULONG)buf,effect->info.tags);

    /* Execute */

    InitProgress( frame, X_EasyTitle, frame->selbox.MinY, frame->selbox.MaxY, PPTBase );

    ExecEasyFilter( frame, X_EasyExec, PPTBase );

    FinishProgress( frame, PPTBase );

    if( frame->errorcode != PERR_OK )
        return NULL;

    return frame;
}
Exemplo n.º 2
0
PERROR MakeKeyMaterial( FRAME *frame, UBYTE *passphrase, struct PPTBase *PPTBase )
{
    ROWPTR cp, tmprow;
    WORD row;
    struct ExecBase *SysBase = PPTBase->lb_Sys;
    SHA_INFO sha = {0};
    PERROR res = PERR_OK;

    sha_init( &sha );

    InitProgress(frame,"Building key...", 0, frame->pix->height );

    /*
     *  First, use the passphrase for the key.
     */

    if( strlen(passphrase) > 0 ) sha_update( &sha, passphrase, strlen(passphrase) );

    if( tmprow = AllocVec( frame->pix->bytes_per_row, 0L ) ) {
        for( row = 0; row < frame->pix->height; row++ ) {
            WORD col;

            cp = GetPixelRow( frame, row );

            if( Progress( frame, row ) ) {
                res = PERR_BREAK;
                break;
            }

            for( col = 0; col < frame->pix->bytes_per_row; col++ ) {
                /* Use only significant bytes */
                tmprow[col] = cp[col] & 0xFE;
            }

            sha_update( &sha, tmprow, frame->pix->bytes_per_row );
        }

        // Use the passphrase again (why?)

        if( strlen(passphrase) > 0 ) sha_update( &sha, passphrase, strlen(passphrase) );

        FinishProgress( frame );
        sha_final( &sha );

        memcpy( key, &sha.digest[0], SHA_DIGESTSIZE );

        D(sha_print( &sha ) );

        FreeVec( tmprow );
    } else {
        SetErrorCode( frame, PERR_OUTOFMEMORY );
        res = PERR_OUTOFMEMORY;
    }

    return res;
}
void CProjectProcessingPage::OnStateChange( CProjectProcessingPageEvent& WXUNUSED(event) )
{
    CMainDocument* pDoc        = wxGetApp().GetDocument();
    CWizardAttachProject* pWAP = ((CWizardAttachProject*)GetParent());
    ACCOUNT_IN* ai             = &pWAP->account_in;
    ACCOUNT_OUT* ao            = &pWAP->account_out;
    unsigned int i;
    PROJECT_ATTACH_REPLY reply;
    wxString strBuffer = wxEmptyString;
    wxDateTime dtStartExecutionTime;
    wxDateTime dtCurrentExecutionTime;
    wxTimeSpan tsExecutionTime;
    bool bPostNewEvent = true;
    int iReturnValue = 0;
	bool creating_account = false;
 
    wxASSERT(pDoc);
    wxASSERT(wxDynamicCast(pDoc, CMainDocument));
 
    switch(GetCurrentState()) {
        case ATTACHPROJECT_INIT:
            pWAP->DisableNextButton();
            pWAP->DisableBackButton();

            StartProgress(m_pProgressIndicator);
            SetNextState(ATTACHPROJECT_ACCOUNTQUERY_BEGIN);
            break;
        case ATTACHPROJECT_ACCOUNTQUERY_BEGIN:
            SetNextState(ATTACHPROJECT_ACCOUNTQUERY_EXECUTE);
            break;
        case ATTACHPROJECT_ACCOUNTQUERY_EXECUTE:
            // Attempt to create the account or reterieve the authenticator.
            ai->clear();
            ao->clear();

            // Newer versions of the server-side software contain the correct
            //   master url in the get_project_config response.  If it is available
            //   use it instead of what the user typed in.
            if (!pWAP->project_config.master_url.empty()) {
                ai->url = pWAP->project_config.master_url;
            } else {
                ai->url = (const char*)pWAP->m_ProjectInfoPage->GetProjectURL().mb_str();
            }

            if (!pWAP->GetProjectAuthenticator().IsEmpty() || 
                pWAP->m_bCredentialsCached || 
                pWAP->m_bCredentialsDetected
            ) {
                if (!pWAP->m_bCredentialsCached || pWAP->m_bCredentialsDetected) {
                    ao->authenticator = (const char*)pWAP->GetProjectAuthenticator().mb_str();
                }
                SetProjectCommunitcationsSucceeded(true);
            } else {
                // Setup initial values for both the create and lookup API
                ai->email_addr = (const char*)pWAP->m_AccountInfoPage->GetAccountEmailAddress().mb_str();
                ai->passwd = (const char*)pWAP->m_AccountInfoPage->GetAccountPassword().mb_str();
                ai->user_name = (const char*)::wxGetUserName().mb_str();
                ai->team_name = pWAP->team_name;
                if (ai->user_name.empty()) {
                    ai->user_name = (const char*)::wxGetUserId().mb_str();
                }

                if (pWAP->m_AccountInfoPage->m_pAccountCreateCtrl->GetValue()) {
					creating_account = true;

                    // Wait until we are done processing the request.
                    dtStartExecutionTime = wxDateTime::Now();
                    dtCurrentExecutionTime = wxDateTime::Now();
                    tsExecutionTime = dtCurrentExecutionTime - dtStartExecutionTime;
                    iReturnValue = 0;
                    ao->error_num = ERR_RETRY;
                    while (
                        !iReturnValue &&
                        ((ERR_IN_PROGRESS == ao->error_num) || (ERR_RETRY == ao->error_num)) && 
                        tsExecutionTime.GetSeconds() <= 60 &&
                        !CHECK_CLOSINGINPROGRESS()
                    ) {
                        if (ERR_RETRY == ao->error_num) {
                            pDoc->rpc.create_account(*ai);
                        }

                        dtCurrentExecutionTime = wxDateTime::Now();
                        tsExecutionTime = dtCurrentExecutionTime - dtStartExecutionTime;
                        iReturnValue = pDoc->rpc.create_account_poll(*ao);

                        IncrementProgress(m_pProgressIndicator);

                        ::wxMilliSleep(500);
                        ::wxSafeYield(GetParent());
                    }

                    if ((!iReturnValue) && !ao->error_num) {
                        pWAP->SetAccountCreatedSuccessfully(true);
                    }
                } else {
					creating_account = false;
 
                    // Wait until we are done processing the request.
                    dtStartExecutionTime = wxDateTime::Now();
                    dtCurrentExecutionTime = wxDateTime::Now();
                    tsExecutionTime = dtCurrentExecutionTime - dtStartExecutionTime;
                    iReturnValue = 0;
                    ao->error_num = ERR_RETRY;
                    while (
                        !iReturnValue &&
                        ((ERR_IN_PROGRESS == ao->error_num) || (ERR_RETRY == ao->error_num)) && 
                        tsExecutionTime.GetSeconds() <= 60 &&
                        !CHECK_CLOSINGINPROGRESS()
                    ) {
                        if (ERR_RETRY == ao->error_num) {
                            pDoc->rpc.lookup_account(*ai);
                        }

                        dtCurrentExecutionTime = wxDateTime::Now();
                        tsExecutionTime = dtCurrentExecutionTime - dtStartExecutionTime;
                        iReturnValue = pDoc->rpc.lookup_account_poll(*ao);

                        IncrementProgress(m_pProgressIndicator);

                        ::wxMilliSleep(500);
                        ::wxSafeYield(GetParent());
                    }
                }
 
                if ((!iReturnValue) && !ao->error_num) {
                    SetProjectCommunitcationsSucceeded(true);
                } else {
                    SetProjectCommunitcationsSucceeded(false);

                    if ((ao->error_num == ERR_DB_NOT_UNIQUE)
						|| (ao->error_num == ERR_NONUNIQUE_EMAIL)
						|| (ao->error_num == ERR_BAD_PASSWD && creating_account)
					) {
                        SetProjectAccountAlreadyExists(true);
                    } else {
                        SetProjectAccountAlreadyExists(false);
                    }

                    if ((ERR_NOT_FOUND == ao->error_num) ||
						(ao->error_num == ERR_DB_NOT_FOUND) ||
                        (ERR_BAD_EMAIL_ADDR == ao->error_num) ||
                        (ERR_BAD_PASSWD == ao->error_num)
                    ) {
                        SetProjectAccountNotFound(true);
                    } else {
                        SetProjectAccountNotFound(false);
                    }

                    strBuffer = pWAP->m_CompletionErrorPage->m_pServerMessagesCtrl->GetLabel();
                    if ((HTTP_STATUS_NOT_FOUND == ao->error_num)) {
                        strBuffer += 
                            _("Required wizard file(s) are missing from the target server.\n(lookup_account.php/create_account.php)\n");
                    } else if ((HTTP_STATUS_INTERNAL_SERVER_ERROR == ao->error_num)) {
                        strBuffer += 
                            _("An internal server error has occurred.\n");
                    } else {
						if (ao->error_msg.size()) {
                            strBuffer += wxString(ao->error_msg.c_str(), wxConvUTF8) + wxString(wxT("\n"));
                        }
                    }
                    pWAP->m_CompletionErrorPage->m_pServerMessagesCtrl->SetLabel(strBuffer);
                }
            }
            SetNextState(ATTACHPROJECT_ATTACHPROJECT_BEGIN);
            break;
        case ATTACHPROJECT_ATTACHPROJECT_BEGIN:
            SetNextState(ATTACHPROJECT_ATTACHPROJECT_EXECUTE);
            break;
        case ATTACHPROJECT_ATTACHPROJECT_EXECUTE:
            if (GetProjectCommunitcationsSucceeded()) {
     
                // Wait until we are done processing the request.
                dtStartExecutionTime = wxDateTime::Now();
                dtCurrentExecutionTime = wxDateTime::Now();
                tsExecutionTime = dtCurrentExecutionTime - dtStartExecutionTime;
                iReturnValue = 0;
                reply.error_num = ERR_RETRY;
                while (
                    !iReturnValue &&
                    ((ERR_IN_PROGRESS == reply.error_num) || (ERR_RETRY == reply.error_num)) && 
                    tsExecutionTime.GetSeconds() <= 60 &&
                    !CHECK_CLOSINGINPROGRESS()
                ) {
                    if (ERR_RETRY == reply.error_num) {
                        if (pWAP->m_bCredentialsCached) {
                            pDoc->rpc.project_attach_from_file();
                        } else {
                            pDoc->rpc.project_attach(
                                ai->url.c_str(),
                                ao->authenticator.c_str(),
                                pWAP->project_config.name.c_str()
                            );
                        }
                    }

                    dtCurrentExecutionTime = wxDateTime::Now();
                    tsExecutionTime = dtCurrentExecutionTime - dtStartExecutionTime;
                    iReturnValue = pDoc->rpc.project_attach_poll(reply);

                    IncrementProgress(m_pProgressIndicator);

                    ::wxMilliSleep(500);
                    ::wxSafeYield(GetParent());
                }
     
                if (!iReturnValue && !reply.error_num) {
                    SetProjectAttachSucceeded(true);
                    pWAP->SetAttachedToProjectSuccessfully(true);
                    pWAP->SetProjectURL(wxString(ai->url.c_str(), wxConvUTF8));
                    pWAP->SetProjectAuthenticator(wxString(ao->authenticator.c_str(), wxConvUTF8));
                } else {
                    SetProjectAttachSucceeded(false);

                    strBuffer = pWAP->m_CompletionErrorPage->m_pServerMessagesCtrl->GetLabel();
                    if ((HTTP_STATUS_INTERNAL_SERVER_ERROR == reply.error_num)) {
                        strBuffer += 
                            _("An internal server error has occurred.\n");
                    } else {
                        for (i=0; i<reply.messages.size(); i++) {
                            strBuffer += wxString(reply.messages[i].c_str(), wxConvUTF8) + wxString(wxT("\n"));
                        }
                    }
                    pWAP->m_CompletionErrorPage->m_pServerMessagesCtrl->SetLabel(wxString(strBuffer, wxConvUTF8));
                }
            } else {
                SetProjectAttachSucceeded(false);
            }
            SetNextState(ATTACHPROJECT_CLEANUP);
            break;
        case ATTACHPROJECT_CLEANUP:
            FinishProgress(m_pProgressIndicator);
            SetNextState(ATTACHPROJECT_END);
            break;
        default:
            // Allow a glimps of what the result was before advancing to the next page.
            wxSleep(1);
            pWAP->EnableNextButton();
            pWAP->EnableBackButton();
            pWAP->SimulateNextButton();
            bPostNewEvent = false;
            break;
    }
 
    Update();
 
    if (bPostNewEvent && !CHECK_CLOSINGINPROGRESS()) {
        CProjectProcessingPageEvent TransitionEvent(wxEVT_PROJECTPROCESSING_STATECHANGE, this);
        AddPendingEvent(TransitionEvent);
    }
}
Exemplo n.º 4
0
//random supersampling
void Raytracer::Render(void)
{
	//need to have a camera, a render surface, and a scene
	if(!cam)
		return;
	if(!rs)
		return;
	if(!sc)
		return;


	//get the data we need
	Vector o = cam->position;
	Vector updir = cam->up;
	Vector rightdir = cam->right;

	int width = rs->GetWidth();
	int height = rs->GetHeight();
	Color *surface = rs->GetSurface();

	float invaspect = lrflti(height) / lrflti(width);
	float xmag = tanf(cam->fov);
	float ymag = xmag * invaspect;

	Vector topleft = o + cam->normal - rightdir * xmag + updir * ymag;
	Vector dx = rightdir * (2.0f * xmag / lrflti(width));
	Vector dy = updir * (-2.0f * ymag / lrflti(height));
	Vector screenpos, currline = topleft, dir;

	int numSamples = multisampling;
	Vector d = dx + dy;
	Vector offset = o + d * 0.5;
	Color accumulator;
	float divider = 1.0f / lrflti(numSamples);

	Ray r;
	r.origin = o;

	Color pixel;
	float dist = 0.0f;
	InitProgress();

	//render each line in parallel
	int y, x, s;
	float u = 0.0f, v = 0.0f;
#ifdef OMP_ENABLE
#pragma omp parallel for default(none) shared(height, width, dy, dx, o, surface, topleft, offset, numSamples, divider) private(x, y, screenpos, pixel, dir, s, accumulator, u, v) firstprivate(r, dist) schedule(dynamic, 2)
#endif
	for(y = 0; y < height; y++)
	{
		screenpos = topleft + (dy * lrflti(y));
		//now each pixel of that line
		for(x = 0; x < width; x++, screenpos += dx)
		{
			//for each sample of that pixel
			accumulator = Color::black;
			for(s = 0; s < numSamples; s++)
			{
				//clear out the pixel
				pixel = Color::black;
				//create the ray
#ifdef DISABLE_JITTER
				dir = screenpos - offset;
#else
				u = lrflti(rand()) * MAX_RAND_DIVIDER;
				v = lrflti(rand()) * MAX_RAND_DIVIDER;
				dir = screenpos - offset + (dx * u) + (dy * v);
#endif
				dir = dir / dir.Length();
				r.direction = dir;
				//trace the actual ray
				Raytrace(r, pixel, 0, dist);
				accumulator += pixel;
			}

			//update the pixel color
			surface[y * width + x] = accumulator * divider;

			//update the progression
			SetProgress(static_cast<float>(y * width + x) / static_cast<float>(width * height));
		}
	}

	FinishProgress();
}
Exemplo n.º 5
0
void CProjectPropertiesPage::OnStateChange( CProjectPropertiesPageEvent& WXUNUSED(event) )
{
    CMainDocument* pDoc = wxGetApp().GetDocument();
    CWizardAttach* pWAP = ((CWizardAttach*)GetParent());
    PROJECT_CONFIG* pc  = &pWAP->project_config;
    CC_STATUS status;
    wxDateTime dtStartExecutionTime;
    wxDateTime dtCurrentExecutionTime;
    wxTimeSpan tsExecutionTime;
    wxString strBuffer = wxEmptyString;
    bool bPostNewEvent = true;
    int  iReturnValue = 0;
 
    wxASSERT(pDoc);
    wxASSERT(wxDynamicCast(pDoc, CMainDocument));
 
    switch(GetCurrentState()) {
        case PROJPROP_INIT:
            pWAP->DisableNextButton();
            pWAP->DisableBackButton();
            StartProgress(m_pProgressIndicator);
            SetNextState(PROJPROP_RETRPROJECTPROPERTIES_BEGIN);
            break;
        case PROJPROP_RETRPROJECTPROPERTIES_BEGIN:
            SetNextState(PROJPROP_RETRPROJECTPROPERTIES_EXECUTE);
            break;
        case PROJPROP_RETRPROJECTPROPERTIES_EXECUTE:
            // Attempt to retrieve the project's account creation policies
 
            // Wait until we are done processing the request.
            dtStartExecutionTime = wxDateTime::Now();
            dtCurrentExecutionTime = wxDateTime::Now();
            tsExecutionTime = dtCurrentExecutionTime - dtStartExecutionTime;
            iReturnValue = 0;
            pc->clear();
            pc->error_num = ERR_RETRY;
            while (
                !iReturnValue &&
                ((ERR_IN_PROGRESS == pc->error_num) || (ERR_RETRY == pc->error_num)) &&
                tsExecutionTime.GetSeconds() <= 60 &&
                !CHECK_CLOSINGINPROGRESS()
            ) {
                if (ERR_RETRY == pc->error_num) {
                    pDoc->rpc.get_project_config(
                        (const char*)pWAP->m_ProjectInfoPage->GetProjectURL().mb_str()
                    );
                }

                dtCurrentExecutionTime = wxDateTime::Now();
                tsExecutionTime = dtCurrentExecutionTime - dtStartExecutionTime;
                iReturnValue = pDoc->rpc.get_project_config_poll(*pc);
                IncrementProgress(m_pProgressIndicator);

                ::wxMilliSleep(500);
                wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_USER_INPUT);
            }
 
            if (
                !iReturnValue
                && (!pc->error_num || pc->error_num == ERR_ACCT_CREATION_DISABLED)
            ) {
                // We either successfully retrieved the project's
                // account creation policies or we were able to talk
                // to the web server and found out they do not support
                // account creation through the wizard.
                // In either case, claim success and set the correct flags
                // to show the correct 'next' page.
                //
                SetProjectPropertiesSucceeded(true);
                SetProjectAccountCreationDisabled(pc->account_creation_disabled);
                SetProjectClientAccountCreationDisabled(pc->client_account_creation_disabled);
                SetTermsOfUseRequired(!pc->terms_of_use.empty());

            } else {

                SetProjectPropertiesSucceeded(false);
                SetProjectPropertiesURLFailure(pc->error_num == ERR_HTTP_PERMANENT);

                bool comm_failure = !iReturnValue && (
                    (ERR_GETHOSTBYNAME == pc->error_num)
                    || (ERR_CONNECT == pc->error_num)
                    || (ERR_XML_PARSE == pc->error_num)
                    || (ERR_PROJECT_DOWN == pc->error_num)
                );
                SetProjectPropertiesCommunicationFailure(comm_failure);

                bool server_reported_error = !iReturnValue && (
                    (ERR_HTTP_PERMANENT != pc->error_num)
                    && (ERR_GETHOSTBYNAME != pc->error_num)
                    && (ERR_CONNECT != pc->error_num)
                    && (ERR_XML_PARSE != pc->error_num)
                    && (ERR_PROJECT_DOWN != pc->error_num)
                );
                SetServerReportedError(server_reported_error);

                if (server_reported_error) {
                    strBuffer = pWAP->m_CompletionErrorPage->m_pServerMessagesCtrl->GetLabel();
				    if (pc->error_msg.size()) {
                        strBuffer += wxString(pc->error_msg.c_str(), wxConvUTF8) + wxString(wxT("\n"));
                    }
                    pWAP->m_CompletionErrorPage->m_pServerMessagesCtrl->SetLabel(strBuffer);
                }
            }

            SetNextState(PROJPROP_DETERMINENETWORKSTATUS_BEGIN);
            break;
        case PROJPROP_DETERMINENETWORKSTATUS_BEGIN:
            SetNextState(PROJPROP_DETERMINENETWORKSTATUS_EXECUTE);
            break;
        case PROJPROP_DETERMINENETWORKSTATUS_EXECUTE:
            // Attempt to determine if we are even connected to a network

            // Wait until we are done processing the request.
            dtStartExecutionTime = wxDateTime::Now();
            dtCurrentExecutionTime = wxDateTime::Now();
            tsExecutionTime = dtCurrentExecutionTime - dtStartExecutionTime;
            iReturnValue = 0;
            status.network_status = NETWORK_STATUS_LOOKUP_PENDING;
            while ((!iReturnValue && (NETWORK_STATUS_LOOKUP_PENDING == status.network_status)) &&
                   tsExecutionTime.GetSeconds() <= 60 &&
                   !CHECK_CLOSINGINPROGRESS()
                  )
            {
                dtCurrentExecutionTime = wxDateTime::Now();
                tsExecutionTime = dtCurrentExecutionTime - dtStartExecutionTime;
                iReturnValue = pDoc->GetCoreClientStatus(status);
                IncrementProgress(m_pProgressIndicator);

                ::wxMilliSleep(500);
                wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_USER_INPUT);
            }

            SetNetworkConnectionNotDetected(NETWORK_STATUS_WANT_CONNECTION == status.network_status);

            SetNextState(PROJPROP_DETERMINEACCOUNTINFOSTATUS_BEGIN);
            break;
        case PROJPROP_DETERMINEACCOUNTINFOSTATUS_BEGIN:
            SetNextState(PROJPROP_DETERMINEACCOUNTINFOSTATUS_EXECUTE);
            break;
        case PROJPROP_DETERMINEACCOUNTINFOSTATUS_EXECUTE:
            // Determine if the account settings are already pre-populated.
            //   If so, advance to the Project Processing page.
            SetCredentialsAlreadyAvailable(pWAP->m_bCredentialsCached || pWAP->m_bCredentialsDetected);

            SetNextState(PROJPROP_CLEANUP);
            break;
        case PROJPROP_CLEANUP:
            FinishProgress(m_pProgressIndicator);
            SetNextState(PROJPROP_END);
            break;
        default:
            // Allow a glimps of what the result was before advancing to the next page.
            wxSleep(1);
            pWAP->EnableNextButton();
            pWAP->EnableBackButton();
            pWAP->SimulateNextButton();
            bPostNewEvent = false;
            break;
    }
 
    Update();
 
    if (bPostNewEvent && !CHECK_CLOSINGINPROGRESS()) {
        CProjectPropertiesPageEvent TransitionEvent(wxEVT_PROJECTPROPERTIES_STATECHANGE, this);
        AddPendingEvent(TransitionEvent);
    }
}
Exemplo n.º 6
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.º 7
0
Arquivo: rip.c Projeto: jalkanen/ppt
EFFECTEXEC(frame,tags,PPTBase,EffectBase)

{
    ROWPTR cp[3];
    WORD row, comps = frame->pix->components;

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

    InitProgress( frame, "Removing isolated pixels...", frame->selbox.MinY, frame->selbox.MaxY );
//    PDebug("\tBegin\n");

    for( row = frame->selbox.MinY; row < frame->selbox.MaxY; row++ ) {
        UWORD col;

        //PDebug("\Reading around row %d\n",row);

        if(GetNPixelRows(frame, cp, row-1, 3) == 0) { /* Get immediate vicinity */
            frame = NULL;
            goto quit;
        }

        if(Progress(frame, row)) {
            frame = NULL;
            goto quit;
        }

        for(col = frame->selbox.MinX; col < frame->selbox.MaxX; col++ ) {
            UWORD count = 0;
            WORD i;
            UBYTE r,g,b;

            switch(frame->pix->colorspace) {

            case CS_RGB:
                if(col == 0) { /* Pick from right side */
                    r = cp[1][ (col+1) * 3 ];
                    g = cp[1][ (col+1) * 3 +1 ];
                    b = cp[1][ (col+1) * 3 +2 ];
                } else { /* pick from left side */
                    r = cp[1][ (col-1) * 3 ];
                    g = cp[1][ (col-1) * 3 +1 ];
                    b = cp[1][ (col-1) * 3 +2 ];
                }
                count = 0;

                // PDebug("\t(%d,%d) : Ref=(%02X-%02X-%02X)\n",row,col,r,g,b);
                for( i = 0; i <= 2; i++) {
                    if( cp[i] ) { /* Skip NULLs */
                        WORD j;
                        for(j = -1; j <= 1; j++ ) {
                            ULONG offset;
                            offset = (col+j)*3;
                            if( cp[i][ offset ] == r ) {
                                if( cp[i][ offset+1 ] == g ) {
                                    if( cp[i][ offset+2 ] == b ) {
                                        // PDebug("\t\tMatch found at (%d,%d)\n", row+i, col+j);
                                        if( !(i == 1 && j == 0) ) /* Don't count middle */
                                            count++;
                                    }
                                }
                            }
                        }
                    }
                }
                break;


            case CS_ARGB:
                if(col == 0) { /* Pick from right side */
                    r = cp[1][ (col+1) * 4 +1 ];
                    g = cp[1][ (col+1) * 4 +2 ];
                    b = cp[1][ (col+1) * 4 +3 ];
                } else { /* pick from left side */
                    r = cp[1][ (col-1) * 4 + 1];
                    g = cp[1][ (col-1) * 4 + 2];
                    b = cp[1][ (col-1) * 4 + 3];
                }
                count = 0;

                // PDebug("\t(%d,%d) : Ref=(%02X-%02X-%02X)\n",row,col,r,g,b);
                for( i = 0; i <= 2; i++) {
                    if( cp[i] ) { /* Skip NULLs */
                        WORD j;
                        for(j = -1; j <= 1; j++ ) {
                            ULONG offset;
                            offset = (col+j)*4;
                            if( cp[i][ offset + 1 ] == r ) {
                                if( cp[i][ offset+2 ] == g ) {
                                    if( cp[i][ offset+3 ] == b ) {
                                        // PDebug("\t\tMatch found at (%d,%d)\n", row+i, col+j);
                                        if( !(i == 1 && j == 0) ) /* Don't count middle */
                                            count++;
                                    }
                                }
                            }
                        }
                    }
                }
                break;

            case CS_GRAYLEVEL:
                /* Colorspace is greyscale */
                if(col == 0)  /* Pick from right side */
                    r = cp[1][ (col+1) ];
                else  /* pick from left side */
                    r = cp[1][ (col-1) ];
                count = 0;

                // PDebug("\t(%d,%d) : Ref=(%02X-%02X-%02X)\n",row,col,r,g,b);
                for( i = 0; i <= 2; i++) {
                    if( cp[i] ) {
                        WORD j;

                        for(j = -1; j <= 1; j++ ) {
                            if( cp[i][ (col+j) ] == r ) {
                                // PDebug("\t\tMatch found at (%d,%d)\n", row+i, col+j);
                                if( !(i == 1 && j == 0) ) /* Don't count middle */
                                    count++;
                            }
                        }
                    }
                }
                break;
            }

            // PDebug("\t\tcount = %d\n",count);
            /* Was this one alone? */
            if(count == 8) {
                UBYTE *scp, *dcp;
                WORD i;

                // PDebug("\tPixel at (%d,%d) is alone\n",row,col);
                dcp = cp[1] + col*comps;
                if( col == 0 )
                    scp = cp[1]+(col+1)*comps;
                else
                    scp = cp[1]+(col-1)*comps;

                for(i = 0; i < comps; i++) {
                    *dcp++ = *scp++;
                }
            } /* count */

        } /* for(col = ...) */
        PutNPixelRows(frame,cp,row-1,3);
    } /* for(row = ...) */

quit:
    FinishProgress(frame);

    return frame;
}
Exemplo n.º 8
0
void CAccountManagerProcessingPage::OnStateChange( CAccountManagerProcessingPageEvent& WXUNUSED(event) )
{
    CMainDocument* pDoc = wxGetApp().GetDocument();
    CWizardAttach* pWA = ((CWizardAttach*)GetParent());
    wxDateTime dtStartExecutionTime;
    wxDateTime dtCurrentExecutionTime;
    wxTimeSpan tsExecutionTime;
    ACCT_MGR_RPC_REPLY reply;
    wxString strBuffer = wxEmptyString;
    std::string url = "";
    std::string username = "";
    std::string password = "";
    bool bPostNewEvent = true;
    int iReturnValue = 0;
    unsigned int i;
 
    wxASSERT(pDoc);
    wxASSERT(wxDynamicCast(pDoc, CMainDocument));
 
    switch(GetCurrentState()) {
        case ATTACHACCTMGR_INIT:
            pWA->DisableNextButton();
            pWA->DisableBackButton();
            StartProgress(m_pProgressIndicator);
            SetNextState(ATTACHACCTMGR_ATTACHACCTMGR_BEGIN);
            break;
        case ATTACHACCTMGR_ATTACHACCTMGR_BEGIN:
            SetNextState(ATTACHACCTMGR_ATTACHACCTMGR_EXECUTE);
            break;
        case ATTACHACCTMGR_ATTACHACCTMGR_EXECUTE:
            // Attempt to attach to the account manager.

            // Newer versions of the server-side software contain the correct
            //   master url in the get_project_config response.  If it is available
            //   use it instead of what the user typed in.
            if (!pWA->project_config.master_url.empty()) {
                url = pWA->project_config.master_url;
            } else {
                url = (const char*)pWA->m_AccountManagerInfoPage->GetProjectURL().mb_str();
            }

            if (pWA->project_config.uses_username) {
                username = (const char*)pWA->m_AccountInfoPage->GetAccountUsername().mb_str();
            } else {
                username = (const char*)pWA->m_AccountInfoPage->GetAccountEmailAddress().mb_str();
            }
            password = (const char*)pWA->m_AccountInfoPage->GetAccountPassword().mb_str();
            
            // Wait until we are done processing the request.
            dtStartExecutionTime = wxDateTime::Now();
            dtCurrentExecutionTime = wxDateTime::Now();
            tsExecutionTime = dtCurrentExecutionTime - dtStartExecutionTime;
            iReturnValue = 0;
            reply.error_num = ERR_RETRY;
            while (
                !iReturnValue && 
                ((ERR_IN_PROGRESS == reply.error_num) || (ERR_RETRY == reply.error_num)) &&
                (tsExecutionTime.GetSeconds() <= 60) &&
                !CHECK_CLOSINGINPROGRESS()
            ) {
                if (ERR_RETRY == reply.error_num) {
                    pDoc->rpc.acct_mgr_rpc(
                        url.c_str(),
                        username.c_str(),
                        password.c_str(),
                        pWA->m_bCredentialsCached
                    );
                }
            
                dtCurrentExecutionTime = wxDateTime::Now();
                tsExecutionTime = dtCurrentExecutionTime - dtStartExecutionTime;
                iReturnValue = pDoc->rpc.acct_mgr_rpc_poll(reply);

                IncrementProgress(m_pProgressIndicator);

                ::wxMilliSleep(500);
                wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_USER_INPUT);
            }
    
            if (!iReturnValue && !reply.error_num) {
                SetProjectAttachSucceeded(true);
                pWA->SetAttachedToProjectSuccessfully(true);
            } else {
                SetProjectAttachSucceeded(false);

                if ((ERR_NOT_FOUND == reply.error_num) ||
					(ERR_DB_NOT_FOUND == reply.error_num) ||
                    (ERR_BAD_EMAIL_ADDR == reply.error_num) ||
                    (ERR_BAD_PASSWD == reply.error_num)
                ) {
                    // For any logon error, make sure we do not attempt to use cached credentials
                    //   on any follow-ups.
                    pWA->m_bCredentialsCached = false;
                    SetProjectAccountNotFound(true);
                } else {
                    SetProjectAccountNotFound(false);
                }

                strBuffer = pWA->m_CompletionErrorPage->m_pServerMessagesCtrl->GetLabel();
                if ((HTTP_STATUS_INTERNAL_SERVER_ERROR == reply.error_num)) {
                    strBuffer += 
                        _("An internal server error has occurred.\n");
                } else {
                    for (i=0; i<reply.messages.size(); i++) {
                        strBuffer += wxString(reply.messages[i].c_str(), wxConvUTF8) + wxString(wxT("\n"));
                    }
                }
                pWA->m_CompletionErrorPage->m_pServerMessagesCtrl->SetLabel(strBuffer);
            }
            SetNextState(ATTACHACCTMGR_CLEANUP);
            break;
        case ATTACHACCTMGR_CLEANUP:
            FinishProgress(m_pProgressIndicator);
            SetNextState(ATTACHACCTMGR_END);
            break;
        default:
            // Allow a glimps of what the result was before advancing to the next page.
            wxSleep(1);
            pWA->EnableNextButton();
            pWA->EnableBackButton();
            pWA->SimulateNextButton();
            bPostNewEvent = false;
            break;
    }
 
    Update();
 
    if (bPostNewEvent && !CHECK_CLOSINGINPROGRESS()) {
        CAccountManagerProcessingPageEvent TransitionEvent(wxEVT_ACCOUNTMANAGERPROCESSING_STATECHANGE, this);
        AddPendingEvent(TransitionEvent);
    }
}
Exemplo n.º 9
0
const u8 * NetReceiver::ReceiveData()
{
	if(connection < 0)
		return NULL;

	if(filebuffer)
		free(filebuffer);
	filebuffer = NULL;

	filebuffer = (u8 *) malloc(filesize);
	if(!filebuffer)
	{
		ShowError(tr("Not enough memory."));
		return NULL;
	}

	StartProgress(tr("Receiving file..."));

	u32 done = 0;
	u32 blocksize = 5*1024;
	char tmptxt[200];
	snprintf(tmptxt, sizeof(tmptxt), "Incomming from: %s", incommingIP);

	int retries = 5;

	do
	{
		if(ProgressWindow::Instance()->IsCanceled())
		{
			FreeData();
			StopProgress();
			ShowError(tr("Transfer cancelled."));
			return NULL;
		}

		if (blocksize > filesize - done)
			blocksize = filesize - done;

		ShowProgress(done, filesize, tmptxt);

		int result = network_read(connection, filebuffer+done, blocksize);
		if(result < 0)
		{
			--retries;
			if(retries == 0)
			{
				FreeData();
				StopProgress();
				ShowError(tr("Transfer failed."));
				return NULL;
			}
		}
		if(!result)
		{
			--retries;
			if(!retries)
				break;
		}

		done += result;

	} while(done < filesize);

	// finish up the progress
	FinishProgress(filesize);

	StopProgress();

	if(done != filesize)
	{
		FreeData();
		ShowError(tr("Filesize doesn't match."));
	}

	char temp[50];
	network_read(connection, (u8 *) temp, 49);
	temp[49] = 0;

	snprintf(FileName, sizeof(FileName), "%s", temp);

	if(UncompressData() == NULL)
	{
		FreeData();
		ShowError(tr("Could not decompress the file."));
	}

	return filebuffer;
}
Exemplo n.º 10
0
Arquivo: file.c Projeto: jalkanen/ppt
int DoConvolute( FRAME *src, FRAME *dest, struct convargs *cargs, struct PPTBase *PPTBase )
{
    UWORD row, xstart = src->selbox.MinX, xend = src->selbox.MaxX;
    WORD crow;
    int d;
    PERROR res = PERR_OK;
    UBYTE buf[40],cspace = src->pix->colorspace;
    ULONG xoffset;
    ROWPTR buffer[7]; /* Has room for 7x7 matrices */

#ifdef DEBUG_MODE
    PDebug("\tDoConvolute()\n");
#endif

    if(SetFilterSize( cargs ) == 0)
        return PERR_GENERAL;

    sprintf(buf,"Convolute: %s [%dx%d]...",cargs->name,cargs->size, cargs->size);

    InitProgress( src, buf, src->selbox.MinY, src->selbox.MaxY );

    d = cargs->size >> 1;
#ifdef DEBUG_MODE
    PDebug("\tConvolution matrix size is %d x %d (%d...%d)\n",cargs->size,cargs->size,-d,d);
#endif
    xoffset = xstart * src->pix->components;

    /*
     *  Do the convolute.
     */

    for( row = src->selbox.MinY; row < src->selbox.MaxY; row++ ) {
        ROWPTR dcp, dcp2;
        WORD col;

        dcp2 = dcp = GetPixelRow( dest, row );
        dcp += xoffset;
        if(GetNPixelRows( src, buffer, row - d, cargs->size ) == 0) {
            res = PERR_GENERAL;
            goto quit;
        }

        if(Progress( src, row )) {
            res = PERR_BREAK;
            goto quit;
        }

        for( col = xstart; col < xend; col++ ) {
            int i;
            LONG valr,valg,valb,vala;

            /*
             *  Now, go through all values
             */

            valr = valb = valg = vala = 0L;

            for(i = -d; i <= d; i++) {
                UBYTE *scp;

                crow = row + i;
                scp = buffer[ i + d ];

                if( crow >= 0 && crow < src->pix->height ) {
                    int j;

                    for(j = -d; j <= d; j++ ) {
                        WORD ccol;

                        ccol = (WORD)col + j;
                        if( ccol >= 0 && ccol < src->pix->width ) {
                            /* Actual convolution */
                            int wt;
                            if( ( wt = cargs->weights[i+3][j+3]) ) {
                                UBYTE *pptr;
                                switch(cspace) {
                                    case CS_RGB:
                                        pptr = scp + MULS16(ccol,3);
                                        valr += (*pptr++) * wt;
                                        valg += (*pptr++) * wt;
                                        valb += (*pptr++) * wt;
                                        break;

                                    case CS_GRAYLEVEL:
                                        pptr = scp + ccol;
                                        valr += (*pptr++) *wt;
                                        break;

                                    case CS_ARGB:
                                        pptr = scp + (ccol<<2);
                                        if( i == 0 && j == 0 ) vala = *pptr;
                                        pptr++; /* Skip alpha */
                                        valr += (*pptr++) * wt;
                                        valg += (*pptr++) * wt;
                                        valb += (*pptr++) * wt;
                                        break;
                                }
                            }
                        } /* if ccol */
                    }
                } /* if crow */
            }

            switch(cspace) {
                case CS_GRAYLEVEL:
                    valr = valr / cargs->div + cargs->bias;
                    if(valr < 0) valr = 0;
                    else { if(valr > 255) valr = 255; }
                    *dcp++ = (UBYTE)valr;
                    break;

                case CS_ARGB:
                    *dcp++ = vala;
                    /* FALLTHROUGH INTENDED */

                case CS_RGB:
                    /* RED  */
                    valr = valr / cargs->div + cargs->bias;
                    if(valr < 0) valr = 0;
                    else { if(valr > 255) valr = 255; }
                    *dcp++ = (UBYTE)valr;

                    /* GREEN*/
                    valg = valg / cargs->div + cargs->bias;
                    if(valg < 0) valg = 0;
                    else { if(valg > 255) valg = 255; }
                    *dcp++ = (UBYTE)valg;

                    /* BLUE */
                    valb = valb / cargs->div + cargs->bias;
                    if(valb < 0) valb = 0;
                    else { if(valb > 255) valb = 255; }
                    *dcp++ = (UBYTE)valb;
                    break;
            }

        }
        PutPixelRow( dest, row, dcp2 );

    }
quit:
    FinishProgress(src);

    return res;
}
Exemplo n.º 11
0
FRAME *DoComposite( FRAME *dest, FRAME *src, struct gFixRectMessage *gfr,
                    MethodID how, WORD mixratio, BOOL tile, struct PPTBase *PPTBase )
{
    WORD row, col;
    WORD dcomps = dest->pix->components,
         scomps = src->pix->components;
    WORD dest_has_alpha = 0, src_has_alpha = 0;
    WORD top, bottom, left, right;

    D(bug("Doing the composite.  gfr = %d,%d,%d,%d\n",
           gfr->x, gfr->y, gfr->dim.Width, gfr->dim.Height));

    /*
     *  Initialize
     */

    if( src->pix->colorspace == CS_ARGB )
        src_has_alpha = 1;

    if( dest->pix->colorspace == CS_ARGB )
        dest_has_alpha = 1;

    if( tile ) {
        top = dest->selbox.MinY;
        left = dest->selbox.MinX;
        bottom = dest->selbox.MaxY;
        right = dest->selbox.MaxX;
    } else {
        top = gfr->y;
        bottom = gfr->y + gfr->dim.Height;
        left = gfr->x;
        right = gfr->x + gfr->dim.Width;
    }

    InitProgress( dest, "Compositing...", top, bottom );

    for( row = top; row < bottom; row++ ) {
        ROWPTR scp, dcp;
        WORD srow;

        srow = (row - gfr->y) % gfr->dim.Height;
        if( srow < 0 && tile ) srow += gfr->dim.Height;

        scp = GetPixelRow(src,  srow);
        dcp = GetPixelRow(dest, row);

        if( !dcp ) continue; /* Skip all areas that are outside */

        if( Progress(dest, row) )
            return NULL;

        for( col = left; col < right; col++ ) {
            LONG a, tr,tg,tb;
            UBYTE *s, *d;
            WORD scol;

            /*
             *  Sanitation check.  Let's not overwrite innocent
             *  memory.
             */

            if( col < 0 || col >= dest->pix->width ) continue;

            scol = ( col - gfr->x ) % gfr->dim.Width;
            if( scol < 0 && tile ) scol += gfr->dim.Width;

            if( src_has_alpha )
                a = (LONG)scp[scomps*scol];

            d = &dcp[dcomps*col+dest_has_alpha];
            s = &scp[scomps*scol+src_has_alpha];

            tr = *(d+0);
            tg = *(d+1);
            tb = *(d+2);

            switch( how ) {
                case Direct:
                    tr = *s; tg = *(s+1); tb = *(s+2);
                    break;

                case Minimum:
                    if( VECTOR_LEN(tr, tg, tb) > VECTOR_LEN(*s, *(s+1), *(s+2)) ) {
                        tr = *s; tg = *(s+1); tb = *(s+2);
                    }
                    break;

                case Maximum:
                    if( VECTOR_LEN(tr, tg, tb) < VECTOR_LEN(*s, *(s+1), *(s+2)) ) {
                        tr = *s; tg = *(s+1); tb = *(s+2);
                    }
                    break;

                case Mix:
                    tr = (mixratio * (*s) + (255-mixratio) * tr ) / 255;
                    tg = (mixratio * (*(s+1)) + (255-mixratio) * tg ) / 255;
                    tb = (mixratio * (*(s+2)) + (255-mixratio) * tb ) / 255;
                    break;

                case TransparentBlack:
                    if( *s || *(s+1) || *(s+2) ) {
                        tr = *s; tg = *(s+1); tb = *(s+2);
                    }
                    break;

                case Add:
                    tr = CLAMP_UP(*(s+0) + tr, 255);
                    tg = CLAMP_UP(*(s+1) + tg, 255);
                    tb = CLAMP_UP(*(s+2) + tb, 255);
                    break;

                case Subtract:
                    tr = CLAMP_DOWN( tr - *(s+0), 0 );
                    tg = CLAMP_DOWN( tg - *(s+1), 0 );
                    tb = CLAMP_DOWN( tb - *(s+2), 0 );
                    break;

                case Multiply:
                    tr = (tr * *(s+0)) / 256;
                    tg = (tg * *(s+1)) / 256;
                    tb = (tb * *(s+2)) / 256;
                    break;
            }

            if( src_has_alpha ) {
                tr = ((255-a) * tr + a * *(d+0) ) /256;
                tg = ((255-a) * tg + a * *(d+1) ) /256;
                tb = ((255-a) * tb + a * *(d+2) ) /256;
            }

            *d     = tr;
            if( dest->pix->colorspace != CS_GRAYLEVEL ) {
                *(d+1) = tg;
                *(d+2) = tb;
            }

#if 0
            for( pix = 0; pix < colors; pix++ ) {
                UBYTE s,d;
                LONG  t;

                d = dcp[dcomps*col+pix+dest_has_alpha];
                s = scp[scomps*(col-gfr->x)+pix+src_has_alpha];
                t = (LONG)d;

                switch(how) {
                    case Direct:
                        t = s;
                        break;

                    case Minimum:
                        if( d > s ) t = s;
                        break;

                    case Maximum:
                        if( d < s ) t = s;
                        break;

                    case Mix:
                        t = (mixratio*s + (255-mixratio)*d)/255;
                        break;

                    case TransparentBlack:
                        if( s != 0 ) t = s;
                        break;

                    case Add:
                        t = d+s;
                        if( t > 255 ) t = 255;
                        break;

                    case Subtract:
                        t = d-s;
                        if( t < 0 ) t = 0;
                        break;

                    case Multiply:
                        t = ((LONG)d * (LONG)s) / 256;
                        break;

                }

                if( src_has_alpha )
                    t = ((255-a) * t + a*d)/255;

                dcp[dcomps*col+pix+dest_has_alpha] = (UBYTE)t;
            }
#endif
        }
        PutPixelRow(dest,row,dcp);
    }

    FinishProgress(dest);

    return dest;
}