*/}}

ourpaint.h 13 KB

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