PVideoFrame __stdcall ShapeMask::GetFrame(int n, IScriptEnvironment* env) { int colorspace; if (vi.IsRGB24()) colorspace = RGB24; else if (vi.IsRGB32()) colorspace = RGB32; else if (vi.IsYUY2()) colorspace = YUV2; else if (vi.IsYV12()) colorspace = YV12; else raiseError(env, "Unsupported color space, must be one of RGB24, RGB32, YUV2 or YV12"); PClip srcClip = toGrayScale(env, child); PVideoFrame src = srcClip->GetFrame(n, env); PVideoFrame dst = env->NewVideoFrame(vi); const uchar* srcp = src->GetReadPtr(); const int src_pitch = src->GetPitch(); const int bpp = vi.BitsPerPixel(); uchar* retp; // No change to the source pixels in the process steps, so ok to cast to non-const // returns a 1 channel gray scale image which needs to be converted to whatever format the source clip is in. retp = process_frame((uchar*)srcp, vi.width, vi.height, src_pitch, colorspace, threshold, minarea, rectonly); if (vi.IsPlanar()) copyPlanar(retp, dst, bpp); else if (vi.IsYUY2()) copyYUY2(retp, dst); else copyRGB(retp, dst, bpp); delete retp; return dst; }
void clearBlock(struct RGBblock *block, int blockNum, int playRoutine, int cycleTime, struct RGBcolor *colorA, RGBcolor *colorB) { int i; block->blockNum = blockNum; block->lastTime = theTime; block->varA = 0; block->dirA = 1; block->varB = 0; block->dirB = 1; for (i=0; i<LEDS_PER_BLOCK; i++) { block->leds[i].red = 0; block->leds[i].green = 0; block->leds[i].blue = 0; } copyRGB(&block->colorA, colorA); copyRGB(&block->colorB, colorB); block->dir = 1; block->cycleTime = cycleTime; block->routine = playRoutine; }
static void toCVTImage( Image& dst, const openni::VideoFrameRef& frame ) { dst.reallocate( frame.getWidth(), frame.getHeight(), Openni2Helper::toIFormat( frame.getVideoMode().getPixelFormat() ) ); switch( frame.getVideoMode().getPixelFormat() ){ case openni::PIXEL_FORMAT_RGB888: copyRGB( dst, ( const uint8_t* )frame.getData(), frame.getStrideInBytes() ); break; default: copyData( dst, ( const uint8_t* )frame.getData(), frame.getStrideInBytes() ); } }
void frameGrabber::getImage(ImageIDL& img) { if (isOpen()) { img.grayImage.dataValid = false; img.rgbImage.dataValid = false; img.hsvImage.dataValid = false; grabImage(img); switch (img.sourceFormat) { case kRGB: copyRGB(img); break; case kGray: copyGray(img); break; default: throw Miro::EOutOfBounds(); break; } } else throw Miro::EDevIO(); }
void swcRectangle::setAltBorderColor(BORDER_SIDE side, const swcColor &color) { switch (side) { case B_TOP: { copyRGB(color, &alt_border_colors[ 0]); copyRGB(color, &alt_border_colors[ 4]); copyRGB(color, &alt_border_colors[ 8]); copyRGB(color, &alt_border_colors[12]); } break; case B_RIGHT: { copyRGB(color, &alt_border_colors[16]); copyRGB(color, &alt_border_colors[20]); copyRGB(color, &alt_border_colors[24]); copyRGB(color, &alt_border_colors[28]); } break; case B_BOTTOM: { copyRGB(color, &alt_border_colors[32]); copyRGB(color, &alt_border_colors[36]); copyRGB(color, &alt_border_colors[40]); copyRGB(color, &alt_border_colors[44]); } break; case B_LEFT: { copyRGB(color, &alt_border_colors[48]); copyRGB(color, &alt_border_colors[52]); copyRGB(color, &alt_border_colors[56]); copyRGB(color, &alt_border_colors[60]); } break; } }
void swcRectangle::setAltColor(CORNER_LOCATION corner, const swcColor &color) { switch (corner) { case C_NW: { copyRGB(color, &alt_colors[ 0]); copyRGB(color, &alt_colors[24]); copyRGB(color, &alt_colors[32]); } break; case C_NE: { copyRGB(color, &alt_colors[ 4]); copyRGB(color, &alt_colors[ 8]); copyRGB(color, &alt_colors[36]); } break; case C_SE: { copyRGB(color, &alt_colors[12]); copyRGB(color, &alt_colors[16]); copyRGB(color, &alt_colors[40]); } break; case C_SW: { copyRGB(color, &alt_colors[20]); copyRGB(color, &alt_colors[28]); copyRGB(color, &alt_colors[44]); } break; } }
void * PNGImageIO_writePNGData(BitmapImage * image, int pixelFormat, bool flipVertical, size_t * outLength) { png_structp pngWriteStruct; png_infop pngInfoStruct; png_byte ** rows = NULL; struct memwriteContext writeContext; int colorType; enum BitmapPixelFormat outputPixelFormat; unsigned char * transformedPixels = NULL, * pixels; unsigned int rowIndex; pngWriteStruct = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); pngInfoStruct = png_create_info_struct(pngWriteStruct); if (setjmp(png_jmpbuf(pngWriteStruct))) { png_destroy_write_struct(&pngWriteStruct, &pngInfoStruct); free(rows); return NULL; } switch (image->pixelFormat) { case BITMAP_PIXEL_FORMAT_RGBA_8888: colorType = PNG_COLOR_TYPE_RGB_ALPHA; break; case BITMAP_PIXEL_FORMAT_RGB_888: colorType = PNG_COLOR_TYPE_RGB; break; case BITMAP_PIXEL_FORMAT_GRAYALPHA_88: colorType = PNG_COLOR_TYPE_GRAY_ALPHA; break; case BITMAP_PIXEL_FORMAT_GRAY_8: colorType = PNG_COLOR_TYPE_GRAY; break; default: png_destroy_write_struct(&pngWriteStruct, &pngInfoStruct); return NULL; } switch (pixelFormat) { case PNG_PIXEL_FORMAT_AUTOMATIC: outputPixelFormat = image->pixelFormat; break; case BITMAP_PIXEL_FORMAT_RGBA_8888: if ((int) image->pixelFormat != pixelFormat) { transformedPixels = malloc(image->width * image->height * 4); if (colorType & PNG_COLOR_MASK_ALPHA) { copyAlpha(transformedPixels, image->pixels, image->width, image->height, 4, BitmapImage_pixelFormatBytes(image->pixelFormat)); } else { addAlphaByte(transformedPixels, image->width, image->height, 4); } if (colorType & PNG_COLOR_MASK_COLOR) { copyRGB(transformedPixels, image->pixels, image->width, image->height, 4, BitmapImage_pixelFormatBytes(image->pixelFormat)); } else { copyGrayToRGB(transformedPixels, image->pixels, image->width, image->height, 4, BitmapImage_pixelFormatBytes(image->pixelFormat)); } } colorType = PNG_COLOR_TYPE_RGB_ALPHA; outputPixelFormat = BITMAP_PIXEL_FORMAT_RGBA_8888; break; case BITMAP_PIXEL_FORMAT_RGB_888: if ((int) image->pixelFormat != pixelFormat) { transformedPixels = malloc(image->width * image->height * 3); if (colorType & PNG_COLOR_MASK_COLOR) { copyRGB(transformedPixels, image->pixels, image->width, image->height, 3, BitmapImage_pixelFormatBytes(image->pixelFormat)); } else { copyGrayToRGB(transformedPixels, image->pixels, image->width, image->height, 3, BitmapImage_pixelFormatBytes(image->pixelFormat)); } } colorType = PNG_COLOR_TYPE_RGB; outputPixelFormat = BITMAP_PIXEL_FORMAT_RGB_888; break; case BITMAP_PIXEL_FORMAT_GRAYALPHA_88: if ((int) image->pixelFormat != pixelFormat) { transformedPixels = malloc(image->width * image->height * 2); if (colorType & PNG_COLOR_MASK_ALPHA) { copyAlpha(transformedPixels, image->pixels, image->width, image->height, 2, BitmapImage_pixelFormatBytes(image->pixelFormat)); } else { addAlphaByte(transformedPixels, image->width, image->height, 2); } if (colorType & PNG_COLOR_MASK_COLOR) { copyRGBToGray(transformedPixels, image->pixels, image->width, image->height, 2, BitmapImage_pixelFormatBytes(image->pixelFormat)); } else { copyGray(transformedPixels, image->pixels, image->width, image->height, 2, BitmapImage_pixelFormatBytes(image->pixelFormat)); } } colorType = PNG_COLOR_TYPE_GRAY_ALPHA; outputPixelFormat = BITMAP_PIXEL_FORMAT_GRAYALPHA_88; break; case BITMAP_PIXEL_FORMAT_GRAY_8: if ((int) image->pixelFormat != pixelFormat) { transformedPixels = malloc(image->width * image->height); if (colorType & PNG_COLOR_MASK_COLOR) { copyRGBToGray(transformedPixels, image->pixels, image->width, image->height, 1, BitmapImage_pixelFormatBytes(image->pixelFormat)); } else { copyGray(transformedPixels, image->pixels, image->width, image->height, 1, BitmapImage_pixelFormatBytes(image->pixelFormat)); } } colorType = PNG_COLOR_TYPE_GRAY; outputPixelFormat = BITMAP_PIXEL_FORMAT_GRAY_8; break; default: png_destroy_write_struct(&pngWriteStruct, &pngInfoStruct); return NULL; } writeContext = memwriteContextInit(malloc(1), 0, 1, true); png_set_write_fn(pngWriteStruct, &writeContext, pngWriteFnMemwrite, pngFlushFnNoOp); png_set_IHDR(pngWriteStruct, pngInfoStruct, image->width, image->height, 8, colorType, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); rows = malloc(sizeof(png_byte *) * image->height); pixels = transformedPixels == NULL ? image->pixels : transformedPixels; for (rowIndex = 0; rowIndex < image->height; rowIndex++) { rows[rowIndex] = pixels + ((flipVertical ? image->height - rowIndex - 1 : rowIndex) * image->width * BitmapImage_pixelFormatBytes(outputPixelFormat)); } png_set_rows(pngWriteStruct, pngInfoStruct, rows); png_write_png(pngWriteStruct, pngInfoStruct, PNG_TRANSFORM_IDENTITY, NULL); free(rows); free(transformedPixels); png_destroy_write_struct(&pngWriteStruct, &pngInfoStruct); *outLength = writeContext.position; return writeContext.data; }