static mitk::Vector3D createVector(mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z) { return createArray<mitk::Vector3D>(x, y, z); } void mitkSlicedGeometry3D_ChangeImageGeometryConsideringOriginOffset_Test() { MITK_TEST_OUTPUT(<< "====== mitkSlicedGeometry3D_ChangeImageGeometryConsideringOriginOffset_Test() ======"); auto origin = createPoint(91.3, -13.3, 0); auto spacing = createVector(1.0, 0.9, 0.3); auto numberOfSlices = 5; auto slicedGeometry = createSlicedGeometry(origin, spacing, numberOfSlices); MITK_TEST_OUTPUT(<< "SlicedGeometry3D isn't an image geometry by default"); MITK_TEST_CONDITION_REQUIRED(slicedGeometry->GetImageGeometry() == false, ""); MITK_TEST_OUTPUT(<< "First and last PlaneGeometry in SlicedGeometry3D are not image geometries"); auto firstPlaneGeometry = slicedGeometry->GetPlaneGeometry(0); auto lastPlaneGeometry = slicedGeometry->GetPlaneGeometry(numberOfSlices - 1); MITK_TEST_CONDITION_REQUIRED(firstPlaneGeometry->GetImageGeometry() == false, ""); MITK_TEST_CONDITION_REQUIRED(lastPlaneGeometry->GetImageGeometry() == false, ""); auto originOfSlicedGeometry = slicedGeometry->GetOrigin(); auto originOfFirstPlaneGeometry = firstPlaneGeometry->GetOrigin(); auto originOfLastPlaneGeometry = lastPlaneGeometry->GetOrigin(); auto firstCornerPointOfSlicedGeometry = slicedGeometry->GetCornerPoint(0); auto secondCornerPointOfFirstPlaneGeometry = firstPlaneGeometry->GetCornerPoint(1); auto thirdCornerPointOfLastPlaneGeometry = lastPlaneGeometry->GetCornerPoint(2); MITK_TEST_OUTPUT(<< "Calling SlicedGeometry3D::ChangeImageGeometryConsideringOriginOffset(true)");
ngx_int_t convert_image(ngx_http_request_t *r, convert_options_t *option_info, Image **image) { ngx_uint_t i; ngx_http_gm_convert_option_t *options; ngx_http_gm_convert_option_t *option; RectangleInfo geometry; RectangleInfo geometry_info; ExceptionInfo exception; Image *resize_image = NULL; u_char *resize_geometry = NULL; u_char *need_crop_resize = NULL; Image *rotate_image = NULL; u_char *rotate_degrees = NULL; ngx_int_t degrees; ngx_int_t degrees_suffix_len = 0; dd("entering"); options = option_info->options->elts; for (i = 0; i < option_info->options->nelts; ++i) { option = &options[i]; if (option->type == NGX_HTTP_GM_RESIZE_OPTION) { dd("starting resize"); resize_geometry = ngx_http_gm_get_str_value(r, option->resize_geometry_cv, &option->resize_geometry); need_crop_resize = (u_char *)ngx_strchr(resize_geometry, 'c'); if (need_crop_resize != NULL) { *need_crop_resize = '^'; } if (resize_geometry == NULL) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "gm filter: resize image, get resize geometry failed"); return NGX_ERROR; } if (ngx_strncmp(resize_geometry, "no", 2) == 0) { continue; } (void) GetImageGeometry(*image, (char *)resize_geometry, 1, &geometry); if ((geometry.width == (*image)->columns) && (geometry.height == (*image)->rows)) continue; ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "resize image geometry: \"%s\"", resize_geometry); GetExceptionInfo(&exception); resize_image = ResizeImage(*image, geometry.width, geometry.height, (*image)->filter,(*image)->blur, &exception); if (resize_image == (Image *) NULL) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "gm filter: resize image failed, " "arg: \"%s\" severity: \"%O\" " "reason: \"%s\", description: \"%s\"", resize_geometry, exception.severity, exception.reason, exception.description); DestroyExceptionInfo(&exception); return NGX_ERROR; } DestroyImage(*image); *image = resize_image; DestroyExceptionInfo(&exception); if (need_crop_resize != NULL) { GetGeometry((char *)resize_geometry, &geometry_info.x, &geometry_info.y, (unsigned long *)(&geometry_info.width), (unsigned long *)(&geometry_info.height)); if (geometry_info.width > (*image)->columns || geometry_info.height > (*image)->rows) { continue; } geometry_info.x = ((*image)->columns - geometry_info.width) / 2; geometry_info.y = ((*image)->rows - geometry_info.height) / 2; GetExceptionInfo(&exception); resize_image = CropImage(*image, &geometry_info, &exception); if (resize_image == (Image *) NULL) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "gm filter: resize croping image failed, " "arg: \"%s\" severity: \"%O\" " "reason: \"%s\", description: \"%s\"", resize_geometry, exception.severity, exception.reason, exception.description); DestroyExceptionInfo(&exception); return NGX_ERROR; } DestroyImage(*image); *image = resize_image; DestroyExceptionInfo(&exception); } } else if (option->type == NGX_HTTP_GM_ROTATE_OPTION) { dd("starting rotate"); rotate_degrees = ngx_http_gm_get_str_value(r, option->rotate_degrees_cv, &option->rotate_degrees); if (rotate_degrees == NULL) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "gm filter: rotate image, get rotate degrees failed"); return NGX_ERROR; } if (ngx_strchr(rotate_degrees,'>') != (char *) NULL) { if ((*image)->columns <= (*image)->rows) continue; degrees_suffix_len = 1; } if (ngx_strchr(rotate_degrees,'<') != (char *) NULL) { if ((*image)->columns >= (*image)->rows) continue; degrees_suffix_len = 1; } degrees = 0; degrees = ngx_atoi(rotate_degrees, ngx_strlen(rotate_degrees) - degrees_suffix_len); if (degrees == 0) { continue; } ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "rotate image degrees: \"%O\"", degrees); GetExceptionInfo(&exception); rotate_image=RotateImage(*image, degrees, &exception); if (rotate_image == (Image *) NULL) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "gm filter: rotate image failed, " "degrees: \"%s\" severity: \"%O\" " "reason: \"%s\", description: \"%s\"", option->rotate_degrees, exception.severity, exception.reason, exception.description); DestroyExceptionInfo(&exception); return NGX_ERROR; } DestroyImage(*image); *image = rotate_image; DestroyExceptionInfo(&exception); } else { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "gm filter: convert command, unkonwn option"); return NGX_ERROR; } } return NGX_OK; }