void Halftone_TX::build_r_function_tex( TEXTUREglptr r_function_map, TEXTUREglptr source ) { uint* histogram_array = new uint[256 * LOD_RES]; uint sample_count = 0; //gets value from the function call below build_pattern_histogram(histogram_array,sample_count,source); // constructing the error correction table if (debug) cerr << "Halftone_TX::build_correction_tex: " << "Building the tone response map ... " << endl; // forward R texture compute_forward_R( sample_count, histogram_array, &(r_function_map->image()) ); if (debug) { r_function_map->image().write_png("test_r_function.png"); } delete[] histogram_array; }
void Halftone_TX::build_correction_tex( TEXTUREglptr correction_map, TEXTUREglptr source ) { stop_watch total_timer; // the histograms are fixed size of 256 buckets // and there is one for each of LOD_RES LOD values uint* histogram_array = new uint[256 * LOD_RES]; uint sample_count = 0; //gets value from the function call below build_pattern_histogram(histogram_array,sample_count,source); // constructing the error correction table if (debug) cerr << "Halftone_TX::build_correction_tex: " << "Building the tone response map ... " << endl; stop_watch inv_r_timer; // correction texture for (int i_lod=0; i_lod<LOD_RES; i_lod++) { //fills in a row of inverse R fot this lod value compute_inverse_R( i_lod, sample_count, histogram_array, &(correction_map->image()) ); } if (debug) { cerr << " Inverse R build time : " << inv_r_timer.elapsed_time() << endl; } if (debug) { cerr << "Total time ellapsed : " << total_timer.elapsed_time() << endl; } delete[] histogram_array; }
void Halftone_TX::build_pattern_histogram( uint* histogram, uint &sample_count, TEXTUREglptr source ) { // hardcoded to 256x256 array of histograms for each lod value assert(histogram); stop_watch hist_timer; if (debug) { cerr << " Constructing histogram array ... "; } for (int i=0 ; i<(256*LOD_RES); i++) histogram[i] = 0; uint X_tex; uint Y_tex; if (source) { X_tex = source->get_size()[0]; Y_tex = source->get_size()[1]; } else { //for procedural pattern we use maximum sampling resolution X_tex = 256; Y_tex = 256; } sample_count = X_tex * Y_tex; // building the regular histogram for each LOD value; for (int i_lod=0; i_lod<LOD_RES; i_lod++) { double f_lod = double(i_lod)/double(LOD_RES-1); // 0.0~1.0 for (uint x=0; x<X_tex; x++) for (uint y=0; y<Y_tex; y++) { double sample; if (source) { //sample the halftone texture double sample_hi = source->image().pixel_r((x*2)%X_tex, (y*2) % Y_tex); double sample_lo = source->image().pixel_r(x, y); sample = min(255.0, interp(sample_lo,sample_hi,f_lod)); } else { //sample procedural dots double sample_hi = procedural_dots((double(x)/double(X_tex-1)) * 2.0 , (double(y)/double(Y_tex-1)) * 2.0); double sample_lo = procedural_dots(double(x)/double(X_tex-1), double(y)/double(Y_tex-1)); sample = min(255.0, interp(sample_lo,sample_hi,f_lod)*255.0); } uint bucket = uint(sample + 0.5 ); histogram[256 * i_lod + bucket]+= 1; } } if (debug) { cerr << "Histogram built time : " << hist_timer.elapsed_time() << endl; } }