*/}}

ourpaint.h 12 KB

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