*/}}

ourpaint.h 12 KB

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