*/}}

ourpaint.h 12 KB

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