Highlighted

Loading BMP into an Effect World

New Here ,
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;
}

 

Adobe Community Professional
Correct answer by shachar carmi | Adobe Community Professional

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.

 

TOPICS
SDK

Views

128

Likes

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

Loading BMP into an Effect World

New Here ,
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;
}

 

Adobe Community Professional
Correct answer by shachar carmi | Adobe Community Professional

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.

 

TOPICS
SDK

Views

129

Likes

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
Oct 02, 2020 0
Most Valuable Participant ,
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

Likes

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
Reply
Loading...
Oct 02, 2020 0
New Here ,
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.

Likes

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
Reply
Loading...
Oct 02, 2020 0
Adobe Community Professional ,
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.

 

Likes

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
Reply
Loading...
Oct 02, 2020 0
New Here ,
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?

Likes

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
Reply
Loading...
Oct 02, 2020 0
Adobe Community Professional ,
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;

 

 

 

Likes

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
Reply
Loading...
Oct 02, 2020 0
New Here ,
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?

Likes

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
Reply
Loading...
Oct 02, 2020 0
Adobe Community Professional ,
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.

Likes

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
Reply
Loading...
Oct 02, 2020 0
New Here ,
Oct 02, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Oct 02, 2020 0