Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

bltting images quickly in C

amsams Posts: 25Member
Consider the code below written in C for bltting images
I am writing a graphics library for mode 13h (320x200x256)

for(y=0; y<diff_y; y++)
{
for(x=0; x<diff_x; x++)
{
pixel = image_buffer[x];
if(pixel!=transprant) // tests for transprancy
video_buffer[xs] = pixel;
}
video_buffer+=screen_width;
image_buffer+=width;
}
there is some more code that does the clipping but this code actually performs bltting. B'cos i have to test for transprancy the inner loop is required which is really a overhead. Is there a way to optimize this fuction. I don't think we can use hardware accleration in DOS to perform bltting, like in DirectX's (Blt() function).
Is there any better / fast method to blt images.i don't know assembly language so i want to do it with C only.

Comments

  • XLoomXLoom Posts: 129Member
    Hi,

    As it has been said so many times in this forum, mode 13h is past. You should consider moving to Windows, Linux or etc operating system, that support better resolutions faster and all the other good things that come with them.
    However, if you still want to use 13h then here are a few tips on how to speed the thing up in C. (By the way, I know you said you didn't want Assembler, but if you reconsider, then I should have a really fast code in Assembler as well that I wrote a long time ago)

    1. It is a bad idea to use image_buffer[x] and video_buffer[xs] (By the way, where do you increment xs?). You should replace it with
    code like this in the inner loop:

    for(x=0; x<diff_x; x++)
    {
    if(image_buffer[0]!=transprant) // tests for transprancy
    video_buffer[0]=image_buffer[0];
    image_buffer++;
    video_buffer++;
    }

    Now you need to change the outer loop as well, because you can no longer add screen_width and image_width.

    int outer_loop_screen_add=screen_width-diff_x;
    int outer_loop_image_add=width-diff_x;

    for(y=0; y<diff_y; y++)
    {

    for(x=0; x<diff_x; x++)
    {
    if(image_buffer[0]!=transprant) // tests for transprancy
    video_buffer[0]=image_buffer[0];
    image_buffer++;
    video_buffer++;
    }

    video_buffer+=outer_loop_screen_add;
    image_buffer+=outer_loop_image_add;
    }

    This is pretty much all I can think of in C, but if you still need more speed, then I suggest you learn a bit of Assembler. The commands for assembler are listed in PC-GPE collection in file 'Intel.doc'
    ftp://x2ftp.oulu.fi/pub/msdos/programming/gpe/pcgpe10.zip
    and the collection contains assembler tutorial as well.
    I hope this helps a bit.

    XLoom

Sign In or Register to comment.