bool CImage::GenerateMipmaps(unsigned int nMipmaps) { // Compressed formats should have mipmaps packed in // if(is_format_compressed(m_pixelFormat)) return false; // We do not support non-square mipmapping at this time // if(!is_power_of_2(m_imageWidth, m_imageHeight)) return false; m_mipMapCount = gmin(get_mipmap_count_from_dim(gmax(gmax(m_imageWidth, m_imageHeight), m_depth)), nMipmaps); m_pPixels = (unsigned char*)realloc(m_pPixels, GetSizeWithMipmaps()); unsigned char *dest, *src = m_pPixels; int c = get_channel_count(m_pixelFormat); int cSize = get_bytes_per_channel(m_pixelFormat); if(IsCubemap()) { int dim = m_imageWidth; for(int i = 1; i < m_mipMapCount; ++i) { int sliceSize = dim * dim * c * cSize; dest = src + 6 * sliceSize; for(unsigned int s = 0; s < 6; ++s) { if(cSize == 1) generate_mipmaps(src + s * sliceSize, dest + s * sliceSize / 4, dim, dim, 1, c); else if(cSize == 2) generate_mipmaps((unsigned short*)(src + s * sliceSize), (unsigned short*)(dest + s * sliceSize / 4), dim, dim, 1, c); else generate_mipmaps((float*)(src + s * sliceSize), (float*)(dest + s * sliceSize / 4), dim, dim, 1, c); } src = dest; dim >>= 1; } } else {
volume_data_type Volume_loader_raw::load_volume(std::string filepath) { std::ifstream volume_file; volume_file.open(filepath, std::ios::in | std::ios::binary); volume_data_type data; if (volume_file.is_open()) { glm::ivec3 vol_dim = get_dimensions(filepath); unsigned channels = get_channel_count(filepath); unsigned byte_per_channel = get_bit_per_channel(filepath) / 8; size_t data_size = vol_dim.x * vol_dim.y * vol_dim.z * channels * byte_per_channel; data.resize(data_size); volume_file.seekg(0, std::ios::beg); volume_file.read((char*)&data.front(), data_size); volume_file.close(); //std::cout << "File " << filepath << " successfully loaded" << std::endl; return data; } else { std::cerr << "File " << filepath << " doesnt exist! Check Filepath!" << std::endl; assert(0); return data; } //never reached assert(0); return data; }
int main(int argc, char *argv[]) { int blob_count = 0, i = 0; int main_channel = 2; /* red - botguy */ double time_of_snapshot = 0.0; double start = 0.0; printf("args: %d\n", argc); if (argc > 1) { if (argv[1][0] == '0') main_channel = 0; else if (argv[1][0] == '1') main_channel = 1; else if (argv[1][0] == '2') main_channel = 2; else if (argv[1][0] == '3') main_channel = 3; } for (i = 0; i < argc; i++) { printf("arg[%d] = %s\n", i, argv[i]); } printf("\n"); int area[NUM_TRACKING]; point2 center[NUM_TRACKING]; rectangle blob[NUM_TRACKING]; //int area1 = 0, areaX = 0; //point2 center; init_grid(); //wait_for_light(0); camera_open(); printf("Num channels: %d", get_channel_count()); camera_update(); time_of_snapshot = seconds(); msleep(300); start = seconds(); do { // Initialize memset(center, 0, sizeof(center)); memset(area, 0, sizeof(area)); clear_grid(); // Begin // Do not do anything with the camera until enough time has passed if (seconds() - time_of_snapshot >= 0.1) { camera_update(); time_of_snapshot = seconds(); blob_count = get_object_count(main_channel); //sprintf(msg, "#:%2d", blob_count); diag(); printf("#:%-2d ", blob_count); if (blob_count > count_of(area)) { blob_count = count_of(area); } if (blob_count > 0) { for (i = 0; i < blob_count; ++i) { area[i] = get_object_area(main_channel, i); center[i] = get_object_center(main_channel, i); blob[i] = get_object_bbox(main_channel, i); plot(&blob[i], i + '0'); } for (i = 0; i < blob_count; ++i) { printf(" %3d", blob[i].width * blob[i].height); } for (; i < count_of(blob); ++i) { printf(" "); } printf(" "); for (i = 0; i < blob_count; ++i) { printf(" %2dx%2d", blob[i].width, blob[i].height); } //show_xy(center[0].x, center[0].y); } //printf(" |%3d %4d <-> %4d %3d| %s\n", delta_left, left, right, delta_right, message); printf("%s\n", message); message[0] = 0; diag(); show_grid(); } //printf("The time is: %f %f\n", seconds(), seconds() - start); } while (seconds() - start <= 4.0); camera_close(); return 0; }