BOOL ContBritImage(LPIMAGE lpImage, LPCONTBRIT_PARMS lpParms) /************************************************************************/ { LPMAPS lpMaps; int i; RECT rUpdate; UPDATE_TYPE UpdateType; FRMDATATYPE type; ImgGetInfo(lpImage, NULL, NULL, NULL, &type); if (type == FDT_LINEART) return(FALSE); else if (type == FDT_PALETTECOLOR && ImgGetMask(lpImage)) return(FALSE); if (!(lpMaps = (LPMAPS)Alloc((long)sizeof(MAPS)))) { lpParms->Common.StatusCode = SC_MEMERROR; Message(IDS_EMEMALLOC); return(FALSE); } ProgressBegin(1, lpParms->Common.idDirty-IDS_UNDOFIRST+IDS_PROGFIRST); ResetMapEx( &lpMaps->MasterMap, MAPPOINTS, NO, YES); ResetMap( &lpMaps->RedMap, MAPPOINTS, NO ); // sometimes Cyan ResetMap( &lpMaps->GreenMap, MAPPOINTS, NO ); // sometimes Magenta ResetMap( &lpMaps->BlueMap, MAPPOINTS, NO ); // sometimes Yellow ResetMap( &lpMaps->BlackMap, MAPPOINTS, NO ); ResetMap( &lpMaps->HueMap, MAXPOINTS, NO ); ResetMap( &lpMaps->SatMap, MAPPOINTS, NO ); lpMaps->MasterMap.Contrast = lpParms->Contrast; for (i = 0; i < NUM_BANDS; ++i) lpMaps->MasterMap.Brightness[i] = lpParms->Brightness[i]; MakeMap(&lpMaps->MasterMap); lpParms->Common.StatusCode = ApplyMaps(lpImage, lpMaps, lpParms->Common.idDirty, &rUpdate, &UpdateType); if (UpdateType) { lpParms->Common.UpdateType = UpdateType; lpParms->Common.rUpdateArea = rUpdate; } FreeUp(lpMaps); ProgressEnd(); return(lpParms->Common.StatusCode == SC_SUCCESS); }
// Uses Mapping.Quarter_HSacrifice & Mapping.Quarter_SSacrifice // to set the highlights midtones and shaddows. void CToneBalanceDlg::set_sacrifice(LPQUARTERSTRUCT lpData, WORD wChannel) { LPMAP lpMap; LPDWORD lpHisto; BOOL bInv; LONG lSum, lSearch, lTotal; int hi, lo, i; // get the map & set its invert flags lpMap = tone_activate_channel( wChannel ); lpHisto = get_histo(lpData->lpHistos, wChannel, &bInv); // determine initail values hi = 170; lo = 85; if (lpHisto) { // Find the total of all entries to scale lTotal = 0; for ( i=0; i<256; i++ ) lTotal += lpHisto[i]; // find the sacrafice lSearch = bInv ? m_nHSacrifice:m_nSSacrifice; lSearch = FMUL( lTotal, FGET( lSearch, 100 ) ); lSum = -1; for ( i=0; i<255; i++ ) { lSum += lpHisto[i]; if ( lSum >= lSearch ) break; } lo = i; // find the sacrafice lSearch = bInv ? m_nSSacrifice:m_nHSacrifice; lSearch = FMUL( lTotal, FGET( lSearch, 100 ) ); lSum = -1; for ( i=255; i>0; i-- ) { lSum += lpHisto[i]; if ( lSum >= lSearch ) break; } hi = i; } if (bInv) { hi = 255-hi; lo = 255-lo; } i = lo; lo = min(lo,hi); hi = max(i,hi); // setup the map if (wChannel == IDC_DO_ALL) ResetMapEx( lpMap, 3, NO, YES); else ResetMap( lpMap, 3, NO ); lpMap->Pnt[0].x = lo; lpMap->Pnt[1].x = lo + (hi-lo)/2; lpMap->Pnt[2].x = hi; }