*/}}

ourpaint.h 12 KB

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