Mon, 30 Apr 2018 15:54:06 +0300
* Auto kerning support for bitmap fonts
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

1  #include "Bitmap.h" 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

2  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

3  #include <fstream> 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

4  #include <algorithm> 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

5  #include <numeric> 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

6  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

7  #include "../Encoding/PNG.h" 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

8  #include "../Encoding/JPEG.h" 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

9  #include "../IO/Stream.h" 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

10  #include "../Utils/Assert.h" 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

11  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

12  namespace Gorgon { namespace Graphics { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

13  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

14  void Bitmap::Prepare() { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

15  if(data) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

16  Graphics::Texture::Set(*data); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

17  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

18  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

19  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

20  void Bitmap::Discard() { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

21  if(data) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

22  delete data; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

23  data=nullptr; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

24  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

25  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

26  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

27  bool Bitmap::Import(const std::string &filename) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

28  auto dotpos = filename.find_last_of('.'); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

29  if(dotpos!=1) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

30  auto ext = filename.substr(dotpos+1); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

31  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

32  if(String::ToLower(ext) == "png") { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

33  return ImportPNG(filename); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

34  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

35  else if(String::ToLower(ext) == "jpg"  String::ToLower(ext) =="jpeg") { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

36  return ImportJPEG(filename); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

37  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

38  else if(String::ToLower(ext) == "bmp") { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

39  return ImportBMP(filename); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

40  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

41  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

42  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

43  std::ifstream file(filename, std::ios::binary); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

44  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

45  static const uint32_t pngsig = 0x474E5089; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

46  static const uint32_t jpgsig1 = 0xE0FFD8FF; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

47  static const uint32_t jpgsig2 = 0xE1FFD8FF; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

48  static const uint32_t bmpsig = 0x4D42; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

49  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

50  uint32_t sig = IO::ReadUInt32(file); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

51  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

52  file.close(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

53  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

54  if(sig == pngsig) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

55  return ImportPNG(filename); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

56  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

57  else if(sig == jpgsig1  sig == jpgsig2) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

58  return ImportJPEG(filename); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

59  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

60  else if((sig&0xffff) == bmpsig) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

61  return ImportBMP(filename); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

62  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

63  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

64  throw std::runtime_error("Unsuppoted file format"); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

65  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

66  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

67  bool Bitmap::Import(std::istream &file) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

68  static const uint32_t pngsig = 0x474E5089; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

69  static const uint32_t jpgsig1 = 0xE0FFD8FF; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

70  static const uint32_t jpgsig2 = 0xE1FFD8FF; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

71  static const uint32_t bmpsig = 0x4D42; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

72  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

73  uint32_t sig = IO::ReadUInt32(file); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

74  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

75  file.seekg(4, std::ios::cur); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

76  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

77  if(sig == pngsig) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

78  return ImportPNG(file); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

79  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

80  else if(sig == jpgsig1  sig == jpgsig2) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

81  return ImportJPEG(file); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

82  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

83  else if((sig&0xffff) == bmpsig) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

84  return ImportBMP(file); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

85  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

86  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

87  throw std::runtime_error("Unsuppoted file format"); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

88  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

89  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

90  bool Bitmap::ImportPNG(const std::string &filename) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

91  std::ifstream file(filename, std::ios::binary); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

92  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

93  if(!file.is_open()  !file.good()) return false; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

94  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

95  Destroy(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

96  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

97  data=new Containers::Image(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

98  Encoding::Png.Decode(file, *data); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

99  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

100  return true; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

101  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

102  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

103  bool Bitmap::ImportJPEG(const std::string &filename) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

104  std::ifstream file(filename, std::ios::binary); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

105  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

106  if(!file.is_open()  !file.good()) return false; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

107  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

108  Destroy(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

109  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

110  data=new Containers::Image(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

111  Encoding::Jpg.Decode(file, *data); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

112  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

113  return true; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

114  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

115  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

116  bool Bitmap::ImportBMP(const std::string &filename) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

117  std::ifstream file(filename, std::ios::binary); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

118  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

119  if(!file.is_open()  !file.good()) return false; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

120  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

121  Destroy(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

122  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

123  data=new Containers::Image(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

124  return data>ImportBMP(filename); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

125  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

126  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

127  bool Bitmap::ImportPNG(std::istream &file) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

128  Destroy(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

129  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

130  data=new Containers::Image(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

131  Encoding::Png.Decode(file, *data); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

132  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

133  return true; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

134  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

135  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

136  bool Bitmap::ImportJPEG(std::istream &file) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

137  Destroy(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

138  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

139  data=new Containers::Image(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

140  Encoding::Jpg.Decode(file, *data); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

141  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

142  return true; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

143  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

144  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

145  bool Bitmap::ImportBMP(std::istream &file) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

146  Destroy(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

147  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

148  data=new Containers::Image(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

149  return data>ImportBMP(file); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

150  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

151  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

152  bool Bitmap::ExportPNG(const std::string &filename) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

153  ASSERT(data, "Image data does not exists"); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

154  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

155  if(GetMode()!=Graphics::ColorMode::RGB && 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

156  GetMode()!=Graphics::ColorMode::RGBA && 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

157  GetMode()!=Graphics::ColorMode::Grayscale && 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

158  GetMode()!=Graphics::ColorMode::Grayscale_Alpha && 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

159  GetMode()!=Graphics::ColorMode::Alpha) 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

160  throw std::runtime_error("Unsupported color mode"); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

161  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

162  std::ofstream file(filename, std::ios::binary); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

163  if(!file.is_open()) 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

164  return false; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

165  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

166  Encoding::Png.Encode(*data, file); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

167  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

168  return true; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

169  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

170  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

171  bool Bitmap::ExportPNG(std::ostream &out) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

172  ASSERT(data, "Image data does not exists"); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

173  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

174  if(GetMode()!=Graphics::ColorMode::RGB && 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

175  GetMode()!=Graphics::ColorMode::RGBA && 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

176  GetMode()!=Graphics::ColorMode::Grayscale && 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

177  GetMode()!=Graphics::ColorMode::Grayscale_Alpha && 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

178  GetMode()!=Graphics::ColorMode::Alpha) 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

179  throw std::runtime_error("Unsupported color mode"); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

180  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

181  Encoding::Png.Encode(*data, out); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

182  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

183  return true; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

184  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

185  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

186  bool Bitmap::ExportBMP(const std::string &filename) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

187  ASSERT(data, "Image data does not exists"); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

188  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

189  return data>ExportBMP(filename); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

190  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

191  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

192  bool Bitmap::ExportBMP(std::ostream &out) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

193  ASSERT(data, "Image data does not exists"); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

194  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

195  return data>ExportBMP(out); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

196  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

197  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

198  bool Bitmap::ExportJPG(const std::string &filename, int quality) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

199  ASSERT(data, "Image data does not exists"); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

200  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

201  if(GetMode()!=Graphics::ColorMode::RGB && 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

202  GetMode()!=Graphics::ColorMode::Grayscale) 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

203  throw std::runtime_error("Unsupported color mode"); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

204  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

205  if(quality < 0  quality > 100) 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

206  throw std::runtime_error("Unsupported quality"); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

207  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

208  std::ofstream file(filename, std::ios::binary); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

209  if(!file.is_open()) 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

210  return false; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

211  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

212  Encoding::Jpg.Encode(*data, file, quality); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

213  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

214  return true; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

215  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

216  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

217  bool Bitmap::ExportJPG(std::ostream &out, int quality) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

218  ASSERT(data, "Image data does not exists"); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

219  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

220  if(GetMode()!=Graphics::ColorMode::RGB && 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

221  GetMode()!=Graphics::ColorMode::Grayscale) 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

222  throw std::runtime_error("Unsupported color mode"); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

223  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

224  if(quality < 0  quality > 100) 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

225  throw std::runtime_error("Unsupported quality"); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

226  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

227  Encoding::Jpg.Encode(*data, out, quality); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

228  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

229  return true; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

230  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

231  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

232  void Bitmap::StripRGB() { 
1142  233  ASSERT(HasAlpha(), "Unsupported color mode"); 
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

234  
1142  235  int alpha = GetAlphaIndex(); 
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

236  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

237  auto &data = *this>data; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

238  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

239  Containers::Image img(data.GetSize(), ColorMode::Alpha); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

240  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

241  for(int y=0; y<data.GetHeight(); y++) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

242  for(int x=0; x<data.GetWidth(); x++) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

243  img(x, y, 0) = data(x, y, alpha); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

244  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

245  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

246  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

247  Assume(img); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

248  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

249  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

250  void Bitmap::StripAlpha() { 
1142  251  if(!HasAlpha()) return; 
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

252  
1142  253  int alpha = GetAlphaIndex(); 
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

254  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

255  auto &data = *this>data; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

256  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

257  Containers::Image img(data.GetSize(), (ColorMode)((int)GetMode()&~(int)ColorMode::Alpha)); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

258  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

259  for(int y=0; y<data.GetHeight(); y++) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

260  for(int x=0; x<data.GetWidth(); x++) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

261  int cc = 0; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

262  for(int c=0; c<(int)data.GetBytesPerPixel(); c++) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

263  if(c!=alpha) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

264  img(x, y, cc++) = data(x, y, c); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

265  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

266  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

267  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

268  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

269  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

270  Assume(img); 
972
40b12ffaea3e
* Animation storage system to unify image, animation, and pointer
cemkalyoncu
parents:
932
diff
changeset

271  } 
40b12ffaea3e
* Animation storage system to unify image, animation, and pointer
cemkalyoncu
parents:
932
diff
changeset

272  
1010  273  std::vector<Geometry::Bounds> Bitmap::CreateLinearAtlas(Containers::Collection<const Bitmap> list, AtlasMargin margins) { 
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

274  std::vector<Geometry::Bounds> ret; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

275  std::map<const Bitmap *, Geometry::Bounds> mapping; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

276  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

277  int N = list.GetSize(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

278  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

279  if(N == 0) return ret; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

280  if(N == 1) return {Geometry::Bounds(0, 0, list[0].GetSize())}; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

281  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

282  int marginwidth = 0; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

283  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

284  if(margins == Zero) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

285  marginwidth = 1; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

286  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

287  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

288  auto mode = list[0].GetMode(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

289  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

290  int minw = list[0].GetWidth() + marginwidth; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

291  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

292  std::vector<const Bitmap *> ordering; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

293  for(auto &bmp : list) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

294  ordering.push_back(&bmp); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

295  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

296  if(minw > bmp.GetWidth() + marginwidth) 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

297  minw = bmp.GetWidth() + marginwidth; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

298  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

299  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

300  //first height based, so the items with similar heights would be next to each other 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

301  //second sort criteria is width as wider items should be packed at start. Items 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

302  //are reverse sorted for performance 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

303  list.Sort([](const Bitmap &l, const Bitmap &r) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

304  if(l.GetHeight() == r.GetHeight()) 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

305  return l.GetWidth() < r.GetWidth(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

306  else 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

307  return l.GetHeight() > r.GetHeight(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

308  }); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

309  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

310  int totalw = std::accumulate(list.begin(), list.end(), 0, [margins](int l, const Bitmap &r) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

311  return l + r.GetWidth() + (margins == Zero ? 1 : 0); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

312  }); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

313  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

314  int avgw = (int)std::ceil(float(totalw) / N); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

315  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

316  // average line height would be skewed towards high 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

317  int avgh = list[int(N*2/3)].GetHeight(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

318  if(margins == Zero) 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

319  avgh += 1; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

320  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

321  int lines = (int)std::round(std::sqrt(float(N)/avgh*avgw)); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

322  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

323  int x = 0, y = 0, maxy = 0; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

324  int w = (int)std::ceil((float)totalw/lines); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

325  w += minw; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

326  int maxx = 0; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

327  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

328  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

329  if(margins == Zero) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

330  x = marginwidth; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

331  y = marginwidth; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

332  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

333  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

334  //build positions 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

335  for(int i=0; i<N; i++) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

336  auto &bmp = *list.Last(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

337  if(x + bmp.GetWidth() + marginwidth < w) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

338  auto size = bmp.GetSize(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

339  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

340  mapping[&bmp] = {x, y, size}; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

341  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

342  x += size.Width + marginwidth; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

343  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

344  if(size.Height > maxy) maxy = size.Height; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

345  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

346  list.Remove(list.GetSize()1); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

347  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

348  else { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

349  bool found = false; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

350  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

351  if(w  x > minw) { //search to find a smaller image 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

352  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

353  int maxw = w  x  1  marginwidth; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

354  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

355  for(auto it = list.Last(); it.IsValid(); it.Previous()) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

356  auto size = it>GetSize(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

357  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

358  if(size.Width <= maxw) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

359  mapping[it.CurrentPtr()] = {x, y, size}; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

360  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

361  x += size.Width + marginwidth; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

362  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

363  if(size.Height > maxy) maxy = size.Height; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

364  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

365  it.Remove(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

366  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

367  found = true; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

368  break; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

369  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

370  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

371  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

372  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

373  if(!found) { //too small 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

374  y += maxy + marginwidth; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

375  maxy = 0; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

376  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

377  if(maxx < x) maxx = x; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

378  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

379  if(margins == Zero) 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

380  x = 1; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

381  else 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

382  x = 0; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

383  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

384  i; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

385  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

386  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

387  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

388  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

389  if(x) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

390  y += maxy; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

391  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

392  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

393  Resize({maxx, y + marginwidth}, mode); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

394  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

395  if(margins == Zero) { 
1019
c72a1acd9bba
* Drag and drop system is now working, dragsource still needs testing
cemkalyoncu
parents:
1010
diff
changeset

396  data>Clear(); 
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

397  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

398  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

399  //channel count 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

400  int C = GetBytesPerPixel(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

401  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

402  for(auto p : mapping) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

403  auto b = p.second; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

404  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

405  if(p.first>GetMode() != mode) 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

406  throw std::runtime_error("Color modes are not uniform in atlas generation"); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

407  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

408  for(int y=0; y<b.Height(); y++) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

409  for(int x=0; x<b.Width(); x++) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

410  for(int c=0; c<C; c++) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

411  (*data)(x+b.Left, y+b.Top, c) = (*p.first)(x, y, c); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

412  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

413  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

414  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

415  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

416  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

417  ret.reserve(N); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

418  for(int i=0; i<N; i++) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

419  ret.push_back(mapping[ordering[i]]); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

420  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

421  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

422  //ExportPNG("atlas.png"); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

423  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

424  return ret; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

425  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

426  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

427  std::vector<TextureImage> Bitmap::CreateAtlasImages(std::vector<Geometry::Bounds> boundaries) const { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

428  if(GetID() == 0) throw std::runtime_error("Cannot map atlas from an unprepared image"); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

429  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

430  std::vector<TextureImage> ret; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

431  ret.reserve(boundaries.size()); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

432  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

433  for(auto b : boundaries) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

434  ret.emplace_back(GetID(), GetMode(), GetSize(), b); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

435  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

436  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

437  return ret; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

438  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

439  
1010  440  Geometry::Margin Bitmap::Trim(bool left, bool top, bool right, bool bottom) { 
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

441  ASSERT(data, "Image data does not exists"); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

442  
1124  443  Geometry::Margin ret(0, 0, 0, 0); 
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

444  
1142  445  if(!HasAlpha()) 
1124  446  return ret; 
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

447  
1142  448  int alpha = GetAlphaIndex(); 
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

449  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

450  auto &data = *this>data; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

451  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

452  if(left) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

453  for(int x=0; x<data.GetWidth(); x++) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

454  bool empty = true; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

455  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

456  for(int y=0; y<data.GetHeight(); y++) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

457  if(data(x, y, alpha) != 0) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

458  empty = false; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

459  break; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

460  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

461  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

462  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

463  if(empty) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

464  ret.Left++; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

465  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

466  else { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

467  break; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

468  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

469  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

470  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

471  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

472  if(top) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

473  for(int y=0; y<data.GetHeight(); y++) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

474  bool empty = true; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

475  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

476  for(int x=0; x<data.GetWidth(); x++) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

477  if(data(x, y, alpha) != 0) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

478  empty = false; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

479  break; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

480  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

481  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

482  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

483  if(empty) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

484  ret.Top++; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

485  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

486  else { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

487  break; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

488  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

489  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

490  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

491  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

492  if(right) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

493  for(int x=data.GetWidth()1; x>=0; x) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

494  bool empty = true; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

495  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

496  for(int y=0; y<data.GetHeight(); y++) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

497  if(data(x, y, alpha) != 0) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

498  empty = false; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

499  break; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

500  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

501  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

502  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

503  if(empty) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

504  ret.Right++; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

505  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

506  else { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

507  break; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

508  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

509  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

510  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

511  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

512  if(bottom) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

513  for(int y=data.GetHeight()1; y>=0; y) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

514  bool empty = true; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

515  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

516  for(int x=0; x<data.GetWidth(); x++) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

517  if(data(x, y, alpha) != 0) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

518  empty = false; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

519  break; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

520  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

521  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

522  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

523  if(empty) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

524  ret.Bottom++; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

525  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

526  else { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

527  break; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

528  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

529  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

530  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

531  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

532  if(ret.TotalX() == 0 && ret.TotalY() == 0) return ret; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

533  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

534  if(ret.TotalX() >= data.GetWidth()  ret.TotalY() >= data.GetHeight()) 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

535  return ret; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

536  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

537  Containers::Image img(data.GetSize()  ret.Total(), GetMode()); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

538  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

539  int yy=0; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

540  for(int y=ret.Top; y<data.GetHeight()  ret.Bottom; y++) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

541  int xx=0; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

542  for(int x=ret.Left; x<data.GetWidth()  ret.Right; x++) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

543  for(int c=0; c<(int)data.GetBytesPerPixel(); c++) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

544  img(xx, yy, c) = data(x, y, c); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

545  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

546  xx++; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

547  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

548  yy++; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

549  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

550  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

551  Assume(img); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

552  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

553  return ret; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

554  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

555  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

556  Containers::Image Bitmap::ReleaseData() { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

557  if(data==nullptr) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

558  #ifndef NDEBUG 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

559  ASSERT_DUMP(false, "No data to release"); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

560  #endif 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

561  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

562  return { }; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

563  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

564  else { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

565  Containers::Image temp=std::move(*data); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

566  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

567  delete data; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

568  data=nullptr; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

569  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

570  return temp; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

571  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

572  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

573  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

574  Graphics::Bitmap Bitmap::Rotate90() const { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

575  ASSERT(data, "Bitmap data is not set"); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

576  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

577  Graphics::Bitmap target(GetHeight(), GetWidth(), GetMode()); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

578  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

579  int h = target.GetHeight(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

580  ForAllPixels([&](int x, int y, int c) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

581  target(y, h  x  1, c) = (*this)(x, y, c); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

582  }); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

583  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

584  return target; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

585  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

586  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

587  Graphics::Bitmap Bitmap::Rotate180() const { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

588  ASSERT(data, "Bitmap data is not set"); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

589  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

590  Graphics::Bitmap target(GetSize(), GetMode()); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

591  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

592  int h = target.GetHeight(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

593  int w = target.GetWidth(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

594  ForAllPixels([&](int x, int y, int c) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

595  target(w  x  1, h  y  1, c) = (*this)(x, y, c); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

596  }); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

597  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

598  return target; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

599  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

600  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

601  Graphics::Bitmap Bitmap::Rotate270() { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

602  ASSERT(data, "Bitmap data is not set"); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

603  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

604  Graphics::Bitmap target(GetHeight(), GetWidth(), GetMode()); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

605  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

606  int w = target.GetWidth(); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

607  ForAllPixels([&](int x, int y, int c) { 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

608  target(w  y  1, x, c) = (*this)(x, y, c); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

609  }); 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

610  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

611  return target; 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

612  } 
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

613  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

614  
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset

615  } } 