void diff_c ( unsigned char *src, unsigned char *src_2, unsigned char *dst, int m, // columnas int n, // filas int src_row_size, int src_2_row_size, int dst_row_size ) { unsigned char (*src_matrix)[src_row_size] = (unsigned char (*)[src_row_size]) src; unsigned char (*src_2_matrix)[src_2_row_size] = (unsigned char (*)[src_2_row_size]) src_2; unsigned char (*dst_matrix)[dst_row_size] = (unsigned char (*)[dst_row_size]) dst; for (int i = 0; i < n; i++) { for (int j = 0; j < 4 * m; j = j + 4) { unsigned char b_diff = ABS_DIFF(src_matrix[i][j], src_2_matrix[i][j]); unsigned char g_diff = ABS_DIFF(src_matrix[i][j+1], src_2_matrix[i][j+1]); unsigned char r_diff = ABS_DIFF(src_matrix[i][j+2], src_2_matrix[i][j+2]); unsigned char diff = MAX_3(b_diff, g_diff, r_diff); dst_matrix[i][j] = diff; dst_matrix[i][j+1] = diff; dst_matrix[i][j+2] = diff; dst_matrix[i][j+3] = 255; } } }
HSV RGB2HSV(RGBf rgb){ HSV hsv; float min, max, delta; int r, g, b; r = rgb.r; g = rgb.g; b = rgb.b; min = MIN_3(r, g, b); max = MAX_3(r, g, b); hsv.v = max; // v delta = max - min; if(delta == 0){ hsv.h = 0; hsv.s = 0; hsv.v = hsv.v / 255.0; return hsv; } if( max != 0 ) { hsv.s = delta / max; // s } else { // r = g = b = 0 // s = 0, v is undefined hsv.s = 0; hsv.h = -1; return hsv; } if( r == max ) hsv.h = ( g - b ) / delta; // between yellow & magenta else if( g == max ) hsv.h = 2 + ( b - r ) / delta; // between cyan & yellow else hsv.h = 4 + ( r - g ) / delta; // between magenta & cyan hsv.h *= 60; // degrees if( hsv.h < 0 ) hsv.h += 360; hsv.s *= 100; hsv.v = hsv.v / 255 * 100; return hsv; }
/** * hpss2fsal_attributes: * Fills an FSAL attributes structure with the info * provided by the hpss handle and the hpss attributes * of an object. * * \param p_hpss_handle_in (input): * Pointer to the HPSS NS object handle. * \param p_hpss_attr_in (input): * Pointer to the HPSS attributes. * \param p_fsalattr_out (input/output): * Pointer to the FSAL attributes. * As input, it defines the attributes that the caller * wants to retrieve (by positioning flags into this structure) * and the output is built considering this input * (it fills the structure according to the flags it contains). * \param p_cred (input) * HPSS Credential. * * \return Major error codes: * - ERR_FSAL_NO_ERROR: no error. * - ERR_FSAL_FAULT: NULL pointer passed as input parameter. * - ERR_FSAL_ATTRNOTSUPP: One of the asked attributes is not supported. * - ERR_FSAL_SERVERFAULT: Unexpected error. */ fsal_status_t hpss2fsal_attributes(ns_ObjHandle_t * p_hpss_handle_in, hpss_Attrs_t * p_hpss_attr_in, fsal_attrib_list_t * p_fsalattr_out) { fsal_attrib_mask_t supp_attr, unsupp_attr; /* sanity checks */ if(!p_hpss_handle_in || !p_hpss_attr_in || !p_fsalattr_out) ReturnCode(ERR_FSAL_FAULT, 0); if(p_fsalattr_out->asked_attributes == 0) { p_fsalattr_out->asked_attributes = global_fs_info.supported_attrs; LogCrit(COMPONENT_FSAL, "Error: p_fsalattr_out->asked_attributes valait 0 dans hpss2fsal_attributes line %d, fichier %s", __LINE__, __FILE__); } /* check that asked attributes are supported */ supp_attr = global_fs_info.supported_attrs; unsupp_attr = (p_fsalattr_out->asked_attributes) & (~supp_attr); if(unsupp_attr) { LogFullDebug(COMPONENT_FSAL, "Unsupported attributes: %#llX removing it from asked attributes ", unsupp_attr); p_fsalattr_out->asked_attributes = p_fsalattr_out->asked_attributes & (~unsupp_attr); /* ReturnCode( ERR_FSAL_ATTRNOTSUPP, 0 ); */ } /* Initialize ACL regardless of whether ACL was asked or not. * This is needed to make sure ACL attribute is initialized. */ p_fsalattr_out->acl = NULL; /* Fills the output struct */ if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_SUPPATTR)) { p_fsalattr_out->supported_attributes = supp_attr; } if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_TYPE)) { p_fsalattr_out->type = hpss2fsal_type(p_hpss_handle_in->Type); } if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_SIZE)) { p_fsalattr_out->filesize = hpss2fsal_64(p_hpss_attr_in->DataLength); } if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_FSID)) { p_fsalattr_out->fsid = hpss2fsal_fsid(p_hpss_attr_in->FilesetId); } if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_ACL)) { if(p_hpss_attr_in->ExtendedACLs == 0) { p_fsalattr_out->acl = NULL; } else { /** @todo : This doesn't convert ACLs for the moment. */ } } if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_FILEID)) { p_fsalattr_out->fileid = (fsal_u64_t) hpss_GetObjId(p_hpss_handle_in); } if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_MODE)) { p_fsalattr_out->mode = hpss2fsal_mode( #if HPSS_MAJOR_VERSION < 7 p_hpss_attr_in->SetUIDBit, p_hpss_attr_in->SetGIDBit, p_hpss_attr_in->SetStickyBit, #else p_hpss_attr_in->ModePerms & NS_PERMS_RD, p_hpss_attr_in->ModePerms & NS_PERMS_WR, p_hpss_attr_in->ModePerms & NS_PERMS_XS, #endif p_hpss_attr_in->UserPerms, p_hpss_attr_in->GroupPerms, p_hpss_attr_in->OtherPerms); } if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_NUMLINKS)) { p_fsalattr_out->numlinks = p_hpss_attr_in->LinkCount; } if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_OWNER)) { p_fsalattr_out->owner = p_hpss_attr_in->UID; } if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_GROUP)) { p_fsalattr_out->group = p_hpss_attr_in->GID; } if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_ATIME)) { LogFullDebug(COMPONENT_FSAL, "Getting ATIME:"); LogFullDebug(COMPONENT_FSAL, "\tTimeLastRead = %d", p_hpss_attr_in->TimeLastRead); LogFullDebug(COMPONENT_FSAL, "\tTimeCreated = %d", p_hpss_attr_in->TimeCreated); if(p_hpss_attr_in->TimeLastRead != 0) p_fsalattr_out->atime = hpss2fsal_time(p_hpss_attr_in->TimeLastRead); else p_fsalattr_out->atime = hpss2fsal_time(p_hpss_attr_in->TimeCreated); } if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_CREATION)) { p_fsalattr_out->creation = hpss2fsal_time(p_hpss_attr_in->TimeCreated); } if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_CTIME)) { p_fsalattr_out->ctime = hpss2fsal_time(p_hpss_attr_in->TimeModified); } if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_MTIME)) { LogFullDebug(COMPONENT_FSAL, "Getting MTIME:"); LogFullDebug(COMPONENT_FSAL, "\tType = %d", hpss2fsal_type(p_hpss_handle_in->Type)); LogFullDebug(COMPONENT_FSAL, "\tTimeLastWritten = %d", p_hpss_attr_in->TimeLastWritten); LogFullDebug(COMPONENT_FSAL, "\tTimeModified = %d", p_hpss_attr_in->TimeModified); LogFullDebug(COMPONENT_FSAL, "\tTimeCreated = %d", p_hpss_attr_in->TimeCreated); switch (hpss2fsal_type(p_hpss_handle_in->Type)) { case FSAL_TYPE_FILE: case FSAL_TYPE_LNK: if(p_hpss_attr_in->TimeLastWritten != 0) p_fsalattr_out->mtime = hpss2fsal_time(p_hpss_attr_in->TimeLastWritten); else p_fsalattr_out->mtime = hpss2fsal_time(p_hpss_attr_in->TimeCreated); break; case FSAL_TYPE_DIR: case FSAL_TYPE_JUNCTION: if(p_hpss_attr_in->TimeModified != 0) p_fsalattr_out->mtime = hpss2fsal_time(p_hpss_attr_in->TimeModified); else p_fsalattr_out->mtime = hpss2fsal_time(p_hpss_attr_in->TimeCreated); break; default: ReturnCode(ERR_FSAL_SERVERFAULT, 0); } } if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_CHGTIME)) { p_fsalattr_out->chgtime = hpss2fsal_time(MAX_3 (p_hpss_attr_in->TimeModified, p_hpss_attr_in->TimeCreated, p_hpss_attr_in->TimeLastWritten)); p_fsalattr_out->change = (uint64_t) p_fsalattr_out->chgtime.seconds ; } if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_SPACEUSED)) { p_fsalattr_out->spaceused = hpss2fsal_64(p_hpss_attr_in->DataLength); } if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_MOUNTFILEID)) { p_fsalattr_out->mounted_on_fileid = hpss2fsal_64(p_hpss_attr_in->FilesetRootId); } /* everything has been copied ! */ ReturnCode(ERR_FSAL_NO_ERROR, 0); }