*/}}

ourpaint.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  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. OUR_PIX_COMPACT* 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_INPUT_D65_P3 6
  276. #define OUR_PNG_READ_INPUT_LINEAR_D65_P3 7
  277. #define OUR_PNG_READ_OUTPUT_CANVAS 0
  278. #define OUR_PNG_READ_OUTPUT_LINEAR_SRGB OUR_PNG_READ_INPUT_LINEAR_SRGB
  279. #define OUR_PNG_READ_OUTPUT_LINEAR_CLAY OUR_PNG_READ_INPUT_LINEAR_CLAY
  280. #define OUR_PNG_READ_OUTPUT_LINEAR_D65_P3 OUR_PNG_READ_INPUT_LINEAR_D65_P3
  281. #define OUR_CANVAS_INTERPRETATION_SRGB 0
  282. #define OUR_CANVAS_INTERPRETATION_CLAY 1
  283. #define OUR_CANVAS_INTERPRETATION_D65_P3 2
  284. #define OUR_EXPORT_BIT_DEPTH_8 0
  285. #define OUR_EXPORT_BIT_DEPTH_16 1
  286. #define OUR_EXPORT_COLOR_MODE_SRGB 0
  287. #define OUR_EXPORT_COLOR_MODE_CLAY 1
  288. #define OUR_EXPORT_COLOR_MODE_FLAT 2
  289. #define OUR_EXPORT_COLOR_MODE_D65_P3 3
  290. #define OUR_BRUSH_PAGE_LIST 128
  291. STRUCTURE(OurPNGReadExtra){
  292. int Confirming;
  293. laSafeString* FilePath;
  294. laSafeString* iccName;
  295. int HassRGB;
  296. int HasProfile;
  297. int InputMode;
  298. int OutputMode;
  299. int Offsets[2];
  300. };
  301. STRUCTURE(OurPNGWriteExtra){
  302. int Confirming;
  303. laSafeString* FilePath;
  304. int BitDepth;
  305. int ColorProfile;
  306. int Transparent;
  307. };
  308. STRUCTURE(OurThreadExportPNGData){
  309. uint32_t* r_sizes;
  310. void** pointers;
  311. int i;
  312. int segy,h;
  313. int fail;
  314. };
  315. NEED_STRUCTURE(OurThreadImportPNGDataMain);
  316. STRUCTURE(OurThreadImportPNGData){
  317. OurThreadImportPNGDataMain* main;
  318. void* data;
  319. OurLayer* l;
  320. int starty;
  321. };
  322. STRUCTURE(OurThreadImportPNGDataMain){
  323. OurThreadImportPNGData* data;
  324. int next,max;
  325. SYSLOCK lock;
  326. };
  327. STRUCTURE(OurPaint){
  328. real pad;
  329. laListHandle CanvasSaverDummyList;
  330. laProp* CanvasSaverDummyProp;
  331. laListHandle BadEvents;
  332. tnsImage* SplashImage;
  333. tnsImage* SplashImageHigh;
  334. laListHandle Pallettes;
  335. OurColorPallette* CurrentPallette;
  336. laListHandle Layers;
  337. OurLayer* CurrentLayer;
  338. laListHandle Brushes;
  339. OurBrush* CurrentBrush;
  340. real SaveBrushSize,SaveEraserSize;
  341. OurDab* Dabs; int NextDab,MaxDab;
  342. float LastBrushCenter[2];
  343. int CanvasVersion;
  344. laSafeString* Notes;
  345. real Smoothness,Hardness;
  346. real LastX, LastY;
  347. real CurrentScale;
  348. real DefaultScale;
  349. int BrushNumber;
  350. real BrushNumberedThicknesses[10];
  351. real BrushBaseSize;
  352. real BrushSize;
  353. int BrushPage;
  354. int Tool,ActiveTool,Erasing,EventErasing,BrushMix;
  355. int LockBackground;
  356. int BackgroundType;
  357. int BackgroundRandom;
  358. real BackgroundFactor;
  359. int PenID,EraserID;
  360. int X,Y,W,H; //border
  361. real BorderFadeWidth;
  362. int ColorInterpretation;
  363. int ShowBorder,UseBorder;
  364. int ShowTiles;
  365. int BrushCircleTiltMode;
  366. int AllowNonPressure,PaintProcessedEvents;
  367. int BadEventsLimit,BadEventCount,BadEventsGiveUp;
  368. int EnableBrushCircle,ShowBrushName,ShowBrushNumber;
  369. int EventHasTwist; real EventTwistAngle; real EventTiltOrientation;
  370. int DefaultBitDepth;
  371. int DefaultColorProfile;
  372. int PaintUndoLimit;
  373. int SpectralMode;
  374. int BrushNumbersOnHeader;
  375. int SketchMode;
  376. int SegmentedWrite;
  377. tnsTexture* SmudgeTexture;
  378. GLuint CanvasShader; GLuint CanvasProgram;
  379. GLuint CompositionShader; GLuint CompositionProgram;
  380. GLint uCanvasType;
  381. GLint uCanvasRandom;
  382. GLint uCanvasFactor;
  383. GLint uImageOffset;
  384. GLint uBrushCorner;
  385. GLint uBrushCenter;
  386. GLint uBrushSize;
  387. GLint uBrushHardness;
  388. GLint uBrushSmudge;
  389. GLint uBrushRecentness;
  390. GLint uBrushColor;
  391. GLint uBrushSlender;
  392. GLint uBrushAngle;
  393. GLint uBrushDirection;
  394. GLint uBrushForce;
  395. GLint uBrushGunkyness;
  396. GLint uBrushRoutineSelection;
  397. GLint uBrushRoutineSelectionES;
  398. GLint uMixRoutineSelection;
  399. GLint uMixRoutineSelectionES;
  400. GLint uBrushErasing;
  401. GLint uBrushMix;
  402. GLint RoutineDoDabs;
  403. GLint RoutineDoSample;
  404. GLint RoutineDoMixNormal;
  405. GLint RoutineDoMixSpectral;
  406. GLint uBlendMode;
  407. GLint uAlphaTop;
  408. GLint uAlphaBottom;
  409. real CurrentColor[3];
  410. real BackgroundColor[3];
  411. uint16_t BColorU16[4];
  412. uint8_t BColorU8[4];
  413. real BorderAlpha;
  414. int ShowStripes;
  415. int ShowGrid;
  416. int ShowRef;
  417. int RefSize;
  418. int RefCategory;
  419. int RefOrientation;
  420. int RefCutHalf;
  421. real RefMargins[3],RefPaddings[2];
  422. int RefBiases[2];
  423. real RefAlpha;
  424. real xmin,xmax,ymin,ymax; // stroke bbox for undo region
  425. int ResetBrush;
  426. int SaveFailed;
  427. int FileRegistered;
  428. uint16_t *ImageBuffer;
  429. int ImageW,ImageH,ImageX,ImageY,LoadX,LoadY,TempLoadX,TempLoadY;
  430. uint8_t* ThumbnailBuffer;
  431. void* icc_LinearsRGB; int iccsize_LinearsRGB;
  432. void* icc_LinearClay; int iccsize_LinearClay;
  433. void* icc_LinearD65P3; int iccsize_LinearD65P3;
  434. void* icc_sRGB; int iccsize_sRGB;
  435. void* icc_Clay; int iccsize_Clay;
  436. void* icc_D65P3; int iccsize_D65P3;
  437. };
  438. int ourProcessInitArgs(int argc, char* argv[]);
  439. int ourInit();
  440. void ourRegisterNodes();
  441. int ourRebuildBrushEval();
  442. int ourEvalBrush();
  443. void ourMakeTranslations_zh_hans();
  444. void ourMakeTranslations_es_ES();
  445. void our_EnableSplashPanel();