• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Loading BMP into an Effect World

Explorer ,
Oct 02, 2020 Oct 02, 2020

Copy link to clipboard

Copied

Hey there! I'm trying to load the contents of a .bmp into a PF_EffectWorld, and I'm having a hard time figuring out how that would work. I've used this code I found online to load the bitmap, and I think it's working. But, now I'm not sure how to transfer the data over. Any ideas?

 

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
typedef struct bitmap
{
    unsigned int width, height;
    unsigned char *pixels;
};
struct bitmap* bmp;
void FreeBmp()
{
    if (bmp && bmp->pixels)
    {
        bmp->width = 0;
        bmp->height = 0;
        free(bmp->pixels);
        free(bmp);
        bmp = NULL;
    }
}
bool LoadBmp(const char *filepath)
{
    bmp = NULL;
    FILE *f = fopen(filepath, "rb");
    if (f)
    {
        bmp = malloc(sizeof(bitmap));
        bmp->width = 0;
        bmp->height = 0;
        bmp->pixels = NULL;
        unsigned char info[54] = {0};
        fread(info, sizeof(unsigned char), 54, f);
        bmp->width = *(unsigned int *)&info[18];
        bmp->height = *(unsigned int *)&info[22];
        unsigned int size = ((((bmp->width * bmp->height) + 31) & ~31) / 8) * bmp->height;
        bmp->pixels = malloc(size);
        fread(bmp->pixels, sizeof(unsigned char), size, f);
        fclose(f);
        for(int i = 0; i < size; i += 3)
        {
            unsigned char tmp = bmp->pixels[i];
            bmp->pixels[i] = bmp->pixels[i + 2];
            bmp->pixels[i + 2] = tmp;
        }
        return true;
    }
    return false;
}

 

TOPICS
SDK

Views

457

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 02, 2020 Oct 02, 2020

i see that in your code you have access to the BMP pixel data. (given that code works. i dind't check it)

you can similarly copy the data into an effect world. once the effect world had been allocated, you can access it's pixel data like so:
PF_Pixel *p = world->data + x + y * (world->rowbytes / sizeof(PF_Pixel));

p->red = bmpPixel->red;//whatever the correct syntax of the bmp pixel data is...

p->green= bmpPixel->green;

ect...

 

note that the order or the RGBA channels in the bmp and in the effec

...

Votes

Translate

Translate
LEGEND ,
Oct 02, 2020 Oct 02, 2020

Copy link to clipboard

Copied

If you want to do any actual processing, you still have to hand it over to the respective effects handlers or for that matter panel code when using it as an icon or custom UI element. Outside the PF suites and all that it does nothing.

 

Mylenium

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 02, 2020 Oct 02, 2020

Copy link to clipboard

Copied

Do you know how I would go about handing the data over? I'm trying to use the .bmp as an effect world. I'm looking for a simple PF_EffectWorld bitmap = loadBMP("/bitmapfile.cmp"); but I know that's probably not possible. I'm just not sure what process I need to go through in order to get that same outcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 02, 2020 Oct 02, 2020

Copy link to clipboard

Copied

i see that in your code you have access to the BMP pixel data. (given that code works. i dind't check it)

you can similarly copy the data into an effect world. once the effect world had been allocated, you can access it's pixel data like so:
PF_Pixel *p = world->data + x + y * (world->rowbytes / sizeof(PF_Pixel));

p->red = bmpPixel->red;//whatever the correct syntax of the bmp pixel data is...

p->green= bmpPixel->green;

ect...

 

note that the order or the RGBA channels in the bmp and in the effect world may not be the same.

also, i've shown the exmaple of copying an 8bit bmp into an 8bit world. that also might not always be the case, so value conversion may be required.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 02, 2020 Oct 02, 2020

Copy link to clipboard

Copied

Okay, I think I'm starting to understand. One last question, if that's alright. If I have the RGB data from my .bmp in a vector, like this:

 

bmpPixel[0]; // Red pixels

bmpPixel[1]; // Green pixels

bmpPixel[2]; // Blue pixels

 

how can I copy that data into the effect world?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 02, 2020 Oct 02, 2020

Copy link to clipboard

Copied

assuming the bmp pixel data is an unsigned char, 0-255, then:

p->red = bmpPixel[0];

p->green = bmpPixel[1];

p->blue = bmpPixel[2];

p->alpha = 255;

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 02, 2020 Oct 02, 2020

Copy link to clipboard

Copied

Wouldn't that just assign the pixel values to the PF_Pixel and not the PF_EffectWorld? Or am I horribly misunderstanding something?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 02, 2020 Oct 02, 2020

Copy link to clipboard

Copied

this line:
PF_Pixel *p = world->data + x + y * (world->rowbytes / sizeof(PF_Pixel));
gets the ram address of a specific pixel in the effect world's buffer. notice that *p is a pointer.

p->red = something;

assings the value to that point in ram, on the red offset for the pixel's address.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 02, 2020 Oct 02, 2020

Copy link to clipboard

Copied

LATEST

Oh my goodness. Yes, I get it now. Thank you for being patient with me on that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines