*/}}

ourpaint.h 11 KB

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