Mercurial > sdl-ios-xcode
comparison src/video/SDL_renderer_sw.c @ 3435:9f62f47d989b
You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
This code still doesn't quite work yet. :)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 16 Nov 2009 07:13:07 +0000 |
parents | 36cf454ba065 |
children | 0267b8b1595c |
comparison
equal
deleted
inserted
replaced
3434:147d6ef5be03 | 3435:9f62f47d989b |
---|---|
64 int y2); | 64 int y2); |
65 static int SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect); | 65 static int SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect); |
66 static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, | 66 static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, |
67 const SDL_Rect * srcrect, const SDL_Rect * dstrect); | 67 const SDL_Rect * srcrect, const SDL_Rect * dstrect); |
68 static int SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, | 68 static int SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, |
69 void * pixels, int pitch); | 69 Uint32 format, void * pixels, int pitch); |
70 static int SW_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, | 70 static int SW_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, |
71 const void * pixels, int pitch); | 71 Uint32 format, const void * pixels, int pitch); |
72 static void SW_RenderPresent(SDL_Renderer * renderer); | 72 static void SW_RenderPresent(SDL_Renderer * renderer); |
73 static void SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture); | 73 static void SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture); |
74 static void SW_DestroyRenderer(SDL_Renderer * renderer); | 74 static void SW_DestroyRenderer(SDL_Renderer * renderer); |
75 | 75 |
76 | 76 |
734 return status; | 734 return status; |
735 } | 735 } |
736 | 736 |
737 static int | 737 static int |
738 SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, | 738 SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, |
739 void * pixels, int pitch) | 739 Uint32 format, void * pixels, int pitch) |
740 { | 740 { |
741 SW_RenderData *data = (SW_RenderData *) renderer->driverdata; | 741 SW_RenderData *data = (SW_RenderData *) renderer->driverdata; |
742 const Uint8 *src; | |
743 Uint8 *dst; | |
744 int src_pitch, dst_pitch, w, h; | |
745 | 742 |
746 if (data->renderer->LockTexture(data->renderer, | 743 if (data->renderer->LockTexture(data->renderer, |
747 data->texture[data->current_texture], | 744 data->texture[data->current_texture], |
748 rect, 0, &data->surface.pixels, | 745 rect, 0, &data->surface.pixels, |
749 &data->surface.pitch) < 0) { | 746 &data->surface.pitch) < 0) { |
750 return -1; | 747 return -1; |
751 } | 748 } |
752 | 749 |
753 src = data->surface.pixels; | 750 SDL_ConvertPixels(rect->w, rect->h, |
754 src_pitch = data->surface.pitch; | 751 data->format, data->surface.pixels, data->surface.pitch, |
755 dst = pixels; | 752 format, pixels, pitch); |
756 dst_pitch = pitch; | |
757 h = rect->h; | |
758 w = rect->w * data->surface.format->BytesPerPixel; | |
759 while (h--) { | |
760 SDL_memcpy(dst, src, w); | |
761 src += src_pitch; | |
762 dst += dst_pitch; | |
763 } | |
764 | 753 |
765 data->renderer->UnlockTexture(data->renderer, | 754 data->renderer->UnlockTexture(data->renderer, |
766 data->texture[data->current_texture]); | 755 data->texture[data->current_texture]); |
767 return 0; | 756 return 0; |
768 } | 757 } |
769 | 758 |
770 static int | 759 static int |
771 SW_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, | 760 SW_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, |
772 const void * pixels, int pitch) | 761 Uint32 format, const void * pixels, int pitch) |
773 { | 762 { |
774 SW_RenderData *data = (SW_RenderData *) renderer->driverdata; | 763 SW_RenderData *data = (SW_RenderData *) renderer->driverdata; |
775 const Uint8 *src; | |
776 Uint8 *dst; | |
777 int src_pitch, dst_pitch, w, h; | |
778 | 764 |
779 if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) { | 765 if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) { |
780 SDL_AddDirtyRect(&data->dirty, rect); | 766 SDL_AddDirtyRect(&data->dirty, rect); |
781 } | 767 } |
782 | 768 |
785 rect, 1, &data->surface.pixels, | 771 rect, 1, &data->surface.pixels, |
786 &data->surface.pitch) < 0) { | 772 &data->surface.pitch) < 0) { |
787 return -1; | 773 return -1; |
788 } | 774 } |
789 | 775 |
790 src = pixels; | 776 SDL_ConvertPixels(rect->w, rect->h, format, pixels, pitch, |
791 src_pitch = pitch; | 777 data->format, data->surface.pixels, data->surface.pitch); |
792 dst = data->surface.pixels; | |
793 dst_pitch = data->surface.pitch; | |
794 h = rect->h; | |
795 w = rect->w * data->surface.format->BytesPerPixel; | |
796 while (h--) { | |
797 SDL_memcpy(dst, src, w); | |
798 src += src_pitch; | |
799 dst += dst_pitch; | |
800 } | |
801 | 778 |
802 data->renderer->UnlockTexture(data->renderer, | 779 data->renderer->UnlockTexture(data->renderer, |
803 data->texture[data->current_texture]); | 780 data->texture[data->current_texture]); |
804 return 0; | 781 return 0; |
805 } | 782 } |