IconEditor: fix FLIP_HOR, add FLIP_VER, fix zoom value for some cases, fix BMP was flipped vertically when saved

git-svn-id: svn://kolibrios.org@7154 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2018-02-08 16:47:35 +00:00
parent eb145a52ea
commit e507f8bd35
2 changed files with 58 additions and 51 deletions

View File

@ -56,54 +56,60 @@ void _colors::move(int _direction)
int r, c; int r, c;
dword first_element_data; dword first_element_data;
if (_direction == MOVE_LEFT) switch(_direction)
{ {
case MOVE_LEFT:
for (r = 0; r < rows; r++) for (r = 0; r < rows; r++)
{ {
first_element_data = get_pixel(r, 0); first_element_data = get_pixel(r, 0);
for (c = 0; c < columns-1; c++) set_pixel(r, c, get_pixel(r, c+1)); for (c = 0; c < columns-1; c++) set_pixel(r, c, get_pixel(r, c+1));
set_pixel(r, columns-1, first_element_data); set_pixel(r, columns-1, first_element_data);
} }
} break;
if (_direction == MOVE_RIGHT) case MOVE_RIGHT:
{
for (r = 0; r < rows; r++) for (r = 0; r < rows; r++)
{ {
first_element_data = get_pixel(r, columns-1); first_element_data = get_pixel(r, columns-1);
for (c = columns-1; c > 0; c--) set_pixel(r, c, get_pixel(r, c-1)); for (c = columns-1; c > 0; c--) set_pixel(r, c, get_pixel(r, c-1));
set_pixel(r, 0, first_element_data); set_pixel(r, 0, first_element_data);
} }
} break;
if (_direction == MOVE_UP) case MOVE_UP:
{
for (c = 0; c < columns; c++) for (c = 0; c < columns; c++)
{ {
first_element_data = get_pixel(0, c); first_element_data = get_pixel(0, c);
for (r = 0; r < rows-1; r++) set_pixel(r, c, get_pixel(r+1, c)); for (r = 0; r < rows-1; r++) set_pixel(r, c, get_pixel(r+1, c));
set_pixel(rows-1, c, first_element_data); set_pixel(rows-1, c, first_element_data);
} }
} break;
if (_direction == MOVE_DOWN) case MOVE_DOWN:
{
for (c = 0; c < columns; c++) for (c = 0; c < columns; c++)
{ {
first_element_data = get_pixel(rows-1, c); first_element_data = get_pixel(rows-1, c);
for (r = rows-1; r > 0; r--) set_pixel(r, c, get_pixel(r-1, c)); for (r = rows-1; r > 0; r--) set_pixel(r, c, get_pixel(r-1, c));
set_pixel(0, c, first_element_data); set_pixel(0, c, first_element_data);
} }
} break;
case FLIP_HOR:
if (_direction == FLIP_HOR)
{
for (r = 0; r < rows; r++) for (r = 0; r < rows; r++)
{ {
for (c = 0; c < columns/2; c++) { for (c = 0; c < columns/2; c++) {
first_element_data = get_pixel(r, c); first_element_data = get_pixel(r, c);
set_pixel(r, c, get_pixel(r, columns-c)); set_pixel(r, c, get_pixel(r, columns-c-1));
set_pixel(r, columns-c, first_element_data); set_pixel(r, columns-c-1, first_element_data);
} }
} }
break;
case FLIP_VER:
for (c = 0; c < columns; c++)
{
for (r = 0; r < rows/2; r++) {
first_element_data = get_pixel(r, c);
set_pixel(r, c, get_pixel(rows-r-1, c));
set_pixel(rows-r-1, c, first_element_data);
}
}
break;
} }
} }

View File

@ -1,12 +1,11 @@
/* /*
* BACKGEN - Background generator * Icon Editor for KolibriOS
* Author: Leency * Author: Leency
* Licence: GPL v2 * Licence: GPL v2
*/ */
/* /*
TODO/BUGS TODO/BUGS
Flip first pixel doesn't work well
Open with param Open with param
*/ */
@ -27,7 +26,7 @@ Open with param
// // // //
//===================================================// //===================================================//
#define T_TITLE "Icon Editor 0.09" #define T_TITLE "Icon Editor 0.09b"
#define TOOLBAR_H 24+8 #define TOOLBAR_H 24+8
#define PALLETE_SIZE 116 #define PALLETE_SIZE 116
@ -272,7 +271,7 @@ void DrawEditArea()
canvas.w = image.columns * zoom.value; canvas.w = image.columns * zoom.value;
canvas.h = image.rows * zoom.value; canvas.h = image.rows * zoom.value;
if (canvas.w+2 > wrapper.w) || (canvas.h+2 > wrapper.h) { if (canvas.w+2 > wrapper.w) || (canvas.h+2 > wrapper.h) {
zoom.value--; zoom.click(BTN_ZOOM_OUT);
DrawEditArea(); DrawEditArea();
return; return;
} }
@ -361,7 +360,9 @@ void EventSave()
{ {
char save_buf[3126]; char save_buf[3126];
memmov(#save_buf, #bmp_32x32x16_header, sizeof(bmp_32x32x16_header)); memmov(#save_buf, #bmp_32x32x16_header, sizeof(bmp_32x32x16_header));
image.move(FLIP_VER); //fix an issue that BMP image is flipped vertically
memmov(#save_buf+sizeof(bmp_32x32x16_header), image.get_image(), sizeof(save_buf)-sizeof(bmp_32x32x16_header)); memmov(#save_buf+sizeof(bmp_32x32x16_header), image.get_image(), sizeof(save_buf)-sizeof(bmp_32x32x16_header));
image.move(FLIP_VER); //restore
if (WriteFile(sizeof(save_buf), #save_buf, "/rd/1/saved_image.bmp")==0) if (WriteFile(sizeof(save_buf), #save_buf, "/rd/1/saved_image.bmp")==0)
{ {
notify("'File saved as /rd/1/saved_image.bmp' -O"); notify("'File saved as /rd/1/saved_image.bmp' -O");