*/}}

ourpaint.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. * Our Paint: A light weight GPU powered painting program.
  3. * Copyright (C) 2022 Wu Yiming
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "la_5.h"
  19. #define OUR_AT_CROP_CENTER 0
  20. #define OUR_AT_CROP_L 1
  21. #define OUR_AT_CROP_R 2
  22. #define OUR_AT_CROP_U 3
  23. #define OUR_AT_CROP_B 4
  24. #define OUR_AT_CROP_UL 5
  25. #define OUR_AT_CROP_UR 6
  26. #define OUR_AT_CROP_BL 7
  27. #define OUR_AT_CROP_BR 8
  28. #define OUR_VERSION_MAJOR 0
  29. #define OUR_VERSION_MINOR 1
  30. STRUCTURE(OurCanvasDraw){
  31. laCanvasExtra Base;
  32. int HideBrushCircle;
  33. int AtCrop;
  34. real CanvasLastX,CanvasLastY;
  35. real CanvasDownX,CanvasDownY;
  36. real LastPressure;
  37. real LastTilt[2];
  38. };
  39. #define OUR_TILE_W 1024
  40. #define OUR_TILES_PER_ROW 100
  41. #define OUR_TILE_CTR (OUR_TILES_PER_ROW/2)
  42. #define OUR_TILE_SEAM 12
  43. #define OUR_TILE_W_USE (OUR_TILE_W-OUR_TILE_SEAM*2)
  44. STRUCTURE(OurTexTile){
  45. tnsTexture* Texture;
  46. uint16_t* Data;
  47. int l,r,u,b;
  48. uint16_t* FullData;
  49. uint16_t* CopyBuffer;
  50. int cl,cr,cu,cb;
  51. };
  52. #define OUR_BLEND_NORMAL 0
  53. #define OUR_BLEND_ADD 1
  54. STRUCTURE(OurLayer){
  55. laListItem Item;
  56. laSafeString Name;
  57. int OffsetX,OffsetY;
  58. real Transparency;
  59. int Lock;
  60. int Hide;
  61. int BlendMode;
  62. OurTexTile** TexTiles[OUR_TILES_PER_ROW];
  63. };
  64. STRUCTURE(OurLayerWrite){
  65. unsigned char* data;
  66. size_t NextData, MaxData;
  67. };
  68. STRUCTURE(OurLayerRead){
  69. unsigned char* data;
  70. size_t NextData;
  71. };
  72. STRUCTURE(OurBrushSettingsNode){
  73. laBaseNode Base;
  74. laNodeOutSocket* CanvasScale; real rCanvasScale;
  75. laNodeOutSocket* Size; real rSize;
  76. laNodeOutSocket* Transparency; real rTransparency;
  77. laNodeOutSocket* Hardness; real rHardness;
  78. laNodeOutSocket* Smudge; real rSmudge;
  79. laNodeOutSocket* DabsPerSize; real rDabsPerSize;
  80. laNodeOutSocket* SmudgeLength; real rSmudgeLength;
  81. laNodeOutSocket* Slender; real rSlender;
  82. laNodeOutSocket* Angle; real rAngle;
  83. laNodeOutSocket* Color;
  84. };
  85. STRUCTURE(OurBrushOutputsNode){
  86. laBaseNode Base;
  87. laNodeInSocket* Offset;
  88. laNodeInSocket* Size;
  89. laNodeInSocket* Transparency;
  90. laNodeInSocket* Hardness;
  91. laNodeInSocket* Smudge;
  92. laNodeInSocket* DabsPerSize;
  93. laNodeInSocket* SmudgeLength;
  94. laNodeInSocket* Slender;
  95. laNodeInSocket* Angle;
  96. laNodeInSocket* Color;
  97. };
  98. STRUCTURE(OurBrushDeviceNode){
  99. laBaseNode Base;
  100. laNodeOutSocket* Pressure; real rPressure;
  101. laNodeOutSocket* Position; real rPosition[2];
  102. laNodeOutSocket* Tilt; real rTilt[2];
  103. laNodeOutSocket* IsEraser; int rIsEraser;
  104. laNodeOutSocket* Speed; real rSpeed;
  105. laNodeOutSocket* Angle; real rAngle;
  106. laNodeOutSocket* Length; real rLength;
  107. laNodeOutSocket* LengthAccum; real rLengthAccum;
  108. };
  109. STRUCTURE(OurBrush){
  110. laListItem Item;
  111. laSafeString Name;
  112. real Size;
  113. real DabsPerSize;
  114. real Hardness;
  115. real Transparency;
  116. real Smudge;
  117. real SmudgeResampleLength; real SmudgeAccum; int SmudgeRestart; real BrushRemainingDist;
  118. real Slender;
  119. real Angle;
  120. real Smoothness;
  121. real MaxStrokeLength;
  122. int PressureSize,PressureHardness,PressureTransparency,PressureSmudge; // the simple way
  123. int Binding,DefaultAsEraser;
  124. int UseNodes; // the flexible way
  125. laRackPage* Rack;
  126. real LastX,LastY,LastAngle;
  127. real EvalColor[3];
  128. real EvalOffset[2];
  129. real EvalSize;
  130. real EvalDabsPerSize;
  131. real EvalHardness;
  132. real EvalTransparency;
  133. real EvalSmudge;
  134. real EvalSmudgeLength;
  135. real EvalSlender;
  136. real EvalAngle;
  137. real EvalSpeed;
  138. real EvalStrokeLength;
  139. real EvalStrokeLengthAccum;
  140. real EvalPressure;
  141. real EvalPosition[2];
  142. real EvalTilt[2];
  143. real EvalStrokeAngle;
  144. int EvalIsEraser;
  145. };
  146. STRUCTURE(OurDab){
  147. float X,Y;
  148. float Size;
  149. float Hardness;
  150. float Smudge; int ResampleSmudge;
  151. float Color[4];
  152. float Slender;
  153. float Angle;
  154. float Recentness;
  155. };
  156. STRUCTURE(OurUndoTile){
  157. laListItem Item;
  158. int col,row;
  159. uint16_t* CopyData;
  160. int l,r,u,b;
  161. };
  162. STRUCTURE(OurUndo){
  163. OurLayer* Layer;
  164. laListHandle Tiles;
  165. };
  166. #define OUR_TOOL_PAINT 0
  167. #define OUR_TOOL_CROP 1
  168. #define OUR_PNG_READ_INPUT_FLAT 0
  169. #define OUR_PNG_READ_INPUT_ICC 1
  170. #define OUR_PNG_READ_INPUT_SRGB 2
  171. #define OUR_PNG_READ_INPUT_LINEAR_SRGB 3
  172. #define OUR_PNG_READ_INPUT_CLAY 4
  173. #define OUR_PNG_READ_INPUT_LINEAR_CLAY 5
  174. #define OUR_PNG_READ_OUTPUT_CANVAS 0
  175. #define OUR_PNG_READ_OUTPUT_LINEAR_SRGB OUR_PNG_READ_INPUT_LINEAR_SRGB
  176. #define OUR_PNG_READ_OUTPUT_LINEAR_CLAY OUR_PNG_READ_INPUT_LINEAR_CLAY
  177. #define OUR_CANVAS_INTERPRETATION_SRGB 0
  178. #define OUR_CANVAS_INTERPRETATION_CLAY 1
  179. #define OUR_EXPORT_BIT_DEPTH_8 0
  180. #define OUR_EXPORT_BIT_DEPTH_16 1
  181. #define OUR_EXPORT_COLOR_MODE_SRGB 0
  182. #define OUR_EXPORT_COLOR_MODE_CLAY 1
  183. #define OUR_EXPORT_COLOR_MODE_FLAT 2
  184. STRUCTURE(OurPNGReadExtra){
  185. int Confirming;
  186. laSafeString* FilePath;
  187. laSafeString* iccName;
  188. int HassRGB;
  189. int HasProfile;
  190. int InputMode;
  191. int OutputMode;
  192. };
  193. STRUCTURE(OurPNGWriteExtra){
  194. int Confirming;
  195. laSafeString* FilePath;
  196. int BitDepth;
  197. int ColorProfile;
  198. };
  199. STRUCTURE(OurPaint){
  200. real pad;
  201. laListHandle CanvasSaverDummyList;
  202. laProp* CanvasSaverDummyProp;
  203. laListHandle Layers;
  204. OurLayer* CurrentLayer;
  205. laListHandle Brushes;
  206. OurBrush* CurrentBrush;
  207. OurDab* Dabs; int NextDab,MaxDab;
  208. laListHandle BrushEval;
  209. real CurrentScale;
  210. int Tool,ActiveTool,Erasing,EventErasing;
  211. int LockBackground;
  212. int PenID,EraserID;
  213. int X,Y,W,H; //border
  214. int ColorInterpretation;
  215. int ShowBorder,UseBorder;
  216. int ShowTiles;
  217. int LockRadius;
  218. int EnableBrushCircle;
  219. int DefaultBitDepth;
  220. int DefaultColorProfile;
  221. int PaintUndoLimit;
  222. tnsTexture* SmudgeTexture;
  223. GLuint CanvasShader; GLuint CanvasProgram;
  224. GLuint CompositionShader; GLuint CompositionProgram;
  225. GLint uBrushCorner;
  226. GLint uBrushCenter;
  227. GLint uBrushSize;
  228. GLint uBrushHardness;
  229. GLint uBrushSmudge;
  230. GLint uBrushRecentness;
  231. GLint uBrushColor;
  232. GLint uBrushSlender;
  233. GLint uBrushAngle;
  234. GLint uBrushRoutineSelection;
  235. GLint uBrushErasing;
  236. GLint RoutineDoDabs;
  237. GLint RoutineDoSample;
  238. GLint uBlendMode;
  239. GLint uAlphaTop;
  240. GLint uAlphaBottom;
  241. real CurrentColor[3];
  242. real BackgroundColor[3];
  243. uint16_t BColorU16[4];
  244. real BorderAlpha;
  245. real xmin,xmax,ymin,ymax; // stroke bbox for undo region
  246. int ResetBrush;
  247. uint16_t *ImageBuffer;
  248. int ImageW,ImageH,ImageX,ImageY,LoadX,LoadY,TempLoadX,TempLoadY;
  249. void* icc_LinearsRGB; int iccsize_LinearsRGB;
  250. void* icc_LinearClay; int iccsize_LinearClay;
  251. void* icc_sRGB; int iccsize_sRGB;
  252. void* icc_Clay; int iccsize_Clay;
  253. };
  254. int ourInit();
  255. void ourRegisterNodes();
  256. int ourRebuildBrushEval();
  257. int ourEvalBrush();
  258. void ourMakeTranslations();