MethodBind::~MethodBind() { #ifdef DEBUG_METHODS_ENABLED if (argument_types) memdelete_arr(argument_types); #endif }
Error ImageLoaderPNG::_load_image(void *rf_up,png_rw_ptr p_func,Image *p_image) { png_structp png; png_infop info; //png = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, NULL, NULL); png = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,_png_error_function,_png_warn_function,(png_voidp)NULL, _png_malloc_fn,_png_free_fn ); ERR_FAIL_COND_V(!png, ERR_OUT_OF_MEMORY); info = png_create_info_struct(png); if (!info) { png_destroy_read_struct(&png,NULL,NULL); ERR_PRINT("Out of Memory"); return ERR_OUT_OF_MEMORY; } if (setjmp(png_jmpbuf(png))) { png_destroy_read_struct(&png,NULL,NULL); ERR_PRINT("PNG Corrupted"); return ERR_FILE_CORRUPT; } png_set_read_fn(png,(void*)rf_up,p_func); png_uint_32 width, height; int depth, color; png_read_info(png, info); png_get_IHDR(png, info, &width, &height, &depth, &color, NULL, NULL, NULL); png_textp t; //https://svn.gov.pt/projects/ccidadao/repository/middleware-offline/trunk/_src/eidmw/FreeImagePTEiD/Source/FreeImage/PluginPNG.cpp //png_get_text(png,info,) /* printf("Image width:%i\n", width); printf("Image Height:%i\n", height); printf("Bit depth:%i\n", depth); printf("Color type:%i\n", color); */ if (depth<8) { //only bit dept 8 per channel is handled png_set_packing(png); }; if (depth > 8) { png_set_strip_16(png); png_read_update_info(png, info); } int palette_colors = 0; int palette_components = 0; int components = 0; Image::Format fmt; switch(color) { case PNG_COLOR_TYPE_GRAY: { fmt=Image::FORMAT_GRAYSCALE; components=1; } break; case PNG_COLOR_TYPE_GRAY_ALPHA: { fmt=Image::FORMAT_GRAYSCALE_ALPHA; components=2; } break; case PNG_COLOR_TYPE_RGB: { fmt=Image::FORMAT_RGB; components=3; } break; case PNG_COLOR_TYPE_RGB_ALPHA: { fmt=Image::FORMAT_RGBA; components=4; } break; case PNG_COLOR_TYPE_PALETTE: { int ntrans = 0; png_get_tRNS(png, info, NULL, &ntrans, NULL); //printf("transparent colors %i\n", ntrans); fmt = ntrans > 0 ? Image::FORMAT_INDEXED_ALPHA : Image::FORMAT_INDEXED; palette_components = ntrans > 0 ? 4 : 3; components = 1; png_colorp colors; png_get_PLTE(png, info, &colors, &palette_colors); } break; default: { ERR_PRINT("INVALID PNG TYPE"); png_destroy_read_struct(&png, &info, NULL); return ERR_UNAVAILABLE; } break; } //int rowsize = png_get_rowbytes(png, info); int rowsize = components * width; DVector<uint8_t> dstbuff; dstbuff.resize( rowsize * height + palette_components * 256 ); // alloc the entire palette? - yes always DVector<uint8_t>::Write dstbuff_write = dstbuff.write(); uint8_t* data = dstbuff_write.ptr(); uint8_t **row_p = memnew_arr( uint8_t*, height ); for (unsigned int i = 0; i < height; i++) { row_p[i] = &data[components*width*i]; } png_read_image(png, (png_bytep*)row_p); if (palette_colors) { uint8_t *r_pal = &data[components*width*height]; // end of the array png_colorp colors; int num; png_get_PLTE(png, info, &colors, &num); int ofs = 0; for (int i=0; i < palette_colors; i++) { r_pal[ofs + 0] = colors[i].red; r_pal[ofs + 1] = colors[i].green; r_pal[ofs + 2] = colors[i].blue; if (palette_components == 4) { r_pal[ofs + 3] = 255; }; ofs += palette_components; }; if (fmt == Image::FORMAT_INDEXED_ALPHA) { png_color_16p alphas; png_bytep alpha_idx; int count; png_get_tRNS(png, info, &alpha_idx, &count, &alphas); for (int i=0; i<count; i++) { //printf("%i: loading alpha fron transparent color %i, values %i, %i, %i, %i, %i\n", i, (int)alpha_idx[i], (int)alphas[i].index, (int)alphas[i].red, (int)alphas[i].green, (int)alphas[i].blue, (int)alphas[i].gray); //r_pal[alpha_idx[i]] = alphas[i].gray >> 8; r_pal[i*4+3] = alpha_idx[i]; }; }; }; memdelete_arr( row_p ); p_image->create( width, height, 0,fmt, dstbuff ); png_destroy_read_struct(&png, &info, NULL ); return OK; }
Error ImageLoaderPNG::_load_image(void *rf_up, png_rw_ptr p_func, Ref<Image> p_image) { png_structp png; png_infop info; //png = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, NULL, NULL); png = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, _png_error_function, _png_warn_function, (png_voidp)NULL, _png_malloc_fn, _png_free_fn); ERR_FAIL_COND_V(!png, ERR_OUT_OF_MEMORY); info = png_create_info_struct(png); if (!info) { png_destroy_read_struct(&png, NULL, NULL); ERR_PRINT("Out of Memory"); return ERR_OUT_OF_MEMORY; } if (setjmp(png_jmpbuf(png))) { png_destroy_read_struct(&png, NULL, NULL); ERR_PRINT("PNG Corrupted"); return ERR_FILE_CORRUPT; } png_set_read_fn(png, (void *)rf_up, p_func); png_uint_32 width, height; int depth, color; png_read_info(png, info); png_get_IHDR(png, info, &width, &height, &depth, &color, NULL, NULL, NULL); //https://svn.gov.pt/projects/ccidadao/repository/middleware-offline/trunk/_src/eidmw/FreeImagePTEiD/Source/FreeImage/PluginPNG.cpp //png_get_text(png,info,) /* printf("Image width:%i\n", width); printf("Image Height:%i\n", height); printf("Bit depth:%i\n", depth); printf("Color type:%i\n", color); */ bool update_info = false; if (depth < 8) { //only bit dept 8 per channel is handled png_set_packing(png); update_info = true; }; if (png_get_color_type(png, info) == PNG_COLOR_TYPE_PALETTE) { png_set_palette_to_rgb(png); update_info = true; } if (depth > 8) { png_set_strip_16(png); update_info = true; } if (png_get_valid(png, info, PNG_INFO_tRNS)) { //png_set_expand_gray_1_2_4_to_8(png); png_set_tRNS_to_alpha(png); update_info = true; } if (update_info) { png_read_update_info(png, info); png_get_IHDR(png, info, &width, &height, &depth, &color, NULL, NULL, NULL); } int components = 0; Image::Format fmt; switch (color) { case PNG_COLOR_TYPE_GRAY: { fmt = Image::FORMAT_L8; components = 1; } break; case PNG_COLOR_TYPE_GRAY_ALPHA: { fmt = Image::FORMAT_LA8; components = 2; } break; case PNG_COLOR_TYPE_RGB: { fmt = Image::FORMAT_RGB8; components = 3; } break; case PNG_COLOR_TYPE_RGB_ALPHA: { fmt = Image::FORMAT_RGBA8; components = 4; } break; default: { ERR_PRINT("INVALID PNG TYPE"); png_destroy_read_struct(&png, &info, NULL); return ERR_UNAVAILABLE; } break; } //int rowsize = png_get_rowbytes(png, info); int rowsize = components * width; PoolVector<uint8_t> dstbuff; dstbuff.resize(rowsize * height); PoolVector<uint8_t>::Write dstbuff_write = dstbuff.write(); uint8_t *data = dstbuff_write.ptr(); uint8_t **row_p = memnew_arr(uint8_t *, height); for (unsigned int i = 0; i < height; i++) { row_p[i] = &data[components * width * i]; } png_read_image(png, (png_bytep *)row_p); memdelete_arr(row_p); p_image->create(width, height, 0, fmt, dstbuff); png_destroy_read_struct(&png, &info, NULL); return OK; }
ConvexPolygonShape2DSW::~ConvexPolygonShape2DSW(){ if (points) memdelete_arr(points); }
AudioEffectStereoEnhanceInstance::~AudioEffectStereoEnhanceInstance() { memdelete_arr(delay_ringbuff); }
static Vector< Vector<Vector2> > _b2d_decompose(const Vector<Vector2>& p_polygon) { Vector< Vector<Vector2> > res; if (p_polygon.size()<3) return res; b2Vec2 *polys = memnew_arr(b2Vec2,p_polygon.size()); for(int i=0;i<p_polygon.size();i++) polys[i]=b2Vec2(p_polygon[i].x,p_polygon[i].y); b2Polygon *p = new b2Polygon(polys,p_polygon.size()); b2Polygon* decomposed = new b2Polygon[p->nVertices - 2]; //maximum number of polys memdelete_arr(polys); int32 nPolys = DecomposeConvex(p, decomposed, p->nVertices - 2); //int32 extra = 0; for (int32 i = 0; i < nPolys; ++i) { // b2FixtureDef* toAdd = &pdarray[i+extra]; // *toAdd = *prototype; //Hmm, shouldn't have to do all this... b2Polygon curr = decomposed[i]; //TODO ewjordan: move this triangle handling to a better place so that //it happens even if this convenience function is not called. if (curr.nVertices == 3){ //Check here for near-parallel edges, since we can't //handle this in merge routine for (int j=0; j<3; ++j){ int32 lower = (j == 0) ? (curr.nVertices - 1) : (j - 1); int32 middle = j; int32 upper = (j == curr.nVertices - 1) ? (0) : (j + 1); float32 dx0 = curr.x[middle] - curr.x[lower]; float32 dy0 = curr.y[middle] - curr.y[lower]; float32 dx1 = curr.x[upper] - curr.x[middle]; float32 dy1 = curr.y[upper] - curr.y[middle]; float32 norm0 = sqrtf(dx0*dx0+dy0*dy0); float32 norm1 = sqrtf(dx1*dx1+dy1*dy1); if ( !(norm0 > 0.0f && norm1 > 0.0f) ) { //Identical points, don't do anything! goto Skip; } dx0 /= norm0; dy0 /= norm0; dx1 /= norm1; dy1 /= norm1; float32 cross = dx0 * dy1 - dx1 * dy0; float32 dot = dx0*dx1 + dy0*dy1; if (fabs(cross) < b2_angularSlop && dot > 0) { //Angle too close, split the triangle across from this point. //This is guaranteed to result in two triangles that satify //the tolerance (one of the angles is 90 degrees) float32 dx2 = curr.x[lower] - curr.x[upper]; float32 dy2 = curr.y[lower] - curr.y[upper]; float32 norm2 = sqrtf(dx2*dx2+dy2*dy2); if (norm2 == 0.0f) { goto Skip; } dx2 /= norm2; dy2 /= norm2; float32 thisArea = curr.GetArea(); float32 thisHeight = 2.0f * thisArea / norm2; float32 buffer2 = dx2; dx2 = dy2; dy2 = -buffer2; //Make two new polygons //printf("dx2: %f, dy2: %f, thisHeight: %f, middle: %d\n",dx2,dy2,thisHeight,middle); float32 newX1[3] = { curr.x[middle]+dx2*thisHeight, curr.x[lower], curr.x[middle] }; float32 newY1[3] = { curr.y[middle]+dy2*thisHeight, curr.y[lower], curr.y[middle] }; float32 newX2[3] = { newX1[0], curr.x[middle], curr.x[upper] }; float32 newY2[3] = { newY1[0], curr.y[middle], curr.y[upper] }; b2Polygon p1(newX1,newY1,3); b2Polygon p2(newX2,newY2,3); if (p1.IsUsable()){ add_to_res(res,p1); //++extra; } else if (B2_POLYGON_REPORT_ERRORS){ printf("Didn't add unusable polygon. Dumping vertices:\n"); p1.print(); } if (p2.IsUsable()){ add_to_res(res,p2); //p2.AddTo(pdarray[i+extra]); //bd->CreateFixture(toAdd); } else if (B2_POLYGON_REPORT_ERRORS){ printf("Didn't add unusable polygon. Dumping vertices:\n"); p2.print(); } goto Skip; } } } if (decomposed[i].IsUsable()){ add_to_res(res,decomposed[i]); //decomposed[i].AddTo(*toAdd); //bd->CreateFixture((const b2FixtureDef*)toAdd); } else if (B2_POLYGON_REPORT_ERRORS){ printf("Didn't add unusable polygon. Dumping vertices:\n"); decomposed[i].print(); } Skip: ; } // delete[] pdarray; delete[] decomposed; delete p; return res;// pdarray; //needs to be deleted after body is created }
void AudioDriverOSX::finish() { memdelete_arr(samples_in); };
void AudioDriverIphone::finish() { memdelete_arr(samples_in); };
AudioDriverNacl::~AudioDriverNacl() { memdelete_arr(samples_in); }
DVector<Face3> Geometry::wrap_geometry(DVector<Face3> p_array, float *p_error) { #define _MIN_SIZE 1.0 #define _MAX_LENGTH 20 int face_count = p_array.size(); DVector<Face3>::Read facesr = p_array.read(); const Face3 *faces = facesr.ptr(); AABB global_aabb; for (int i = 0; i < face_count; i++) { if (i == 0) { global_aabb = faces[i].get_aabb(); } else { global_aabb.merge_with(faces[i].get_aabb()); } } global_aabb.grow_by(0.01); // avoid numerical error // determine amount of cells in grid axis int div_x, div_y, div_z; if (global_aabb.size.x / _MIN_SIZE < _MAX_LENGTH) div_x = (int)(global_aabb.size.x / _MIN_SIZE) + 1; else div_x = _MAX_LENGTH; if (global_aabb.size.y / _MIN_SIZE < _MAX_LENGTH) div_y = (int)(global_aabb.size.y / _MIN_SIZE) + 1; else div_y = _MAX_LENGTH; if (global_aabb.size.z / _MIN_SIZE < _MAX_LENGTH) div_z = (int)(global_aabb.size.z / _MIN_SIZE) + 1; else div_z = _MAX_LENGTH; Vector3 voxelsize = global_aabb.size; voxelsize.x /= div_x; voxelsize.y /= div_y; voxelsize.z /= div_z; // create and initialize cells to zero //print_line("Wrapper: Initializing Cells"); uint8_t ***cell_status = memnew_arr(uint8_t **, div_x); for (int i = 0; i < div_x; i++) { cell_status[i] = memnew_arr(uint8_t *, div_y); for (int j = 0; j < div_y; j++) { cell_status[i][j] = memnew_arr(uint8_t, div_z); for (int k = 0; k < div_z; k++) { cell_status[i][j][k] = 0; } } } // plot faces into cells //print_line("Wrapper (1/6): Plotting Faces"); for (int i = 0; i < face_count; i++) { Face3 f = faces[i]; for (int j = 0; j < 3; j++) { f.vertex[j] -= global_aabb.pos; } _plot_face(cell_status, 0, 0, 0, div_x, div_y, div_z, voxelsize, f); } // determine which cells connect to the outside by traversing the outside and recursively flood-fill marking //print_line("Wrapper (2/6): Flood Filling"); for (int i = 0; i < div_x; i++) { for (int j = 0; j < div_y; j++) { _mark_outside(cell_status, i, j, 0, div_x, div_y, div_z); _mark_outside(cell_status, i, j, div_z - 1, div_x, div_y, div_z); } } for (int i = 0; i < div_z; i++) { for (int j = 0; j < div_y; j++) { _mark_outside(cell_status, 0, j, i, div_x, div_y, div_z); _mark_outside(cell_status, div_x - 1, j, i, div_x, div_y, div_z); } } for (int i = 0; i < div_x; i++) { for (int j = 0; j < div_z; j++) { _mark_outside(cell_status, i, 0, j, div_x, div_y, div_z); _mark_outside(cell_status, i, div_y - 1, j, div_x, div_y, div_z); } } // build faces for the inside-outside cell divisors //print_line("Wrapper (3/6): Building Faces"); DVector<Face3> wrapped_faces; for (int i = 0; i < div_x; i++) { for (int j = 0; j < div_y; j++) { for (int k = 0; k < div_z; k++) { _build_faces(cell_status, i, j, k, div_x, div_y, div_z, wrapped_faces); } } } //print_line("Wrapper (4/6): Transforming Back Vertices"); // transform face vertices to global coords int wrapped_faces_count = wrapped_faces.size(); DVector<Face3>::Write wrapped_facesw = wrapped_faces.write(); Face3 *wrapped_faces_ptr = wrapped_facesw.ptr(); for (int i = 0; i < wrapped_faces_count; i++) { for (int j = 0; j < 3; j++) { Vector3 &v = wrapped_faces_ptr[i].vertex[j]; v = v * voxelsize; v += global_aabb.pos; } } // clean up grid //print_line("Wrapper (5/6): Grid Cleanup"); for (int i = 0; i < div_x; i++) { for (int j = 0; j < div_y; j++) { memdelete_arr(cell_status[i][j]); } memdelete_arr(cell_status[i]); } memdelete_arr(cell_status); if (p_error) *p_error = voxelsize.length(); //print_line("Wrapper (6/6): Finished."); return wrapped_faces; }