*/}}

ourpaint.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. /*
  2. * Our Paint: A light weight GPU powered painting program.
  3. * Copyright (C) 2022-2023 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. #ifndef OURPAINT_GIT_BRANCH
  20. #define OURPAINT_GIT_BRANCH "Release 1"
  21. #endif
  22. // No need to show hash when not compiled from git repo.
  23. //#ifndef OURPAINT_GIT_HASH
  24. //#define OURPAINT_GIT_HASH "?"
  25. //#endif
  26. extern unsigned char DATA_SPLASH[];
  27. extern unsigned char DATA_SPLASH_HIGHDPI[];
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. extern const char OUR_CANVAS_SHADER[];
  32. extern const char OUR_COMPOSITION_SHADER[];
  33. #ifdef __cplusplus
  34. } // extern "C"
  35. #endif
  36. #define OUR_AT_CROP_CENTER 0
  37. #define OUR_AT_CROP_L 1
  38. #define OUR_AT_CROP_R 2
  39. #define OUR_AT_CROP_U 3
  40. #define OUR_AT_CROP_B 4
  41. #define OUR_AT_CROP_UL 5
  42. #define OUR_AT_CROP_UR 6
  43. #define OUR_AT_CROP_BL 7
  44. #define OUR_AT_CROP_BR 8
  45. #define OUR_VERSION_MAJOR 0
  46. #define OUR_VERSION_MINOR 1
  47. STRUCTURE(OurCanvasDraw){
  48. laCanvasExtra Base;
  49. int HideBrushCircle;
  50. int AtCrop;
  51. real CanvasLastX,CanvasLastY;
  52. real CanvasDownX,CanvasDownY;
  53. real LastPressure;
  54. real LastTilt[2];
  55. };
  56. #define OUR_TILE_W 1024
  57. #define OUR_TILES_PER_ROW 100
  58. #define OUR_TILE_CTR (OUR_TILES_PER_ROW/2)
  59. #define OUR_TILE_SEAM 12
  60. #define OUR_TILE_W_USE (OUR_TILE_W-OUR_TILE_SEAM*2)
  61. STRUCTURE(OurTexTile){
  62. tnsTexture* Texture;
  63. uint16_t* Data;
  64. int l,r,u,b;
  65. uint16_t* FullData;
  66. uint16_t* CopyBuffer;
  67. int cl,cr,cu,cb;
  68. };
  69. #define OUR_BLEND_NORMAL 0
  70. #define OUR_BLEND_ADD 1
  71. STRUCTURE(OurLayer){
  72. laListItem Item;
  73. laSafeString Name;
  74. int OffsetX,OffsetY;
  75. real Transparency;
  76. int Lock;
  77. int Hide;
  78. int BlendMode;
  79. OurTexTile** TexTiles[OUR_TILES_PER_ROW];
  80. };
  81. STRUCTURE(OurLayerWrite){
  82. unsigned char* data;
  83. size_t NextData, MaxData;
  84. };
  85. STRUCTURE(OurLayerRead){
  86. unsigned char* data;
  87. size_t NextData;
  88. };
  89. STRUCTURE(OurBrushSettingsNode){
  90. laBaseNode Base;
  91. laNodeOutSocket* CanvasScale; real rCanvasScale;
  92. laNodeOutSocket* Size; real rSize;
  93. laNodeOutSocket* Transparency; real rTransparency;
  94. laNodeOutSocket* Hardness; real rHardness;
  95. laNodeOutSocket* Smudge; real rSmudge;
  96. laNodeOutSocket* DabsPerSize; real rDabsPerSize;
  97. laNodeOutSocket* SmudgeLength; real rSmudgeLength;
  98. laNodeOutSocket* Slender; real rSlender;
  99. laNodeOutSocket* Angle; real rAngle;
  100. laNodeOutSocket* Color;
  101. };
  102. STRUCTURE(OurBrushOutputsNode){
  103. laBaseNode Base;
  104. laNodeInSocket* Offset;
  105. laNodeInSocket* Size;
  106. laNodeInSocket* Transparency;
  107. laNodeInSocket* Hardness;
  108. laNodeInSocket* Smudge;
  109. laNodeInSocket* DabsPerSize;
  110. laNodeInSocket* SmudgeLength;
  111. laNodeInSocket* Slender;
  112. laNodeInSocket* Angle;
  113. laNodeInSocket* Color;
  114. };
  115. STRUCTURE(OurBrushDeviceNode){
  116. laBaseNode Base;
  117. laNodeOutSocket* Pressure; real rPressure;
  118. laNodeOutSocket* Position; real rPosition[2];
  119. laNodeOutSocket* Tilt; real rTilt[2];
  120. laNodeOutSocket* IsEraser; int rIsEraser;
  121. laNodeOutSocket* Speed; real rSpeed;
  122. laNodeOutSocket* Angle; real rAngle;
  123. laNodeOutSocket* Length; real rLength;
  124. laNodeOutSocket* LengthAccum; real rLengthAccum;
  125. };
  126. STRUCTURE(OurBrush){
  127. laListItem Item;
  128. laSafeString Name;
  129. real Size;
  130. real DabsPerSize;
  131. real Hardness;
  132. real Transparency;
  133. real Smudge;
  134. real SmudgeResampleLength; real SmudgeAccum; int SmudgeRestart; real BrushRemainingDist;
  135. real Slender;
  136. real Angle;
  137. real Smoothness;
  138. real MaxStrokeLength;
  139. int PressureSize,PressureHardness,PressureTransparency,PressureSmudge; // the simple way
  140. int Binding,DefaultAsEraser;
  141. int UseNodes; // the flexible way
  142. laRackPage* Rack;
  143. real LastX,LastY,LastAngle;
  144. real EvalColor[3];
  145. real EvalOffset[2];
  146. real EvalSize;
  147. real EvalDabsPerSize;
  148. real EvalHardness;
  149. real EvalTransparency;
  150. real EvalSmudge;
  151. real EvalSmudgeLength;
  152. real EvalSlender;
  153. real EvalAngle;
  154. real EvalSpeed;
  155. real EvalStrokeLength;
  156. real EvalStrokeLengthAccum;
  157. real EvalPressure;
  158. real EvalPosition[2];
  159. real EvalTilt[2];
  160. real EvalStrokeAngle;
  161. int EvalIsEraser;
  162. };
  163. STRUCTURE(OurDab){
  164. float X,Y;
  165. float Size;
  166. float Hardness;
  167. float Smudge; int ResampleSmudge;
  168. float Color[4];
  169. float Slender;
  170. float Angle;
  171. float Recentness;
  172. };
  173. STRUCTURE(OurUndoTile){
  174. laListItem Item;
  175. int col,row;
  176. uint16_t* CopyData;
  177. int l,r,u,b;
  178. };
  179. STRUCTURE(OurUndo){
  180. OurLayer* Layer;
  181. laListHandle Tiles;
  182. };
  183. #define OUR_TOOL_PAINT 0
  184. #define OUR_TOOL_CROP 1
  185. #define OUR_PNG_READ_INPUT_FLAT 0
  186. #define OUR_PNG_READ_INPUT_ICC 1
  187. #define OUR_PNG_READ_INPUT_SRGB 2
  188. #define OUR_PNG_READ_INPUT_LINEAR_SRGB 3
  189. #define OUR_PNG_READ_INPUT_CLAY 4
  190. #define OUR_PNG_READ_INPUT_LINEAR_CLAY 5
  191. #define OUR_PNG_READ_OUTPUT_CANVAS 0
  192. #define OUR_PNG_READ_OUTPUT_LINEAR_SRGB OUR_PNG_READ_INPUT_LINEAR_SRGB
  193. #define OUR_PNG_READ_OUTPUT_LINEAR_CLAY OUR_PNG_READ_INPUT_LINEAR_CLAY
  194. #define OUR_CANVAS_INTERPRETATION_SRGB 0
  195. #define OUR_CANVAS_INTERPRETATION_CLAY 1
  196. #define OUR_EXPORT_BIT_DEPTH_8 0
  197. #define OUR_EXPORT_BIT_DEPTH_16 1
  198. #define OUR_EXPORT_COLOR_MODE_SRGB 0
  199. #define OUR_EXPORT_COLOR_MODE_CLAY 1
  200. #define OUR_EXPORT_COLOR_MODE_FLAT 2
  201. STRUCTURE(OurPNGReadExtra){
  202. int Confirming;
  203. laSafeString* FilePath;
  204. laSafeString* iccName;
  205. int HassRGB;
  206. int HasProfile;
  207. int InputMode;
  208. int OutputMode;
  209. };
  210. STRUCTURE(OurPNGWriteExtra){
  211. int Confirming;
  212. laSafeString* FilePath;
  213. int BitDepth;
  214. int ColorProfile;
  215. };
  216. STRUCTURE(OurPaint){
  217. real pad;
  218. laListHandle CanvasSaverDummyList;
  219. laProp* CanvasSaverDummyProp;
  220. laListHandle BadEvents;
  221. tnsImage* SplashImage;
  222. tnsImage* SplashImageHigh;
  223. laListHandle Layers;
  224. OurLayer* CurrentLayer;
  225. laListHandle Brushes;
  226. OurBrush* CurrentBrush;
  227. real SaveBrushSize,SaveEraserSize;
  228. OurDab* Dabs; int NextDab,MaxDab;
  229. laListHandle BrushEval;
  230. real CurrentScale;
  231. real DefaultScale;
  232. int Tool,ActiveTool,Erasing,EventErasing;
  233. int LockBackground;
  234. int PenID,EraserID;
  235. int X,Y,W,H; //border
  236. int ColorInterpretation;
  237. int ShowBorder,UseBorder;
  238. int ShowTiles;
  239. int AllowNonPressure,PaintProcessedEvents;
  240. int BadEventsLimit,BadEventCount,BadEventsGiveUp;
  241. int LockRadius;
  242. int EnableBrushCircle;
  243. int DefaultBitDepth;
  244. int DefaultColorProfile;
  245. int PaintUndoLimit;
  246. int SpectralMode;
  247. tnsTexture* SmudgeTexture;
  248. GLuint CanvasShader; GLuint CanvasProgram;
  249. GLuint CompositionShader; GLuint CompositionProgram;
  250. GLint uBrushCorner;
  251. GLint uBrushCenter;
  252. GLint uBrushSize;
  253. GLint uBrushHardness;
  254. GLint uBrushSmudge;
  255. GLint uBrushRecentness;
  256. GLint uBrushColor;
  257. GLint uBrushSlender;
  258. GLint uBrushAngle;
  259. GLint uBrushRoutineSelection;
  260. GLint uMixRoutineSelection;
  261. GLint uBrushErasing;
  262. GLint RoutineDoDabs;
  263. GLint RoutineDoSample;
  264. GLint RoutineDoMixNormal;
  265. GLint RoutineDoMixSpectral;
  266. GLint uBlendMode;
  267. GLint uAlphaTop;
  268. GLint uAlphaBottom;
  269. real CurrentColor[3];
  270. real BackgroundColor[3];
  271. uint16_t BColorU16[4];
  272. uint8_t BColorU8[4];
  273. real BorderAlpha;
  274. real xmin,xmax,ymin,ymax; // stroke bbox for undo region
  275. int ResetBrush;
  276. uint16_t *ImageBuffer;
  277. int ImageW,ImageH,ImageX,ImageY,LoadX,LoadY,TempLoadX,TempLoadY;
  278. void* icc_LinearsRGB; int iccsize_LinearsRGB;
  279. void* icc_LinearClay; int iccsize_LinearClay;
  280. void* icc_sRGB; int iccsize_sRGB;
  281. void* icc_Clay; int iccsize_Clay;
  282. };
  283. int ourInit();
  284. void ourRegisterNodes();
  285. int ourRebuildBrushEval();
  286. int ourEvalBrush();
  287. void ourMakeTranslations();
  288. void our_EnableSplashPanel();