*/}}

ourpaint.h 14 KB

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