|
|
bf1d82 |
#pragma once
|
|
|
bf1d82 |
|
|
|
bf1d82 |
#ifndef MYPAINTTOONZBRUSH_H
|
|
|
bf1d82 |
#define MYPAINTTOONZBRUSH_H
|
|
|
bf1d82 |
|
|
|
bf1d82 |
#include <toonz mypaint.h=""></toonz>
|
|
|
bf1d82 |
#include "traster.h"
|
|
|
bf1d82 |
#include "trastercm.h"
|
|
|
bf1d82 |
#include "tcurves.h"
|
|
|
bf1d82 |
#include <qpainter></qpainter>
|
|
|
bf1d82 |
#include <qimage></qimage>
|
|
|
bf1d82 |
|
|
|
bf1d82 |
class RasterController {
|
|
|
bf1d82 |
public:
|
|
shun-iwasawa |
98926d |
virtual ~RasterController() {}
|
|
|
bf1d82 |
virtual bool askRead(const TRect &rect) { return true; }
|
|
|
bf1d82 |
virtual bool askWrite(const TRect &rect) { return true; }
|
|
|
bf1d82 |
};
|
|
|
bf1d82 |
|
|
|
bf1d82 |
//=======================================================
|
|
|
bf1d82 |
//
|
|
|
bf1d82 |
// Raster32PMyPaintSurface
|
|
|
bf1d82 |
//
|
|
|
bf1d82 |
//=======================================================
|
|
|
bf1d82 |
|
|
shun-iwasawa |
98926d |
class Raster32PMyPaintSurface : public mypaint::Surface {
|
|
|
bf1d82 |
private:
|
|
|
bf1d82 |
class Internal;
|
|
|
bf1d82 |
|
|
|
7a5892 |
TRaster32P ras;
|
|
|
bf1d82 |
RasterController *controller;
|
|
|
bf1d82 |
Internal *internal;
|
|
|
bf1d82 |
|
|
shun-iwasawa |
98926d |
inline static void readPixel(const void *pixelPtr, float &colorR,
|
|
shun-iwasawa |
98926d |
float &colorG, float &colorB, float &colorA) {
|
|
shun-iwasawa |
98926d |
const TPixel32 &pixel = *(const TPixel32 *)pixelPtr;
|
|
shun-iwasawa |
98926d |
colorR = (float)pixel.r / (float)TPixel32::maxChannelValue;
|
|
shun-iwasawa |
98926d |
colorG = (float)pixel.g / (float)TPixel32::maxChannelValue;
|
|
shun-iwasawa |
98926d |
colorB = (float)pixel.b / (float)TPixel32::maxChannelValue;
|
|
shun-iwasawa |
98926d |
colorA = (float)pixel.m / (float)TPixel32::maxChannelValue;
|
|
|
bf1d82 |
}
|
|
|
bf1d82 |
|
|
shun-iwasawa |
98926d |
inline static void writePixel(void *pixelPtr, float colorR, float colorG,
|
|
shun-iwasawa |
98926d |
float colorB, float colorA) {
|
|
shun-iwasawa |
98926d |
TPixel32 &pixel = *(TPixel32 *)pixelPtr;
|
|
|
bf1d82 |
pixel.r = (TPixel32::Channel)roundf(colorR * TPixel32::maxChannelValue);
|
|
|
bf1d82 |
pixel.g = (TPixel32::Channel)roundf(colorG * TPixel32::maxChannelValue);
|
|
|
bf1d82 |
pixel.b = (TPixel32::Channel)roundf(colorB * TPixel32::maxChannelValue);
|
|
|
bf1d82 |
pixel.m = (TPixel32::Channel)roundf(colorA * TPixel32::maxChannelValue);
|
|
|
bf1d82 |
}
|
|
|
bf1d82 |
|
|
shun-iwasawa |
98926d |
inline static bool askRead(void *surfaceController,
|
|
shun-iwasawa |
98926d |
const void * /* surfacePointer */, int x0, int y0,
|
|
shun-iwasawa |
98926d |
int x1, int y1) {
|
|
shun-iwasawa |
98926d |
Raster32PMyPaintSurface &owner =
|
|
shun-iwasawa |
98926d |
*((Raster32PMyPaintSurface *)surfaceController);
|
|
shun-iwasawa |
98926d |
return !owner.controller ||
|
|
shun-iwasawa |
98926d |
owner.controller->askRead(TRect(x0, y0, x1, y1));
|
|
|
bf1d82 |
}
|
|
|
bf1d82 |
|
|
shun-iwasawa |
98926d |
inline static bool askWrite(void *surfaceController,
|
|
shun-iwasawa |
98926d |
const void * /* surfacePointer */, int x0, int y0,
|
|
shun-iwasawa |
98926d |
int x1, int y1) {
|
|
shun-iwasawa |
98926d |
Raster32PMyPaintSurface &owner =
|
|
shun-iwasawa |
98926d |
*((Raster32PMyPaintSurface *)surfaceController);
|
|
shun-iwasawa |
98926d |
return !owner.controller ||
|
|
shun-iwasawa |
98926d |
owner.controller->askWrite(TRect(x0, y0, x1, y1));
|
|
|
bf1d82 |
}
|
|
|
bf1d82 |
|
|
|
bf1d82 |
public:
|
|
|
bf1d82 |
explicit Raster32PMyPaintSurface(const TRaster32P &ras);
|
|
shun-iwasawa |
98926d |
explicit Raster32PMyPaintSurface(const TRaster32P &ras,
|
|
shun-iwasawa |
98926d |
RasterController &controller);
|
|
|
bf1d82 |
~Raster32PMyPaintSurface();
|
|
|
bf1d82 |
|
|
shun-iwasawa |
98926d |
bool getColor(float x, float y, float radius, float &colorR, float &colorG,
|
|
shun-iwasawa |
98926d |
float &colorB, float &colorA) override;
|
|
|
bf1d82 |
|
|
|
bf1d82 |
bool drawDab(const mypaint::Dab &dab) override;
|
|
|
bf1d82 |
|
|
|
bf1d82 |
bool getAntialiasing() const;
|
|
|
bf1d82 |
void setAntialiasing(bool value);
|
|
|
7a5892 |
|
|
shun-iwasawa |
87c65e |
RasterController *getController() const { return controller; }
|
|
|
bf1d82 |
};
|
|
|
bf1d82 |
|
|
|
bf1d82 |
//=======================================================
|
|
|
bf1d82 |
//
|
|
|
bf1d82 |
// MyPaintToonzBrush
|
|
|
bf1d82 |
//
|
|
|
bf1d82 |
//=======================================================
|
|
|
bf1d82 |
|
|
|
bf1d82 |
class MyPaintToonzBrush {
|
|
|
bf1d82 |
private:
|
|
|
bf1d82 |
struct Params {
|
|
|
bf1d82 |
union {
|
|
shun-iwasawa |
98926d |
struct {
|
|
|
7a5892 |
double x, y, pressure, tx, ty, time;
|
|
shun-iwasawa |
98926d |
};
|
|
shun-iwasawa |
98926d |
struct {
|
|
|
7a5892 |
double values[6];
|
|
shun-iwasawa |
98926d |
};
|
|
|
bf1d82 |
};
|
|
|
bf1d82 |
|
|
shun-iwasawa |
87c65e |
inline explicit Params(double x = 0.0, double y = 0.0,
|
|
shun-iwasawa |
87c65e |
double pressure = 0.0, double tx = 0.0,
|
|
shun-iwasawa |
87c65e |
double ty = 0.0, double time = 0.0)
|
|
|
7a5892 |
: x(x), y(y), pressure(pressure), tx(tx), ty(ty), time(time) {}
|
|
|
bf1d82 |
|
|
|
bf1d82 |
inline void setMedian(Params &a, Params &b) {
|
|
shun-iwasawa |
87c65e |
for (int i = 0; i < (int)sizeof(values) / sizeof(values[0]); ++i)
|
|
shun-iwasawa |
98926d |
values[i] = 0.5 * (a.values[i] + b.values[i]);
|
|
|
bf1d82 |
}
|
|
|
bf1d82 |
};
|
|
|
bf1d82 |
|
|
|
bf1d82 |
struct Segment {
|
|
|
bf1d82 |
Params p1, p2;
|
|
|
bf1d82 |
};
|
|
|
bf1d82 |
|
|
shun-iwasawa |
87c65e |
TRaster32P m_ras;
|
|
shun-iwasawa |
87c65e |
Raster32PMyPaintSurface m_mypaintSurface;
|
|
shun-iwasawa |
87c65e |
mypaint::Brush m_brush;
|
|
|
bf1d82 |
|
|
shun-iwasawa |
87c65e |
bool m_reset;
|
|
shun-iwasawa |
87c65e |
Params m_previous, m_current;
|
|
shun-iwasawa |
87c65e |
bool m_interpolation;
|
|
|
bf1d82 |
|
|
|
bf1d82 |
public:
|
|
shun-iwasawa |
87c65e |
MyPaintToonzBrush(const TRaster32P &ras, RasterController &controller,
|
|
shun-iwasawa |
87c65e |
const mypaint::Brush &brush, bool interpolation = false);
|
|
|
bf1d82 |
void beginStroke();
|
|
shun-iwasawa |
87c65e |
void strokeTo(const TPointD &position, double pressure, const TPointD &tilt,
|
|
shun-iwasawa |
87c65e |
double dtime);
|
|
|
bf1d82 |
void endStroke();
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
// colormapped
|
|
shun-iwasawa |
98926d |
void updateDrawing(const TRasterCM32P rasCM, const TRasterCM32P rasBackupCM,
|
|
manongjohn |
6c9506 |
const TRect &bbox, int styleId, bool lockAlpha) const;
|
|
|
7a5892 |
|
|
shun-iwasawa |
87c65e |
const TRaster32P &getRaster() const { return m_ras; }
|
|
shun-iwasawa |
87c65e |
RasterController &getController() {
|
|
shun-iwasawa |
87c65e |
return *m_mypaintSurface.getController();
|
|
shun-iwasawa |
87c65e |
}
|
|
shun-iwasawa |
87c65e |
const mypaint::Brush &getBrush() const { return m_brush; }
|
|
|
bf1d82 |
};
|
|
|
bf1d82 |
|
|
|
bf1d82 |
#endif // T_BLUREDBRUSH
|