|
|
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 |
|
|
|
7a5892 |
RasterController* getController() const
|
|
|
7a5892 |
{ 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 |
|
|
|
7a5892 |
inline explicit Params(double x = 0.0, double y = 0.0, double pressure = 0.0,
|
|
|
7a5892 |
double tx = 0.0, 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 |
98926d |
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 |
|
|
|
7a5892 |
TRaster32P ras;
|
|
|
7a5892 |
Raster32PMyPaintSurface mypaintSurface;
|
|
|
bf1d82 |
mypaint::Brush brush;
|
|
|
bf1d82 |
|
|
|
bf1d82 |
bool reset;
|
|
|
bf1d82 |
Params previous, current;
|
|
|
d8eddc |
bool interpolation;
|
|
|
bf1d82 |
|
|
|
bf1d82 |
public:
|
|
|
d8eddc |
MyPaintToonzBrush(
|
|
|
d8eddc |
const TRaster32P &ras,
|
|
|
d8eddc |
RasterController &controller,
|
|
|
d8eddc |
const mypaint::Brush &brush,
|
|
|
d8eddc |
bool interpolation = false );
|
|
|
bf1d82 |
void beginStroke();
|
|
|
7a5892 |
void strokeTo(
|
|
|
7a5892 |
const TPointD &position,
|
|
|
7a5892 |
double pressure,
|
|
|
7a5892 |
const TPointD &tilt,
|
|
|
7a5892 |
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 |
|
|
|
7a5892 |
const TRaster32P& getRaster() const
|
|
|
7a5892 |
{ return ras; }
|
|
|
7a5892 |
RasterController& getController()
|
|
|
7a5892 |
{ return *mypaintSurface.getController(); }
|
|
|
7a5892 |
const mypaint::Brush& getBrush() const
|
|
|
7a5892 |
{ return brush; }
|
|
|
bf1d82 |
};
|
|
|
bf1d82 |
|
|
|
bf1d82 |
#endif // T_BLUREDBRUSH
|