*/}}

ourpaint.h 13 KB

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