*/}}

ourpaint.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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 2
  47. #define OUR_VERSION_SUB 1
  48. #define OUR_PAINT_NAME_STRING "Our Paint v0.2"
  49. #define OUR_SIGNAL_PICK 1
  50. #define OUR_SIGNAL_MOVE 2
  51. #define OUR_SIGNAL_PICK 3
  52. #define OUR_SIGNAL_TOGGLE_ERASING 4
  53. #define OUR_SIGNAL_ZOOM_IN 5
  54. #define OUR_SIGNAL_ZOOM_OUT 6
  55. #define OUR_SIGNAL_BRUSH_BIGGER 7
  56. #define OUR_SIGNAL_BRUSH_SMALLER 8
  57. #define OUR_SIGNAL_TOGGLE_SKETCH 9
  58. #define OUR_SIGNAL_SELECT_BRUSH_NUMBER_0 10
  59. #define OUR_SIGNAL_SELECT_BRUSH_NUMBER_1 11
  60. #define OUR_SIGNAL_SELECT_BRUSH_NUMBER_2 12
  61. #define OUR_SIGNAL_SELECT_BRUSH_NUMBER_3 13
  62. #define OUR_SIGNAL_SELECT_BRUSH_NUMBER_4 14
  63. #define OUR_SIGNAL_SELECT_BRUSH_NUMBER_5 15
  64. #define OUR_SIGNAL_SELECT_BRUSH_NUMBER_6 16
  65. #define OUR_SIGNAL_SELECT_BRUSH_NUMBER_7 17
  66. #define OUR_SIGNAL_SELECT_BRUSH_NUMBER_8 18
  67. #define OUR_SIGNAL_SELECT_BRUSH_NUMBER_9 19
  68. #define OUR_SIGNAL_SELECT_BRUSH_FREE 20
  69. STRUCTURE(OurCanvasDraw){
  70. laCanvasExtra Base;
  71. int HideBrushCircle;
  72. int AtCrop;
  73. real CanvasLastX,CanvasLastY;
  74. real CanvasDownX,CanvasDownY;
  75. real PointerX,PointerY,DownTilt;
  76. real LastPressure;
  77. real LastTilt[2];
  78. real LastTwist;
  79. int MovedX,MovedY;
  80. };
  81. #define OUR_DPC (600*0.3937007874)
  82. #define OUR_TILE_W 1024
  83. #define OUR_TILES_PER_ROW 100
  84. #define OUR_TILE_CTR (OUR_TILES_PER_ROW/2)
  85. #define OUR_TILE_SEAM 12
  86. #define OUR_TILE_W_USE (OUR_TILE_W-OUR_TILE_SEAM*2)
  87. STRUCTURE(OurTexTile){
  88. tnsTexture* Texture;
  89. uint16_t* Data;
  90. int l,r,u,b;
  91. uint16_t* FullData;
  92. uint16_t* CopyBuffer;
  93. int cl,cr,cu,cb;
  94. };
  95. #define OUR_BLEND_NORMAL 0
  96. #define OUR_BLEND_ADD 1
  97. STRUCTURE(OurLayer){
  98. laListItem Item;
  99. laSafeString* Name;
  100. int OffsetX,OffsetY;
  101. real Transparency;
  102. int Lock;
  103. int Hide;
  104. int BlendMode;
  105. int AsSketch;
  106. OurTexTile** TexTiles[OUR_TILES_PER_ROW];
  107. };
  108. STRUCTURE(OurLayerWrite){
  109. unsigned char* data;
  110. size_t NextData, MaxData;
  111. };
  112. STRUCTURE(OurLayerRead){
  113. unsigned char* data;
  114. size_t NextData;
  115. };
  116. STRUCTURE(OurBrushSettingsNode){
  117. laBaseNode Base;
  118. laNodeOutSocket* CanvasScale; real rCanvasScale;
  119. laNodeOutSocket* Size; real rSize;
  120. laNodeOutSocket* Transparency; real rTransparency;
  121. laNodeOutSocket* Hardness; real rHardness;
  122. laNodeOutSocket* Smudge; real rSmudge;
  123. laNodeOutSocket* DabsPerSize; real rDabsPerSize;
  124. laNodeOutSocket* SmudgeLength; real rSmudgeLength;
  125. laNodeOutSocket* Slender; real rSlender;
  126. laNodeOutSocket* Angle; real rAngle;
  127. laNodeOutSocket* Gunkyness; real rGunkyness;
  128. laNodeOutSocket* Force; real rForce;
  129. laNodeOutSocket* Color;
  130. laNodeOutSocket* Iteration; int rIteration;
  131. laNodeOutSocket* Custom1; real rCustom1;
  132. laNodeOutSocket* Custom2; real rCustom2;
  133. };
  134. STRUCTURE(OurBrushOutputsNode){
  135. laBaseNode Base;
  136. laNodeInSocket* Offset;
  137. laNodeInSocket* Size;
  138. laNodeInSocket* Transparency;
  139. laNodeInSocket* Hardness;
  140. laNodeInSocket* Smudge;
  141. laNodeInSocket* DabsPerSize;
  142. laNodeInSocket* SmudgeLength;
  143. laNodeInSocket* Slender;
  144. laNodeInSocket* Angle;
  145. laNodeInSocket* Color;
  146. laNodeInSocket* Gunkyness;
  147. laNodeInSocket* Force;
  148. laNodeInSocket* Repeats;
  149. laNodeInSocket* Discard;
  150. };
  151. STRUCTURE(OurBrushDeviceNode){
  152. laBaseNode Base;
  153. laNodeOutSocket* Pressure; real rPressure;
  154. laNodeOutSocket* Position; real rPosition[2];
  155. laNodeOutSocket* Tilt; real rTilt[2];
  156. laNodeOutSocket* Twist; real rTwist;
  157. laNodeOutSocket* IsEraser; int rIsEraser;
  158. laNodeOutSocket* Speed; real rSpeed;
  159. laNodeOutSocket* Angle; real rAngle;
  160. laNodeOutSocket* Length; real rLength;
  161. laNodeOutSocket* LengthAccum; real rLengthAccum;
  162. };
  163. STRUCTURE(OurBrush){
  164. laListItem Item;
  165. laSafeString* Name;
  166. real Size;
  167. real DabsPerSize;
  168. real Hardness;
  169. real Transparency;
  170. real Smudge;
  171. real SmudgeResampleLength; real SmudgeAccum; int SmudgeRestart; real BrushRemainingDist;
  172. real Slender;
  173. real Angle;
  174. real Force, Gunkyness;
  175. real Smoothness;
  176. real MaxStrokeLength;
  177. real Custom1,Custom2; laSafeString *Custom1Name,*Custom2Name;
  178. int Iteration;
  179. int PressureSize,PressureHardness,PressureTransparency,PressureSmudge,PressureForce,TwistAngle; // the simple way
  180. int Binding,DefaultAsEraser;
  181. int ShowInPages;
  182. real VisualOffset;
  183. real VisualOffsetAngle;
  184. int16_t OffsetFollowPenTilt;
  185. int16_t UseNodes; // the flexible way
  186. laRackPage* Rack;
  187. real LastX,LastY,LastAngle;
  188. real EvalColor[3];
  189. real EvalOffset[2];
  190. real EvalSize;
  191. real EvalDabsPerSize;
  192. real EvalHardness;
  193. real EvalTransparency;
  194. real EvalSmudge;
  195. real EvalSmudgeLength;
  196. real EvalSlender;
  197. real EvalAngle;
  198. real EvalForce, EvalGunkyness;
  199. real EvalSpeed;
  200. real EvalStrokeLength;
  201. real EvalStrokeLengthAccum;
  202. real EvalPressure;
  203. real EvalPosition[2];
  204. real EvalTilt[2];
  205. real EvalTwist;
  206. real EvalStrokeAngle;
  207. int EvalIsEraser;
  208. int EvalRepeats;
  209. int EvalDiscard;
  210. };
  211. STRUCTURE(OurDab){
  212. float X,Y;
  213. float Size;
  214. float Hardness;
  215. float Smudge; int ResampleSmudge;
  216. float Color[4];
  217. float Slender;
  218. float Angle;
  219. float Direction[2];
  220. float Force;
  221. float Gunkyness;
  222. float Recentness;
  223. };
  224. NEED_STRUCTURE(OurColorPallette);
  225. STRUCTURE(OurColorItem){
  226. laListItem Item;
  227. tnsVector3d Color;
  228. OurColorPallette* Parent;
  229. };
  230. STRUCTURE(OurColorPallette){
  231. laListItem Item;
  232. laSafeString* Name;
  233. laListHandle Colors;
  234. };
  235. STRUCTURE(OurUndoTile){
  236. laListItem Item;
  237. int col,row;
  238. uint16_t* CopyData;
  239. int l,r,u,b;
  240. };
  241. STRUCTURE(OurUndo){
  242. OurLayer* Layer;
  243. laListHandle Tiles;
  244. };
  245. STRUCTURE(OurMoveUndo){
  246. OurLayer* Layer;
  247. int dx,dy;
  248. };
  249. #define OUR_TOOL_PAINT 0
  250. #define OUR_TOOL_CROP 1
  251. #define OUR_TOOL_MOVE 2
  252. #define OUR_PNG_READ_INPUT_FLAT 0
  253. #define OUR_PNG_READ_INPUT_ICC 1
  254. #define OUR_PNG_READ_INPUT_SRGB 2
  255. #define OUR_PNG_READ_INPUT_LINEAR_SRGB 3
  256. #define OUR_PNG_READ_INPUT_CLAY 4
  257. #define OUR_PNG_READ_INPUT_LINEAR_CLAY 5
  258. #define OUR_PNG_READ_OUTPUT_CANVAS 0
  259. #define OUR_PNG_READ_OUTPUT_LINEAR_SRGB OUR_PNG_READ_INPUT_LINEAR_SRGB
  260. #define OUR_PNG_READ_OUTPUT_LINEAR_CLAY OUR_PNG_READ_INPUT_LINEAR_CLAY
  261. #define OUR_CANVAS_INTERPRETATION_SRGB 0
  262. #define OUR_CANVAS_INTERPRETATION_CLAY 1
  263. #define OUR_EXPORT_BIT_DEPTH_8 0
  264. #define OUR_EXPORT_BIT_DEPTH_16 1
  265. #define OUR_EXPORT_COLOR_MODE_SRGB 0
  266. #define OUR_EXPORT_COLOR_MODE_CLAY 1
  267. #define OUR_EXPORT_COLOR_MODE_FLAT 2
  268. #define OUR_BRUSH_PAGE_LIST 128
  269. STRUCTURE(OurPNGReadExtra){
  270. int Confirming;
  271. laSafeString* FilePath;
  272. laSafeString* iccName;
  273. int HassRGB;
  274. int HasProfile;
  275. int InputMode;
  276. int OutputMode;
  277. int Offsets[2];
  278. };
  279. STRUCTURE(OurPNGWriteExtra){
  280. int Confirming;
  281. laSafeString* FilePath;
  282. int BitDepth;
  283. int ColorProfile;
  284. int Transparent;
  285. };
  286. STRUCTURE(OurPaint){
  287. real pad;
  288. laListHandle CanvasSaverDummyList;
  289. laProp* CanvasSaverDummyProp;
  290. laListHandle BadEvents;
  291. tnsImage* SplashImage;
  292. tnsImage* SplashImageHigh;
  293. laListHandle Pallettes;
  294. OurColorPallette* CurrentPallette;
  295. laListHandle Layers;
  296. OurLayer* CurrentLayer;
  297. laListHandle Brushes;
  298. OurBrush* CurrentBrush;
  299. real SaveBrushSize,SaveEraserSize;
  300. OurDab* Dabs; int NextDab,MaxDab;
  301. float LastBrushCenter[2];
  302. int CanvasVersion;
  303. laSafeString* Notes;
  304. real Smoothness;
  305. real LastX, LastY;
  306. real CurrentScale;
  307. real DefaultScale;
  308. int BrushNumber;
  309. real BrushNumberedThicknesses[10];
  310. int BrushPage;
  311. int Tool,ActiveTool,Erasing,EventErasing,BrushMix;
  312. int LockBackground;
  313. int BackgroundType;
  314. int BackgroundRandom;
  315. real BackgroundFactor;
  316. int PenID,EraserID;
  317. int X,Y,W,H; //border
  318. int ColorInterpretation;
  319. int ShowBorder,UseBorder;
  320. int ShowTiles;
  321. int AllowNonPressure,PaintProcessedEvents;
  322. int BadEventsLimit,BadEventCount,BadEventsGiveUp;
  323. int LockRadius;
  324. int EnableBrushCircle,ShowBrushName; int EventHasTwist; real EventTwistAngle;
  325. int DefaultBitDepth;
  326. int DefaultColorProfile;
  327. int PaintUndoLimit;
  328. int SpectralMode;
  329. int BrushNumbersOnHeader;
  330. int SketchMode;
  331. tnsTexture* SmudgeTexture;
  332. GLuint CanvasShader; GLuint CanvasProgram;
  333. GLuint CompositionShader; GLuint CompositionProgram;
  334. GLint uCanvasType;
  335. GLint uCanvasRandom;
  336. GLint uCanvasFactor;
  337. GLint uImageOffset;
  338. GLint uBrushCorner;
  339. GLint uBrushCenter;
  340. GLint uBrushSize;
  341. GLint uBrushHardness;
  342. GLint uBrushSmudge;
  343. GLint uBrushRecentness;
  344. GLint uBrushColor;
  345. GLint uBrushSlender;
  346. GLint uBrushAngle;
  347. GLint uBrushDirection;
  348. GLint uBrushForce;
  349. GLint uBrushGunkyness;
  350. GLint uBrushRoutineSelection;
  351. GLint uMixRoutineSelection;
  352. GLint uBrushErasing;
  353. GLint uBrushMix;
  354. GLint RoutineDoDabs;
  355. GLint RoutineDoSample;
  356. GLint RoutineDoMixNormal;
  357. GLint RoutineDoMixSpectral;
  358. GLint uBlendMode;
  359. GLint uAlphaTop;
  360. GLint uAlphaBottom;
  361. real CurrentColor[3];
  362. real BackgroundColor[3];
  363. uint16_t BColorU16[4];
  364. uint8_t BColorU8[4];
  365. real BorderAlpha;
  366. int ShowStripes;
  367. int ShowGrid;
  368. int ShowRef;
  369. int RefSize;
  370. int RefCategory;
  371. int RefOrientation;
  372. int RefCutHalf;
  373. real RefMargins[3],RefPaddings[2];
  374. int RefBiases[2];
  375. real RefAlpha;
  376. real xmin,xmax,ymin,ymax; // stroke bbox for undo region
  377. int ResetBrush;
  378. int SaveFailed;
  379. uint16_t *ImageBuffer;
  380. int ImageW,ImageH,ImageX,ImageY,LoadX,LoadY,TempLoadX,TempLoadY;
  381. uint8_t* ThumbnailBuffer;
  382. void* icc_LinearsRGB; int iccsize_LinearsRGB;
  383. void* icc_LinearClay; int iccsize_LinearClay;
  384. void* icc_sRGB; int iccsize_sRGB;
  385. void* icc_Clay; int iccsize_Clay;
  386. };
  387. int ourProcessInitArgs(int argc, char* argv[]);
  388. int ourInit();
  389. void ourRegisterNodes();
  390. int ourRebuildBrushEval();
  391. int ourEvalBrush();
  392. void ourMakeTranslations();
  393. void our_EnableSplashPanel();