static int gralloc_lock(gralloc_module_t const* module, buffer_handle_t handle, int usage, int l, int t, int w, int h, void** vaddr) { int err = 0; if (private_handle_t::validate(handle) < 0) { ALOGE("Locking invalid buffer, returning error"); return -EINVAL; } private_handle_t* hnd = (private_handle_t*)handle; #ifdef SAMSUNG_EXYNOS_CACHE_UMP if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_UMP) { #ifdef USE_PARTIAL_FLUSH private_handle_rect *psRect; psRect = find_rect((int)hnd->ump_id); psRect->l = l; psRect->t = t; psRect->w = w; psRect->h= h; psRect->locked = 1; #endif } #endif if (usage & (GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK)) *vaddr = (void*)hnd->base; if (usage & GRALLOC_USAGE_YUV_ADDR) { vaddr[0] = (void*)hnd->base; vaddr[1] = (void*)(hnd->base + hnd->uoffset); vaddr[2] = (void*)(hnd->base + hnd->uoffset + hnd->voffset); } return err; }
static int gralloc_unlock(gralloc_module_t const* module, buffer_handle_t handle) { if (private_handle_t::validate(handle) < 0) { ALOGE("Unlocking invalid buffer, returning error"); return -EINVAL; } private_handle_t* hnd = (private_handle_t*)handle; #ifdef SAMSUNG_EXYNOS_CACHE_UMP if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_UMP) { #ifdef USE_PARTIAL_FLUSH private_handle_rect *psRect; psRect = find_rect((int)hnd->ump_id); ump_cpu_msync_now((ump_handle)hnd->ump_mem_handle, UMP_MSYNC_CLEAN, (void *)(hnd->base + (psRect->stride * psRect->t)), psRect->stride * psRect->h ); return 0; #endif ump_cpu_msync_now((ump_handle)hnd->ump_mem_handle, UMP_MSYNC_CLEAN_AND_INVALIDATE, NULL, 0); } #endif if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION) ion_msync(hnd->ion_client, hnd->fd, IMSYNC_DEV_TO_RW | IMSYNC_SYNC_FOR_DEV, hnd->size, hnd->offset); if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_IOCTL) { int ret; exynos_mem_flush_range mem; mem.start = hnd->paddr; mem.length = hnd->size; ret = ioctl(gMemfd, EXYNOS_MEM_PADDR_CACHE_FLUSH, &mem); if (ret < 0) { ALOGE("Error in exynos-mem : EXYNOS_MEM_PADDR_CACHE_FLUSH (%d)\n", ret); return false; } } return 0; }
object *baseline(unsigned char *image, unsigned char *mask, int width, int height, int *n_object) { int i = 0, j = 0, k = 0; int n; /* number of objects */ int *area; /* area */ double *len; /* perimeter length */ double *circ; /* circularity index */ double *input_val; /*Color features*/ double *clr_mn_value, *clr_std_dev, *clr_skew, *clr_kurtosis, **clr_hist; /*Texture features*/ double ***glcmat, *ang_sec_mom, *contr, *corr, *var; double *inv_diff_mom, *sum_av, *sum_entrp, *sum_varnc; double *entrp, *diff_var, *diff_entrp; object *obj; /* for storing results */ int **obj_id = (int **)malloc(height*sizeof(int *)); if (obj_id == NULL){ printf("Could not allocate %d bytes.\n", height*sizeof(int *)); exit(0); } else{ for (i = 0; i < height; i++){ obj_id[i] = (int *)malloc(width*sizeof(int)); if (obj_id[i] == NULL){ printf("Could not allocate %d bytes for i=%d index.\n", width*sizeof(int), i); exit(0); } } } /* assign ID to each object and returns the number of objects */ n = assign_id(mask, width, height, obj_id); /* allocate memories */ area = (int *)malloc(n * sizeof(int)); if (area == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(int))); exit(-1); } len = (double *)malloc(n * sizeof(double)); if (len == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } circ = (double *)malloc(n * sizeof(double)); if (circ == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } obj = (object *)malloc(n * sizeof(object)); if (obj == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(object))); exit(-1); } /*Colors*/ clr_mn_value = (double *)malloc(n * sizeof(double)); if (clr_mn_value == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } input_val = (double *)malloc(n * sizeof(double)); if (input_val == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } clr_std_dev = (double *)malloc(n * sizeof(double)); if (clr_std_dev == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } clr_skew = (double *)malloc(n * sizeof(double)); if (clr_skew == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } clr_kurtosis = (double *)malloc(n * sizeof(double)); if (clr_kurtosis == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } clr_hist = (double **)malloc(n*sizeof(double *)); if (clr_hist == NULL){ printf("Could not allocate %d bytes.\n", n*sizeof(double *)); exit(0); } else{ for (i = 0; i < n; i++){ clr_hist[i] = (double *)malloc(256*sizeof(double)); if (clr_hist[i] == NULL){ printf("Could not allocate %d bytes for i=%d index.\n", 256*sizeof(double), i); exit(0); } else{ for (j = 0; j<256; j++){ clr_hist[i][j] = 0.0; } } } } /*Texture*/ glcmat = (double ***)malloc(n * sizeof(double**)); if (glcmat == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double**))); exit(-1); } else{ for (i = 0;i < n; i++){ glcmat[i] = (double **)malloc(256 * sizeof(double *)); if (glcmat[i] == NULL){ printf("Cannot allocate %d bytes for memory.\n", (256 * sizeof(double *))); exit(-1); } else{ for (j = 0;j < 256; j++){ glcmat[i][j] = (double *)malloc(256 * sizeof(double)); if (glcmat[i][j] == NULL){ printf("Cannot allocate %d bytes for memory.\n", (256 * sizeof(double))); exit(-1); } else{ for (k = 0;k < 256;k++){ glcmat[i][j][k] = 0.0; } } }/*for j*/ } }/*for i*/ } ang_sec_mom = (double *)malloc(n * sizeof(double)); if (ang_sec_mom == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } memset(ang_sec_mom, 0, (n * sizeof(double))); contr = (double *)malloc(n * sizeof(double)); if (contr == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } memset(contr, 0, (n * sizeof(double))); corr = (double *)malloc(n * sizeof(double)); if (corr == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } memset(corr, 0, (n * sizeof(double))); var = (double *)malloc(n * sizeof(double)); if (var == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } memset(var, 0, (n * sizeof(double))); inv_diff_mom = (double *)malloc(n * sizeof(double)); if (inv_diff_mom == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } memset(inv_diff_mom, 0, (n * sizeof(double))); sum_av = (double *)malloc(n * sizeof(double)); if (sum_av == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } memset(sum_av, 0, (n * sizeof(double))); sum_entrp = (double *)malloc(n * sizeof(double)); if (sum_entrp == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } memset(sum_entrp, 0, (n * sizeof(double))); sum_varnc = (double *)malloc(n * sizeof(double)); if (sum_varnc == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } memset(sum_varnc, 0, (n * sizeof(double))); entrp = (double *)malloc(n * sizeof(double)); if (entrp == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } memset(entrp, 0, (n * sizeof(double))); diff_var = (double *)malloc(n * sizeof(double)); if (diff_var == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } memset(diff_var, 0, (n * sizeof(double))); diff_entrp = (double *)malloc(n * sizeof(double)); if (diff_entrp == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } memset(diff_entrp, 0, (n * sizeof(double))); /* calcuate areas */ calculate_area(obj_id, width, height, n, area); /* calcuate perimeter length */ calculate_length(obj_id, width, height, n, len, image); /* calcuate cirularity index */ /* morphological_feature_circularity_index(area, len, n, circ); morphological_feature_object_moment(1.0, 1.0, obj_id, width, height, n, image, circ); morphological_feature_central_moments(0.0, 0.0, obj_id, width, height, n, image, circ); morphological_feature_object_orientation(obj_id, width, height, n, image, circ); */ morphological_feature_object_eccentricity(obj_id, width, height, n, image, circ); /* morphological_feature_central_invariant_moments(1.0, 1.0, obj_id, width, height, n, image, circ); */ /*color features*/ /* color_feature_mean(obj_id, width, height, n, area, image, clr_mn_value); color_feature_standard_deviation(obj_id, width, height, n, area, image, clr_mn_value, clr_std_dev); color_feature_skewness(obj_id, width, height, n, area, image, clr_mn_value, clr_skew); color_feature_kurtosis(obj_id, width, height, n, area, image, clr_mn_value, clr_kurtosis); color_feature_histogram(0, obj_id, width, height, n, area, image, clr_hist); */ /*texture features*/ /* glcm(0, obj_id, width, height, n, image, glcmat); texture_feature_angular_second_moment(glcmat, n, ang_sec_mom); texture_feature_contrast(glcmat, n, contr); texture_feature_correlation(glcmat, n, corr); texture_feature_variance(glcmat, n, var); texture_feature_inverse_diff_moment(glcmat, n, inv_diff_mom); texture_feature_sum_average(glcmat, n, sum_av); texture_feature_sum_entropy(glcmat, n, sum_entrp); texture_feature_sum_variance(glcmat, n, sum_entrp, sum_varnc); texture_feature_entropy(glcmat, n, entrp); texture_feature_difference_variance(glcmat, n, diff_var); texture_feature_difference_entropy(glcmat, n, diff_entrp); */ double weight = 0.0; for (i = 0; i < n; i++) { /*Morphological feature*/ input_val[i] = circ[i]; /*Color features*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*clr_mn_value[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*clr_std_dev[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*clr_skew[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*clr_kurtosis[i];*/ /*input_val[i] = weight*circ[i] + weight*clr_mn_value[i] + weight*clr_std_dev[i] + weight*clr_skew[i] + weight*clr_kurtosis[i];*/ /*input_val[i] = weight*clr_mn_value[i] + weight*clr_std_dev[i] + weight*clr_skew[i] + weight*clr_kurtosis[i];*/ /*Texture features*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*ang_sec_mom[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*contr[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*corr[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*var[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*inv_diff_mom[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*sum_av[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*sum_entrp[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*sum_varnc[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*entrp[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*diff_var[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*diff_entrp[i];*/ } /* k-means clustering */ /*k_means(circ, obj, n);*/ k_means(input_val, obj, n); /* choose representatives (smallest number for each cluster) */ for (i = 0; i < n; i++) obj[i].rep = 0; for (j = 0; j < NUM_CLASS; j++) { for (i = 0; i < n; i++) { if (obj[i].label == j) { obj[i].rep = 1; break; } } } /* find bounding box */ find_rect(obj_id, width, height, n, obj); for (i = 0; i < height; i++) free(obj_id[i]); free(obj_id); free(area); free(len); free(circ); free(input_val); /*color features*/ free(clr_mn_value); free(clr_std_dev); free(clr_skew); free(clr_kurtosis); for (i = 0; i < n; i++) free(clr_hist[i]); free(clr_hist); /*texture features*/ for (i=0;i<n;i++){ for (j=0;j<256;j++){ free(glcmat[i][j]); }/*for j*/ free(glcmat[i]); }/*for i*/ free(glcmat); free(ang_sec_mom); free(contr); free(corr); free(var); free(inv_diff_mom); free(sum_av); free(sum_entrp); free(sum_varnc); free(entrp); free(diff_var); free(diff_entrp); *n_object = n; return obj; }