Use bitsPerPixel
This commit is contained in:
@@ -41,7 +41,7 @@ class ImageBuffer {
|
||||
@:noCompletion private var __srcImageData:#if (js && html5) ImageData #else Dynamic #end;
|
||||
|
||||
|
||||
public function new (data:UInt8Array = null, width:Int = 0, height:Int = 0, bitsPerPixel:Int = 4, format:PixelFormat = null) {
|
||||
public function new (data:UInt8Array = null, width:Int = 0, height:Int = 0, bitsPerPixel:Int = 32, format:PixelFormat = null) {
|
||||
|
||||
this.data = data;
|
||||
this.width = width;
|
||||
|
||||
@@ -20,10 +20,11 @@ namespace lime {
|
||||
~ImageBuffer ();
|
||||
|
||||
void Blit (const unsigned char *data, int x, int y, int width, int height);
|
||||
void Resize (int width, int height, int bpp = 4);
|
||||
void Resize (int width, int height, int bitsPerPixel = 32);
|
||||
int Stride ();
|
||||
value Value ();
|
||||
|
||||
int bpp;
|
||||
int bitsPerPixel;
|
||||
Bytes *data;
|
||||
PixelFormat format;
|
||||
int height;
|
||||
|
||||
@@ -219,7 +219,7 @@ namespace lime {
|
||||
|
||||
void SDLWindow::SetIcon (ImageBuffer *imageBuffer) {
|
||||
|
||||
SDL_Surface *surface = SDL_CreateRGBSurfaceFrom (imageBuffer->data->Data (), imageBuffer->width, imageBuffer->height, imageBuffer->bpp * 8, imageBuffer->width * imageBuffer->bpp, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
|
||||
SDL_Surface *surface = SDL_CreateRGBSurfaceFrom (imageBuffer->data->Data (), imageBuffer->width, imageBuffer->height, imageBuffer->bitsPerPixel, imageBuffer->Stride (), 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
|
||||
|
||||
if (surface) {
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace lime {
|
||||
|
||||
width = 0;
|
||||
height = 0;
|
||||
bpp = 4;
|
||||
bitsPerPixel = 32;
|
||||
format = RGBA;
|
||||
data = 0;
|
||||
transparent = false;
|
||||
@@ -43,7 +43,7 @@ namespace lime {
|
||||
|
||||
width = val_int (val_field (imageBuffer, id_width));
|
||||
height = val_int (val_field (imageBuffer, id_height));
|
||||
bpp = val_int (val_field (imageBuffer, id_bitsPerPixel));
|
||||
bitsPerPixel = val_int (val_field (imageBuffer, id_bitsPerPixel));
|
||||
format = (PixelFormat)val_int (val_field (imageBuffer, id_format));
|
||||
transparent = val_bool (val_field (imageBuffer, id_transparent));
|
||||
value data_value = val_field (imageBuffer, id_data);
|
||||
@@ -68,36 +68,46 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
int stride = Stride ();
|
||||
unsigned char *bytes = this->data->Data ();
|
||||
|
||||
for (int i = 0; i < height; i++) {
|
||||
|
||||
memcpy (&bytes[(i + y) * this->width + x], &data[i * width], width * bpp);
|
||||
memcpy (&bytes[(i + y) * this->width + x], &data[i * width], stride);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ImageBuffer::Resize (int width, int height, int bpp) {
|
||||
void ImageBuffer::Resize (int width, int height, int bitsPerPixel) {
|
||||
|
||||
this->bpp = bpp;
|
||||
this->bitsPerPixel = bitsPerPixel;
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
|
||||
int stride = Stride ();
|
||||
|
||||
if (!this->data) {
|
||||
|
||||
this->data = new Bytes (width * height * bpp);
|
||||
this->data = new Bytes (height * stride);
|
||||
|
||||
} else {
|
||||
|
||||
this->data->Resize (width * height * bpp);
|
||||
this->data->Resize (height * stride);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
int ImageBuffer::Stride () {
|
||||
|
||||
return width * (((bitsPerPixel + 3) & ~0x3) >> 3);
|
||||
|
||||
}
|
||||
|
||||
|
||||
value ImageBuffer::Value () {
|
||||
|
||||
if (!init) {
|
||||
@@ -116,7 +126,7 @@ namespace lime {
|
||||
mValue = alloc_empty_object ();
|
||||
alloc_field (mValue, id_width, alloc_int (width));
|
||||
alloc_field (mValue, id_height, alloc_int (height));
|
||||
alloc_field (mValue, id_bitsPerPixel, alloc_int (bpp));
|
||||
alloc_field (mValue, id_bitsPerPixel, alloc_int (bitsPerPixel));
|
||||
alloc_field (mValue, id_data, data ? data->Value () : alloc_null ());
|
||||
alloc_field (mValue, id_transparent, alloc_bool (transparent));
|
||||
alloc_field (mValue, id_format, alloc_int (format));
|
||||
|
||||
@@ -250,7 +250,7 @@ namespace lime {
|
||||
|
||||
jpeg_start_decompress (&cinfo);
|
||||
int components = cinfo.num_components;
|
||||
imageBuffer->Resize (cinfo.output_width, cinfo.output_height);
|
||||
imageBuffer->Resize (cinfo.output_width, cinfo.output_height, 32);
|
||||
|
||||
unsigned char *bytes = imageBuffer->data->Data ();
|
||||
unsigned char *scanline = new unsigned char [imageBuffer->width * imageBuffer->height * components];
|
||||
@@ -338,7 +338,7 @@ namespace lime {
|
||||
|
||||
JSAMPROW row_pointer = &row_buf[0];
|
||||
unsigned char* imageData = imageBuffer->data->Data();
|
||||
int stride = w * imageBuffer->bpp;
|
||||
int stride = imageBuffer->Stride ();
|
||||
|
||||
while (cinfo.next_scanline < cinfo.image_height) {
|
||||
|
||||
|
||||
@@ -182,9 +182,8 @@ namespace lime {
|
||||
|
||||
//png_set_bgr (png_ptr);
|
||||
|
||||
int bpp = 4;
|
||||
const unsigned int stride = width * bpp;
|
||||
imageBuffer->Resize (width, height, bpp);
|
||||
imageBuffer->Resize (width, height, 32);
|
||||
const unsigned int stride = imageBuffer->Stride ();
|
||||
unsigned char *bytes = imageBuffer->data->Data ();
|
||||
|
||||
int number_of_passes = png_set_interlace_handling (png_ptr);
|
||||
@@ -259,7 +258,7 @@ namespace lime {
|
||||
|
||||
bool do_alpha = (color_type == PNG_COLOR_TYPE_RGBA);
|
||||
unsigned char* imageData = imageBuffer->data->Data();
|
||||
int stride = w * imageBuffer->bpp;
|
||||
int stride = imageBuffer->Stride ();
|
||||
|
||||
{
|
||||
QuickVec<unsigned char> row_data (w * 4);
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace lime {
|
||||
|
||||
void ImageDataUtil::ColorTransform (Image* image, Rectangle* rect, ColorMatrix* colorMatrix) {
|
||||
|
||||
int stride = image->buffer->width * 4;
|
||||
int stride = image->buffer->Stride ();
|
||||
int offset;
|
||||
|
||||
int rowStart = int (rect->y + image->offsetY);
|
||||
@@ -87,13 +87,13 @@ namespace lime {
|
||||
|
||||
void ImageDataUtil::CopyChannel (Image* image, Image* sourceImage, Rectangle* sourceRect, Vector2* destPoint, int srcChannel, int destChannel) {
|
||||
|
||||
int srcStride = sourceImage->buffer->width * 4;
|
||||
int srcStride = sourceImage->buffer->Stride ();
|
||||
int srcPosition = ((sourceRect->x + sourceImage->offsetX) * 4) + (srcStride * (sourceRect->y + sourceImage->offsetY)) + srcChannel;
|
||||
int srcRowOffset = srcStride - int (4 * (sourceRect->width + sourceImage->offsetX));
|
||||
int srcRowEnd = 4 * (sourceRect->x + sourceImage->offsetX + sourceRect->width);
|
||||
uint8_t* srcData = (uint8_t*)sourceImage->buffer->data->Data ();
|
||||
|
||||
int destStride = image->buffer->width * 4;
|
||||
int destStride = image->buffer->Stride ();
|
||||
int destPosition = ((destPoint->x + image->offsetX) * 4) + (destStride * (destPoint->y + image->offsetY)) + destChannel;
|
||||
int destRowOffset = destStride - int (4 * (sourceRect->width + image->offsetX));
|
||||
int destRowEnd = 4 * (destPoint->x + image->offsetX + sourceRect->width);
|
||||
@@ -131,11 +131,11 @@ namespace lime {
|
||||
int columnOffset = int (destPoint->x + image->offsetX - sourceRect->x - sourceImage->offsetY);
|
||||
|
||||
uint8_t* sourceData = (uint8_t*)sourceImage->buffer->data->Data ();
|
||||
int sourceStride = sourceImage->buffer->width * 4;
|
||||
int sourceStride = sourceImage->buffer->Stride ();
|
||||
int sourceOffset = 0;
|
||||
|
||||
uint8_t* data = (uint8_t*)image->buffer->data->Data ();
|
||||
int stride = image->buffer->width * 4;
|
||||
int stride = image->buffer->Stride ();
|
||||
int offset = 0;
|
||||
|
||||
int rows = sourceRect->y + sourceRect->height + sourceImage->offsetY;
|
||||
@@ -323,7 +323,7 @@ namespace lime {
|
||||
uint8_t* data = (uint8_t*)pixels->Data ();
|
||||
uint8_t* srcData = (uint8_t*)image->buffer->data->Data ();
|
||||
|
||||
int srcStride = int (image->buffer->width * 4);
|
||||
int srcStride = image->buffer->Stride ();
|
||||
int srcPosition = int ((rect->x * 4) + (srcStride * rect->y));
|
||||
int srcRowOffset = srcStride - int (4 * rect->width);
|
||||
int srcRowEnd = int (4 * (rect->x + rect->width));
|
||||
@@ -373,11 +373,11 @@ namespace lime {
|
||||
int columnOffset = int (destPoint->x + image->offsetX - sourceRect->x - sourceImage->offsetY);
|
||||
|
||||
uint8_t* sourceData = (uint8_t*)sourceImage->buffer->data->Data ();
|
||||
int sourceStride = sourceImage->buffer->width * 4;
|
||||
int sourceStride = sourceImage->buffer->Stride ();
|
||||
int sourceOffset = 0;
|
||||
|
||||
uint8_t* data = (uint8_t*)image->buffer->data->Data ();
|
||||
int stride = image->buffer->width * 4;
|
||||
int stride = image->buffer->Stride ();
|
||||
int offset = 0;
|
||||
|
||||
int rowEnd = int (sourceRect->y + sourceRect->height + sourceImage->offsetY);
|
||||
|
||||
Reference in New Issue
Block a user