does vlc support bgra color format? - libvlc

libvlc_video_set_format(player, "RGBA", size.cx, size.cy, size.cx << 2);
it can set the libvlc output RGBA pixel data, if I use opengl to render these data, it is very simple, but if I take d3d to render, I must do a RGBA to BGRA convert. I had tried "BGRA" string, but failed. Does any method to make libvlc with d3d works better?

I had found the answer: libvlc_video_set_format(player, "RV32", size.cx, size.cy, size.cx << 2); this code can be set the output format to ARGB32

Related

Extract pixels buffer from Image Gdi+

I would like to extract pixel buffer from Gdiplus::Image
Here is my code :
Gdiplus::Bitmap bitmap(GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), BPP4 * GetSystemMetrics(SM_CXSCREEN), PixelFormat32bppARGB, data);
Gdiplus::Image *pThumbnail = bitmap.GetThumbnailImage(mWidthResolutionSelected, mHeightResolutionSelected, NULL, NULL);
How to get pixel buffer after the scale with GetThumbnailImage from pThumbnail ?
Thanks
You cast pThumbnail to a Bitmap* and then you use the LockBits method to get a BitmapData object, which contains the Scan0 field, which is a pointer to the pixel data. Don't forget to call UnlockBits when you're done.

Get pixel data from Graphics object in Codename One

I'm trying to implement the Gaussian blur filter on Graphics object, but I can't find function for get pixel information or transform Graphics object to byte array (with RGB data).
That isn't supported since hardware accelerated surfaces might not provide that information.
However, you can do something else. Just paint the current form onto a mutable image and then just get the RGB of the mutable image which you can then use to create a new Image from an RGB e.g. something close to this:
Display d = Display.getInstance();
Image img = Image.createImage(d.getDisplayWidth(), d.getDisplayHeight());
Graphics g = img.getGraphics();
d.getCurrent().paintBackgrounds(g);
d.getCurrent().paintComponent(g, false);
int[] bufferArray = img.getRGB();
// blur...
Image blurredImage = Image.createImage(bufferArray, img.getWidth(), img.getHeight());

MagickWand: transparent SVG part rendered as white background

I am trying to read SVG images using ImageMagick (6.8.8-7) and get valid transparent pixels.
The code below is working well with PNG format, but for SVG i can only have some white background.
So i tried to add MagickSetBackgroundColor, and MagickSetImageBackgroundColor with some merging layers but i still can't make it works.
Below an extract from the PoC:
MagickWandGenesis();
m_wand = NewMagickWand();
MagickReadImage(m_wand, file_name);
hasAlfa = MagickGetImageAlphaChannel(m_wand);
fprintf(stderr, "alpha channel detection: %d\n", hasAlfa);
if (hasAlfa == MagickTrue) {
PixelWand *color;
MagickWand *new_wand;
imagedata = malloc(w*h*4);
color = NewPixelWand();
PixelSetColor(color, "none");
MagickSetBackgroundColor(m_wand, color);
MagickSetImageBackgroundColor(m_wand, color);
new_wand = MagickMergeImageLayers(m_wand, MergeLayer);
DestroyMagickWand(m_wand);
m_wand = new_wand;
mrc = MagickExportImagePixels(m_wand, 0, 0, (size_t)w, (size_t)h, "RGBA", CharPixel, imagedata);
fprintf(stderr, "R:%d G:%d B:%d A:%d\nR:%d G:%d B:%d A:%d\n", imagedata[0], imagedata[1], imagedata[2], imagedata[3], imagedata[4], imagedata[5], imagedata[6], imagedata[7]);
}
Result using a PNG image:
size: 9 x 11
alpha channel detection: 1
R:0 G:0 B:0 A:0
R:0 G:0 B:0 A:0
Result using a SVG image:
size: 640 x 1000
alpha channel detection: 1
R:255 G:255 B:255 A:255
R:255 G:255 B:255 A:255
Any clues ?
I hope, I understood your question. To convert transparence from svg to png a pixel has to be defined as transparent.
You can define transparency in svg using "opacity", but in svg transparency is only given for next layer (not alpha-layer, that shines through all objects like in alpha).
If you want alpha transparency on an png, it's really the best way to define (i.e. white), and set that to alpha transperency

SKIA - Inaccurate value returned by measureText()

I have a problem measuring text using skia measureText() function.
The value returned is inaccurate.
SkPaint *skPaint = new SkPaint();
SkTypeface* myFont = SkTypeface::CreateFromName("Impact", SkTypeface::kNormal);
skPaint->setTypeface(myFont);
skPaint->setAntiAlias(true);
skPaint->setTextAlign(SkPaint::kLeft_Align);
skPaint->setTextEncoding(SkPaint::kUTF16_TextEncoding);
skPaint->setTextSize(SkIntToScalar(120));
skPaint->setColor(0xff000001);
canvas->drawText(text, length, SkIntToScalar(x) , SkIntToScalar(y) , *skPaint);
SkScalar width = skPaint->measureText(text, length);
The width returned by measureText() is 451.
I checked the generated bitmap text via a photo editor app, the actual width is only 438.
Any thoughts on getting the accurate width of text in SKIA?
Thank you!
I believe what you are trying to match will come from "bounds"
SkRect bounds;
SkScalar textWidth = paint.measureText("some", 4, &bounds);
which is a minimum rectangle to fit a given text, whereas textWidth is slightly larger than that.
I faced this issue too. Dont know why exactly it happens, maybe because of kerning differences, but i came to this:
SizeF RenderTextAndroid::GetStringSizeF() {
UpdateFont();
const base::string16& text = GetLayoutText();
std::vector<SkScalar> widths(text.length());
paint_.getTextWidths(text.c_str(), GetStrByteLen(text), &widths[0], NULL);
return SizeF(std::accumulate(widths.begin(), widths.end(), 0),
font_metrics_.fBottom - font_metrics_.fTop);
}
Where UpdateFont just sets new parameters to SkPaint

Converting 24bit RGB image to 8bit grayscale with opencv-node in node.js

I'm trying to capture images within node.js from a webcam connected to a Raspberry Pi. Capturing works fine, but now when I want to transmit the images I have some serious problems with framerate and lags.
Now my first idea was to convert the RGB images to 8bit grayscale, that should increase the performance by factor 3 (i hope..).
I'm using node.js and opencv-node for this. Here you can see some code snippet for the moment:
var startT = new Date().getTime();
var capture = new cv.VideoCapture();
var frame = new cv.Mat;
var grey = new cv.Mat;
var imgPath = __dirname + "/ramdisk/";
var frame_number = 0;
capture.open(0);
if (!capture.isOpened())
{
console.log("aCapLive could not open capture!");
return;
}
function ImgCap()
{
var elapsed = (new Date().getTime() - startT) / 1000;
capture.read(frame);
cv.imwrite(imgPath+".bmp", frame);
id = setImmediate(ImgCap);
}
ImgCap();
I tried to use something like
cv.cvtColor(frame, grey, "CV_BGR2GRAY");
after reading the image but i only get some TypeError saying that argument 2 has to be an integer... I dont know what to do at the moment. I referred to http://docs.opencv.org/doc/tutorials/introduction/load_save_image/load_save_image.html#explanation for converting a rgb to a grayscale image.
Beside I'm still not sure if this just gives mit a 24bit grayscale image instead of 8bit..?!
Thanks for any help in advance! :)
use CV_BGR2GRAY instead of "CV_BGR2GRAY".
the former is an integral constant, the latter a char*
and, no fear, that will be 8bit grayscale.

Resources