mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-20 14:17:30 +09:00
parent
0ff3276b09
commit
2dc214fa3b
2 changed files with 63 additions and 14 deletions
|
|
@ -68,6 +68,8 @@
|
||||||
#include "CanvasImageCache.h"
|
#include "CanvasImageCache.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "jsapi.h"
|
#include "jsapi.h"
|
||||||
#include "jsfriendapi.h"
|
#include "jsfriendapi.h"
|
||||||
|
|
@ -2083,6 +2085,18 @@ CanvasRenderingContext2D::GetInputStream(const char* aMimeType,
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PoisonData = Preferences::GetBool("canvas.poisondata",false);
|
||||||
|
if (PoisonData) {
|
||||||
|
srand(time(NULL));
|
||||||
|
// Image buffer is always a packed BGRA array (BGRX -> BGR[FF])
|
||||||
|
// so always 4-byte pixels.
|
||||||
|
// GetImageBuffer => SurfaceToPackedBGRA [=> ConvertBGRXToBGRA]
|
||||||
|
for (int32_t j = 0; j < mWidth * mHeight * 4; ++j) {
|
||||||
|
if (imageBuffer[j] !=0 && imageBuffer[j] != 255)
|
||||||
|
imageBuffer[j] += rand() % 3 - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ImageEncoder::GetInputStream(mWidth, mHeight, imageBuffer.get(),
|
return ImageEncoder::GetInputStream(mWidth, mHeight, imageBuffer.get(),
|
||||||
format, encoder, aEncoderOptions,
|
format, encoder, aEncoderOptions,
|
||||||
aStream);
|
aStream);
|
||||||
|
|
@ -5698,6 +5712,14 @@ CanvasRenderingContext2D::GetImageData(JSContext* aCx, double aSx,
|
||||||
return imageData.forget();
|
return imageData.forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline uint8_t PoisonValue(uint8_t v)
|
||||||
|
{
|
||||||
|
if (v==0 || v==255)
|
||||||
|
return v; //don't fuzz edges to prevent overflow/underflow
|
||||||
|
|
||||||
|
return v + rand() %3 -1;
|
||||||
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
CanvasRenderingContext2D::GetImageDataArray(JSContext* aCx,
|
CanvasRenderingContext2D::GetImageDataArray(JSContext* aCx,
|
||||||
int32_t aX,
|
int32_t aX,
|
||||||
|
|
@ -5712,6 +5734,10 @@ CanvasRenderingContext2D::GetImageDataArray(JSContext* aCx,
|
||||||
|
|
||||||
MOZ_ASSERT(aWidth && aHeight);
|
MOZ_ASSERT(aWidth && aHeight);
|
||||||
|
|
||||||
|
bool PoisonData = Preferences::GetBool("canvas.poisondata",false);
|
||||||
|
if (PoisonData)
|
||||||
|
srand(time(NULL));
|
||||||
|
|
||||||
CheckedInt<uint32_t> len = CheckedInt<uint32_t>(aWidth) * aHeight * 4;
|
CheckedInt<uint32_t> len = CheckedInt<uint32_t>(aWidth) * aHeight * 4;
|
||||||
if (!len.isValid()) {
|
if (!len.isValid()) {
|
||||||
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
||||||
|
|
@ -5784,21 +5810,31 @@ CanvasRenderingContext2D::GetImageDataArray(JSContext* aCx,
|
||||||
|
|
||||||
uint8_t* dst = data + dstWriteRect.y * (aWidth * 4) + dstWriteRect.x * 4;
|
uint8_t* dst = data + dstWriteRect.y * (aWidth * 4) + dstWriteRect.x * 4;
|
||||||
|
|
||||||
|
uint8_t a,r,g,b;
|
||||||
|
|
||||||
if (mOpaque) {
|
if (mOpaque) {
|
||||||
for (int32_t j = 0; j < dstWriteRect.height; ++j) {
|
for (int32_t j = 0; j < dstWriteRect.height; ++j) {
|
||||||
for (int32_t i = 0; i < dstWriteRect.width; ++i) {
|
for (int32_t i = 0; i < dstWriteRect.width; ++i) {
|
||||||
// XXX Is there some useful swizzle MMX we can use here?
|
// XXX Is there some useful swizzle MMX we can use here?
|
||||||
#if MOZ_LITTLE_ENDIAN
|
#if MOZ_LITTLE_ENDIAN
|
||||||
uint8_t b = *src++;
|
b = *src++;
|
||||||
uint8_t g = *src++;
|
g = *src++;
|
||||||
uint8_t r = *src++;
|
r = *src++;
|
||||||
src++;
|
src++;
|
||||||
#else
|
#else
|
||||||
src++;
|
src++;
|
||||||
uint8_t r = *src++;
|
r = *src++;
|
||||||
uint8_t g = *src++;
|
g = *src++;
|
||||||
uint8_t b = *src++;
|
b = *src++;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Poison data for trackers if enabled
|
||||||
|
if (PoisonData) {
|
||||||
|
PoisonValue(r);
|
||||||
|
PoisonValue(g);
|
||||||
|
PoisonValue(b);
|
||||||
|
}
|
||||||
|
|
||||||
*dst++ = r;
|
*dst++ = r;
|
||||||
*dst++ = g;
|
*dst++ = g;
|
||||||
*dst++ = b;
|
*dst++ = b;
|
||||||
|
|
@ -5812,16 +5848,25 @@ CanvasRenderingContext2D::GetImageDataArray(JSContext* aCx,
|
||||||
for (int32_t i = 0; i < dstWriteRect.width; ++i) {
|
for (int32_t i = 0; i < dstWriteRect.width; ++i) {
|
||||||
// XXX Is there some useful swizzle MMX we can use here?
|
// XXX Is there some useful swizzle MMX we can use here?
|
||||||
#if MOZ_LITTLE_ENDIAN
|
#if MOZ_LITTLE_ENDIAN
|
||||||
uint8_t b = *src++;
|
b = *src++;
|
||||||
uint8_t g = *src++;
|
g = *src++;
|
||||||
uint8_t r = *src++;
|
r = *src++;
|
||||||
uint8_t a = *src++;
|
a = *src++;
|
||||||
#else
|
#else
|
||||||
uint8_t a = *src++;
|
a = *src++;
|
||||||
uint8_t r = *src++;
|
r = *src++;
|
||||||
uint8_t g = *src++;
|
g = *src++;
|
||||||
uint8_t b = *src++;
|
b = *src++;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Poison data for trackers if enabled
|
||||||
|
if (PoisonData) {
|
||||||
|
PoisonValue(a);
|
||||||
|
PoisonValue(r);
|
||||||
|
PoisonValue(g);
|
||||||
|
PoisonValue(b);
|
||||||
|
}
|
||||||
|
|
||||||
// Convert to non-premultiplied color
|
// Convert to non-premultiplied color
|
||||||
*dst++ = gfxUtils::sUnpremultiplyTable[a * 256 + r];
|
*dst++ = gfxUtils::sUnpremultiplyTable[a * 256 + r];
|
||||||
*dst++ = gfxUtils::sUnpremultiplyTable[a * 256 + g];
|
*dst++ = gfxUtils::sUnpremultiplyTable[a * 256 + g];
|
||||||
|
|
|
||||||
|
|
@ -4448,6 +4448,10 @@ pref("image.multithreaded_decoding.limit", -1);
|
||||||
// cache.
|
// cache.
|
||||||
pref("canvas.image.cache.limit", 0);
|
pref("canvas.image.cache.limit", 0);
|
||||||
|
|
||||||
|
// Allow track-fobics to deliberately poison canvas data for
|
||||||
|
// toDataURL() and getImageData()
|
||||||
|
pref("canvas.poisondata", false);
|
||||||
|
|
||||||
// WebGL prefs
|
// WebGL prefs
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
// Disable MSAA on mobile.
|
// Disable MSAA on mobile.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue