*/}}

ourpaint.h 14 KB

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