Refactor sactcg.c

This commit is contained in:
kichikuou
2021-11-07 21:23:45 +09:00
parent ca1e47c093
commit e08ba5fb03
2 changed files with 168 additions and 408 deletions
+84 -204
View File
@@ -48,7 +48,19 @@ static cginfo_t *cgs[CGMAX];
return NG; \
} \
static cginfo_t *nt_scg_new(enum cgtype type, int no, surface_t *sf) {
cginfo_t *info = calloc(1, sizeof(cginfo_t));
info->type = type;
info->no = no;
info->sf = sf;
info->refcnt = 1;
nt_scg_free(no);
cgs[no] = info;
return info;
}
/*
cgの読み込み
@@ -58,8 +70,6 @@ static cginfo_t *cgs[CGMAX];
@param no: 読み込むCG番号
*/
static cginfo_t *nt_scg_get(int no) {
cginfo_t *i;
if (no >= (CGMAX -1)) {
WARNING("no is too large (should be %d < %d)\n", (no), CGMAX);
return NULL;
@@ -67,21 +77,13 @@ static cginfo_t *nt_scg_get(int no) {
if (cgs[no] != NULL)
return cgs[no];
i = malloc(sizeof(cginfo_t));
i->type = CG_LINKED;
i->no = no;
i->refcnt = 1;
i->sf = sf_loadcg_no(no -1);
if (i->sf == NULL) {
surface_t *sf = sf_loadcg_no(no - 1);
if (!sf) {
WARNING("load fail (%d)\n", no -1);
free(i);
return NULL;
}
cgs[no] = i;
return i;
return nt_scg_new(CG_LINKED, no, sf);
}
cginfo_t *nt_scg_addref(int no) {
@@ -102,115 +104,60 @@ void nt_scg_deref(cginfo_t *cg) {
// 指定の大きさ、色の矩形の CG を作成
int nt_scg_create(int wNumCG, int wWidth, int wHeight, int wR, int wG, int wB, int wBlendRate) {
cginfo_t *i;
spcg_assert_no(wNumCG);
i = malloc(sizeof(cginfo_t));
i->type = CG_SET;
i->no = wNumCG;
i->refcnt = 1;
i->sf = sf_create_surface(wWidth, wHeight, sf0->depth);
gr_fill(i->sf, 0, 0, wWidth, wHeight, wR, wG, wB);
gr_fill_alpha_map(i->sf, 0, 0, wWidth, wHeight, wBlendRate);
// もし前に作成したものがあり、未開放の場合は開放
nt_scg_free(wNumCG);
cgs[wNumCG] = i;
surface_t *sf = sf_create_surface(wWidth, wHeight, sf0->depth);
gr_fill(sf, 0, 0, wWidth, wHeight, wR, wG, wB);
gr_fill_alpha_map(sf, 0, 0, wWidth, wHeight, wBlendRate);
nt_scg_new(CG_SET, wNumCG, sf);
return OK;
}
// 指定のCGを反転させたCGを作成
int nt_scg_create_reverse(int wNumCG, int wNumSrcCG, int wReverseX, int wReverseY) {
cginfo_t *i, *srccg;
surface_t *src;
spcg_assert_no(wNumCG);
spcg_assert_no(wNumSrcCG);
// 元にするCGを参照 (LINKCGなら読み込み)
if (!(srccg = nt_scg_get(wNumSrcCG))) {
cginfo_t *src = nt_scg_get(wNumSrcCG);
if (!src)
return NG;
}
i = malloc(sizeof(cginfo_t));
i->type = CG_REVERSE;
i->no = wNumCG;
i->refcnt = 1;
src = srccg->sf;
i->sf = stretch(src, src->width, src->height, (wReverseX << 1) | wReverseY);
// もし前に作成したものがあり、未開放の場合は開放
nt_scg_free(wNumCG);
cgs[wNumCG] = i;
surface_t *sf = stretch(src->sf, src->sf->width, src->sf->height, (wReverseX << 1) | wReverseY);
nt_scg_new(CG_REVERSE, wNumCG, sf);
return OK;
}
// 指定のCGを拡大/縮小したCGを作成
int nt_scg_create_stretch(int wNumCG, int wWidth, int wHeight, int wNumSrcCG) {
cginfo_t *i, *srccg;
surface_t *src;
spcg_assert_no(wNumCG);
spcg_assert_no(wNumSrcCG);
// 元にするCGを参照 (LINKCGなら読み込み)
if (!(srccg = nt_scg_get(wNumSrcCG))) {
cginfo_t *src = nt_scg_get(wNumSrcCG);
if (!src)
return NG;
}
i = malloc(sizeof(cginfo_t));
i->type = CG_STRETCH;
i->no = wNumCG;
i->refcnt = 1;
src = srccg->sf;
i->sf = stretch(src, wWidth, wHeight, 0);
// もし前に作成したものがあり、未開放の場合は開放
nt_scg_free(wNumCG);
cgs[wNumCG] = i;
surface_t *sf = stretch(src->sf, wWidth, wHeight, 0);
nt_scg_new(CG_STRETCH, wNumCG, sf);
return OK;
}
// ベースCGの上にブレンドCGを重ねた CG を作成
int nt_scg_create_blend(int wNumDstCG, int wNumBaseCG, int wX, int wY, int wNumBlendCG, int wAlphaMapMode) {
cginfo_t *i, *basecg, *blendcg;
spcg_assert_no(wNumDstCG);
spcg_assert_no(wNumBaseCG);
spcg_assert_no(wNumBlendCG);
// 元にするCGを参照 (LINKCGなら読み込み)
basecg = nt_scg_get(wNumBaseCG);
blendcg = nt_scg_get(wNumBlendCG);
cginfo_t *basecg = nt_scg_get(wNumBaseCG);
cginfo_t *blendcg = nt_scg_get(wNumBlendCG);
if (!basecg || !blendcg) return NG;
i = malloc(sizeof(cginfo_t));
i->type = CG_SET;
i->no = wNumDstCG;
i->refcnt = 1;
i->sf = blend(basecg->sf, wX , wY, blendcg->sf, wAlphaMapMode);
// もし前に作成したものがあり、未開放の場合は開放
nt_scg_free(wNumDstCG);
cgs[wNumDstCG] = i;
surface_t *sf = blend(basecg->sf, wX, wY, blendcg->sf, wAlphaMapMode);
nt_scg_new(CG_SET, wNumDstCG, sf);
return OK;
}
// 指定の文字列のCGを作成
int nt_scg_create_text(int wNumCG, int wSize, int wR, int wG, int wB, char *cText) {
cginfo_t *i;
spcg_assert_no(wNumCG);
// 勝手に出ていいのかな?
@@ -218,30 +165,20 @@ int nt_scg_create_text(int wNumCG, int wSize, int wR, int wG, int wB, char *cTex
ags_setFont(FONT_GOTHIC, wSize);
agsurface_t *glyph = ags_drawStringToSurface(cText);
i = malloc(sizeof(cginfo_t));
i->type = CG_SET;
i->no = wNumCG;
i->refcnt = 1;
i->sf = sf_create_surface(glyph->width, wSize, nact->ags.dib->depth);
gr_fill(i->sf, 0, 0, glyph->width, wSize, wR, wG, wB);
gr_draw_amap(i->sf, 0, 0, glyph->pixel, glyph->width, wSize, glyph->bytes_per_line);
// もし前に作成したものがあり、未開放の場合は開放
nt_scg_free(wNumCG);
cgs[wNumCG] = i;
surface_t *sf = sf_create_surface(glyph->width, wSize, nact->ags.dib->depth);
gr_fill(sf, 0, 0, glyph->width, wSize, wR, wG, wB);
gr_draw_amap(sf, 0, 0, glyph->pixel, glyph->width, wSize, glyph->bytes_per_line);
nt_scg_new(CG_SET, wNumCG, sf);
return OK;
}
// 数字文字列のCGを作成
int nt_scg_create_textnum(int wNumCG, int wSize, int wR, int wG, int wB, int wFigs, int wZeroPadding, int wValue) {
cginfo_t *i;
char s[256], ss[256];
spcg_assert_no(wNumCG);
char s[256], ss[256];
if (wZeroPadding) {
char *sss = "%%0%dd";
sprintf(ss, sss, wFigs);
@@ -254,129 +191,72 @@ int nt_scg_create_textnum(int wNumCG, int wSize, int wR, int wG, int wB, int wFi
ags_setFont(FONT_GOTHIC, wSize);
agsurface_t *glyph = ags_drawStringToSurface(s);
i = malloc(sizeof(cginfo_t));
i->type = CG_SET;
i->no = wNumCG;
i->refcnt = 1;
i->sf = sf_create_surface(glyph->width, wSize, nact->ags.dib->depth);
gr_fill(i->sf, 0, 0, glyph->width, wSize, wR, wG, wB);
gr_draw_amap(i->sf, 0, 0, glyph->pixel, glyph->width, wSize, glyph->bytes_per_line);
// もし前に作成したものがあり、未開放の場合は開放
nt_scg_free(wNumCG);
cgs[wNumCG] = i;
surface_t *sf = sf_create_surface(glyph->width, wSize, nact->ags.dib->depth);
gr_fill(sf, 0, 0, glyph->width, wSize, wR, wG, wB);
gr_draw_amap(sf, 0, 0, glyph->pixel, glyph->width, wSize, glyph->bytes_per_line);
nt_scg_new(CG_SET, wNumCG, sf);
return OK;
}
// CGを複製
int nt_scg_copy(int wNumDstCG, int wNumSrcCG) {
cginfo_t *i, *srccg;
spcg_assert_no(wNumDstCG);
spcg_assert_no(wNumSrcCG);
// 元にするCGを参照 (LINKCGなら読み込み)
if (!(srccg = nt_scg_get(wNumSrcCG))) {
cginfo_t *src = nt_scg_get(wNumSrcCG);
if (!src)
return NG;
}
i = malloc(sizeof(cginfo_t));
i->type = CG_SET;
i->no = wNumDstCG;
i->refcnt = 1;
i->sf = sf_dup(srccg->sf);
// もし前に作成したものがあり、未開放の場合は開放
nt_scg_free(wNumDstCG);
cgs[wNumDstCG] = i;
nt_scg_new(CG_SET, wNumDstCG, sf_dup(src->sf));
return OK;
}
// CGの一部を切りぬいたCGを作成
int nt_scg_cut(int wNumDstCG, int wNumSrcCG, int wX, int wY, int wWidth, int wHeight) {
cginfo_t *i, *srccg;
surface_t *dst, *src;
spcg_assert_no(wNumDstCG);
spcg_assert_no(wNumSrcCG);
// 元にするCGを参照 (LINKCGなら読み込み)
if (!(srccg = nt_scg_get(wNumSrcCG))) {
cginfo_t *src = nt_scg_get(wNumSrcCG);
if (!src)
return NG;
}
i = malloc(sizeof(cginfo_t));
i->type = CG_SET;
i->no = wNumDstCG;
i->refcnt = 1;
src = srccg->sf;
if (src->alpha) {
dst = sf_create_surface(wWidth, wHeight, src->depth);
} else {
dst = sf_create_pixel(wWidth, wHeight, src->depth);
}
if (src->pixel) {
gr_copy(dst, 0, 0, src, wX, wY, wWidth, wHeight);
}
if (src->alpha) {
gr_copy_alpha_map(dst, 0, 0, src, wX, wY, wWidth, wHeight);
}
i->sf = dst;
// もし前に作成したものがあり、未開放の場合は開放
nt_scg_free(wNumDstCG);
cgs[wNumDstCG] = i;
surface_t *sf = src->sf->alpha
? sf_create_surface(wWidth, wHeight, src->sf->depth)
: sf_create_pixel(wWidth, wHeight, src->sf->depth);
if (src->sf->pixel)
gr_copy(sf, 0, 0, src->sf, wX, wY, wWidth, wHeight);
if (src->sf->alpha)
gr_copy_alpha_map(sf, 0, 0, src->sf, wX, wY, wWidth, wHeight);
nt_scg_new(CG_SET, wNumDstCG, sf);
return OK;
}
// 元のCGの一部を切りぬいたCGを作成
int nt_scg_partcopy(int wNumDstCG, int wNumSrcCG, int wX, int wY, int wWidth, int wHeight) {
cginfo_t *i, *srccg;
surface_t *dst, *src;
spcg_assert_no(wNumDstCG);
spcg_assert_no(wNumSrcCG);
// 元にするCGを参照 (LINKCGなら読み込み)
if (!(srccg = nt_scg_get(wNumSrcCG))) {
return NG;
}
i = malloc(sizeof(cginfo_t));
i->type = CG_SET;
i->no = wNumDstCG;
i->refcnt = 1;
src = srccg->sf;
if (src->alpha) {
dst = sf_create_surface(src->width, src->height, src->depth);
gr_fill_alpha_map(dst, 0, 0, src->width, src->height, 255);
cginfo_t *src = nt_scg_get(wNumSrcCG);
if (!src)
return NG;
surface_t *sf;
if (src->sf->alpha) {
sf = sf_create_surface(src->sf->width, src->sf->height, src->sf->depth);
gr_fill_alpha_map(sf, 0, 0, src->sf->width, src->sf->height, 255);
} else {
dst = sf_create_pixel(src->width, src->height, src->depth);
sf = sf_create_pixel(src->sf->width, src->sf->height, src->sf->depth);
}
if (src->pixel) {
gr_copy(dst, wX, wY, src, wX, wY, wWidth, wHeight);
}
if (src->alpha) {
gr_copy_alpha_map(dst, wX, wY, src, wX, wY, wWidth, wHeight);
}
i->sf = dst;
// もし前に作成したものがあり、未開放の場合は開放
nt_scg_free(wNumDstCG);
cgs[wNumDstCG] = i;
if (src->sf->pixel)
gr_copy(sf, wX, wY, src->sf, wX, wY, wWidth, wHeight);
if (src->sf->alpha)
gr_copy_alpha_map(sf, wX, wY, src->sf, wX, wY, wWidth, wHeight);
nt_scg_new(CG_SET, wNumDstCG, sf);
return OK;
}
+84 -204
View File
@@ -45,7 +45,19 @@
return NG; \
} \
static cginfo_t *scg_new(enum cgtype type, int no, surface_t *sf) {
cginfo_t *info = calloc(1, sizeof(cginfo_t));
info->type = type;
info->no = no;
info->sf = sf;
info->refcnt = 1;
scg_free(no);
sact.cg[no] = info;
return info;
}
/*
cgの読み込み
@@ -55,8 +67,6 @@
@param no: 読み込むCG番号
*/
static cginfo_t *scg_get(int no) {
cginfo_t *i;
if (no >= (CGMAX -1)) {
WARNING("no is too large (should be %d < %d)\n", (no), CGMAX);
return NULL;
@@ -64,21 +74,13 @@ static cginfo_t *scg_get(int no) {
if (sact.cg[no] != NULL)
return sact.cg[no];
i = malloc(sizeof(cginfo_t));
i->type = CG_LINKED;
i->no = no;
i->refcnt = 1;
i->sf = sf_loadcg_no(no -1);
if (i->sf == NULL) {
surface_t *sf = sf_loadcg_no(no - 1);
if (!sf) {
WARNING("load fail (%d)\n", no -1);
free(i);
return NULL;
}
sact.cg[no] = i;
return i;
return scg_new(CG_LINKED, no, sf);
}
cginfo_t *scg_addref(int no) {
@@ -99,115 +101,60 @@ void scg_deref(cginfo_t *cg) {
// 指定の大きさ、色の矩形の CG を作成
int scg_create(int wNumCG, int wWidth, int wHeight, int wR, int wG, int wB, int wBlendRate) {
cginfo_t *i;
spcg_assert_no(wNumCG);
i = malloc(sizeof(cginfo_t));
i->type = CG_SET;
i->no = wNumCG;
i->refcnt = 1;
i->sf = sf_create_surface(wWidth, wHeight, sf0->depth);
gr_fill(i->sf, 0, 0, wWidth, wHeight, wR, wG, wB);
gr_fill_alpha_map(i->sf, 0, 0, wWidth, wHeight, wBlendRate);
// もし前に作成したものがあり、未開放の場合は開放
scg_free(wNumCG);
sact.cg[wNumCG] = i;
surface_t *sf = sf_create_surface(wWidth, wHeight, sf0->depth);
gr_fill(sf, 0, 0, wWidth, wHeight, wR, wG, wB);
gr_fill_alpha_map(sf, 0, 0, wWidth, wHeight, wBlendRate);
scg_new(CG_SET, wNumCG, sf);
return OK;
}
// 指定のCGを反転させたCGを作成
int scg_create_reverse(int wNumCG, int wNumSrcCG, int wReverseX, int wReverseY) {
cginfo_t *i, *srccg;
surface_t *src;
spcg_assert_no(wNumCG);
spcg_assert_no(wNumSrcCG);
// 元にするCGを参照 (LINKCGなら読み込み)
if (!(srccg = scg_get(wNumSrcCG))) {
cginfo_t *src = scg_get(wNumSrcCG);
if (!src)
return NG;
}
i = malloc(sizeof(cginfo_t));
i->type = CG_REVERSE;
i->no = wNumCG;
i->refcnt = 1;
src = srccg->sf;
i->sf = stretch(src, src->width, src->height, (wReverseX << 1) | wReverseY);
// もし前に作成したものがあり、未開放の場合は開放
scg_free(wNumCG);
sact.cg[wNumCG] = i;
surface_t *sf = stretch(src->sf, src->sf->width, src->sf->height, (wReverseX << 1) | wReverseY);
scg_new(CG_REVERSE, wNumCG, sf);
return OK;
}
// 指定のCGを拡大/縮小したCGを作成
int scg_create_stretch(int wNumCG, int wWidth, int wHeight, int wNumSrcCG) {
cginfo_t *i, *srccg;
surface_t *src;
spcg_assert_no(wNumCG);
spcg_assert_no(wNumSrcCG);
// 元にするCGを参照 (LINKCGなら読み込み)
if (!(srccg = scg_get(wNumSrcCG))) {
cginfo_t *src = scg_get(wNumSrcCG);
if (!src)
return NG;
}
i = malloc(sizeof(cginfo_t));
i->type = CG_STRETCH;
i->no = wNumCG;
i->refcnt = 1;
src = srccg->sf;
i->sf = stretch(src, wWidth, wHeight, 0);
// もし前に作成したものがあり、未開放の場合は開放
scg_free(wNumCG);
sact.cg[wNumCG] = i;
surface_t *sf = stretch(src->sf, wWidth, wHeight, 0);
scg_new(CG_STRETCH, wNumCG, sf);
return OK;
}
// ベースCGの上にブレンドCGを重ねた CG を作成
int scg_create_blend(int wNumDstCG, int wNumBaseCG, int wX, int wY, int wNumBlendCG, int wAlphaMapMode) {
cginfo_t *i, *basecg, *blendcg;
spcg_assert_no(wNumDstCG);
spcg_assert_no(wNumBaseCG);
spcg_assert_no(wNumBlendCG);
// 元にするCGを参照 (LINKCGなら読み込み)
basecg = scg_get(wNumBaseCG);
blendcg = scg_get(wNumBlendCG);
cginfo_t *basecg = scg_get(wNumBaseCG);
cginfo_t *blendcg = scg_get(wNumBlendCG);
if (!basecg || !blendcg) return NG;
i = malloc(sizeof(cginfo_t));
i->type = CG_SET;
i->no = wNumDstCG;
i->refcnt = 1;
i->sf = blend(basecg->sf, wX , wY, blendcg->sf, wAlphaMapMode);
// もし前に作成したものがあり、未開放の場合は開放
scg_free(wNumDstCG);
sact.cg[wNumDstCG] = i;
surface_t *sf = blend(basecg->sf, wX, wY, blendcg->sf, wAlphaMapMode);
scg_new(CG_SET, wNumDstCG, sf);
return OK;
}
// 指定の文字列のCGを作成
int scg_create_text(int wNumCG, int wSize, int wR, int wG, int wB, int wText) {
cginfo_t *i;
spcg_assert_no(wNumCG);
// 勝手に出ていいのかな?
@@ -215,30 +162,20 @@ int scg_create_text(int wNumCG, int wSize, int wR, int wG, int wB, int wText) {
ags_setFont(FONT_GOTHIC, wSize);
agsurface_t *glyph = ags_drawStringToSurface(svar_get(wText));
i = malloc(sizeof(cginfo_t));
i->type = CG_SET;
i->no = wNumCG;
i->refcnt = 1;
i->sf = sf_create_surface(glyph->width, wSize, nact->ags.dib->depth);
gr_fill(i->sf, 0, 0, glyph->width, wSize, wR, wG, wB);
gr_draw_amap(i->sf, 0, 0, glyph->pixel, glyph->width, wSize, glyph->bytes_per_line);
// もし前に作成したものがあり、未開放の場合は開放
scg_free(wNumCG);
sact.cg[wNumCG] = i;
surface_t *sf = sf_create_surface(glyph->width, wSize, nact->ags.dib->depth);
gr_fill(sf, 0, 0, glyph->width, wSize, wR, wG, wB);
gr_draw_amap(sf, 0, 0, glyph->pixel, glyph->width, wSize, glyph->bytes_per_line);
scg_new(CG_SET, wNumCG, sf);
return OK;
}
// 数字文字列のCGを作成
int scg_create_textnum(int wNumCG, int wSize, int wR, int wG, int wB, int wFigs, int wZeroPadding, int wValue) {
cginfo_t *i;
char s[256], ss[256];
spcg_assert_no(wNumCG);
char s[256], ss[256];
if (wZeroPadding) {
char *sss = "%%0%dd";
sprintf(ss, sss, wFigs);
@@ -251,129 +188,72 @@ int scg_create_textnum(int wNumCG, int wSize, int wR, int wG, int wB, int wFigs,
ags_setFont(FONT_GOTHIC, wSize);
agsurface_t *glyph = ags_drawStringToSurface(s);
i = malloc(sizeof(cginfo_t));
i->type = CG_SET;
i->no = wNumCG;
i->refcnt = 1;
i->sf = sf_create_surface(glyph->width, wSize, nact->ags.dib->depth);
gr_fill(i->sf, 0, 0, glyph->width, wSize, wR, wG, wB);
gr_draw_amap(i->sf, 0, 0, glyph->pixel, glyph->width, wSize, glyph->bytes_per_line);
// もし前に作成したものがあり、未開放の場合は開放
scg_free(wNumCG);
sact.cg[wNumCG] = i;
surface_t *sf = sf_create_surface(glyph->width, wSize, nact->ags.dib->depth);
gr_fill(sf, 0, 0, glyph->width, wSize, wR, wG, wB);
gr_draw_amap(sf, 0, 0, glyph->pixel, glyph->width, wSize, glyph->bytes_per_line);
scg_new(CG_SET, wNumCG, sf);
return OK;
}
// CGを複製
int scg_copy(int wNumDstCG, int wNumSrcCG) {
cginfo_t *i, *srccg;
spcg_assert_no(wNumDstCG);
spcg_assert_no(wNumSrcCG);
// 元にするCGを参照 (LINKCGなら読み込み)
if (!(srccg = scg_get(wNumSrcCG))) {
cginfo_t *src = scg_get(wNumSrcCG);
if (!src)
return NG;
}
i = malloc(sizeof(cginfo_t));
i->type = CG_SET;
i->no = wNumDstCG;
i->refcnt = 1;
i->sf = sf_dup(srccg->sf);
// もし前に作成したものがあり、未開放の場合は開放
scg_free(wNumDstCG);
sact.cg[wNumDstCG] = i;
scg_new(CG_SET, wNumDstCG, sf_dup(src->sf));
return OK;
}
// CGの一部を切りぬいたCGを作成
int scg_cut(int wNumDstCG, int wNumSrcCG, int wX, int wY, int wWidth, int wHeight) {
cginfo_t *i, *srccg;
surface_t *dst, *src;
spcg_assert_no(wNumDstCG);
spcg_assert_no(wNumSrcCG);
// 元にするCGを参照 (LINKCGなら読み込み)
if (!(srccg = scg_get(wNumSrcCG))) {
cginfo_t *src = scg_get(wNumSrcCG);
if (!src)
return NG;
}
i = malloc(sizeof(cginfo_t));
i->type = CG_SET;
i->no = wNumDstCG;
i->refcnt = 1;
src = srccg->sf;
if (src->alpha) {
dst = sf_create_surface(wWidth, wHeight, src->depth);
} else {
dst = sf_create_pixel(wWidth, wHeight, src->depth);
}
if (src->pixel) {
gr_copy(dst, 0, 0, src, wX, wY, wWidth, wHeight);
}
if (src->alpha) {
gr_copy_alpha_map(dst, 0, 0, src, wX, wY, wWidth, wHeight);
}
i->sf = dst;
// もし前に作成したものがあり、未開放の場合は開放
scg_free(wNumDstCG);
sact.cg[wNumDstCG] = i;
surface_t *sf = src->sf->alpha
? sf_create_surface(wWidth, wHeight, src->sf->depth)
: sf_create_pixel(wWidth, wHeight, src->sf->depth);
if (src->sf->pixel)
gr_copy(sf, 0, 0, src->sf, wX, wY, wWidth, wHeight);
if (src->sf->alpha)
gr_copy_alpha_map(sf, 0, 0, src->sf, wX, wY, wWidth, wHeight);
scg_new(CG_SET, wNumDstCG, sf);
return OK;
}
// 元のCGの一部を切りぬいたCGを作成
int scg_partcopy(int wNumDstCG, int wNumSrcCG, int wX, int wY, int wWidth, int wHeight) {
cginfo_t *i, *srccg;
surface_t *dst, *src;
spcg_assert_no(wNumDstCG);
spcg_assert_no(wNumSrcCG);
// 元にするCGを参照 (LINKCGなら読み込み)
if (!(srccg = scg_get(wNumSrcCG))) {
return NG;
}
i = malloc(sizeof(cginfo_t));
i->type = CG_SET;
i->no = wNumDstCG;
i->refcnt = 1;
src = srccg->sf;
if (src->alpha) {
dst = sf_create_surface(src->width, src->height, src->depth);
gr_fill_alpha_map(dst, 0, 0, src->width, src->height, 255);
cginfo_t *src = scg_get(wNumSrcCG);
if (!src)
return NG;
surface_t *sf;
if (src->sf->alpha) {
sf = sf_create_surface(src->sf->width, src->sf->height, src->sf->depth);
gr_fill_alpha_map(sf, 0, 0, src->sf->width, src->sf->height, 255);
} else {
dst = sf_create_pixel(src->width, src->height, src->depth);
sf = sf_create_pixel(src->sf->width, src->sf->height, src->sf->depth);
}
if (src->pixel) {
gr_copy(dst, wX, wY, src, wX, wY, wWidth, wHeight);
}
if (src->alpha) {
gr_copy_alpha_map(dst, wX, wY, src, wX, wY, wWidth, wHeight);
}
i->sf = dst;
// もし前に作成したものがあり、未開放の場合は開放
scg_free(wNumDstCG);
sact.cg[wNumDstCG] = i;
if (src->sf->pixel)
gr_copy(sf, wX, wY, src->sf, wX, wY, wWidth, wHeight);
if (src->sf->alpha)
gr_copy_alpha_map(sf, wX, wY, src->sf, wX, wY, wWidth, wHeight);
scg_new(CG_SET, wNumDstCG, sf);
return OK;
}