*/}}

ourpaint.h 14 KB

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