diff options
Diffstat (limited to 'scene/io')
-rw-r--r-- | scene/io/SCsub | 7 | ||||
-rw-r--r-- | scene/io/resource_format_image.cpp | 266 | ||||
-rw-r--r-- | scene/io/resource_format_image.h | 55 | ||||
-rw-r--r-- | scene/io/resource_format_wav.cpp | 277 | ||||
-rw-r--r-- | scene/io/resource_format_wav.h | 46 |
5 files changed, 0 insertions, 651 deletions
diff --git a/scene/io/SCsub b/scene/io/SCsub deleted file mode 100644 index bf9125be7f..0000000000 --- a/scene/io/SCsub +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env python - -Import('env') - -env.add_source_files(env.scene_sources, "*.cpp") - -Export('env') diff --git a/scene/io/resource_format_image.cpp b/scene/io/resource_format_image.cpp deleted file mode 100644 index 04b6177c3c..0000000000 --- a/scene/io/resource_format_image.cpp +++ /dev/null @@ -1,266 +0,0 @@ -/*************************************************************************/ -/* resource_format_image.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "resource_format_image.h" - -#if 0 -#include "io/image_loader.h" -#include "os/os.h" -#include "project_settings.h" -#include "scene/resources/texture.h" -RES ResourceFormatLoaderImage::load(const String &p_path, const String& p_original_path, Error *r_error) { - - if (r_error) - *r_error=ERR_CANT_OPEN; - - if (p_path.get_extension()=="cube") { - // open as cubemap txture - - CubeMap* ptr = memnew(CubeMap); - Ref<CubeMap> cubemap( ptr ); - - Error err; - FileAccess *f = FileAccess::open(p_path,FileAccess::READ,&err); - if (err) { - - ERR_FAIL_COND_V( err, RES() ); - } - - String base_path=p_path.substr( 0, p_path.find_last("/")+1 ); - - for(int i=0;i<6;i++) { - - String file = f->get_line().strip_edges(); - Image image; - - Error err = ImageLoader::load_image(base_path+file,&image); - - - if (err) { - - memdelete(f); - ERR_FAIL_COND_V( err, RES() ); - } - - if (i==0) { - - //cubemap->create(image.get_width(),image.get_height(),image.get_format(),Texture::FLAGS_DEFAULT|Texture::FLAG_CUBEMAP); - } - - static const CubeMap::Side cube_side[6]= { - CubeMap::SIDE_LEFT, - CubeMap::SIDE_RIGHT, - CubeMap::SIDE_BOTTOM, - CubeMap::SIDE_TOP, - CubeMap::SIDE_FRONT, - CubeMap::SIDE_BACK - }; - - cubemap->set_side(cube_side[i],image); - } - - memdelete(f); - - cubemap->set_name(p_path.get_file()); - if (r_error) - *r_error=OK; - - return cubemap; - - } else { - // simple image - - ImageTexture* ptr = memnew(ImageTexture); - Ref<ImageTexture> texture( ptr ); - - uint64_t begtime; - double total; - - Image image; - - if (debug_load_times) - begtime=OS::get_singleton()->get_ticks_usec(); - - - Error err = ImageLoader::load_image(p_path,&image); - - if (!err && debug_load_times) { - double total=USEC_TO_SEC((OS::get_singleton()->get_ticks_usec()-begtime)); - print_line("IMAGE: "+itos(image.get_width())+"x"+itos(image.get_height())); - print_line(" -load: "+rtos(total)); - } - - - ERR_EXPLAIN("Failed loading image: "+p_path); - ERR_FAIL_COND_V(err, RES()); - if (r_error) - *r_error=ERR_FILE_CORRUPT; - -#ifdef DEBUG_ENABLED -#ifdef TOOLS_ENABLED - - if (max_texture_size && (image.get_width() > max_texture_size || image.get_height() > max_texture_size)) { - - - if (bool(ProjectSettings::get_singleton()->get("debug/image_loader/max_texture_size_alert"))) { - OS::get_singleton()->alert("Texture is too large: '"+p_path+"', at "+itos(image.get_width())+"x"+itos(image.get_height())+". Max allowed size is: "+itos(max_texture_size)+"x"+itos(max_texture_size)+".","BAD ARTIST, NO COOKIE!"); - } - - ERR_EXPLAIN("Texture is too large: '"+p_path+"', at "+itos(image.get_width())+"x"+itos(image.get_height())+". Max allowed size is: "+itos(max_texture_size)+"x"+itos(max_texture_size)+"."); - ERR_FAIL_V(RES()); - } -#endif -#endif - - - uint32_t flags=load_image_flags(p_path); - - if (debug_load_times) - begtime=OS::get_singleton()->get_ticks_usec(); - - //print_line("img: "+p_path+" flags: "+itos(flags)); - texture->create_from_image( image,flags ); - texture->set_name(p_path.get_file()); - - - if (debug_load_times) { - total=USEC_TO_SEC(OS::get_singleton()->get_ticks_usec()-begtime); - print_line(" -make texture: "+rtos(total)); - } - - if (r_error) - *r_error=OK; - - return RES( texture ); - } - - -} - -uint32_t ResourceFormatLoaderImage::load_image_flags(const String &p_path) { - - - FileAccess *f2 = FileAccess::open(p_path+".flags",FileAccess::READ); - Map<String,bool> flags_found; - if (f2) { - - while(!f2->eof_reached()) { - String l2 = f2->get_line(); - int eqpos = l2.find("="); - if (eqpos!=-1) { - String flag=l2.substr(0,eqpos).strip_edges(); - String val=l2.substr(eqpos+1,l2.length()).strip_edges().to_lower(); - flags_found[flag]=(val=="true" || val=="1")?true:false; - } - } - memdelete(f2); - } - - - uint32_t flags=0; - - if (flags_found.has("filter")) { - if (flags_found["filter"]) - flags|=Texture::FLAG_FILTER; - } else if (bool(GLOBAL_DEF("rendering/image_loader/filter",true))) { - flags|=Texture::FLAG_FILTER; - } - - - if (flags_found.has("gen_mipmaps")) { - if (flags_found["gen_mipmaps"]) - flags|=Texture::FLAG_MIPMAPS; - } else if (bool(GLOBAL_DEF("rendering/image_loader/gen_mipmaps",true))) { - flags|=Texture::FLAG_MIPMAPS; - } - - if (flags_found.has("repeat")) { - if (flags_found["repeat"]) - flags|=Texture::FLAG_REPEAT; - } else if (bool(GLOBAL_DEF("rendering/image_loader/repeat",true))) { - flags|=Texture::FLAG_REPEAT; - } - - if (flags_found.has("anisotropic")) { - if (flags_found["anisotropic"]) - flags|=Texture::FLAG_ANISOTROPIC_FILTER; - } - - if (flags_found.has("tolinear")) { - if (flags_found["tolinear"]) - flags|=Texture::FLAG_CONVERT_TO_LINEAR; - } - - if (flags_found.has("mirroredrepeat")) { - if (flags_found["mirroredrepeat"]) - flags|=Texture::FLAG_MIRRORED_REPEAT; - } - - return flags; -} - -bool ResourceFormatLoaderImage::handles_type(const String& p_type) const { - - return ClassDB::is_parent_class(p_type,"Texture") || ClassDB::is_parent_class(p_type,"CubeMap"); -} - -void ResourceFormatLoaderImage::get_recognized_extensions(List<String> *p_extensions) const { - - ImageLoader::get_recognized_extensions(p_extensions); - p_extensions->push_back("cube"); -} - -String ResourceFormatLoaderImage::get_resource_type(const String &p_path) const { - - String ext=p_path.get_extension().to_lower(); - if (ext=="cube") - return "CubeMap"; - - List<String> extensions; - ImageLoader::get_recognized_extensions(&extensions); - - for(List<String>::Element *E=extensions.front();E;E=E->next()) { - if (E->get()==ext) - return "ImageTexture"; - } - return ""; -} - - -ResourceFormatLoaderImage::ResourceFormatLoaderImage() { - - max_texture_size = GLOBAL_DEF("debug/image_loader/max_texture_size",0); - GLOBAL_DEF("debug/image_loader/max_texture_size_alert",false); - debug_load_times=GLOBAL_DEF("debug/image_loader/image_load_times",false); - GLOBAL_DEF("rendering/image_loader/filter",true); - GLOBAL_DEF("rendering/image_loader/gen_mipmaps",true); - GLOBAL_DEF("rendering/image_loader/repeat",false); - -} -#endif diff --git a/scene/io/resource_format_image.h b/scene/io/resource_format_image.h deleted file mode 100644 index 2cf6315f17..0000000000 --- a/scene/io/resource_format_image.h +++ /dev/null @@ -1,55 +0,0 @@ -/*************************************************************************/ -/* resource_format_image.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef RESOURCE_FORMAT_IMAGE_H -#define RESOURCE_FORMAT_IMAGE_H - -#if 0 - -#include "io/resource_loader.h" -#include "io/resource_saver.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ -class ResourceFormatLoaderImage : public ResourceFormatLoader { - - bool debug_load_times; - int max_texture_size; -public: - virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL); - static uint32_t load_image_flags(const String &p_path); - virtual void get_recognized_extensions(List<String> *p_extensions) const; - virtual bool handles_type(const String& p_type) const; - virtual String get_resource_type(const String &p_path) const; - - ResourceFormatLoaderImage(); -}; - -#endif -#endif diff --git a/scene/io/resource_format_wav.cpp b/scene/io/resource_format_wav.cpp deleted file mode 100644 index dabbb79de3..0000000000 --- a/scene/io/resource_format_wav.cpp +++ /dev/null @@ -1,277 +0,0 @@ -/*************************************************************************/ -/* resource_format_wav.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#if 0 -#include "resource_format_wav.h" -#include "os/file_access.h" -#include "scene/resources/sample.h" - - -RES ResourceFormatLoaderWAV::load(const String &p_path, const String& p_original_path, Error *r_error) { - if (r_error) - *r_error=ERR_FILE_CANT_OPEN; - - Error err; - FileAccess *file=FileAccess::open(p_path, FileAccess::READ,&err); - - ERR_FAIL_COND_V( err!=OK, RES() ); - - if (r_error) - *r_error=ERR_FILE_CORRUPT; - - /* CHECK RIFF */ - char riff[5]; - riff[4]=0; - file->get_buffer((uint8_t*)&riff,4); //RIFF - - if (riff[0]!='R' || riff[1]!='I' || riff[2]!='F' || riff[3]!='F') { - - file->close(); - memdelete(file); - ERR_FAIL_V( RES() ); - } - - - /* GET FILESIZE */ - uint32_t filesize=file->get_32(); - - /* CHECK WAVE */ - - char wave[4]; - - file->get_buffer((uint8_t*)&wave,4); //RIFF - - if (wave[0]!='W' || wave[1]!='A' || wave[2]!='V' || wave[3]!='E') { - - - file->close(); - memdelete(file); - ERR_EXPLAIN("Not a WAV file (no WAVE RIFF Header)") - ERR_FAIL_V( RES() ); - } - - bool format_found=false; - bool data_found=false; - int format_bits=0; - int format_channels=0; - int format_freq=0; - Sample::LoopFormat loop=Sample::LOOP_NONE; - int loop_begin=0; - int loop_end=0; - - - Ref<Sample> sample( memnew( Sample ) ); - - - while (!file->eof_reached()) { - - - /* chunk */ - char chunkID[4]; - file->get_buffer((uint8_t*)&chunkID,4); //RIFF - - /* chunk size */ - uint32_t chunksize=file->get_32(); - uint32_t file_pos=file->get_position(); //save file pos, so we can skip to next chunk safely - - if (file->eof_reached()) { - - //ERR_PRINT("EOF REACH"); - break; - } - - if (chunkID[0]=='f' && chunkID[1]=='m' && chunkID[2]=='t' && chunkID[3]==' ' && !format_found) { - /* IS FORMAT CHUNK */ - - uint16_t compression_code=file->get_16(); - - - if (compression_code!=1) { - ERR_PRINT("Format not supported for WAVE file (not PCM). Save WAVE files as uncompressed PCM instead."); - break; - } - - format_channels=file->get_16(); - if (format_channels!=1 && format_channels !=2) { - - ERR_PRINT("Format not supported for WAVE file (not stereo or mono)"); - break; - - } - - format_freq=file->get_32(); //sampling rate - - file->get_32(); // average bits/second (unused) - file->get_16(); // block align (unused) - format_bits=file->get_16(); // bits per sample - - if (format_bits%8) { - - ERR_PRINT("Strange number of bits in sample (not 8,16,24,32)"); - break; - } - - /* Don't need anything else, continue */ - format_found=true; - } - - - if (chunkID[0]=='d' && chunkID[1]=='a' && chunkID[2]=='t' && chunkID[3]=='a' && !data_found) { - /* IS FORMAT CHUNK */ - data_found=true; - - if (!format_found) { - ERR_PRINT("'data' chunk before 'format' chunk found."); - break; - - } - - int frames=chunksize; - - frames/=format_channels; - frames/=(format_bits>>3); - - /*print_line("chunksize: "+itos(chunksize)); - print_line("channels: "+itos(format_channels)); - print_line("bits: "+itos(format_bits)); -*/ - sample->create( - (format_bits==8) ? Sample::FORMAT_PCM8 : Sample::FORMAT_PCM16, - (format_channels==2)?true:false, - frames ); - sample->set_mix_rate( format_freq ); - - int len=frames; - if (format_channels==2) - len*=2; - if (format_bits>8) - len*=2; - - PoolVector<uint8_t> data; - data.resize(len); - PoolVector<uint8_t>::Write dataw = data.write(); - void * data_ptr = dataw.ptr(); - - for (int i=0;i<frames;i++) { - - - for (int c=0;c<format_channels;c++) { - - - if (format_bits==8) { - // 8 bit samples are UNSIGNED - - uint8_t s = file->get_8(); - s-=128; - int8_t *sp=(int8_t*)&s; - - int8_t *data_ptr8=&((int8_t*)data_ptr)[i*format_channels+c]; - - *data_ptr8=*sp; - - } else { - //16+ bits samples are SIGNED - // if sample is > 16 bits, just read extra bytes - - uint32_t data=0; - for (int b=0;b<(format_bits>>3);b++) { - - data|=((uint32_t)file->get_8())<<(b*8); - } - data<<=(32-format_bits); - - - int32_t s=data; - - int16_t *data_ptr16=&((int16_t*)data_ptr)[i*format_channels+c]; - - *data_ptr16=s>>16; - } - } - - } - - dataw=PoolVector<uint8_t>::Write(); - - sample->set_data(data); - - - if (file->eof_reached()) { - file->close(); - memdelete(file); - ERR_EXPLAIN("Premature end of file."); - ERR_FAIL_V(RES()); - } - } - - if (chunkID[0]=='s' && chunkID[1]=='m' && chunkID[2]=='p' && chunkID[3]=='l') { - //loop point info! - - for(int i=0;i<10;i++) - file->get_32(); // i wish to know why should i do this... no doc! - - loop=file->get_32()?Sample::LOOP_PING_PONG:Sample::LOOP_FORWARD; - loop_begin=file->get_32(); - loop_end=file->get_32(); - - } - file->seek( file_pos+chunksize ); - } - - sample->set_loop_format(loop); - sample->set_loop_begin(loop_begin); - sample->set_loop_end(loop_end); - - file->close(); - memdelete(file); - - if (r_error) - *r_error=OK; - - - return sample; - -} -void ResourceFormatLoaderWAV::get_recognized_extensions(List<String> *p_extensions) const { - - p_extensions->push_back("wav"); -} -bool ResourceFormatLoaderWAV::handles_type(const String& p_type) const { - - return (p_type=="Sample"); -} - -String ResourceFormatLoaderWAV::get_resource_type(const String &p_path) const { - - if (p_path.get_extension().to_lower()=="wav") - return "Sample"; - return ""; -} - -#endif diff --git a/scene/io/resource_format_wav.h b/scene/io/resource_format_wav.h deleted file mode 100644 index 9105689670..0000000000 --- a/scene/io/resource_format_wav.h +++ /dev/null @@ -1,46 +0,0 @@ -/*************************************************************************/ -/* resource_format_wav.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef RESOURCE_FORMAT_WAV_H -#define RESOURCE_FORMAT_WAV_H - -#if 0 -#include "io/resource_loader.h" - -class ResourceFormatLoaderWAV : public ResourceFormatLoader { -public: - virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL); - virtual void get_recognized_extensions(List<String> *p_extensions) const; - virtual bool handles_type(const String& p_type) const; - virtual String get_resource_type(const String &p_path) const; - -}; - -#endif -#endif // RESOURCE_FORMAT_WAV_H |