*/}}

ourpaint.h 14 KB

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