*/}}

ourpaint.h 13 KB

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