Linux.org.ua
Технічні питання => Розробка => Гілку створено: Михайло Даниленко від 2008-07-05 17:17:46
-
Хтось із ним працював?
Що я роблю не так (debian lenny)?
/** Perform a stretch blit between two surfaces of the same format.
* NOTE: This function is not safe to call from multiple threads!
*
* This function will stretch a srcrect smoothly to the full area of
* the dst surface. If no srcrect is given then the full area of the
* src surface is stretched smoothly to the full dst surface. The
* dstrect is ignored always.
*
* This function will also watch for a clip rectangle on the src
* surface. This may speed up handling in your programs by creating
* a larger src surface with an associated viewframe, and the srcrect
* argument needs not be recomputed.
*/
extern int SDL_StretchSurfaceRect(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect);
/** Perform a stretch blit between two surfaces of the same format.
* NOTE: This function is not safe to call from multiple threads!
*
* This function will stretch a srcrect smoothly to the full area of
* the dst surface. If no srcrect is given then the full area of the
* src surface is stretched smoothly to the full dst surface. The
* dstrect is ignored always.
*
* Remember that this is the inverse meaning, the main SDL lib will
* ignore the srcrect and only watch for the dstrect if any.
*/
extern int SDL_StretchSurfaceBlit(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect);
/**
* This function will stretch to 150%. This is not only a fast function
* but it is also safe to call from multiple threads. If the srcrect
* is given then only that rect is copied. Otherwise the full src
* surface is copied to the full dst surface. The dstrect is ignored.
*/
extern int SDL_StretchSurface_23(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect);
[isbear:~] cat i.c
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL_stretch/SDL_stretch.h>
/* first arg - n, r, b or 2 - method of stretching,
* sechond arg - image to show.
* should stretch center of image x2
* ( with method '2' - x1.5) */
int main ( int argc, char **argv )
{
SDL_Surface *s;
SDL_Surface *i;
SDL_Surface *i1;
SDL_Rect sr;
SDL_Rect ir;
SDL_Rect i1r;
SDL_Init ( SDL_INIT_VIDEO );
s = SDL_SetVideoMode ( 1024, 768, 16, SDL_FULLSCREEN|SDL_ANYFORMAT );
sr.x = 0;
sr.y = 0;
sr.w = s->w;
sr.h = s->h;
fprintf ( stderr, "Screen: %d, %d, %d, %d\n", sr.x, sr.y, sr.w, sr.h );
i = IMG_Load ( argv[2] );
ir.x = 0;
ir.y = 0;
ir.w = i->w;
ir.h = i->h;
fprintf ( stderr, "Image: %d, %d, %d, %d\n", ir.x, ir.y, ir.w, ir.h );
/* Easy way to get surface with the same format as i :) */
i1 = IMG_Load ( argv[2] );
i1r.x = i1->w / 4;
i1r.y = i1->h / 4;
i1r.w = i1->w / 2;
i1r.h = i1->h / 2;
fprintf ( stderr, "Stretch area: %d, %d, %d, %d\n", i1r.x, i1r.y, i1r.w, i1r.h );
switch ( *argv[1] ) {
case 'n':
break;
case 'r':
SDL_StretchSurfaceRect ( i1, &i1r, i, &ir );
break;
case 'b':
SDL_StretchSurfaceBlit ( i1, &i1r, i, &ir );
break;
case '2':
SDL_StretchSurface_23 ( i1, &i1r, i, &ir );
break;
}
fprintf ( stderr, "Stretced image: %d, %d\n", i->w, i->h );
SDL_BlitSurface ( i, &ir, s, &sr );
SDL_UpdateRect ( s, sr.x, sr.y, sr.w, sr.h );
sleep ( 6 );
SDL_Quit ();
}
/* The End. */
[isbear:~] gcc -I/usr/include/SDL -lSDL -lSDL_image -lSDL_stretch i.c
[isbear:~] ./a.out r picts/24-05-08_1136.jpg
Screen: 0, 0, 1024, 768
Image: 0, 0, 1200, 1600
Stretch area: 300, 400, 600, 800
Stretced image: 1200, 1600
[isbear:~] ./a.out b picts/24-05-08_1136.jpg
Screen: 0, 0, 1024, 768
Image: 0, 0, 1200, 1600
Stretch area: 300, 400, 600, 800
Stretced image: 1200, 1600
[isbear:~] ./a.out 2 picts/24-05-08_1136.jpg
Screen: 0, 0, 1024, 768
Image: 0, 0, 1200, 1600
Stretch area: 300, 400, 600, 800
Stretced image: 1200, 1600
[isbear:~] ./a.out n picts/24-05-08_1136.jpg
Screen: 0, 0, 1024, 768
Image: 0, 0, 1200, 1600
Stretch area: 300, 400, 600, 800
Stretced image: 1200, 1600
[isbear:~]
Власне, тут не видно, це треба на екран виводити, але чому воно не розтягує?
На екрані з'являється ніби як дійсно центр малюнку, але у кутку (майже оригінального розміру), а не на весь сурфейс. На додачу зліва якийсь артефакт - стиснута копія частини малюнку.
Із методом розтягування 23 взагалі якась дивина - то він сегфолтиться, то показує кашу...
-
Добре, це вже не треба, я знайшов libsdl-gfx rotozoom (хоча якщо у когось працює - скажіть, щоб я знав).
Тепер стосовно цього ротозума - я його юзаю із perl:
my $zo = SDL::Tool::Graphic->new();
my $zoomed = $zo->zoom ( $chunk, $z, $z, 1 );
Так от, після того, як я блітаю сурфейс $zoomed на екран, отримую етюд у багряних відтінках. До того ж чорний колір стає прозорим. Питання: що я роблю не так?
-
Угу, вже знайшов, хоча й не зовсім розумію чому, але якщо попередньо зробити сурфейсу display_format, все працює...