Esempio n. 1
0
void Palette::PresetApply(PalettePreset &preset)
{
static const U16 b_arr[] = { 0, 1, 3, 0, 0, 1, 3, 0, 0, 1, 3, 0, 0, 1, 3 };
static const U16 r_arr[] = { 0, 0, 0, 1, 3, 1, 3, 0, 0, 0, 0, 1, 3, 1, 3 };
static const U16 g_arr[] = { 0, 0, 0, 0, 0, 0, 0, 1, 3, 1, 3, 1, 3, 1, 3 };
const auto &coeffs = preset.CoeffsGet();
const U16 brights[] = { coeffs.zz, coeffs.zn, coeffs.nn, coeffs.zb, coeffs.nb, 0 /*dummy*/, coeffs.bb };
U16 r, g, b;
U16 tr, tg, tb;

    D_LOG(D_DEBUG, D_LOG_MSG("Apply palette preset: %s", CSTR(preset.NameGet())));
    clear();
    for (auto row = 0; row < PALETTE_ROWS; ++row) {
        for (auto col = row; col < PALETTE_COLUMS; ++col) {
            b = brights[b_arr[row] + b_arr[col]];
            r = brights[r_arr[row] + r_arr[col]];
            g = brights[g_arr[row] + g_arr[col]];

            tr = ((r * coeffs.r11) + (g * coeffs.g12) + (b * coeffs.b13)) / (U16)0x100;
            tg = ((r * coeffs.r21) + (g * coeffs.g22) + (b * coeffs.b23)) / (U16)0x100;
            tb = ((r * coeffs.r31) + (g * coeffs.g32) + (b * coeffs.b33)) / (U16)0x100;
            const PaletteItem item(tr, tg, tb);
            if (TRUE != IsDuplicate(item)) { // Filter duplicate colors.
                append(item);
                //D_LOG(D_DEBUG, D_LOG_MSG("row=%i,\tcol=%i,\tr=%i,\tg=%i,\tb=%i", row, col, tr, tg, tb));
            }
        }
    }
}
Esempio n. 2
0
void BreakptMgr::ReconcileBreakpoints(const std::vector<BreakpointInfo>& li)
{
    std::vector<BreakpointInfo> updated_bps;
    std::vector<BreakpointInfo>::const_iterator li_iter = li.begin();
    for (; li_iter != li.end(); ++li_iter) {
        int index = FindBreakpointById(li_iter->debugger_id, m_bps);
        if (index == wxNOT_FOUND) {

            if(IsDuplicate(*li_iter, updated_bps))
                continue;

            // This will happen e.g. if a bp was auto-set on Main()
            // If so, its internal_id will be invalid
            BreakpointInfo bp = *li_iter;
            bp.internal_id = GetNextID();
            updated_bps.push_back(bp);

        } else {
            // We've match the debugger_id from -break-list with a bp
            // Update the ignore-count, then store it in a new vector
            BreakpointInfo bp = m_bps.at(index);
            bp.ignore_number  = li_iter->ignore_number;
            bp.what           = li_iter->what;
            bp.at             = li_iter->at;

            // Remove it from the m_bps list
            m_bps.erase(m_bps.begin()+index);

            SetBestBPType(bp);  // as this might have just changed
            updated_bps.push_back(bp);
        }
    }
    // All the still-existing bps have been added to updated_bps
    // So throw away m_bps (which will contain stale bps) and replace with the new vector
    // First though, delete all markers. Otherwise, if the last in a file has been deleted...
    DeleteAllBreakpointMarkers();

    // All the stale breakpoints should be assigned to the 'm_pendingBreakpointList'
    m_pendingBreakpointsList = m_bps;

    m_bps.clear();
    SetBreakpoints(updated_bps);

    RefreshBreakpointMarkers();
    // update the Breakpoints pane too
    clMainFrame::Get()->GetDebuggerPane()->GetBreakpointView()->Initialize();
}
nsresult
sbMediaListDuplicateFilter::Advance()
{
  nsresult rv;

  mozilla::ReentrantMonitorAutoEnter mon(mMonitor);

  if (!mInitialized) {
    // Only enumerate if we need to check for duplicates.
    if (mRemoveDuplicates) {
      rv = mDest->EnumerateAllItems(this, sbIMediaList::ENUMERATIONTYPE_SNAPSHOT);
      NS_ENSURE_SUCCESS(rv, rv);
    }
    // Always consider ourselves initialized past this point.
    mInitialized = PR_TRUE;
  }

  PRBool more;
  rv = mSource->HasMoreElements(&more);
  NS_ENSURE_SUCCESS(rv, rv);

  mCurrentItem = nsnull;
  while (more && !mCurrentItem) {
    nsCOMPtr<nsISupports> supports;
    rv = mSource->GetNext(getter_AddRefs(supports));
    NS_ENSURE_SUCCESS(rv, rv);
    mCurrentItem = do_QueryInterface(supports);

    if (mCurrentItem) {
      if (mRemoveDuplicates) {
        bool isDuplicate = false;
        rv = IsDuplicate(mCurrentItem, isDuplicate);
        NS_ENSURE_SUCCESS(rv, rv);
        if (isDuplicate) {
          ++mDuplicateItems;
          // Skipping duplicates then continue enumerating
          mCurrentItem = nsnull;
        }
      }
      ++mTotalItems;
    }
  }
  return NS_OK;
}
Esempio n. 4
0
void ReadConfig(char * ConfigFile) {
    char logMsg[RE_SIZE*3];
    const char *error;
    int erroffset;
    BOOL done= FALSE;
    FILE *infile ;
    unsigned char *p1;
    unsigned char *p2;
    pcre * re;
    //RewriteRule * root= NULL;
    RewriteRule * current= NULL;
    RewriteRule * previous;
    int lineNum=0; 
    int nRules=0;
    int nFailed=0;
    char delims[]= " \n\r\t";

    unsigned char * buffer;

    LogMe(1, "ReadConfig");

    buffer = (unsigned char *)malloc(RE_SIZE);
    if (buffer==NULL) return ;

    /* read config file here, slurping in Rewrite rules */ 

    infile= fopen(ConfigFile, "r");
    if (infile==NULL) return;

    while (!done) {
	lineNum++;
	if (fgets((char *)buffer, RE_SIZE, infile) == NULL) break;

	p1 = buffer;
	while (isspace(*p1)) p1++;
	if (*p1 == 0) continue; // nothing
	if (*p1 == '#') continue; // comment
	p2= strtok(p1, " ");
	if (strnicmp(p2,REWRITE_RULE, strlen(REWRITE_RULE))==0) {
	    char *pPattern = strtok (NULL, delims);
	    char *pReplacement = strtok (NULL, delims);
	    char *pModifiers = strtok (NULL, delims);

	    sprintf(logMsg,"ini line %3d: RewriteRule %3d %-46s %-42s %8s", 
		    lineNum, nRules+1, pPattern, pReplacement, pModifiers );
	    LogMe(1, logMsg);

	    if (IsDuplicate(pPattern)) {
		sprintf(logMsg,"ini file line %d: duplicate expression '%s'", lineNum, pPattern);
		LogMe(1, logMsg);
		continue; 
	    }
	    
	    // Want to create a compiled regex here

	    re = pcre_compile(
			      pPattern,              /* the pattern */
			      0,                    /* default options */
			      &error,               /* for error message */
			      &erroffset,           /* for error offset */
			      NULL);                /* use default character tables */

	    nRules++;
	    if (re == NULL) {
		sprintf(logMsg,"compilation of expression '%s' failed at offset %d: %s", pPattern, erroffset, error);
		LogMe(1, logMsg);
		nFailed++;
	    }
	    
	    previous= current;

	    current= (RewriteRule *) malloc(sizeof(RewriteRule)); 
	    if (root==NULL) root= current; 

	    current->RE= re; //  NULL or not
	    current->Pattern= (char*) malloc(strlen(pPattern)+1); 
	    strcpy(current->Pattern, pPattern);
	    current->Replacement= (char*) malloc(strlen(pReplacement)+1); 
	    strcpy(current->Replacement, pReplacement);
	    current->next= NULL;
	    current->previous= previous;  //NULL for first node, not-NULL for successive

	    if (previous!=NULL) 
		previous->next= current; 
	}

	else if (strnicmp(p2,ITERATION_LIMIT, strlen(ITERATION_LIMIT))==0) {
	    char *pLimit = strtok (NULL, delims);
	    if (pLimit!=NULL) IterationLimit= atoi(pLimit);
	    else IterationLimit=DEFAULT_ITERATION_LIMIT;
	    sprintf(logMsg,"setting Iteration Limit to %d", IterationLimit);
	    LogMe(1, logMsg);
	}

	else if (strnicmp(p2,MAX_MATCH_COUNT, strlen(MAX_MATCH_COUNT))==0) {
	    char *pCount = strtok (NULL, delims);
	    if (pCount!=NULL) MaxMatchCount= atoi(pCount);
	    else MaxMatchCount=DEFAULT_MATCH_COUNT;
	    sprintf(logMsg,"setting MaxMatchCount to %d", MaxMatchCount);
	    LogMe(1, logMsg);
	}

	else {
	    sprintf(logMsg,"ini file line %d: Ignoring line: '%s'", lineNum, p2);
	    LogMe(1, logMsg);
	}
    }

    sprintf(logMsg,"Found %d rules (%d failed) on %d lines", nRules, nFailed, lineNum);
    LogMe(1, logMsg);

    fclose(infile);
    free(buffer);
    return ;
}