static int DoRenderOp(T *map, int width, int height, int d, imRenderFunc render_func, float* param, int counter, int plus) { IM_INT_PROCESSING; #ifdef _OPENMP #pragma omp parallel for if (IM_OMP_MINHEIGHT(height)) #endif for(int y = 0; y < height; y++) { #ifdef _OPENMP #pragma omp flush (processing) #endif IM_BEGIN_PROCESSING; int offset = y * width; for(int x = 0; x < width; x++) { if (plus) { int size_of = sizeof(imbyte); float value = (float)map[offset + x] + render_func(x, y, d, param); if (sizeof(T) == size_of) map[offset + x] = (T)IM_BYTECROP(value); else map[offset + x] = (T)value; } else map[offset + x] = (T)render_func(x, y, d, param); } IM_COUNT_PROCESSING; #ifdef _OPENMP #pragma omp flush (processing) #endif IM_END_PROCESSING; } return processing; }
void imProcessQuantizeGrayUniform(const imImage* src_image, imImage* dst_image, int grays) { int i, value; imbyte *dst_map=(imbyte*)dst_image->data[0], *src_map=(imbyte*)src_image->data[0]; imbyte re_map[256]; memset(re_map, 0, 256); float factor = (float)grays/256.0f; float factor256 = 256.0f/(float)grays; for (i = 0; i < 256; i++) { value = imResample(i, factor); value = imResample(value, factor256); re_map[i] = (imbyte)IM_BYTECROP(value); } int total_count = src_image->count*src_image->depth; for (i = 0; i < total_count; i++) dst_map[i] = re_map[src_map[i]]; }
static int DoGrayMorphConvolve(T *map, T* new_map, int width, int height, const imImage* kernel, int counter, int ismax, DT) { int kw = kernel->width; int kh2 = kernel->height/2; int kw2 = kernel->width/2; DT* kernel_data = (DT*)kernel->data[0]; IM_INT_PROCESSING; #ifdef _OPENMP #pragma omp parallel for if (IM_OMP_MINHEIGHT(height)) #endif for(int j = 0; j < height; j++) { #ifdef _OPENMP #pragma omp flush (processing) #endif IM_BEGIN_PROCESSING; int new_offset = j * width; for(int i = 0; i < width; i++) { DT value, max = 0, min = 0; int init = 0; for(int y = -kh2; y <= kh2; y++) { int line_offset; DT* kernel_line = kernel_data + (y+kh2)*kw; if ((j + y < 0) || // pass the bottom border (j + y >= height)) // pass the top border continue; else line_offset = (j + y) * width; for(int x = -kw2; x <= kw2; x++) { if (kernel_line[x+kw2] != -1) { if ((i + x < 0) || // pass the left border (i + x >= width)) // pass the right border continue; else value = kernel_line[x+kw2] + map[line_offset + (i + x)]; if (init == 0) // first time here for each pass { if (ismax) max = value; else min = value; init = 1; } else { if (ismax && value > max) max = value; if (!ismax && value < min) min = value; } } } } int size_of = sizeof(imbyte); if (sizeof(T) == size_of) { if (ismax) new_map[new_offset + i] = (T)IM_BYTECROP(max); else new_map[new_offset + i] = (T)IM_BYTECROP(min); } else { if (ismax) new_map[new_offset + i] = (T)max; else new_map[new_offset + i] = (T)min; } } IM_COUNT_PROCESSING; #ifdef _OPENMP #pragma omp flush (processing) #endif IM_END_PROCESSING; } return processing; }