Blame toonz/sources/common/trop/runsmap.cpp
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "runsmap.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void RunsMap::setRunLength(TPixelGR8 *pix, TUINT32 length) {
|
|
Shinya Kitaoka |
120a6e |
TPixelGR8 *origPix = pix;
|
|
Shinya Kitaoka |
120a6e |
pix = origPix;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPixelGR8 *pixRev = pix + length - 1;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
--length;
|
|
Shinya Kitaoka |
120a6e |
if (length < 3)
|
|
Shinya Kitaoka |
120a6e |
pix->value = pixRev->value = (length << 6);
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
pix->value = pixRev->value = (3 << 6);
|
|
Shinya Kitaoka |
120a6e |
++pix, --pixRev;
|
|
Shinya Kitaoka |
120a6e |
if (length < 255)
|
|
Shinya Kitaoka |
120a6e |
pix->value = pixRev->value = length;
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
pix->value = pixRev->value = 255;
|
|
Shinya Kitaoka |
120a6e |
++pix, pixRev -= 4;
|
|
Shinya Kitaoka |
120a6e |
TUINT32 *l = (TUINT32 *)pix;
|
|
Shinya Kitaoka |
120a6e |
*l = length;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
assert(runLength(origPix) == (length + 1));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TUINT32 RunsMap::runLength(const TPixelGR8 *pix, bool reversed) const {
|
|
Shinya Kitaoka |
120a6e |
int length = pix->value >> 6;
|
|
Shinya Kitaoka |
120a6e |
if (length >= 3) {
|
|
Shinya Kitaoka |
120a6e |
pix += (reversed) ? -1 : 1, length = pix->value;
|
|
Shinya Kitaoka |
120a6e |
if (length >= 255) {
|
|
Shinya Kitaoka |
120a6e |
pix += (reversed) ? -4 : 1;
|
|
Shinya Kitaoka |
120a6e |
length = *(TUINT32 *)pix;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
return length + 1;
|
|
Toshihiro Shimizu |
890ddd |
}
|