Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function to return an array with all points and RGB colors. #230

Open
fabricocouto opened this issue Nov 9, 2024 · 2 comments
Open

Function to return an array with all points and RGB colors. #230

fabricocouto opened this issue Nov 9, 2024 · 2 comments
Assignees

Comments

@fabricocouto
Copy link
Contributor

fabricocouto commented Nov 9, 2024

// Function to return an array with all points and RGB colors.
EMB_PUBLIC EmbStitchInfo* emb_pattern_getAllStitches(EmbPattern* pattern, int* stitchCount) {
    if (!pattern || !pattern->stitch_list || !stitchCount) return NULL;

    *stitchCount = pattern->stitch_list->count; // Define o número de pontos
    EmbStitchInfo* stitches = (EmbStitchInfo*)malloc(*stitchCount * sizeof(EmbStitchInfo));

    if (!stitches) return NULL;  

   
    for (int i = 0; i < *stitchCount; i++) {
        stitches[i].x = pattern->stitch_list->stitch[i].x;
        stitches[i].y = pattern->stitch_list->stitch[i].y;
        stitches[i].flags = pattern->stitch_list->stitch[i].flags;

 
        int colorIndex = pattern->stitch_list->stitch[i].color;
        if (colorIndex < pattern->thread_list->count) {
            EmbColor color = pattern->thread_list->thread[colorIndex].color;
            stitches[i].red = color.r;
            stitches[i].green = color.g;
            stitches[i].blue = color.b;
        }
        else {
            // Cor padrão caso o índice não seja válido
            stitches[i].red = 0;
            stitches[i].green = 0;
            stitches[i].blue = 0;
        }
    }

    return stitches;  
}

EMB_PUBLIC void emb_freeStitchInfoList(EmbStitchInfo* stitches) {
    free(stitches);
}
@robin-swift
Copy link
Member

I don't quite understand what this is for. Can you give me a simple use case, please?

@robin-swift robin-swift self-assigned this Nov 19, 2024
@fabricocouto
Copy link
Contributor Author

I don't quite understand what this is for. Can you give me a simple use case, please?

image
So that I could view the colors correctly in C#, I don't know why but I had to do that

var i = 0;
for (i = 0; i < stitchCount; i++)
{
IntPtr stitchPtr = IntPtr.Add(stitchesPtr, i * Marshal.SizeOf());
stitches[i] = Marshal.PtrToStructure(stitchPtr);
var flags = (StitchType)stitches[i].flags;
if (flags == StitchType.fSTOP || flags == StitchType.colorchnge)
{
var colors = Color.FromArgb(255,stitches[i-1].red, stitches[i-1].green, stitches[i-1].blue);
patternclass. AddColor(ref colors);
}
}

I already have a separate viewer in C# so I would only need the point listing and the color listing.

there is a reading error because the format does not read correctly, I haven't stopped yet to check the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants